mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-28 19:55:20 +08:00
chore: fix failing unit tests
This commit is contained in:
@@ -1049,7 +1049,7 @@ mod tests {
|
||||
median_burn: block_commit_1.burn_fee.into(),
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256::max(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
candidate: block_commit_1.clone(),
|
||||
}],
|
||||
},
|
||||
@@ -1068,14 +1068,14 @@ mod tests {
|
||||
0xffffffffffffffff,
|
||||
0x7fffffffffffffff,
|
||||
]),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
candidate: block_commit_1.clone(),
|
||||
},
|
||||
BurnSamplePoint {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
@@ -1095,7 +1095,7 @@ mod tests {
|
||||
burns: block_commit_1.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256([
|
||||
0xffffffffffffffff,
|
||||
@@ -1109,7 +1109,7 @@ mod tests {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
@@ -1129,7 +1129,7 @@ mod tests {
|
||||
burns: block_commit_1.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256([
|
||||
0xffffffffffffffff,
|
||||
@@ -1143,7 +1143,7 @@ mod tests {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
@@ -1163,7 +1163,7 @@ mod tests {
|
||||
burns: block_commit_1.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256([
|
||||
0xffffffffffffffff,
|
||||
@@ -1177,7 +1177,7 @@ mod tests {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
@@ -1197,7 +1197,7 @@ mod tests {
|
||||
burns: block_commit_1.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256([
|
||||
0xffffffffffffffff,
|
||||
@@ -1211,7 +1211,7 @@ mod tests {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
@@ -1231,7 +1231,7 @@ mod tests {
|
||||
burns: block_commit_1.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256([
|
||||
0xffffffffffffffff,
|
||||
@@ -1245,7 +1245,7 @@ mod tests {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: ((block_commit_1.burn_fee + block_commit_2.burn_fee) / 2)
|
||||
.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
@@ -1272,7 +1272,7 @@ mod tests {
|
||||
BurnSamplePoint {
|
||||
burns: block_commit_1.burn_fee.into(),
|
||||
median_burn: block_commit_2.burn_fee.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256::zero(),
|
||||
range_end: Uint256([
|
||||
0x3ed94d3cb0a84709,
|
||||
@@ -1285,7 +1285,7 @@ mod tests {
|
||||
BurnSamplePoint {
|
||||
burns: block_commit_2.burn_fee.into(),
|
||||
median_burn: block_commit_2.burn_fee.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0x3ed94d3cb0a84709,
|
||||
0x0963dded799a7c1a,
|
||||
@@ -1303,7 +1303,7 @@ mod tests {
|
||||
BurnSamplePoint {
|
||||
burns: (block_commit_3.burn_fee).into(),
|
||||
median_burn: block_commit_3.burn_fee.into(),
|
||||
frequency: 10,
|
||||
frequency: 1,
|
||||
range_start: Uint256([
|
||||
0x7db29a7961508e12,
|
||||
0x12c7bbdaf334f834,
|
||||
|
||||
@@ -297,10 +297,7 @@ impl BlockSnapshot {
|
||||
// phase)
|
||||
let epoch_frequency_usize =
|
||||
usize::try_from(epoch_id.mining_commitment_frequency()).expect("Infallible");
|
||||
if sampled_window_len > 1
|
||||
&& epoch_frequency_usize >= sampled_window_len
|
||||
&& miner_frequency < epoch_id.mining_commitment_frequency()
|
||||
{
|
||||
if usize::from(miner_frequency) < epoch_frequency_usize.min(sampled_window_len) {
|
||||
// this miner didn't mine often enough to win anyway
|
||||
info!("Miner did not mine often enough to win";
|
||||
"miner_sender" => %winning_block_sender,
|
||||
@@ -345,16 +342,16 @@ impl BlockSnapshot {
|
||||
return (AtcRational::zero(), false);
|
||||
};
|
||||
|
||||
if block_burn_total >= windowed_median_burns {
|
||||
// clamp to 1.0, and ATC increased
|
||||
return (AtcRational::one(), false);
|
||||
}
|
||||
|
||||
if windowed_median_burns == 0 {
|
||||
// no carried commit, so null miner wins by default.
|
||||
return (AtcRational::zero(), true);
|
||||
}
|
||||
|
||||
if block_burn_total >= windowed_median_burns {
|
||||
// clamp to 1.0, and ATC increased
|
||||
return (AtcRational::one(), false);
|
||||
}
|
||||
|
||||
(
|
||||
AtcRational::frac(block_burn_total, windowed_median_burns),
|
||||
true,
|
||||
@@ -929,46 +926,40 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_check_is_miner_active() {
|
||||
assert_eq!(StacksEpochId::Epoch30.mining_commitment_frequency(), 10);
|
||||
assert_eq!(StacksEpochId::Epoch25.mining_commitment_frequency(), 6);
|
||||
assert_eq!(StacksEpochId::Epoch30.mining_commitment_frequency(), 3);
|
||||
assert_eq!(StacksEpochId::Epoch25.mining_commitment_frequency(), 0);
|
||||
|
||||
// reward phase
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
10,
|
||||
&BurnchainSigner("".to_string()),
|
||||
10
|
||||
));
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
10,
|
||||
&BurnchainSigner("".to_string()),
|
||||
9
|
||||
));
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
10,
|
||||
&BurnchainSigner("".to_string()),
|
||||
8
|
||||
));
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
10,
|
||||
&BurnchainSigner("".to_string()),
|
||||
7
|
||||
));
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
10,
|
||||
6,
|
||||
&BurnchainSigner("".to_string()),
|
||||
6
|
||||
));
|
||||
assert!(!BlockSnapshot::check_miner_is_active(
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
10,
|
||||
6,
|
||||
&BurnchainSigner("".to_string()),
|
||||
5
|
||||
));
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
6,
|
||||
&BurnchainSigner("".to_string()),
|
||||
4
|
||||
));
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
6,
|
||||
&BurnchainSigner("".to_string()),
|
||||
3
|
||||
));
|
||||
assert!(!BlockSnapshot::check_miner_is_active(
|
||||
StacksEpochId::Epoch30,
|
||||
6,
|
||||
&BurnchainSigner("".to_string()),
|
||||
2
|
||||
));
|
||||
|
||||
// prepare phase
|
||||
assert!(BlockSnapshot::check_miner_is_active(
|
||||
@@ -1037,7 +1028,7 @@ mod test {
|
||||
// no carried commit
|
||||
assert_eq!(
|
||||
BlockSnapshot::get_miner_commit_carryover(Some(2), Some(0)),
|
||||
(AtcRational::zero(), false)
|
||||
(AtcRational::zero(), true)
|
||||
);
|
||||
|
||||
// assumed carryover
|
||||
|
||||
Reference in New Issue
Block a user