Skip to content

Commit 30867bc

Browse files
committed
Cleanup tests
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent cda023e commit 30867bc

File tree

1 file changed

+47
-18
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+47
-18
lines changed

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

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ pub fn wait_for_block_acceptance_from_signers(
11661166
/// with the provided signer signature hash
11671167
pub fn wait_for_block_rejections_from_signers(
11681168
timeout_secs: u64,
1169+
signer_signature_hash: &Sha512Trunc256Sum,
11691170
expected_signers: &[StacksPublicKey],
11701171
) -> Result<Vec<BlockRejection>, String> {
11711172
let mut result = Vec::new();
@@ -1182,7 +1183,9 @@ pub fn wait_for_block_rejections_from_signers(
11821183
let rejected_pubkey = rejection
11831184
.recover_public_key()
11841185
.expect("Failed to recover public key from rejection");
1185-
if expected_signers.contains(&rejected_pubkey) {
1186+
if rejection.signer_signature_hash == *signer_signature_hash
1187+
&& expected_signers.contains(&rejected_pubkey)
1188+
{
11861189
Some((rejected_pubkey, rejection))
11871190
} else {
11881191
None
@@ -5566,8 +5569,12 @@ fn locally_accepted_blocks_overriden_by_global_rejection() {
55665569
let proposed_block_n_1 =
55675570
wait_for_block_proposal(30, info_before.stacks_tip_height + 1, &miner_pk)
55685571
.expect("Timed out waiting for block N+1' to be proposed");
5569-
wait_for_block_rejections_from_signers(short_timeout_secs, &rejecting_signers)
5570-
.expect("Timed out waiting for block rejection of N+1");
5572+
wait_for_block_rejections_from_signers(
5573+
short_timeout_secs,
5574+
&proposed_block_n_1.header.signer_signature_hash(),
5575+
&rejecting_signers,
5576+
)
5577+
.expect("Timed out waiting for block rejection of N+1");
55715578
let info_after = signer_test.get_peer_info();
55725579
assert_eq!(info_before, info_after);
55735580

@@ -5707,12 +5714,17 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
57075714
sender_nonce += 1;
57085715
info!("Submitted tx {tx} in to mine block N+1");
57095716
// The rejecting signers will reject the block, but it will still be accepted globally
5710-
wait_for_block_rejections_from_signers(short_timeout, &rejecting_signers)
5711-
.expect("Timed out waiting for block rejection of N+1");
57125717
let block_n_1 =
57135718
wait_for_block_pushed_by_miner_key(30, info_before.stacks_tip_height + 1, &miner_pk)
57145719
.expect("Timed out waiting for block N+1 to be mined");
57155720

5721+
wait_for_block_rejections_from_signers(
5722+
short_timeout,
5723+
&block_n_1.header.signer_signature_hash(),
5724+
&rejecting_signers,
5725+
)
5726+
.expect("Timed out waiting for block rejection of N+1");
5727+
57165728
// Assert the block was mined and the tip advanced to N+1
57175729
let info_after = signer_test.get_peer_info();
57185730
assert_eq!(info_after.stacks_tip, block_n_1.header.block_hash());
@@ -6062,8 +6074,14 @@ fn reorg_locally_accepted_blocks_across_tenures_fails() {
60626074
.running_nodes
60636075
.btc_regtest_controller
60646076
.build_next_block(1);
6065-
wait_for_block_rejections_from_signers(30, &non_ignoring_signers)
6066-
.expect("Timed out waiting for block rejections of N+1");
6077+
let proposal = wait_for_block_proposal(30, info_before.stacks_tip_height + 1, &miner_pk)
6078+
.expect("Timed out waiting for block N+1 to be proposed");
6079+
wait_for_block_rejections_from_signers(
6080+
30,
6081+
&proposal.header.signer_signature_hash(),
6082+
&non_ignoring_signers,
6083+
)
6084+
.expect("Timed out waiting for block rejections of N+1");
60676085

60686086
let info_after = signer_test.get_peer_info();
60696087
// Ensure that the block was NOT accepted globally so the stacks tip has NOT advanced to N+1'
@@ -7167,7 +7185,8 @@ fn block_validation_check_rejection_timeout_heuristic() {
71677185
None,
71687186
None,
71697187
);
7170-
7188+
let miner_sk = signer_test.running_nodes.conf.miner.mining_key.unwrap();
7189+
let miner_pk = StacksPublicKey::from_private(&miner_sk);
71717190
let all_signers: Vec<_> = signer_test
71727191
.signer_stacks_private_keys
71737192
.iter()
@@ -7179,6 +7198,7 @@ fn block_validation_check_rejection_timeout_heuristic() {
71797198
// note we just use mined nakamoto_blocks as the second block is not going to be confirmed
71807199

71817200
let mut test_rejections = |signer_split_index: usize, expected_timeout: u64| {
7201+
test_observer::clear();
71827202
let blocks_before = test_observer::get_mined_nakamoto_blocks().len();
71837203
let (ignore_signers, reject_signers) = all_signers.split_at(signer_split_index);
71847204

@@ -7187,14 +7207,23 @@ fn block_validation_check_rejection_timeout_heuristic() {
71877207
TEST_REJECT_ALL_BLOCK_PROPOSAL.set(reject_signers.to_vec());
71887208
TEST_IGNORE_ALL_BLOCK_PROPOSALS.set(ignore_signers.to_vec());
71897209

7210+
let height_before = signer_test.get_peer_info().stacks_tip_height;
71907211
next_block_and(
71917212
&mut signer_test.running_nodes.btc_regtest_controller,
71927213
30,
71937214
|| Ok(test_observer::get_mined_nakamoto_blocks().len() > blocks_before),
71947215
)
71957216
.unwrap();
71967217

7197-
wait_for_block_rejections_from_signers(timeout.as_secs(), &reject_signers).unwrap();
7218+
let proposal = wait_for_block_proposal(30, height_before + 1, &miner_pk)
7219+
.expect("Timed out waiting for block proposal");
7220+
7221+
wait_for_block_rejections_from_signers(
7222+
timeout.as_secs(),
7223+
&proposal.header.signer_signature_hash(),
7224+
&reject_signers,
7225+
)
7226+
.unwrap();
71987227

71997228
wait_for(60, || {
72007229
Ok(signer_test
@@ -7381,7 +7410,7 @@ fn block_validation_pending_table() {
73817410
.iter()
73827411
.map(|c| StacksPublicKey::from_private(&c.stacks_private_key))
73837412
.collect::<Vec<_>>();
7384-
wait_for_block_rejections_from_signers(30, &signer_keys)
7413+
wait_for_block_rejections_from_signers(30, &block.header.signer_signature_hash(), &signer_keys)
73857414
.expect("Timed out waiting for block rejections");
73867415

73877416
info!("------------------------- Shutdown -------------------------");
@@ -8607,7 +8636,7 @@ fn incoming_signers_ignore_block_proposals() {
86078636
signer_test.propose_block(block, short_timeout);
86088637
// Verify the signers rejected the second block via the endpoint
86098638
signer_test.wait_for_validate_reject_response(short_timeout, signer_signature_hash_2);
8610-
wait_for_block_rejections_from_signers(30, &all_signers)
8639+
wait_for_block_rejections_from_signers(30, &signer_signature_hash_2, &all_signers)
86118640
.expect("Timed out waiting for block rejections");
86128641
no_next_signer_messages();
86138642

@@ -8625,7 +8654,7 @@ fn incoming_signers_ignore_block_proposals() {
86258654
///
86268655
/// Test Execution:
86278656
/// The node mines to the next reward cycle.
8628-
/// Sends a status request to the signers to ensure both the current and previous reward cycle signers are active.
8657+
/// Sends a status request to the signers to ensure both the current and previoustimeout_heur reward cycle signers are active.
86298658
/// A valid Nakamoto block is proposed.
86308659
/// Two invalid Nakamoto blocks are proposed.
86318660
///
@@ -11617,10 +11646,10 @@ fn mark_miner_as_invalid_if_reorg_is_rejected() {
1161711646
let signer_signature_hash = block_n_1_prime.header.signer_signature_hash();
1161811647
wait_for_block_acceptance_from_signers(30, &signer_signature_hash, &approving_signers)
1161911648
.expect("Timed out waiting for block acceptance from approving signers");
11620-
let rejections = wait_for_block_rejections_from_signers(30, &rejecting_signers)
11621-
.expect("Timed out waiting for block rejection from rejecting signers");
11649+
let rejections =
11650+
wait_for_block_rejections_from_signers(30, &signer_signature_hash, &rejecting_signers)
11651+
.expect("Timed out waiting for block rejection from rejecting signers");
1162211652
for rejection in rejections {
11623-
assert_eq!(rejection.signer_signature_hash, signer_signature_hash);
1162411653
assert_eq!(
1162511654
rejection.response_data.reject_reason,
1162611655
RejectReason::ReorgNotAllowed,
@@ -11638,10 +11667,10 @@ fn mark_miner_as_invalid_if_reorg_is_rejected() {
1163811667
info!("------------------------- Wait for 5 rejections -------------------------");
1163911668

1164011669
let signer_signature_hash = block_n_1_prime.header.signer_signature_hash();
11641-
let rejections = wait_for_block_rejections_from_signers(30, &all_signers)
11642-
.expect("Timed out waiting for block rejection from all signers");
11670+
let rejections =
11671+
wait_for_block_rejections_from_signers(30, &signer_signature_hash, &all_signers)
11672+
.expect("Timed out waiting for block rejection from all signers");
1164311673
for rejection in rejections {
11644-
assert_eq!(rejection.signer_signature_hash, signer_signature_hash);
1164511674
assert!(
1164611675
rejection.response_data.reject_reason == RejectReason::ReorgNotAllowed
1164711676
|| rejection.response_data.reject_reason == RejectReason::InvalidMiner

0 commit comments

Comments
 (0)