Skip to content

Commit 49ba5a5

Browse files
committed
refactor(test): update tests to use builder API
- update tests test_tx_graph and test_tx_graph_conflicts to use builder API
1 parent 9c14492 commit 49ba5a5

4 files changed

Lines changed: 382 additions & 671 deletions

File tree

crates/chain/tests/test_indexed_tx_graph.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use bdk_chain::{
1111
SpkIterator,
1212
};
1313
use bdk_testenv::{
14-
TestEnv, anyhow::{self}, bitcoind::{Input, Output}, block_id, hash, spk, utils::{DESCRIPTORS, new_tx}
14+
anyhow::{self},
15+
bitcoind::{Input, Output},
16+
block_id, hash, spk,
17+
utils::{new_tx, DESCRIPTORS},
18+
TestEnv,
1519
};
1620
use bitcoin::{
1721
secp256k1::Secp256k1, Address, Amount, BlockHash, Network, OutPoint, ScriptBuf, Transaction,

crates/chain/tests/test_tx_graph.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ fn test_chain_spends() {
11391139
);
11401140

11411141
// Chain position of the `tx_2` is now none, as it is older than `tx_2_conflict`
1142-
assert!(canonical_positions.get(&tx_2.compute_txid()).is_none());
1142+
assert!(!canonical_positions.contains_key(&tx_2.compute_txid()));
11431143
}
11441144
}
11451145

@@ -1278,30 +1278,20 @@ fn call_map_anchors_with_non_deterministic_anchor() {
12781278
}
12791279

12801280
let template = [
1281-
TxTemplate {
1282-
tx_name: "tx1",
1283-
inputs: &[TxInTemplate::Bogus],
1284-
outputs: &[TxOutTemplate::new(10000, Some(1))],
1285-
anchors: &[block_id!(1, "A")],
1286-
last_seen: None,
1287-
..Default::default()
1288-
},
1289-
TxTemplate {
1290-
tx_name: "tx2",
1291-
inputs: &[TxInTemplate::PrevTx("tx1", 0)],
1292-
outputs: &[TxOutTemplate::new(20000, Some(2))],
1293-
anchors: &[block_id!(2, "B")],
1294-
..Default::default()
1295-
},
1296-
TxTemplate {
1297-
tx_name: "tx3",
1298-
inputs: &[TxInTemplate::PrevTx("tx2", 0)],
1299-
outputs: &[TxOutTemplate::new(30000, Some(3))],
1300-
anchors: &[block_id!(3, "C"), block_id!(4, "D")],
1301-
..Default::default()
1302-
},
1281+
TxTemplate::new("tx1")
1282+
.with_inputs(vec![TxInTemplate::Bogus])
1283+
.with_outputs(vec![TxOutTemplate::new(10_000, Some(1))])
1284+
.with_anchors(vec![block_id!(1, "A")]),
1285+
TxTemplate::new("tx2")
1286+
.with_inputs(vec![TxInTemplate::PrevTx("tx1".into(), 0)])
1287+
.with_outputs(vec![TxOutTemplate::new(20_000, Some(2))])
1288+
.with_anchors(vec![block_id!(2, "B")]),
1289+
TxTemplate::new("tx3")
1290+
.with_inputs(vec![TxInTemplate::PrevTx("tx2".into(), 0)])
1291+
.with_outputs(vec![TxOutTemplate::new(30_000, Some(3))])
1292+
.with_anchors(vec![block_id!(3, "C"), block_id!(4, "D")]),
13031293
];
1304-
let graph = init_graph(&template).tx_graph;
1294+
let graph = init_graph(template).tx_graph;
13051295
let new_graph = graph.clone().map_anchors(|a| NonDeterministicAnchor {
13061296
anchor_block: a,
13071297
// A non-deterministic value

0 commit comments

Comments
 (0)