diff --git a/crates/chain/tests/test_tx_graph_conflicts.rs b/crates/chain/tests/test_tx_graph_conflicts.rs index 2e64e3912..a2b6abdc3 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 {