Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Add basic submitpackage test
Browse files Browse the repository at this point in the history
We don't actually test package submission semantics, but most of the
type de/ser logic by submitting a package of two already-known txs.
  • Loading branch information
tnull committed Nov 7, 2024
1 parent ec80919 commit 4230085
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions integration_test/src/v28/raw_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,70 @@
//! API docs of `bitcoind v28.0`.
/// Requires `Client` to be in scope
#[macro_export] macro_rules! impl_test_v28__submitpackage {
#[macro_export]
macro_rules! impl_test_v28__submitpackage {
() => {
#[test]
fn submitpackage() {
// TODO
//let bitcoind = $crate::bitcoind_no_wallet();

let bitcoind = $crate::bitcoind_with_default_wallet();

// Submitting the empty package should simply fail.
assert!(bitcoind.client.submit_package(&[], None, None).is_err());

// Premine to get some funds
let address = bitcoind.client.new_address().expect("failed to get new address");
let json =
bitcoind.client.generate_to_address(101, &address).expect("generatetoaddress");
json.into_model().unwrap();

// Send to ourselves, mine, send again to generate two transactions.
let (tx_0, tx_1) = {
let new_address = bitcoind.client.new_address().expect("failed to get new address");
let txid = bitcoind
.client
.send_to_address(&new_address, bitcoin::Amount::from_sat(1000000))
.unwrap()
.into_model()
.unwrap()
.txid;

let _ =
bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress");

let best_block_hash = bitcoind.client.best_block_hash().unwrap();
let best_block = bitcoind.client.get_block(best_block_hash).unwrap();
let tx_0 = best_block.txdata[1].clone();

let new_address = bitcoind.client.new_address().expect("failed to get new address");
let txid = bitcoind
.client
.send_to_address(&new_address, bitcoin::Amount::from_sat(1000000))
.unwrap()
.into_model()
.unwrap()
.txid;

let _ =
bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress");

let best_block_hash = bitcoind.client.best_block_hash().unwrap();
let best_block = bitcoind.client.get_block(best_block_hash).unwrap();
let tx_1 = best_block.txdata[1].clone();
(tx_0, tx_1)
};

// The call for submitting this package should succeed, but yield an 'already known'
// error for all transactions.
let res = bitcoind
.client
.submit_package(&[tx_0, tx_1], None, None)
.expect("failed to submit package");
for (_, tx_result) in &res.tx_results {
assert!(tx_result.error.is_some());
}
assert!(res.replaced_transactions.is_empty());
}
};
}

0 comments on commit 4230085

Please sign in to comment.