Skip to content

Commit 682ab54

Browse files
committed
test(chain): add several basic scenarios to test transaction conflicts
1 parent b777396 commit 682ab54

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

crates/chain/tests/test_tx_graph_conflicts.rs

+91
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,76 @@ 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+
},
378+
Scenario {
379+
name: "B and B' spend A and conflict, no other transactions, B' has higher last_seen",
380+
tx_templates: &[
381+
TxTemplate {
382+
tx_name: "A",
383+
inputs: &[TxInTemplate::Bogus],
384+
outputs: &[TxOutTemplate::new(10000, Some(0))],
385+
last_seen: None,
386+
..Default::default()
387+
},
388+
TxTemplate {
389+
tx_name: "B",
390+
inputs: &[TxInTemplate::PrevTx("A", 0)],
391+
outputs: &[TxOutTemplate::new(20000, Some(1))],
392+
last_seen: Some(100),
393+
..Default::default()
394+
},
395+
TxTemplate {
396+
tx_name: "B'",
397+
inputs: &[TxInTemplate::PrevTx("A", 0)],
398+
outputs: &[TxOutTemplate::new(30000, Some(2))],
399+
last_seen: Some(200),
400+
..Default::default()
401+
},
402+
],
403+
exp_chain_txs: HashSet::from(["A", "B'"]),
404+
exp_chain_txouts: HashSet::from([("A", 0), ("B'", 0)]),
405+
exp_unspents: HashSet::from([("B'", 0)]),
406+
exp_balance: Balance {
407+
immature: Amount::ZERO,
408+
trusted_pending: Amount::from_sat(30000),
409+
untrusted_pending: Amount::ZERO,
410+
confirmed: Amount::ZERO,
411+
},
412+
},
322413
Scenario {
323414
name: "B and B' spend A and conflict, C spends B, all the transactions are unconfirmed, B' has higher last_seen than B",
324415
tx_templates: &[

0 commit comments

Comments
 (0)