@@ -169,6 +169,7 @@ fn main() {
169169 test_invalidate_block_reconsider_block ( & cl) ;
170170 test_key_pool_refill ( & cl) ;
171171 test_create_raw_transaction ( & cl) ;
172+ test_decode_raw_transaction ( & cl) ;
172173 test_fund_raw_transaction ( & cl) ;
173174 test_test_mempool_accept ( & cl) ;
174175 test_wallet_create_funded_psbt ( & cl) ;
@@ -645,6 +646,35 @@ fn test_create_raw_transaction(cl: &Client) {
645646 assert_eq ! ( hex, serialize( & tx) . to_hex( ) ) ;
646647}
647648
649+ fn test_decode_raw_transaction ( cl : & Client ) {
650+ let options = json:: ListUnspentQueryOptions {
651+ minimum_amount : Some ( btc ( 2 ) ) ,
652+ ..Default :: default ( )
653+ } ;
654+ let unspent = cl. list_unspent ( Some ( 6 ) , None , None , None , Some ( options) ) . unwrap ( ) ;
655+ let unspent = unspent. into_iter ( ) . nth ( 0 ) . unwrap ( ) ;
656+
657+ let input = json:: CreateRawTransactionInput {
658+ txid : unspent. txid ,
659+ vout : unspent. vout ,
660+ sequence : None ,
661+ } ;
662+ let mut output = HashMap :: new ( ) ;
663+ output. insert ( RANDOM_ADDRESS . to_string ( ) , btc ( 1 ) ) ;
664+
665+ let tx =
666+ cl. create_raw_transaction ( & [ input. clone ( ) ] , & output, Some ( 500_000 ) , Some ( true ) ) . unwrap ( ) ;
667+ let hex = cl. create_raw_transaction_hex ( & [ input] , & output, Some ( 500_000 ) , Some ( true ) ) . unwrap ( ) ;
668+
669+ let decoded_transaction = cl. decode_raw_transaction ( hex, None ) . unwrap ( ) ;
670+
671+ assert_eq ! ( tx. txid( ) , decoded_transaction. txid) ;
672+ assert_eq ! ( 500_000 , decoded_transaction. locktime) ;
673+
674+ assert_eq ! ( decoded_transaction. vin[ 0 ] . txid. unwrap( ) , unspent. txid) ;
675+ assert_eq ! ( decoded_transaction. vout[ 0 ] . clone( ) . value, btc( 1 ) ) ;
676+ }
677+
648678fn test_fund_raw_transaction ( cl : & Client ) {
649679 let addr = cl. get_new_address ( None , None ) . unwrap ( ) ;
650680 let mut output = HashMap :: new ( ) ;
0 commit comments