From: 志宇 Date: Tue, 26 Nov 2024 04:10:18 +0000 (+1100) Subject: test(chain): Add transitive anchor tests X-Git-Tag: v1.0.0-beta.6~2^2~11 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/struct.InsertBlockNotMatchingError.html?a=commitdiff_plain;h=4325e2c25e037129c7878f347dd32cc48b771bb3;p=bdk test(chain): Add transitive anchor tests --- diff --git a/crates/chain/tests/test_tx_graph_conflicts.rs b/crates/chain/tests/test_tx_graph_conflicts.rs index 2e64e391..a2b6abdc 100644 --- a/crates/chain/tests/test_tx_graph_conflicts.rs +++ b/crates/chain/tests/test_tx_graph_conflicts.rs @@ -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 {