Skip to content

Commit f78c778

Browse files
committed
test: add TestPeer coverage for get-block-info?
* add support to TestPeer for changing network_id/chain_id * test get-block-info? behavior in Clarity1 with primary testnet chain id and a different chain id
1 parent 01694b7 commit f78c778

File tree

7 files changed

+614
-25
lines changed

7 files changed

+614
-25
lines changed

stackslib/src/burnchains/tests/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ pub struct TestMiner {
123123
pub nonce: u64,
124124
pub spent_at_nonce: HashMap<u64, u128>, // how much uSTX this miner paid in a given tx's nonce
125125
pub test_with_tx_fees: bool, // set to true to make certain helper methods attach a pre-defined tx fee
126+
pub chain_id: u32,
126127
}
127128

128129
pub struct TestMinerFactory {
129130
pub key_seed: [u8; 32],
130131
pub next_miner_id: usize,
132+
pub chain_id: u32,
131133
}
132134

133135
impl TestMiner {
@@ -136,6 +138,7 @@ impl TestMiner {
136138
privks: &Vec<StacksPrivateKey>,
137139
num_sigs: u16,
138140
hash_mode: &AddressHashMode,
141+
chain_id: u32,
139142
) -> TestMiner {
140143
TestMiner {
141144
burnchain: burnchain.clone(),
@@ -150,6 +153,7 @@ impl TestMiner {
150153
nonce: 0,
151154
spent_at_nonce: HashMap::new(),
152155
test_with_tx_fees: true,
156+
chain_id,
153157
}
154158
}
155159

@@ -314,15 +318,7 @@ impl TestMinerFactory {
314318
TestMinerFactory {
315319
key_seed: [0u8; 32],
316320
next_miner_id: 1,
317-
}
318-
}
319-
320-
pub fn from_u16(seed: u16) -> TestMinerFactory {
321-
let mut bytes = [0u8; 32];
322-
(&mut bytes[0..2]).copy_from_slice(&seed.to_be_bytes());
323-
TestMinerFactory {
324-
key_seed: bytes,
325-
next_miner_id: seed as usize,
321+
chain_id: CHAIN_ID_TESTNET,
326322
}
327323
}
328324

@@ -346,7 +342,7 @@ impl TestMinerFactory {
346342
}
347343

348344
test_debug!("New miner: {:?} {}:{:?}", &hash_mode, num_sigs, &keys);
349-
let mut m = TestMiner::new(burnchain, &keys, num_sigs, &hash_mode);
345+
let mut m = TestMiner::new(burnchain, &keys, num_sigs, &hash_mode, self.chain_id);
350346
m.id = self.next_miner_id;
351347
self.next_miner_id += 1;
352348
m

0 commit comments

Comments
 (0)