Skip to content

Commit ace1656

Browse files
committed
increase_nonce_for_tx panics if address doesn't exist
1 parent 89beb51 commit ace1656

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

stackslib/src/chainstate/tests/consensus.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,21 @@ impl TestTxFactory {
414414
///
415415
/// * `tx_spec` - The original specification of the transaction whose sender's
416416
/// nonce should be incremented.
417+
///
418+
/// # Panics
419+
///
420+
/// Panics if the sender's address is not found in the nonce counter map.
417421
pub fn increase_nonce_for_tx(&mut self, tx_spec: &TestTxSpec) {
418422
let sender_privk = match tx_spec {
419423
TestTxSpec::Transfer { from, .. } => from,
420424
TestTxSpec::ContractDeploy { sender, .. } => sender,
421425
TestTxSpec::ContractCall { sender, .. } => sender,
422426
};
423427
let address = StacksAddress::p2pkh(false, &StacksPublicKey::from_private(sender_privk));
424-
let nonce = self.nonce_counter.entry(address).or_insert(0);
428+
let nonce = self
429+
.nonce_counter
430+
.get_mut(&address)
431+
.unwrap_or_else(|| panic!("Nonce not found for address {address}"));
425432
*nonce += 1;
426433
}
427434

0 commit comments

Comments
 (0)