Skip to content

Commit 425ba9b

Browse files
committed
feat: ensure burn ops on included in tenure_change block
1 parent ced4577 commit 425ba9b

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,6 +4044,10 @@ fn burn_ops_integration_test() {
40444044
let stacker_sk_2 = Secp256k1PrivateKey::new();
40454045
let stacker_addr_2 = tests::to_addr(&stacker_sk_2);
40464046

4047+
let sender_sk = Secp256k1PrivateKey::new();
4048+
let sender_addr = tests::to_addr(&sender_sk);
4049+
let mut sender_nonce = 0;
4050+
40474051
let mut signers = TestSigners::new(vec![signer_sk_1.clone()]);
40484052

40494053
let stacker_sk = setup_stacker(&mut naka_conf);
@@ -4057,6 +4061,10 @@ fn burn_ops_integration_test() {
40574061
PrincipalData::from(stacker_addr_2.clone()).to_string(),
40584062
1000000,
40594063
);
4064+
naka_conf.add_initial_balance(
4065+
PrincipalData::from(sender_addr.clone()).to_string(),
4066+
100_000_000,
4067+
);
40604068

40614069
test_observer::spawn();
40624070
let observer_port = test_observer::EVENT_OBSERVER_PORT;
@@ -4426,7 +4434,8 @@ fn burn_ops_integration_test() {
44264434

44274435
info!("Submitted 2 stack STX ops at height {block_height}, mining a few blocks...");
44284436

4429-
// the second block should process the vote, after which the balances should be unchanged
4437+
// the second block should process the ops
4438+
// Also mine 2 interim blocks to ensure the stack-stx ops are not processed in them
44304439
for _i in 0..2 {
44314440
next_block_and_mine_commit(
44324441
&mut btc_regtest_controller,
@@ -4435,6 +4444,29 @@ fn burn_ops_integration_test() {
44354444
&commits_submitted,
44364445
)
44374446
.unwrap();
4447+
for interim_block_ix in 0..2 {
4448+
info!("Mining interim block {interim_block_ix}");
4449+
let blocks_processed_before = coord_channel
4450+
.lock()
4451+
.expect("Mutex poisoned")
4452+
.get_stacks_blocks_processed();
4453+
// submit a tx so that the miner will mine an extra block
4454+
let transfer_tx =
4455+
make_stacks_transfer(&sender_sk, sender_nonce, 200, &stacker_addr_1.into(), 10000);
4456+
sender_nonce += 1;
4457+
submit_tx(&http_origin, &transfer_tx);
4458+
4459+
loop {
4460+
let blocks_processed = coord_channel
4461+
.lock()
4462+
.expect("Mutex poisoned")
4463+
.get_stacks_blocks_processed();
4464+
if blocks_processed > blocks_processed_before {
4465+
break;
4466+
}
4467+
thread::sleep(Duration::from_millis(100));
4468+
}
4469+
}
44384470
}
44394471

44404472
let mut stack_stx_found = false;
@@ -4449,10 +4481,12 @@ fn burn_ops_integration_test() {
44494481
"stack event observer num transactions: {:?}",
44504482
transactions.len()
44514483
);
4452-
for tx in transactions.iter() {
4484+
let mut block_has_tenure_change = false;
4485+
for tx in transactions.iter().rev() {
44534486
let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap();
44544487
if raw_tx == "0x00" {
44554488
info!("Found a burn op: {:?}", tx);
4489+
assert!(block_has_tenure_change, "Block should have a tenure change");
44564490
let burnchain_op = tx.get("burnchain_op").unwrap().as_object().unwrap();
44574491
if burnchain_op.contains_key("transfer_stx") {
44584492
let transfer_stx_obj = burnchain_op.get("transfer_stx").unwrap();
@@ -4472,6 +4506,7 @@ fn burn_ops_integration_test() {
44724506
"Transfer STX op: sender: {}, recipient: {}, transfered_ustx: {}",
44734507
sender, recipient, transfered_ustx
44744508
);
4509+
assert!(!transfer_stx_found, "Transfer STX op should be unique");
44754510
transfer_stx_found = true;
44764511
continue;
44774512
}
@@ -4490,6 +4525,7 @@ fn burn_ops_integration_test() {
44904525
assert_eq!(sender, stacker_addr_2.to_string());
44914526
assert_eq!(delegate_to, stacker_addr_1.to_string());
44924527
assert_eq!(delegated_ustx, 100_000);
4528+
assert!(!delegate_stx_found, "Delegate STX op should be unique");
44934529
delegate_stx_found = true;
44944530
continue;
44954531
}
@@ -4529,8 +4565,16 @@ fn burn_ops_integration_test() {
45294565
.expect_result_ok()
45304566
.expect("Expected OK result for stack-stx op");
45314567

4568+
assert!(!stack_stx_found, "Stack STX op should be unique");
45324569
stack_stx_found = true;
45334570
stack_stx_burn_op_tx_count += 1;
4571+
} else {
4572+
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
4573+
let parsed =
4574+
StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap();
4575+
if let TransactionPayload::TenureChange(_tenure_change) = parsed.payload {
4576+
block_has_tenure_change = true;
4577+
}
45344578
}
45354579
}
45364580
}

0 commit comments

Comments
 (0)