Skip to content

Commit 3be2cfb

Browse files
committed
test: make sure to sign block proposals submitted manually in tests
1 parent 328d946 commit 3be2cfb

File tree

1 file changed

+46
-0
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ impl SignerTest<SpawnedSigner> {
398398
}
399399
}
400400

401+
fn get_miner_key(&self) -> &Secp256k1PrivateKey {
402+
self.running_nodes.conf.miner.mining_key.as_ref().unwrap()
403+
}
404+
401405
/// Propose a block to the signers
402406
fn propose_block(&mut self, block: NakamotoBlock, timeout: Duration) {
403407
let miners_contract_id = boot_code_id(MINERS_NAME, false);
@@ -409,6 +413,9 @@ impl SignerTest<SpawnedSigner> {
409413
.get_headers_height();
410414
let reward_cycle = self.get_current_reward_cycle();
411415
let signer_signature_hash = block.header.signer_signature_hash();
416+
let signed_by = block.header.recover_miner_pk().expect(
417+
"FATAL: signer tests should only propose blocks that have been signed by the signer test miner. Otherwise, signers won't even consider them via this channel."
418+
);
412419
let message = SignerMessage::BlockProposal(BlockProposal {
413420
block,
414421
burn_height,
@@ -421,6 +428,9 @@ impl SignerTest<SpawnedSigner> {
421428
.miner
422429
.mining_key
423430
.expect("No mining key");
431+
assert_eq!(signed_by, Secp256k1PublicKey::from_private(&miner_sk),
432+
"signer tests should only propose blocks that have been signed by the signer test miner. Otherwise, signers won't even consider them via this channel.");
433+
424434
// Submit the block proposal to the miner's slot
425435
let mut accepted = false;
426436
let mut version = 0;
@@ -1258,6 +1268,10 @@ fn block_proposal_rejection() {
12581268

12591269
// First propose a block to the signers that does not have the correct consensus hash or BitVec. This should be rejected BEFORE
12601270
// the block is submitted to the node for validation.
1271+
block
1272+
.header
1273+
.sign_miner(signer_test.get_miner_key())
1274+
.unwrap();
12611275
let block_signer_signature_hash_1 = block.header.signer_signature_hash();
12621276
signer_test.propose_block(block.clone(), short_timeout);
12631277

@@ -1270,6 +1284,10 @@ fn block_proposal_rejection() {
12701284
block.header.consensus_hash = view.cur_sortition.consensus_hash;
12711285
block.header.chain_length = 35; // We have mined 35 blocks so far.
12721286

1287+
block
1288+
.header
1289+
.sign_miner(signer_test.get_miner_key())
1290+
.unwrap();
12731291
let block_signer_signature_hash_2 = block.header.signer_signature_hash();
12741292
signer_test.propose_block(block, short_timeout);
12751293

@@ -7193,6 +7211,10 @@ fn block_validation_response_timeout() {
71937211
block.header.consensus_hash = view.cur_sortition.consensus_hash;
71947212
block.header.chain_length = info_before.stacks_tip_height + 1;
71957213

7214+
block
7215+
.header
7216+
.sign_miner(signer_test.get_miner_key())
7217+
.unwrap();
71967218
let block_signer_signature_hash_1 = block.header.signer_signature_hash();
71977219
signer_test.propose_block(block, timeout);
71987220

@@ -7478,6 +7500,10 @@ fn block_validation_pending_table() {
74787500
block.header.pox_treatment = BitVec::ones(1).unwrap();
74797501
block.header.consensus_hash = view.cur_sortition.consensus_hash;
74807502
block.header.chain_length = peer_info.stacks_tip_height + 1;
7503+
block
7504+
.header
7505+
.sign_miner(signer_test.get_miner_key())
7506+
.unwrap();
74817507
let block_signer_signature_hash = block.header.signer_signature_hash();
74827508
signer_test.propose_block(block.clone(), short_timeout);
74837509

@@ -8135,11 +8161,19 @@ fn block_proposal_max_age_rejections() {
81358161
.block_proposal_max_age_secs
81368162
.saturating_add(1),
81378163
);
8164+
block
8165+
.header
8166+
.sign_miner(signer_test.get_miner_key())
8167+
.unwrap();
81388168
let block_signer_signature_hash_1 = block.header.signer_signature_hash();
81398169
signer_test.propose_block(block.clone(), short_timeout);
81408170

81418171
// Next propose a recent invalid block
81428172
block.header.timestamp = get_epoch_time_secs();
8173+
block
8174+
.header
8175+
.sign_miner(signer_test.get_miner_key())
8176+
.unwrap();
81438177
let block_signer_signature_hash_2 = block.header.signer_signature_hash();
81448178
signer_test.propose_block(block, short_timeout);
81458179

@@ -8740,6 +8774,10 @@ fn incoming_signers_ignore_block_proposals() {
87408774
txs: vec![],
87418775
};
87428776
block.header.timestamp = get_epoch_time_secs();
8777+
block
8778+
.header
8779+
.sign_miner(signer_test.get_miner_key())
8780+
.unwrap();
87438781
let signer_signature_hash_1 = block.header.signer_signature_hash();
87448782

87458783
info!("------------------------- Test Attempt to Mine Invalid Block {signer_signature_hash_1} -------------------------");
@@ -8758,6 +8796,10 @@ fn incoming_signers_ignore_block_proposals() {
87588796
block.header.consensus_hash = view.cur_sortition.consensus_hash;
87598797
block.header.chain_length =
87608798
get_chain_info(&signer_test.running_nodes.conf).stacks_tip_height + 1;
8799+
block
8800+
.header
8801+
.sign_miner(signer_test.get_miner_key())
8802+
.unwrap();
87618803
let signer_signature_hash_2 = block.header.signer_signature_hash();
87628804

87638805
info!("------------------------- Test Attempt to Mine Invalid Block {signer_signature_hash_2} -------------------------");
@@ -8926,6 +8968,10 @@ fn outgoing_signers_ignore_block_proposals() {
89268968
block.header.consensus_hash = view.cur_sortition.consensus_hash;
89278969
block.header.chain_length =
89288970
get_chain_info(&signer_test.running_nodes.conf).stacks_tip_height + 1;
8971+
block
8972+
.header
8973+
.sign_miner(signer_test.get_miner_key())
8974+
.unwrap();
89298975
let signer_signature_hash = block.header.signer_signature_hash();
89308976

89318977
info!("------------------------- Test Attempt to Mine Invalid Block {signer_signature_hash} -------------------------");

0 commit comments

Comments
 (0)