Skip to content

Commit 1e99793

Browse files
committed
feat(testenv): add make_checkpoint_tip
This creates a checkpoint linked list which contains all blocks.
1 parent ee21ffe commit 1e99793

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

crates/testenv/src/lib.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use bdk_chain::bitcoin::{
2-
address::NetworkChecked, block::Header, hash_types::TxMerkleNode, hashes::Hash,
3-
secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, CompactTarget,
4-
ScriptBuf, ScriptHash, Transaction, TxIn, TxOut, Txid,
1+
use bdk_chain::{
2+
bitcoin::{
3+
address::NetworkChecked, block::Header, hash_types::TxMerkleNode, hashes::Hash, secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, CompactTarget, ScriptBuf, ScriptHash, Transaction, TxIn, TxOut, Txid
4+
},
5+
local_chain::CheckPoint,
6+
BlockId,
57
};
68
use bitcoincore_rpc::{
79
bitcoincore_rpc_json::{GetBlockTemplateModes, GetBlockTemplateRules},
@@ -234,6 +236,18 @@ impl TestEnv {
234236
.send_to_address(address, amount, None, None, None, None, None, None)?;
235237
Ok(txid)
236238
}
239+
240+
/// Create a checkpoint linked list of all the blocks in the chain.
241+
pub fn make_checkpoint_tip(&self) -> CheckPoint {
242+
CheckPoint::from_block_ids((0_u32..).map_while(|height| {
243+
self.bitcoind
244+
.client
245+
.get_block_hash(height as u64)
246+
.ok()
247+
.map(|hash| BlockId { height, hash })
248+
}))
249+
.expect("must craft tip")
250+
}
237251
}
238252

239253
#[cfg(test)]

0 commit comments

Comments
 (0)