Skip to content

Commit

Permalink
fix test build
Browse files Browse the repository at this point in the history
  • Loading branch information
kantai committed Jan 14, 2025
1 parent 52b2f68 commit 57d796b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
8 changes: 5 additions & 3 deletions stacks-signer/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub(crate) mod tests {
use stacks_common::util::hash::{Hash160, Sha256Sum};

use super::*;
use crate::config::{GlobalConfig, SignerConfig};
use crate::config::{GlobalConfig, SignerConfig, SignerConfigMode};

pub struct MockServerClient {
pub server: TcpListener,
Expand Down Expand Up @@ -393,8 +393,10 @@ pub(crate) mod tests {
}
SignerConfig {
reward_cycle,
signer_id: 0,
signer_slot_id: SignerSlotID(rand::thread_rng().gen_range(0..num_signers)), // Give a random signer slot id between 0 and num_signers
signer_mode: SignerConfigMode::Normal {
signer_id: 0,
signer_slot_id: SignerSlotID(rand::thread_rng().gen_range(0..num_signers)), // Give a random signer slot id between 0 and num_signers
},
signer_entries: SignerEntries {
signer_addr_to_id,
signer_id_to_pk,
Expand Down
20 changes: 19 additions & 1 deletion stacks-signer/src/client/stackerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,25 @@ impl<M: MessageSlotID + 'static> From<&SignerConfig> for StackerDB<M> {
}

impl<M: MessageSlotID + 'static> StackerDB<M> {
/// Create a new StackerDB client running in normal operation
#[cfg(any(test, feature = "testing"))]
/// Create a StackerDB client in normal operation (i.e., not a dry-run signer)
pub fn new_normal(
host: &str,
stacks_private_key: StacksPrivateKey,
is_mainnet: bool,
reward_cycle: u64,
signer_slot_id: SignerSlotID,
) -> Self {
Self::new(
host,
stacks_private_key,
is_mainnet,
reward_cycle,
StackerDBMode::Normal { signer_slot_id },
)
}

/// Create a new StackerDB client
fn new(
host: &str,
stacks_private_key: StacksPrivateKey,
Expand Down
20 changes: 3 additions & 17 deletions testnet/stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020-2024 Stacks Open Internet Foundation
// Copyright (C) 2020-2025 Stacks Open Internet Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -15,20 +15,6 @@
mod v0;

use std::collections::HashSet;
// Copyright (C) 2020-2024 Stacks Open Internet Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
Expand Down Expand Up @@ -696,7 +682,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp

/// Get the latest block response from the given slot
pub fn get_latest_block_response(&self, slot_id: u32) -> BlockResponse {
let mut stackerdb = StackerDB::new(
let mut stackerdb = StackerDB::new_normal(
&self.running_nodes.conf.node.rpc_bind,
StacksPrivateKey::new(), // We are just reading so don't care what the key is
false,
Expand Down Expand Up @@ -764,7 +750,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
private_key: &StacksPrivateKey,
reward_cycle: u64,
) {
let mut stackerdb = StackerDB::new(
let mut stackerdb = StackerDB::new_normal(
&self.running_nodes.conf.node.rpc_bind,
private_key.clone(),
false,
Expand Down
8 changes: 4 additions & 4 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3304,7 +3304,7 @@ fn empty_sortition() {

info!("------------------------- Test Delayed Block is Rejected -------------------------");
let reward_cycle = signer_test.get_current_reward_cycle();
let mut stackerdb = StackerDB::new(
let mut stackerdb = StackerDB::new_normal(
&signer_test.running_nodes.conf.node.rpc_bind,
StacksPrivateKey::new(), // We are just reading so don't care what the key is
false,
Expand Down Expand Up @@ -10157,7 +10157,7 @@ fn incoming_signers_ignore_block_proposals() {
.expect("Timed out waiting for a block to be mined");

let blocks_before = mined_blocks.load(Ordering::SeqCst);
let mut stackerdb = StackerDB::new(
let mut stackerdb = StackerDB::new_normal(
&signer_test.running_nodes.conf.node.rpc_bind,
StacksPrivateKey::new(), // We are just reading so don't care what the key is
false,
Expand Down Expand Up @@ -10332,7 +10332,7 @@ fn outgoing_signers_ignore_block_proposals() {
.unwrap()
.signer_signature_hash;
let blocks_before = mined_blocks.load(Ordering::SeqCst);
let mut stackerdb = StackerDB::new(
let mut stackerdb = StackerDB::new_normal(
&signer_test.running_nodes.conf.node.rpc_bind,
StacksPrivateKey::new(), // We are just reading so don't care what the key is
false,
Expand Down Expand Up @@ -10733,7 +10733,7 @@ fn injected_signatures_are_ignored_across_boundaries() {

// The first 50% of the signers are the ones that are ignoring block proposals and thus haven't sent a signature yet
let forced_signer = &signer_test.signer_stacks_private_keys[ignoring_signers.len()];
let mut stackerdb = StackerDB::new(
let mut stackerdb = StackerDB::new_normal(
&signer_test.running_nodes.conf.node.rpc_bind,
forced_signer.clone(),
false,
Expand Down

0 comments on commit 57d796b

Please sign in to comment.