|
6 | 6 | //! API docs of `bitcoind v28.0`.
|
7 | 7 |
|
8 | 8 | /// Requires `Client` to be in scope
|
9 |
| -#[macro_export] macro_rules! impl_test_v28__submitpackage { |
| 9 | +#[macro_export] |
| 10 | +macro_rules! impl_test_v28__submitpackage { |
10 | 11 | () => {
|
11 | 12 | #[test]
|
12 | 13 | fn submitpackage() {
|
13 |
| - // TODO |
| 14 | + //let bitcoind = $crate::bitcoind_no_wallet(); |
| 15 | + |
| 16 | + let bitcoind = $crate::bitcoind_with_default_wallet(); |
| 17 | + |
| 18 | + // Submitting the empty package should simply fail. |
| 19 | + assert!(bitcoind.client.submit_package(&[], None, None).is_err()); |
| 20 | + |
| 21 | + // Premine to get some funds |
| 22 | + let address = bitcoind.client.new_address().expect("failed to get new address"); |
| 23 | + let json = |
| 24 | + bitcoind.client.generate_to_address(101, &address).expect("generatetoaddress"); |
| 25 | + json.into_model().unwrap(); |
| 26 | + |
| 27 | + // Send to ourselves, mine, send again to generate two transactions. |
| 28 | + let (tx_0, tx_1) = { |
| 29 | + let new_address = bitcoind.client.new_address().expect("failed to get new address"); |
| 30 | + let txid = bitcoind |
| 31 | + .client |
| 32 | + .send_to_address(&new_address, bitcoin::Amount::from_sat(1000000)) |
| 33 | + .unwrap() |
| 34 | + .into_model() |
| 35 | + .unwrap() |
| 36 | + .txid; |
| 37 | + |
| 38 | + let _ = |
| 39 | + bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress"); |
| 40 | + |
| 41 | + let best_block_hash = bitcoind.client.best_block_hash().unwrap(); |
| 42 | + let best_block = bitcoind.client.get_block(best_block_hash).unwrap(); |
| 43 | + let tx_0 = best_block.txdata[1].clone(); |
| 44 | + |
| 45 | + let new_address = bitcoind.client.new_address().expect("failed to get new address"); |
| 46 | + let txid = bitcoind |
| 47 | + .client |
| 48 | + .send_to_address(&new_address, bitcoin::Amount::from_sat(1000000)) |
| 49 | + .unwrap() |
| 50 | + .into_model() |
| 51 | + .unwrap() |
| 52 | + .txid; |
| 53 | + |
| 54 | + let _ = |
| 55 | + bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress"); |
| 56 | + |
| 57 | + let best_block_hash = bitcoind.client.best_block_hash().unwrap(); |
| 58 | + let best_block = bitcoind.client.get_block(best_block_hash).unwrap(); |
| 59 | + let tx_1 = best_block.txdata[1].clone(); |
| 60 | + (tx_0, tx_1) |
| 61 | + }; |
| 62 | + |
| 63 | + // The call for submitting this package should succeed, but yield an 'already known' |
| 64 | + // error for all transactions. |
| 65 | + let res = bitcoind |
| 66 | + .client |
| 67 | + .submit_package(&[tx_0, tx_1], None, None) |
| 68 | + .expect("failed to submit package"); |
| 69 | + for (_, tx_result) in &res.tx_results { |
| 70 | + assert!(tx_result.error.is_some()); |
| 71 | + } |
| 72 | + assert!(res.replaced_transactions.is_empty()); |
14 | 73 | }
|
15 | 74 | };
|
16 | 75 | }
|
0 commit comments