Merge rust-bitcoin/rust-bitcoin#2782: Format the `pow` module
f6129317bd
Run the formatter (Tobin C. Harding)fa4d3d4417
Add whitespace (Tobin C. Harding) Pull request description: #2781 done by a human. ACKs for top commit: apoelstra: ACKf6129317bd
sad Tree-SHA512: a72b507995a70ab2b5c2bb717d8bbc4b47f3190157e5d526d33e6a9fd2ad990295806a36e0bda0ac988b1e175d8356c6e6d277337d0ed0a5e0499ad3f336a930
This commit is contained in:
commit
02ae925f83
|
@ -1791,10 +1791,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn compact_target_from_upwards_difficulty_adjustment_using_headers() {
|
||||
use crate::{block::Version, constants::genesis_block, TxMerkleNode};
|
||||
use hashes::Hash;
|
||||
|
||||
use crate::block::Version;
|
||||
use crate::constants::genesis_block;
|
||||
use crate::TxMerkleNode;
|
||||
let params = Params::new(crate::Network::Signet);
|
||||
let epoch_start = genesis_block(¶ms).header;
|
||||
|
||||
// Block 2015, the only information used are `bits` and `time`
|
||||
let current = Header {
|
||||
version: Version::ONE,
|
||||
|
@ -1802,19 +1806,23 @@ mod tests {
|
|||
merkle_root: TxMerkleNode::all_zeros(),
|
||||
time: 1599332177,
|
||||
bits: epoch_start.bits,
|
||||
nonce: epoch_start.nonce
|
||||
nonce: epoch_start.nonce,
|
||||
};
|
||||
let adjustment = CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params);
|
||||
let adjustment =
|
||||
CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params);
|
||||
let adjustment_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target
|
||||
assert_eq!(adjustment, adjustment_bits);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_target_from_downwards_difficulty_adjustment_using_headers() {
|
||||
use crate::{block::Version, TxMerkleNode};
|
||||
use hashes::Hash;
|
||||
|
||||
use crate::block::Version;
|
||||
use crate::TxMerkleNode;
|
||||
let params = Params::new(crate::Network::Signet);
|
||||
let starting_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target
|
||||
|
||||
// Block 2016, the only information used is `time`
|
||||
let epoch_start = Header {
|
||||
version: Version::ONE,
|
||||
|
@ -1822,8 +1830,9 @@ mod tests {
|
|||
merkle_root: TxMerkleNode::all_zeros(),
|
||||
time: 1599332844,
|
||||
bits: starting_bits,
|
||||
nonce: 0
|
||||
nonce: 0,
|
||||
};
|
||||
|
||||
// Block 4031, the only information used are `bits` and `time`
|
||||
let current = Header {
|
||||
version: Version::ONE,
|
||||
|
@ -1831,9 +1840,10 @@ mod tests {
|
|||
merkle_root: TxMerkleNode::all_zeros(),
|
||||
time: 1600591200,
|
||||
bits: starting_bits,
|
||||
nonce: 0
|
||||
nonce: 0,
|
||||
};
|
||||
let adjustment = CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params);
|
||||
let adjustment =
|
||||
CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params);
|
||||
let adjustment_bits = CompactTarget::from_consensus(503397348); // Block 4032 compact target
|
||||
assert_eq!(adjustment, adjustment_bits);
|
||||
}
|
||||
|
@ -1844,9 +1854,8 @@ mod tests {
|
|||
let starting_bits = CompactTarget::from_consensus(503403001);
|
||||
let timespan = (0.2 * params.pow_target_timespan as f64) as u64;
|
||||
let got = CompactTarget::from_next_work_required(starting_bits, timespan, params);
|
||||
let want = Target::from_compact(starting_bits)
|
||||
.min_transition_threshold()
|
||||
.to_compact_lossy();
|
||||
let want =
|
||||
Target::from_compact(starting_bits).min_transition_threshold().to_compact_lossy();
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
|
||||
|
@ -1854,11 +1863,10 @@ mod tests {
|
|||
fn compact_target_from_minimum_downward_difficulty_adjustment() {
|
||||
let params = Params::new(crate::Network::Signet);
|
||||
let starting_bits = CompactTarget::from_consensus(403403001); // High difficulty for Signet
|
||||
let timespan = 5 * params.pow_target_timespan; // Really slow.
|
||||
let timespan = 5 * params.pow_target_timespan; // Really slow.
|
||||
let got = CompactTarget::from_next_work_required(starting_bits, timespan, ¶ms);
|
||||
let want = Target::from_compact(starting_bits)
|
||||
.max_transition_threshold(params)
|
||||
.to_compact_lossy();
|
||||
let want =
|
||||
Target::from_compact(starting_bits).max_transition_threshold(params).to_compact_lossy();
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
|
||||
|
@ -1866,7 +1874,7 @@ mod tests {
|
|||
fn compact_target_from_adjustment_is_max_target() {
|
||||
let params = Params::new(crate::Network::Signet);
|
||||
let starting_bits = CompactTarget::from_consensus(503543726); // Genesis compact target on Signet
|
||||
let timespan = 5 * params.pow_target_timespan; // Really slow.
|
||||
let timespan = 5 * params.pow_target_timespan; // Really slow.
|
||||
let got = CompactTarget::from_next_work_required(starting_bits, timespan, ¶ms);
|
||||
let want = params.max_attainable_target.to_compact_lossy();
|
||||
assert_eq!(got, want);
|
||||
|
|
Loading…
Reference in New Issue