Skip to content

Commit

Permalink
test(chain) use Anchor generic on init_graph
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Feb 8, 2024
1 parent de9542f commit 425a697
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions crates/chain/tests/test_tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use bdk_chain::{
use bitcoin::{
absolute, hashes::Hash, BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid,
};
use common::*;
use core::iter;
use std::vec;
use rand::RngCore;

#[test]
fn insert_txouts() {
Expand Down Expand Up @@ -1172,3 +1174,38 @@ fn test_missing_blocks() {
),
]);
}

#[test]
fn call_map_anchors_with_non_deterministic_anchor() {
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
/// A non-deterministic anchor
pub struct NonDeterministicAnchor {
pub anchor_block: BlockId,
pub non_deterministic_field: u32,
}

let block_id = BlockId {
height: 99,
hash: h!("random blockhash"),
};
let template = [TxTemplate {
tx_name: "unconfirmed_coinbase",
inputs: &[TxInTemplate::Coinbase],
outputs: &[TxOutTemplate::new(5000, Some(0))],
anchors: &[ConfirmationHeightAnchor {
anchor_block: block_id,
confirmation_height: 100,
}],
..Default::default()
}];
let (graph, _, _) = init_graph(&template);
let rand = rand::thread_rng().next_u32();
let new_graph = graph.map_anchors(|a| NonDeterministicAnchor {
anchor_block: a.anchor_block,
non_deterministic_field: rand,
});
let anchors = new_graph.all_anchors();
assert_eq!(anchors.len(), 1);
assert_eq!(anchors.iter().next().unwrap().0.anchor_block, block_id);
assert_eq!(anchors.iter().next().unwrap().0.non_deterministic_field, rand);
}

0 comments on commit 425a697

Please sign in to comment.