|
14 | 14 | extern crate lazy_static;
|
15 | 15 |
|
16 | 16 | use std::collections::HashMap;
|
| 17 | +use std::str::FromStr; |
17 | 18 |
|
18 | 19 | use bitcoincore_rpc::json;
|
19 | 20 | use bitcoincore_rpc::jsonrpc::error::Error as JsonRpcError;
|
@@ -169,6 +170,7 @@ fn main() {
|
169 | 170 | test_invalidate_block_reconsider_block(&cl);
|
170 | 171 | test_key_pool_refill(&cl);
|
171 | 172 | test_create_raw_transaction(&cl);
|
| 173 | + test_decode_raw_transaction(&cl); |
172 | 174 | test_fund_raw_transaction(&cl);
|
173 | 175 | test_test_mempool_accept(&cl);
|
174 | 176 | test_wallet_create_funded_psbt(&cl);
|
@@ -645,6 +647,38 @@ fn test_create_raw_transaction(cl: &Client) {
|
645 | 647 | assert_eq!(hex, serialize(&tx).to_hex());
|
646 | 648 | }
|
647 | 649 |
|
| 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!( |
| 677 | + decoded_transaction.vout[0].clone().script_pub_key.address.unwrap(), |
| 678 | + Address::from_str(&RANDOM_ADDRESS.to_string()).unwrap() |
| 679 | + ); |
| 680 | +} |
| 681 | + |
648 | 682 | fn test_fund_raw_transaction(cl: &Client) {
|
649 | 683 | let addr = cl.get_new_address(None, None).unwrap();
|
650 | 684 | let mut output = HashMap::new();
|
|
0 commit comments