@@ -94,7 +94,9 @@ use wsts::net::Message;
94
94
95
95
use super :: bitcoin_regtest:: BitcoinCoreController ;
96
96
use crate :: config:: { EventKeyType , EventObserverConfig , InitialBalance } ;
97
- use crate :: nakamoto_node:: miner:: { TEST_BLOCK_ANNOUNCE_STALL , TEST_BROADCAST_STALL } ;
97
+ use crate :: nakamoto_node:: miner:: {
98
+ TEST_BLOCK_ANNOUNCE_STALL , TEST_BROADCAST_STALL , TEST_MINE_STALL ,
99
+ } ;
98
100
use crate :: neon:: { Counters , RunLoopCounter } ;
99
101
use crate :: operations:: BurnchainOpSigner ;
100
102
use crate :: run_loop:: boot_nakamoto;
@@ -5074,6 +5076,7 @@ fn clarity_burn_state() {
5074
5076
let mut signers = TestSigners :: default ( ) ;
5075
5077
let ( mut naka_conf, _miner_account) = naka_neon_integration_conf ( None ) ;
5076
5078
let http_origin = format ! ( "http://{}" , & naka_conf. node. rpc_bind) ;
5079
+ // Increase the wait on interim blocks to prevent a stacks block being mined before we force it to be
5077
5080
naka_conf. miner . wait_on_interim_blocks = Duration :: from_secs ( 1 ) ;
5078
5081
let sender_sk = Secp256k1PrivateKey :: new ( ) ;
5079
5082
let sender_signer_sk = Secp256k1PrivateKey :: new ( ) ;
@@ -5185,21 +5188,68 @@ fn clarity_burn_state() {
5185
5188
vec ! [ & Value :: UInt ( burn_block_height) ] ,
5186
5189
) ;
5187
5190
result. expect_result_ok ( ) . expect ( "Read-only call failed" ) ;
5191
+
5192
+ // Pause mining to prevent the stacks block from being mined before the tenure change is processed
5193
+ TEST_MINE_STALL . lock ( ) . unwrap ( ) . replace ( true ) ;
5194
+ // Submit a tx for the next block (the next block will be a new tenure, so the burn block height will increment)
5195
+ let call_tx = tests:: make_contract_call (
5196
+ & sender_sk,
5197
+ sender_nonce,
5198
+ tx_fee,
5199
+ & sender_addr,
5200
+ contract_name,
5201
+ "bar" ,
5202
+ & [ Value :: UInt ( burn_block_height + 1 ) ] ,
5203
+ ) ;
5204
+ sender_nonce += 1 ;
5205
+ submit_tx ( & http_origin, & call_tx) ;
5188
5206
}
5189
5207
5190
5208
let commits_before = commits_submitted. load ( Ordering :: SeqCst ) ;
5191
- next_block_and_mine_commit (
5192
- & mut btc_regtest_controller,
5193
- 60 ,
5194
- & coord_channel,
5195
- & commits_submitted,
5196
- )
5209
+ let blocks_processed_before = coord_channel
5210
+ . lock ( )
5211
+ . expect ( "Mutex poisoned" )
5212
+ . get_stacks_blocks_processed ( ) ;
5213
+ next_block_and ( & mut btc_regtest_controller, 60 , || {
5214
+ Ok ( commits_submitted. load ( Ordering :: SeqCst ) > commits_before)
5215
+ } )
5216
+ . unwrap ( ) ;
5217
+ TEST_MINE_STALL . lock ( ) . unwrap ( ) . replace ( false ) ;
5218
+ wait_for ( 20 , || {
5219
+ Ok ( coord_channel
5220
+ . lock ( )
5221
+ . expect ( "Mutex poisoned" )
5222
+ . get_stacks_blocks_processed ( )
5223
+ > blocks_processed_before)
5224
+ } )
5197
5225
. unwrap ( ) ;
5198
5226
5199
5227
let info = get_chain_info ( & naka_conf) ;
5200
5228
burn_block_height = info. burn_block_height as u128 ;
5201
5229
info ! ( "Expecting burn block height to be {}" , burn_block_height) ;
5202
5230
5231
+ // Assert that the contract call was successful
5232
+ test_observer:: get_mined_nakamoto_blocks ( )
5233
+ . last ( )
5234
+ . unwrap ( )
5235
+ . tx_events
5236
+ . iter ( )
5237
+ . for_each ( |event| match event {
5238
+ TransactionEvent :: Success ( TransactionSuccessEvent { result, fee, .. } ) => {
5239
+ // Ignore coinbase and tenure transactions
5240
+ if * fee == 0 {
5241
+ return ;
5242
+ }
5243
+
5244
+ info ! ( "Contract call result: {}" , result) ;
5245
+ result. clone ( ) . expect_result_ok ( ) . expect ( "Ok result" ) ;
5246
+ }
5247
+ _ => {
5248
+ info ! ( "Unsuccessful event: {:?}" , event) ;
5249
+ panic ! ( "Expected a successful transaction" ) ;
5250
+ }
5251
+ } ) ;
5252
+
5203
5253
// mine the interim blocks
5204
5254
for interim_block_ix in 0 ..inter_blocks_per_tenure {
5205
5255
info ! ( "Mining interim block {interim_block_ix}" ) ;
0 commit comments