diff --git a/crates/chain/tests/common/mod.rs b/crates/chain/tests/common/mod.rs index 7d7288bdfc..560f66feef 100644 --- a/crates/chain/tests/common/mod.rs +++ b/crates/chain/tests/common/mod.rs @@ -1,6 +1,6 @@ #[allow(unused_macros)] macro_rules! h { - ($index:literal) => {{ + ($index:expr) => {{ bitcoin::hashes::Hash::hash($index.as_bytes()) }}; } diff --git a/crates/chain/tests/test_tx_graph.rs b/crates/chain/tests/test_tx_graph.rs index 967b6418c5..109012a76e 100644 --- a/crates/chain/tests/test_tx_graph.rs +++ b/crates/chain/tests/test_tx_graph.rs @@ -828,11 +828,11 @@ fn test_inserting_anchor_without_tx() { let mut graph = TxGraph::::default(); let txs = [common::new_tx(0), common::new_tx(1)]; let chain: LocalChain = (0..=5) - .map(|ht| (ht, BlockHash::hash(format!("Block Hash {}", ht).as_bytes()))) + .map(|i| (i, h!(i.to_string()))) .collect::>() .into(); let tip = chain.tip().unwrap(); - let additions = graph.insert_anchor_preview(txs[0].txid(), chain.get_block(0).unwrap().clone()); + let additions = graph.insert_anchor(txs[0].txid(), chain.get_block(0).unwrap().clone()); // Additions should only include the Anchor for the Tx-Block 1 and 2 assert_eq!( @@ -845,7 +845,10 @@ fn test_inserting_anchor_without_tx() { } ); - graph.apply_additions(additions); + // graph should be recoverable from additions + let mut graph_recovered = TxGraph::::default(); + graph_recovered.apply_additions(additions); + assert_eq!(graph, graph_recovered); // We can not directly check whether an Anchor is part of a TxGraph // so we check if a txid is connected to the correct Anchor / Block. @@ -856,9 +859,13 @@ fn test_inserting_anchor_without_tx() { Confirmed(&chain.get_block(0).unwrap()) ); - // Add transactions - let _ = graph.insert_tx(txs[0].clone()); - let _ = graph.insert_tx(txs[1].clone()); + let additions2 = graph.insert_tx(txs[0].clone()); + let additions3 = graph.insert_tx(txs[1].clone()); + + // graph should be recoverable from additions + graph_recovered.apply_additions(additions2); + graph_recovered.apply_additions(additions3); + assert_eq!(graph, graph_recovered); // Transaction 0 should have an Anchor assert_eq!(