parent
fa4d3d4417
commit
f6129317bd
|
@ -1791,8 +1791,11 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_target_from_upwards_difficulty_adjustment_using_headers() {
|
fn compact_target_from_upwards_difficulty_adjustment_using_headers() {
|
||||||
use crate::{block::Version, constants::genesis_block, TxMerkleNode};
|
|
||||||
use hashes::Hash;
|
use hashes::Hash;
|
||||||
|
|
||||||
|
use crate::block::Version;
|
||||||
|
use crate::constants::genesis_block;
|
||||||
|
use crate::TxMerkleNode;
|
||||||
let params = Params::new(crate::Network::Signet);
|
let params = Params::new(crate::Network::Signet);
|
||||||
let epoch_start = genesis_block(¶ms).header;
|
let epoch_start = genesis_block(¶ms).header;
|
||||||
|
|
||||||
|
@ -1803,17 +1806,20 @@ mod tests {
|
||||||
merkle_root: TxMerkleNode::all_zeros(),
|
merkle_root: TxMerkleNode::all_zeros(),
|
||||||
time: 1599332177,
|
time: 1599332177,
|
||||||
bits: epoch_start.bits,
|
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
|
let adjustment_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target
|
||||||
assert_eq!(adjustment, adjustment_bits);
|
assert_eq!(adjustment, adjustment_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_target_from_downwards_difficulty_adjustment_using_headers() {
|
fn compact_target_from_downwards_difficulty_adjustment_using_headers() {
|
||||||
use crate::{block::Version, TxMerkleNode};
|
|
||||||
use hashes::Hash;
|
use hashes::Hash;
|
||||||
|
|
||||||
|
use crate::block::Version;
|
||||||
|
use crate::TxMerkleNode;
|
||||||
let params = Params::new(crate::Network::Signet);
|
let params = Params::new(crate::Network::Signet);
|
||||||
let starting_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target
|
let starting_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target
|
||||||
|
|
||||||
|
@ -1824,7 +1830,7 @@ mod tests {
|
||||||
merkle_root: TxMerkleNode::all_zeros(),
|
merkle_root: TxMerkleNode::all_zeros(),
|
||||||
time: 1599332844,
|
time: 1599332844,
|
||||||
bits: starting_bits,
|
bits: starting_bits,
|
||||||
nonce: 0
|
nonce: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Block 4031, the only information used are `bits` and `time`
|
// Block 4031, the only information used are `bits` and `time`
|
||||||
|
@ -1834,9 +1840,10 @@ mod tests {
|
||||||
merkle_root: TxMerkleNode::all_zeros(),
|
merkle_root: TxMerkleNode::all_zeros(),
|
||||||
time: 1600591200,
|
time: 1600591200,
|
||||||
bits: starting_bits,
|
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
|
let adjustment_bits = CompactTarget::from_consensus(503397348); // Block 4032 compact target
|
||||||
assert_eq!(adjustment, adjustment_bits);
|
assert_eq!(adjustment, adjustment_bits);
|
||||||
}
|
}
|
||||||
|
@ -1847,9 +1854,8 @@ mod tests {
|
||||||
let starting_bits = CompactTarget::from_consensus(503403001);
|
let starting_bits = CompactTarget::from_consensus(503403001);
|
||||||
let timespan = (0.2 * params.pow_target_timespan as f64) as u64;
|
let timespan = (0.2 * params.pow_target_timespan as f64) as u64;
|
||||||
let got = CompactTarget::from_next_work_required(starting_bits, timespan, params);
|
let got = CompactTarget::from_next_work_required(starting_bits, timespan, params);
|
||||||
let want = Target::from_compact(starting_bits)
|
let want =
|
||||||
.min_transition_threshold()
|
Target::from_compact(starting_bits).min_transition_threshold().to_compact_lossy();
|
||||||
.to_compact_lossy();
|
|
||||||
assert_eq!(got, want);
|
assert_eq!(got, want);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1859,9 +1865,8 @@ mod tests {
|
||||||
let starting_bits = CompactTarget::from_consensus(403403001); // High difficulty for 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 got = CompactTarget::from_next_work_required(starting_bits, timespan, ¶ms);
|
||||||
let want = Target::from_compact(starting_bits)
|
let want =
|
||||||
.max_transition_threshold(params)
|
Target::from_compact(starting_bits).max_transition_threshold(params).to_compact_lossy();
|
||||||
.to_compact_lossy();
|
|
||||||
assert_eq!(got, want);
|
assert_eq!(got, want);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue