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