@@ -5159,6 +5159,37 @@ fn continue_after_fast_block_no_sortition() {
5159
5159
let rl1_commits = signer_test. running_nodes . commits_submitted . clone ( ) ;
5160
5160
let blocks_mined1 = signer_test. running_nodes . nakamoto_blocks_mined . clone ( ) ;
5161
5161
5162
+ // Some helper functions for verifying the blocks contain their expected transactions
5163
+ let verify_last_block_contains_tenure_change_tx = |cause : TenureChangeCause | {
5164
+ let blocks = test_observer:: get_blocks ( ) ;
5165
+ let tenure_change_tx = & blocks. last ( ) . unwrap ( ) ;
5166
+ let transactions = tenure_change_tx[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5167
+ let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5168
+ let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5169
+ let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5170
+ let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5171
+ match & parsed. payload {
5172
+ TransactionPayload :: TenureChange ( payload) => {
5173
+ assert_eq ! ( payload. cause, cause) ;
5174
+ }
5175
+ _ => panic ! ( "Expected tenure change transaction, got {parsed:?}" ) ,
5176
+ } ;
5177
+ } ;
5178
+
5179
+ let verify_last_block_contains_transfer_tx = || {
5180
+ let blocks = test_observer:: get_blocks ( ) ;
5181
+ let tenure_change_tx = & blocks. last ( ) . unwrap ( ) ;
5182
+ let transactions = tenure_change_tx[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5183
+ let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5184
+ let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5185
+ let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5186
+ let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5187
+ assert ! (
5188
+ matches!( parsed. payload, TransactionPayload :: TokenTransfer ( _, _, _) ) ,
5189
+ "Expected token transfer transaction, got {parsed:?}"
5190
+ ) ;
5191
+ } ;
5192
+
5162
5193
info ! ( "------------------------- Pause Miner 2's Block Commits -------------------------" ) ;
5163
5194
5164
5195
// Make sure Miner 2 cannot win a sortition at first.
@@ -5254,19 +5285,7 @@ fn continue_after_fast_block_no_sortition() {
5254
5285
} )
5255
5286
. unwrap ( ) ;
5256
5287
5257
- let blocks = test_observer:: get_blocks ( ) ;
5258
- let tenure_change_tx = & blocks. last ( ) . unwrap ( ) ;
5259
- let transactions = tenure_change_tx[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5260
- let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5261
- let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5262
- let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5263
- let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5264
- match & parsed. payload {
5265
- TransactionPayload :: TenureChange ( payload) => {
5266
- assert_eq ! ( payload. cause, TenureChangeCause :: BlockFound ) ;
5267
- }
5268
- _ => panic ! ( "Expected tenure change transaction, got {parsed:?}" ) ,
5269
- } ;
5288
+ verify_last_block_contains_tenure_change_tx ( TenureChangeCause :: BlockFound ) ;
5270
5289
5271
5290
info ! ( "------------------------- Make Signers Reject All Subsequent Proposals -------------------------" ) ;
5272
5291
@@ -5303,6 +5322,7 @@ fn continue_after_fast_block_no_sortition() {
5303
5322
rl2_skip_commit_op. set ( true ) ;
5304
5323
5305
5324
let burn_height_before = get_burn_height ( ) ;
5325
+
5306
5326
info ! ( "------------------------- Miner 2 Mines an Empty Tenure B -------------------------" ;
5307
5327
"burn_height_before" => burn_height_before,
5308
5328
"rejections_before" => rejections_before,
@@ -5418,25 +5438,11 @@ fn continue_after_fast_block_no_sortition() {
5418
5438
info ! (
5419
5439
"------------------------- Verify Tenure Change Tx in Miner B's Block N -------------------------"
5420
5440
) ;
5421
-
5422
- let blocks = test_observer:: get_blocks ( ) ;
5423
- assert_eq ! ( blocks. len( ) , nmb_old_blocks + 1 , ) ;
5424
- let tenure_change_block = & blocks. last ( ) . unwrap ( ) ;
5425
- let transactions = tenure_change_block[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5426
- let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5427
- let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5428
- let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5429
- let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5430
- match & parsed. payload {
5431
- TransactionPayload :: TenureChange ( payload) => {
5432
- assert_eq ! ( payload. cause, TenureChangeCause :: BlockFound ) ;
5433
- }
5434
- _ => panic ! ( "Expected tenure change transaction, got {parsed:?}" ) ,
5435
- } ;
5441
+ verify_last_block_contains_tenure_change_tx ( TenureChangeCause :: BlockFound ) ;
5436
5442
5437
5443
info ! ( "------------------------- Wait for Miner B's Block N+1 -------------------------" ) ;
5438
5444
5439
- let nmb_old_blocks = blocks . len ( ) ;
5445
+ let nmb_old_blocks = test_observer :: get_blocks ( ) . len ( ) ;
5440
5446
let blocks_processed_before_2 = blocks_mined2. load ( Ordering :: SeqCst ) ;
5441
5447
let stacks_height_before = signer_test
5442
5448
. stacks_client
@@ -5472,22 +5478,10 @@ fn continue_after_fast_block_no_sortition() {
5472
5478
5473
5479
info ! ( "------------------------- Verify Miner B's Block N+1 -------------------------" ) ;
5474
5480
5475
- let blocks = test_observer:: get_blocks ( ) ;
5476
- assert_eq ! ( blocks. len( ) , nmb_old_blocks + 1 , ) ;
5477
- let tenure_extend_block = blocks. last ( ) . unwrap ( ) ;
5478
- let transactions = tenure_extend_block[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5479
- let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5480
- let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5481
- let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5482
- let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5483
- assert ! (
5484
- matches!( parsed. payload, TransactionPayload :: TokenTransfer ( _, _, _) ) ,
5485
- "Expected Token Transfer Transaction. Got {:?}" ,
5486
- parsed. payload
5487
- ) ;
5481
+ verify_last_block_contains_transfer_tx ( ) ;
5488
5482
5489
5483
info ! ( "------------------------- Mine An Empty Sortition -------------------------" ) ;
5490
- let nmb_old_blocks = blocks . len ( ) ;
5484
+ let nmb_old_blocks = test_observer :: get_blocks ( ) . len ( ) ;
5491
5485
next_block_and (
5492
5486
& mut signer_test. running_nodes . btc_regtest_controller ,
5493
5487
60 ,
@@ -5500,20 +5494,7 @@ fn continue_after_fast_block_no_sortition() {
5500
5494
btc_blocks_mined += 1 ;
5501
5495
5502
5496
info ! ( "------------------------- Verify Miner B's Issues a Tenure Change Extend in Block N+2 -------------------------" ) ;
5503
- let blocks = test_observer:: get_blocks ( ) ;
5504
- assert_eq ! ( blocks. len( ) , nmb_old_blocks + 1 , ) ;
5505
- let tenure_extend_block = & blocks. last ( ) . unwrap ( ) ;
5506
- let transactions = tenure_extend_block[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5507
- let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5508
- let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5509
- let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5510
- let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5511
- match & parsed. payload {
5512
- TransactionPayload :: TenureChange ( payload) => {
5513
- assert_eq ! ( payload. cause, TenureChangeCause :: Extended ) ;
5514
- }
5515
- _ => panic ! ( "Expected tenure change transaction, got {parsed:?}" ) ,
5516
- } ;
5497
+ verify_last_block_contains_tenure_change_tx ( TenureChangeCause :: Extended ) ;
5517
5498
5518
5499
info ! ( "------------------------- Unpause Miner A's Block Commits -------------------------" ) ;
5519
5500
let commits_before_1 = rl1_commits. load ( Ordering :: SeqCst ) ;
@@ -5527,7 +5508,7 @@ fn continue_after_fast_block_no_sortition() {
5527
5508
. unwrap ( ) ;
5528
5509
5529
5510
info ! ( "------------------------- Run Miner A's Tenure -------------------------" ) ;
5530
- let nmb_old_blocks = blocks . len ( ) ;
5511
+ let nmb_old_blocks = test_observer :: get_blocks ( ) . len ( ) ;
5531
5512
let burn_height_before = get_burn_height ( ) ;
5532
5513
let blocks_processed_before_1 = blocks_mined1. load ( Ordering :: SeqCst ) ;
5533
5514
next_block_and (
@@ -5548,19 +5529,7 @@ fn continue_after_fast_block_no_sortition() {
5548
5529
assert_eq ! ( tip. miner_pk_hash. unwrap( ) , mining_pkh_1) ;
5549
5530
5550
5531
info ! ( "------------------------- Verify Miner A's Issued a Tenure Change in Block N+4 -------------------------" ) ;
5551
- let blocks = test_observer:: get_blocks ( ) ;
5552
- let tenure_change_tx = & blocks. last ( ) . unwrap ( ) ;
5553
- let transactions = tenure_change_tx[ "transactions" ] . as_array ( ) . unwrap ( ) ;
5554
- let tx = transactions. first ( ) . expect ( "No transactions in block" ) ;
5555
- let raw_tx = tx[ "raw_tx" ] . as_str ( ) . unwrap ( ) ;
5556
- let tx_bytes = hex_bytes ( & raw_tx[ 2 ..] ) . unwrap ( ) ;
5557
- let parsed = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) . unwrap ( ) ;
5558
- match & parsed. payload {
5559
- TransactionPayload :: TenureChange ( payload) => {
5560
- assert_eq ! ( payload. cause, TenureChangeCause :: BlockFound ) ;
5561
- }
5562
- _ => panic ! ( "Expected tenure change transaction, got {parsed:?}" ) ,
5563
- } ;
5532
+ verify_last_block_contains_tenure_change_tx ( TenureChangeCause :: BlockFound ) ;
5564
5533
5565
5534
info ! (
5566
5535
"------------------------- Confirm Burn and Stacks Block Heights -------------------------"
0 commit comments