Skip to content

Commit 1964463

Browse files
committed
chore: simplify logic in test
1 parent 640fd6d commit 1964463

File tree

1 file changed

+25
-31
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+25
-31
lines changed

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,47 +5230,41 @@ fn reorg_locally_accepted_blocks_across_tenures_fails() {
52305230
assert_ne!(info_after.stacks_tip.to_string(), block_n_1.block_hash);
52315231

52325232
info!("------------------------- Starting Tenure B -------------------------");
5233-
// Start a new tenure and ensure the miner can propose a new block N+1' that is accepted by all signers
52345233
let blocks_before = mined_blocks.load(Ordering::SeqCst);
52355234
let info_before = signer_test
52365235
.stacks_client
52375236
.get_peer_info()
52385237
.expect("Failed to get peer info");
5238+
5239+
// Clear the test observer so any old rejections are not counted
5240+
test_observer::clear();
5241+
5242+
// Start a new tenure and ensure the we see the expected rejections
52395243
next_block_and(
52405244
&mut signer_test.running_nodes.btc_regtest_controller,
52415245
60,
52425246
|| {
5243-
let info = signer_test.stacks_client.get_peer_info().unwrap();
5244-
Ok(info.burn_block_height > info_before.burn_block_height)
5247+
let rejected_signers = test_observer::get_stackerdb_chunks()
5248+
.into_iter()
5249+
.flat_map(|chunk| chunk.modified_slots)
5250+
.filter_map(|chunk| {
5251+
let message = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
5252+
.expect("Failed to deserialize SignerMessage");
5253+
match message {
5254+
SignerMessage::BlockResponse(BlockResponse::Rejected(BlockRejection {
5255+
signature,
5256+
signer_signature_hash,
5257+
..
5258+
})) => non_ignoring_signers.iter().find(|key| {
5259+
key.verify(signer_signature_hash.bits(), &signature).is_ok()
5260+
}),
5261+
_ => None,
5262+
}
5263+
})
5264+
.collect::<Vec<_>>();
5265+
Ok(rejected_signers.len() + ignoring_signers.len() == num_signers)
52455266
},
52465267
)
5247-
.unwrap();
5248-
5249-
info!(
5250-
"------------------------- Attempt to mine Nakamoto Block N+1' in Tenure B -------------------------"
5251-
);
5252-
// The miner's proposed block should get rejected by all the signers that PREVIOUSLY accepted the block
5253-
wait_for(short_timeout, || {
5254-
let rejected_signers = test_observer::get_stackerdb_chunks()
5255-
.into_iter()
5256-
.flat_map(|chunk| chunk.modified_slots)
5257-
.filter_map(|chunk| {
5258-
let message = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
5259-
.expect("Failed to deserialize SignerMessage");
5260-
match message {
5261-
SignerMessage::BlockResponse(BlockResponse::Rejected(BlockRejection {
5262-
signature,
5263-
signer_signature_hash,
5264-
..
5265-
})) => non_ignoring_signers
5266-
.iter()
5267-
.find(|key| key.verify(signer_signature_hash.bits(), &signature).is_ok()),
5268-
_ => None,
5269-
}
5270-
})
5271-
.collect::<Vec<_>>();
5272-
Ok(rejected_signers.len() + ignoring_signers.len() == num_signers)
5273-
})
52745268
.expect("FAIL: Timed out waiting for block proposal rejections");
52755269

52765270
let blocks_after = mined_blocks.load(Ordering::SeqCst);
@@ -5279,7 +5273,7 @@ fn reorg_locally_accepted_blocks_across_tenures_fails() {
52795273
.get_peer_info()
52805274
.expect("Failed to get peer info");
52815275
assert_eq!(blocks_after, blocks_before);
5282-
assert_eq!(info_after, info_before);
5276+
assert_eq!(info_after.stacks_tip, info_before.stacks_tip);
52835277
// Ensure that the block was NOT accepted globally so the stacks tip has NOT advanced to N+1'
52845278
let nakamoto_blocks = test_observer::get_mined_nakamoto_blocks();
52855279
let block_n_1_prime = nakamoto_blocks.last().unwrap();

0 commit comments

Comments
 (0)