Skip to content

Commit 2beb4b3

Browse files
committed
test(chain): Add transitive anchor tests
1 parent 68c38a2 commit 2beb4b3

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

crates/chain/tests/test_tx_graph_conflicts.rs

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ fn test_tx_conflict_handling() {
8181
exp_chain_txouts: HashSet::from([("confirmed_genesis", 0), ("confirmed_conflict", 0)]),
8282
exp_unspents: HashSet::from([("confirmed_conflict", 0)]),
8383
exp_balance: Balance {
84-
immature: Amount::ZERO,
85-
trusted_pending: Amount::ZERO,
86-
untrusted_pending: Amount::ZERO,
8784
confirmed: Amount::from_sat(20000),
85+
..Default::default()
8886
},
8987
},
9088
Scenario {
@@ -593,6 +591,79 @@ fn test_tx_conflict_handling() {
593591
confirmed: Amount::from_sat(50000),
594592
},
595593
},
594+
Scenario {
595+
name: "transitively confirmed ancestors",
596+
tx_templates: &[
597+
TxTemplate {
598+
tx_name: "first",
599+
inputs: &[TxInTemplate::Bogus],
600+
outputs: &[TxOutTemplate::new(1000, Some(0))],
601+
..Default::default()
602+
},
603+
TxTemplate {
604+
tx_name: "second",
605+
inputs: &[TxInTemplate::PrevTx("first", 0)],
606+
outputs: &[TxOutTemplate::new(900, Some(0))],
607+
..Default::default()
608+
},
609+
TxTemplate {
610+
tx_name: "anchored",
611+
inputs: &[TxInTemplate::PrevTx("second", 0)],
612+
outputs: &[TxOutTemplate::new(800, Some(0))],
613+
anchors: &[block_id!(3, "D")],
614+
..Default::default()
615+
},
616+
],
617+
exp_chain_txs: HashSet::from(["first", "second", "anchored"]),
618+
exp_chain_txouts: HashSet::from([("first", 0), ("second", 0), ("anchored", 0)]),
619+
exp_unspents: HashSet::from([("anchored", 0)]),
620+
exp_balance: Balance {
621+
immature: Amount::ZERO,
622+
trusted_pending: Amount::ZERO,
623+
untrusted_pending: Amount::ZERO,
624+
confirmed: Amount::from_sat(800),
625+
}
626+
},
627+
Scenario {
628+
name: "transitively anchored txs should have priority over last seen",
629+
tx_templates: &[
630+
TxTemplate {
631+
tx_name: "root",
632+
inputs: &[TxInTemplate::Bogus],
633+
outputs: &[TxOutTemplate::new(10_000, Some(0))],
634+
anchors: &[block_id!(1, "B")],
635+
..Default::default()
636+
},
637+
TxTemplate {
638+
tx_name: "last_seen_conflict",
639+
inputs: &[TxInTemplate::PrevTx("root", 0)],
640+
outputs: &[TxOutTemplate::new(9900, Some(1))],
641+
last_seen: Some(1000),
642+
..Default::default()
643+
},
644+
TxTemplate {
645+
tx_name: "transitively_anchored_conflict",
646+
inputs: &[TxInTemplate::PrevTx("root", 0)],
647+
outputs: &[TxOutTemplate::new(9000, Some(1))],
648+
last_seen: Some(100),
649+
..Default::default()
650+
},
651+
TxTemplate {
652+
tx_name: "anchored",
653+
inputs: &[TxInTemplate::PrevTx("transitively_anchored_conflict", 0)],
654+
outputs: &[TxOutTemplate::new(8000, Some(2))],
655+
anchors: &[block_id!(4, "E")],
656+
..Default::default()
657+
},
658+
],
659+
exp_chain_txs: HashSet::from(["root", "transitively_anchored_conflict", "anchored"]),
660+
exp_chain_txouts: HashSet::from([("root", 0), ("transitively_anchored_conflict", 0), ("anchored", 0)]),
661+
exp_unspents: HashSet::from([("anchored", 0)]),
662+
exp_balance: Balance {
663+
confirmed: Amount::from_sat(8000),
664+
..Default::default()
665+
}
666+
}
596667
];
597668

598669
for scenario in scenarios {

0 commit comments

Comments
 (0)