forked from bitcoindevkit/bdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tx testing utils to testenv crate
- add `tx_utils` to house all transaction utilities moved from `crates/chain/test/common` - deleted all moved macros and functions in `crates/chain/test/common/mod` - add `bitcoin` crate to `testenv` crate - add `tx_utils` mod to lib in testenv [Issue: bitcoindevkit#1602]
- Loading branch information
Showing
4 changed files
with
79 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#[allow(unused_macros)] | ||
#[macro_export] | ||
macro_rules! block_id { | ||
($height:expr, $hash:literal) => {{ | ||
bdk_chain::BlockId { | ||
height: $height, | ||
hash: bitcoin::hashes::Hash::hash($hash.as_bytes()), | ||
} | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
#[macro_export] | ||
macro_rules! h { | ||
($index:literal) => {{ | ||
bitcoin::hashes::Hash::hash($index.as_bytes()) | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
#[macro_export] | ||
macro_rules! local_chain { | ||
[ $(($height:expr, $block_hash:expr)), * ] => {{ | ||
#[allow(unused_mut)] | ||
bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $block_hash).into()),*].into_iter().collect()) | ||
.expect("chain must have genesis block") | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
#[macro_export] | ||
macro_rules! chain_update { | ||
[ $(($height:expr, $hash:expr)), * ] => {{ | ||
#[allow(unused_mut)] | ||
bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $hash).into()),*].into_iter().collect()) | ||
.expect("chain must have genesis block") | ||
.tip() | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
#[macro_export] | ||
macro_rules! changeset { | ||
(checkpoints: $($tail:tt)*) => { changeset!(index: TxHeight, checkpoints: $($tail)*) }; | ||
( | ||
index: $ind:ty, | ||
checkpoints: [ $(( $height:expr, $cp_to:expr )),* ] | ||
$(,txids: [ $(( $txid:expr, $tx_to:expr )),* ])? | ||
) => {{ | ||
use bdk_chain::collections::BTreeMap; | ||
|
||
#[allow(unused_mut)] | ||
bdk_chain::sparse_chain::ChangeSet::<$ind> { | ||
checkpoints: { | ||
let mut changes = BTreeMap::default(); | ||
$(changes.insert($height, $cp_to);)* | ||
changes | ||
}, | ||
txids: { | ||
let mut changes = BTreeMap::default(); | ||
$($(changes.insert($txid, $tx_to.map(|h: TxHeight| h.into()));)*)? | ||
changes | ||
} | ||
} | ||
}}; | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn new_tx(lt: u32) -> bitcoin::Transaction { | ||
bitcoin::Transaction { | ||
version: bitcoin::transaction::Version::non_standard(0x00), | ||
lock_time: bitcoin::absolute::LockTime::from_consensus(lt), | ||
input: vec![], | ||
output: vec![], | ||
} | ||
} |