]> Untitled Git - bdk/commitdiff
test(chain): Add transitive anchor tests
author志宇 <hello@evanlinjin.me>
Tue, 26 Nov 2024 04:10:18 +0000 (15:10 +1100)
committer志宇 <hello@evanlinjin.me>
Tue, 10 Dec 2024 10:39:23 +0000 (21:39 +1100)
crates/chain/tests/test_tx_graph_conflicts.rs

index 2e64e391293d98049ece6ef585994b2f8e0731a4..a2b6abdc349ac4a8cf73be704848923056881190 100644 (file)
@@ -81,10 +81,8 @@ fn test_tx_conflict_handling() {
             exp_chain_txouts: HashSet::from([("confirmed_genesis", 0), ("confirmed_conflict", 0)]),
             exp_unspents: HashSet::from([("confirmed_conflict", 0)]),
             exp_balance: Balance {
-                immature: Amount::ZERO,
-                trusted_pending: Amount::ZERO,
-                untrusted_pending: Amount::ZERO,
                 confirmed: Amount::from_sat(20000),
+                ..Default::default()
             },
         },
         Scenario {
@@ -593,6 +591,79 @@ fn test_tx_conflict_handling() {
                 confirmed: Amount::from_sat(50000),
             },
         },
+        Scenario {
+            name: "transitively confirmed ancestors",
+            tx_templates: &[
+                TxTemplate {
+                    tx_name: "first",
+                    inputs: &[TxInTemplate::Bogus],
+                    outputs: &[TxOutTemplate::new(1000, Some(0))],
+                    ..Default::default()
+                },
+                TxTemplate {
+                    tx_name: "second",
+                    inputs: &[TxInTemplate::PrevTx("first", 0)],
+                    outputs: &[TxOutTemplate::new(900, Some(0))],
+                    ..Default::default()
+                },
+                TxTemplate {
+                    tx_name: "anchored",
+                    inputs: &[TxInTemplate::PrevTx("second", 0)],
+                    outputs: &[TxOutTemplate::new(800, Some(0))],
+                    anchors: &[block_id!(3, "D")],
+                    ..Default::default()
+                },
+            ],
+            exp_chain_txs: HashSet::from(["first", "second", "anchored"]),
+            exp_chain_txouts: HashSet::from([("first", 0), ("second", 0), ("anchored", 0)]),
+            exp_unspents: HashSet::from([("anchored", 0)]),
+            exp_balance: Balance {
+                immature: Amount::ZERO,
+                trusted_pending: Amount::ZERO,
+                untrusted_pending: Amount::ZERO,
+                confirmed: Amount::from_sat(800),
+            }
+        },
+        Scenario {
+            name: "transitively anchored txs should have priority over last seen",
+            tx_templates: &[
+                TxTemplate {
+                    tx_name: "root",
+                    inputs: &[TxInTemplate::Bogus],
+                    outputs: &[TxOutTemplate::new(10_000, Some(0))],
+                    anchors: &[block_id!(1, "B")],
+                    ..Default::default()
+                },
+                TxTemplate {
+                    tx_name: "last_seen_conflict",
+                    inputs: &[TxInTemplate::PrevTx("root", 0)],
+                    outputs: &[TxOutTemplate::new(9900, Some(1))],
+                    last_seen: Some(1000),
+                    ..Default::default()
+                },
+                TxTemplate {
+                    tx_name: "transitively_anchored_conflict",
+                    inputs: &[TxInTemplate::PrevTx("root", 0)],
+                    outputs: &[TxOutTemplate::new(9000, Some(1))],
+                    last_seen: Some(100),
+                    ..Default::default()
+                },
+                TxTemplate {
+                    tx_name: "anchored",
+                    inputs: &[TxInTemplate::PrevTx("transitively_anchored_conflict", 0)],
+                    outputs: &[TxOutTemplate::new(8000, Some(2))],
+                    anchors: &[block_id!(4, "E")],
+                    ..Default::default()
+                },
+            ],
+            exp_chain_txs: HashSet::from(["root", "transitively_anchored_conflict", "anchored"]),
+            exp_chain_txouts: HashSet::from([("root", 0), ("transitively_anchored_conflict", 0), ("anchored", 0)]),
+            exp_unspents: HashSet::from([("anchored", 0)]),
+            exp_balance: Balance {
+                confirmed: Amount::from_sat(8000),
+                ..Default::default()
+            }
+        }
     ];
 
     for scenario in scenarios {