Skip to content

Commit 8374f70

Browse files
committed
test(chain): add several basic scenarios to test transaction conflicts
1 parent 721eb54 commit 8374f70

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

crates/chain/tests/test_tx_graph_conflicts.rs

+56
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ fn test_tx_conflict_handling() {
4444
let chain_tip = local_chain.tip().block_id();
4545

4646
let scenarios = [
47+
Scenario {
48+
name: "only A exists, no other txs",
49+
tx_templates: &[
50+
TxTemplate {
51+
tx_name: "A",
52+
inputs: &[TxInTemplate::Bogus],
53+
outputs: &[TxOutTemplate::new(10000, Some(0))],
54+
last_seen: None,
55+
..Default::default()
56+
},
57+
],
58+
exp_chain_txs: HashSet::from(["A"]),
59+
exp_chain_txouts: HashSet::from([("A", 0)]),
60+
exp_unspents: HashSet::from([("A", 0)]),
61+
exp_balance: Balance {
62+
immature: Amount::ZERO,
63+
trusted_pending: Amount::from_sat(10000),
64+
untrusted_pending: Amount::ZERO,
65+
confirmed: Amount::ZERO,
66+
},
67+
},
4768
Scenario {
4869
name: "coinbase tx cannot be in mempool and be unconfirmed",
4970
tx_templates: &[
@@ -319,6 +340,41 @@ fn test_tx_conflict_handling() {
319340
confirmed: Amount::from_sat(50000),
320341
},
321342
},
343+
Scenario {
344+
name: "B and B' spend A, B' is confirmed",
345+
tx_templates: &[
346+
TxTemplate {
347+
tx_name: "A",
348+
inputs: &[TxInTemplate::Bogus],
349+
outputs: &[TxOutTemplate::new(10000, Some(0))],
350+
last_seen: None,
351+
..Default::default()
352+
},
353+
TxTemplate {
354+
tx_name: "B",
355+
inputs: &[TxInTemplate::PrevTx("A", 0)],
356+
outputs: &[TxOutTemplate::new(20000, Some(1))],
357+
last_seen: Some(100),
358+
..Default::default()
359+
},
360+
TxTemplate {
361+
tx_name: "B'",
362+
inputs: &[TxInTemplate::PrevTx("A", 0)],
363+
outputs: &[TxOutTemplate::new(30000, Some(2))],
364+
anchors: &[block_id!(1, "B")],
365+
..Default::default()
366+
},
367+
],
368+
exp_chain_txs: HashSet::from(["A", "B'"]),
369+
exp_chain_txouts: HashSet::from([("A", 0), ("B'", 0)]),
370+
exp_unspents: HashSet::from([("B'", 0)]),
371+
exp_balance: Balance {
372+
immature: Amount::ZERO,
373+
trusted_pending: Amount::ZERO,
374+
untrusted_pending: Amount::ZERO,
375+
confirmed: Amount::from_sat(30000),
376+
},
377+
},
322378
Scenario {
323379
name: "B and B' spend A and conflict, C spends B, all the transactions are unconfirmed, B' has higher last_seen than B",
324380
tx_templates: &[

0 commit comments

Comments
 (0)