Skip to content

Commit 21af655

Browse files
committed
test: add tenure_extend_cost_threshold integration test
Also update the configs in other tests so that they do not need to wait for the default tenure extend threshold.
1 parent 8803ff1 commit 21af655

File tree

1 file changed

+116
-3
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+116
-3
lines changed

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

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,9 @@ fn tenure_extend_after_idle_signers() {
26302630
|config| {
26312631
config.tenure_idle_timeout = idle_timeout;
26322632
},
2633-
|_| {},
2633+
|config| {
2634+
config.miner.tenure_extend_cost_threshold = 0;
2635+
},
26342636
None,
26352637
None,
26362638
);
@@ -2680,7 +2682,9 @@ fn tenure_extend_with_other_transactions() {
26802682
|config| {
26812683
config.tenure_idle_timeout = idle_timeout;
26822684
},
2683-
|_| {},
2685+
|config| {
2686+
config.miner.tenure_extend_cost_threshold = 0;
2687+
},
26842688
None,
26852689
None,
26862690
);
@@ -2787,6 +2791,7 @@ fn tenure_extend_after_idle_miner() {
27872791
},
27882792
|config| {
27892793
config.miner.tenure_timeout = miner_idle_timeout;
2794+
config.miner.tenure_extend_cost_threshold = 0;
27902795
},
27912796
None,
27922797
None,
@@ -2863,6 +2868,7 @@ fn tenure_extend_succeeds_after_rejected_attempt() {
28632868
},
28642869
|config| {
28652870
config.miner.tenure_timeout = miner_idle_timeout;
2871+
config.miner.tenure_extend_cost_threshold = 0;
28662872
},
28672873
None,
28682874
None,
@@ -2951,7 +2957,9 @@ fn stx_transfers_dont_effect_idle_timeout() {
29512957
|config| {
29522958
config.tenure_idle_timeout = idle_timeout;
29532959
},
2954-
|_| {},
2960+
|config| {
2961+
config.miner.tenure_extend_cost_threshold = 0;
2962+
},
29552963
None,
29562964
None,
29572965
);
@@ -3085,6 +3093,7 @@ fn idle_tenure_extend_active_mining() {
30853093
|config| {
30863094
// accept all proposals in the node
30873095
config.connection_options.block_proposal_max_age_secs = u64::MAX;
3096+
config.miner.tenure_extend_cost_threshold = 0;
30883097
},
30893098
None,
30903099
None,
@@ -12592,3 +12601,107 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1259212601
run_loop_2_thread.join().unwrap();
1259312602
signer_test.shutdown();
1259412603
}
12604+
12605+
#[test]
12606+
#[ignore]
12607+
/// This test verifies that a miner will produce a TenureExtend transaction
12608+
/// only after it has reached the cost threshold.
12609+
fn tenure_extend_cost_threshold() {
12610+
if env::var("BITCOIND_TEST") != Ok("1".into()) {
12611+
return;
12612+
}
12613+
12614+
let deployer_sk = Secp256k1PrivateKey::random();
12615+
let deployer_addr = tests::to_addr(&deployer_sk);
12616+
let num_txs = 10;
12617+
let tx_fee = 10000;
12618+
let deploy_fee = 190200;
12619+
12620+
info!("------------------------- Test Setup -------------------------");
12621+
let num_signers = 5;
12622+
let idle_timeout = Duration::from_secs(10);
12623+
let mut signer_test: SignerTest<SpawnedSigner> = SignerTest::new_with_config_modifications(
12624+
num_signers,
12625+
vec![(deployer_addr, deploy_fee + tx_fee * num_txs)],
12626+
|config| {
12627+
config.tenure_idle_timeout = idle_timeout;
12628+
},
12629+
|config| {
12630+
config.miner.tenure_extend_cost_threshold = 5;
12631+
},
12632+
None,
12633+
None,
12634+
);
12635+
let naka_conf = signer_test.running_nodes.conf.clone();
12636+
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
12637+
12638+
signer_test.boot_to_epoch_3();
12639+
12640+
info!("---- Nakamoto booted, starting test ----");
12641+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
12642+
12643+
info!("---- Waiting for a tenure extend ----");
12644+
12645+
// Now, wait for a block with a tenure extend
12646+
wait_for(idle_timeout.as_secs() + 10, || {
12647+
Ok(last_block_contains_tenure_change_tx(
12648+
TenureChangeCause::Extended,
12649+
))
12650+
})
12651+
.expect_err("Received a tenure extend before cost threshold was reached");
12652+
12653+
// Now deploy a contract and call it in order to cross the threshold.
12654+
let contract_src = format!(
12655+
r#"
12656+
(define-data-var my-var uint u0)
12657+
(define-public (f) (begin {} (ok 1))) (begin (f))
12658+
"#,
12659+
["(var-get my-var)"; 250].join(" ")
12660+
);
12661+
12662+
// First, lets deploy the contract
12663+
let mut nonce = 0;
12664+
let contract_tx = make_contract_publish(
12665+
&deployer_sk,
12666+
nonce,
12667+
deploy_fee,
12668+
naka_conf.burnchain.chain_id,
12669+
"small-contract",
12670+
&contract_src,
12671+
);
12672+
submit_tx(&http_origin, &contract_tx);
12673+
nonce += 1;
12674+
12675+
// Wait for the contract to be included in a block
12676+
wait_for(60, || {
12677+
let account = get_account(&http_origin, &deployer_addr);
12678+
Ok(account.nonce == nonce)
12679+
})
12680+
.expect("Contract not included in block");
12681+
12682+
// Now, lets call the contract a bunch of times to increase the tenure cost
12683+
for _ in 0..num_txs {
12684+
let call_tx = make_contract_call(
12685+
&deployer_sk,
12686+
nonce,
12687+
tx_fee,
12688+
naka_conf.burnchain.chain_id,
12689+
&deployer_addr,
12690+
"small-contract",
12691+
"f",
12692+
&[],
12693+
);
12694+
submit_tx(&http_origin, &call_tx);
12695+
nonce += 1;
12696+
}
12697+
12698+
// Now, wait for a block with a tenure extend
12699+
wait_for(idle_timeout.as_secs() + 10, || {
12700+
Ok(last_block_contains_tenure_change_tx(
12701+
TenureChangeCause::Extended,
12702+
))
12703+
})
12704+
.expect("Timed out waiting for a block with a tenure extend");
12705+
12706+
signer_test.shutdown();
12707+
}

0 commit comments

Comments
 (0)