Skip to content

Commit

Permalink
Run the formatter
Browse files Browse the repository at this point in the history
Run `just fmt`, no other changes.
  • Loading branch information
tcharding committed May 19, 2024
1 parent fa4d3d4 commit f612931
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions bitcoin/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,8 +1791,11 @@ 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(&params).header;

Expand All @@ -1803,17 +1806,20 @@ 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

Expand All @@ -1824,7 +1830,7 @@ 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`
Expand All @@ -1834,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);
}
Expand All @@ -1847,29 +1854,27 @@ 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);
}

#[test]
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, &params);
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);
}

#[test]
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, &params);
let want = params.max_attainable_target.to_compact_lossy();
assert_eq!(got, want);
Expand Down

0 comments on commit f612931

Please sign in to comment.