Skip to content

Commit 1deecd0

Browse files
committed
refactored testing
1 parent 980ccb1 commit 1deecd0

File tree

1 file changed

+39
-30
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+39
-30
lines changed

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

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -759,39 +759,43 @@ impl MultipleMinerTest {
759759
Ok(txid)
760760
}
761761

762-
pub fn send_contract_publish(&mut self, contract_name: &str, contract_src: &str) -> String {
763-
let http_origin = format!(
764-
"http://{}",
765-
&self.signer_test.running_nodes.conf.node.rpc_bind
766-
);
762+
pub fn send_contract_publish(
763+
&mut self,
764+
sender_nonce: u64,
765+
contract_name: &str,
766+
contract_src: &str,
767+
) -> String {
768+
let http_origin = self.node_http();
769+
let sender_addr = tests::to_addr(&self.sender_sk);
767770
let contract_tx = make_contract_publish(
768771
&self.sender_sk,
769-
self.sender_nonce,
772+
sender_nonce,
770773
self.send_fee + contract_name.len() as u64 + contract_src.len() as u64,
771774
self.signer_test.running_nodes.conf.burnchain.chain_id,
772775
contract_name,
773776
contract_src,
774777
);
775-
self.sender_nonce += 1;
776778
submit_tx(&http_origin, &contract_tx)
777779
}
778780

779781
/// Sends a contract publish tx to the stacks node and waits for the stacks node to mine it
780782
/// Returns the txid of the transfer tx.
781783
pub fn send_and_mine_contract_publish(
782784
&mut self,
785+
sender_nonce: u64,
783786
contract_name: &str,
784787
contract_src: &str,
785788
timeout_secs: u64,
786789
) -> Result<String, String> {
787790
let stacks_height_before = self.get_peer_stacks_tip_height();
788791

789-
let txid = self.send_contract_publish(contract_name, contract_src);
792+
let txid = self.send_contract_publish(sender_nonce, contract_name, contract_src);
790793

791794
// wait for the new block to be mined
792795
wait_for(timeout_secs, || {
793796
Ok(self.get_peer_stacks_tip_height() > stacks_height_before)
794-
})?;
797+
})
798+
.unwrap();
795799

796800
// wait for the observer to see it
797801
self.wait_for_test_observer_blocks(timeout_secs);
@@ -805,25 +809,22 @@ impl MultipleMinerTest {
805809

806810
pub fn send_contract_call(
807811
&mut self,
812+
sender_nonce: u64,
808813
contract_name: &str,
809814
function_name: &str,
810815
function_args: &[clarity::vm::Value],
811816
) -> String {
812-
let http_origin = format!(
813-
"http://{}",
814-
&self.signer_test.running_nodes.conf.node.rpc_bind
815-
);
817+
let http_origin = self.node_http();
816818
let contract_tx = make_contract_call(
817819
&self.sender_sk,
818-
self.sender_nonce,
820+
sender_nonce,
819821
self.send_fee,
820822
self.signer_test.running_nodes.conf.burnchain.chain_id,
821823
&tests::to_addr(&self.sender_sk),
822824
contract_name,
823825
function_name,
824826
function_args,
825827
);
826-
self.sender_nonce += 1;
827828
submit_tx(&http_origin, &contract_tx)
828829
}
829830

@@ -8232,7 +8233,7 @@ fn block_proposal_max_age_rejections() {
82328233
let short_timeout = Duration::from_secs(30);
82338234

82348235
info!("------------------------- Send Block Proposal To Signers -------------------------");
8235-
let info_before = get_chain_info(&signer_test.running_nodes.conf);
8236+
let _ = get_chain_info(&signer_test.running_nodes.conf);
82368237
let mut block = NakamotoBlock {
82378238
header: NakamotoBlockHeader::empty(),
82388239
txs: vec![],
@@ -8301,7 +8302,9 @@ fn block_proposal_max_age_rejections() {
83018302
.unwrap_or((0, 0));
83028303
assert_eq!(block_2_status.1, 0, "Block 2 should always be rejected");
83038304

8304-
info!("Block 2 status"; "accepted" => block_2_status.1, "rejected" => block_2_status.0);
8305+
info!("Block 2 status";
8306+
"accepted" => %block_2_status.1, "rejected" => %block_2_status.0
8307+
);
83058308
Ok(block_2_status.0 > num_signers * 7 / 10)
83068309
})
83078310
.expect("Timed out waiting for block rejections");
@@ -12474,19 +12477,25 @@ fn miner_rejection_by_contract_call_execution_time_expired() {
1247412477
// First, lets deploy the contract
1247512478
let dummy_contract_src = "(define-public (dummy (number uint)) (begin (ok (+ number u1))))";
1247612479

12480+
let sender_nonce = 0;
12481+
1247712482
let _ = miners
12478-
.send_and_mine_contract_publish("dummy-contract", dummy_contract_src, 60)
12483+
.send_and_mine_contract_publish(sender_nonce, "dummy-contract", dummy_contract_src, 60)
1247912484
.expect("Failed to publish contract in a new block");
1248012485

1248112486
info!("------------------------- Miner 1 Mines a Nakamoto Block N+1 -------------------------");
1248212487

1248312488
let stacks_height_before = miners.get_peer_stacks_tip_height();
1248412489

12485-
let tx1 = miners.send_transfer_tx();
12490+
let (tx1, sender_nonce) = miners.send_transfer_tx();
1248612491

1248712492
// try calling the contract (has to fail)
12488-
let contract_call_txid =
12489-
miners.send_contract_call("dummy-contract", "dummy", &[clarity::vm::Value::UInt(1)]);
12493+
let contract_call_txid = miners.send_contract_call(
12494+
sender_nonce + 1,
12495+
"dummy-contract",
12496+
"dummy",
12497+
&[clarity::vm::Value::UInt(1)],
12498+
);
1249012499

1249112500
let _ = wait_for(60, || {
1249212501
Ok(miners.get_peer_stacks_tip_height() > stacks_height_before)
@@ -12499,8 +12508,6 @@ fn miner_rejection_by_contract_call_execution_time_expired() {
1249912508

1250012509
info!("------------------------- Miner 1 Mines a Nakamoto Block N+2 -------------------------");
1250112510

12502-
miners.sender_nonce -= 1;
12503-
1250412511
let tx2 = miners
1250512512
.send_and_mine_transfer_tx(60)
1250612513
.expect("Failed to mine N + 2");
@@ -12523,8 +12530,12 @@ fn miner_rejection_by_contract_call_execution_time_expired() {
1252312530

1252412531
let stacks_height_before = miners.get_peer_stacks_tip_height();
1252512532

12526-
let contract_call_txid =
12527-
miners.send_contract_call("dummy-contract", "dummy", &[clarity::vm::Value::UInt(1)]);
12533+
let contract_call_txid = miners.send_contract_call(
12534+
sender_nonce + 2,
12535+
"dummy-contract",
12536+
"dummy",
12537+
&[clarity::vm::Value::UInt(1)],
12538+
);
1252812539

1252912540
let _ = wait_for_block_pushed_by_miner_key(30, stacks_height_before + 1, &miner_pk_2)
1253012541
.expect("Failed to get block N+3");
@@ -12607,10 +12618,10 @@ fn miner_rejection_by_contract_publish_execution_time_expired() {
1260712618
let dummy_contract_src =
1260812619
"(define-public (dummy (number uint)) (begin (ok (+ number u1))))(+ 1 1)";
1260912620

12610-
let tx1 = miners.send_transfer_tx();
12621+
let (tx1, sender_nonce) = miners.send_transfer_tx();
1261112622

1261212623
let _ = miners
12613-
.send_and_mine_contract_publish("dummy-contract", dummy_contract_src, 60)
12624+
.send_and_mine_contract_publish(sender_nonce + 1, "dummy-contract", dummy_contract_src, 60)
1261412625
.expect_err("Expected an error while publishing contract in a new block");
1261512626

1261612627
assert_eq!(last_block_contains_txid(&tx1), true);
@@ -12627,10 +12638,8 @@ fn miner_rejection_by_contract_publish_execution_time_expired() {
1262712638

1262812639
info!("------------------------- Miner 2 Mines Block N+1 -------------------------");
1262912640

12630-
miners.sender_nonce -= 1;
12631-
1263212641
let _ = miners
12633-
.send_and_mine_contract_publish("dummy-contract", dummy_contract_src, 60)
12642+
.send_and_mine_contract_publish(sender_nonce + 1, "dummy-contract", dummy_contract_src, 60)
1263412643
.expect("Failed to publish contract in a new block");
1263512644

1263612645
verify_sortition_winner(&sortdb, &miner_pkh_2);

0 commit comments

Comments
 (0)