Skip to content

Commit

Permalink
chore: move test
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Oct 18, 2024
1 parent 23057d9 commit e272540
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4867,44 +4867,6 @@ fn burn_ops_integration_test() {
);
assert!(transfer_stx_found, "Expected transfer STX op");

let mut last_tenture_height = 0;
for block in blocks.iter() {
let transactions = block.get("transactions").unwrap().as_array().unwrap();
let mut block_has_tenure_change = false;
for tx in transactions.iter().rev() {
let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap();
if raw_tx != "0x00" {
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
let parsed =
StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap();
if let TransactionPayload::TenureChange(_tenure_change) = parsed.payload {
block_has_tenure_change = true;
continue;
}
}
}
// if `signer_bitvec` is set on a block, then it's a nakamoto block
let is_nakamoto_block = block.get("signer_bitvec").is_some();

let tenure_height = block.get("tenure_height").unwrap().as_u64().unwrap();
let block_height = block.get("block_height").unwrap().as_u64().unwrap();

if is_nakamoto_block {
if block_has_tenure_change {
// tenure change block should have tenure height 1 more than the last tenure height
assert_eq!(last_tenture_height + 1, tenure_height);
last_tenture_height = tenure_height;
} else {
// tenure extend block should have the same tenure height as the last tenure height
assert_eq!(last_tenture_height, tenure_height);
}
} else {
// epoch2.x block tenure height is the same as the block height
assert_eq!(tenure_height, block_height);
last_tenture_height = block_height;
}
}

assert!(delegate_stx_found, "Expected delegate STX op");
let sortdb = btc_regtest_controller.sortdb_mut();
let sortdb_conn = sortdb.conn();
Expand Down Expand Up @@ -8366,6 +8328,45 @@ fn check_block_info() {
"Contract 3 should be able to fetch the StacksBlockId of the tip"
);

let blocks = test_observer::get_blocks();
let mut last_tenture_height = 0;
for block in blocks.iter() {
let transactions = block.get("transactions").unwrap().as_array().unwrap();
let mut block_has_tenure_change = false;
for tx in transactions.iter().rev() {
let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap();
if raw_tx != "0x00" {
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
let parsed =
StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap();
if let TransactionPayload::TenureChange(_tenure_change) = parsed.payload {
block_has_tenure_change = true;
continue;
}
}
}
// if `signer_bitvec` is set on a block, then it's a nakamoto block
let is_nakamoto_block = block.get("signer_bitvec").is_some();

let tenure_height = block.get("tenure_height").unwrap().as_u64().unwrap();
let block_height = block.get("block_height").unwrap().as_u64().unwrap();

if is_nakamoto_block {
if block_has_tenure_change {
// tenure change block should have tenure height 1 more than the last tenure height
assert_eq!(last_tenture_height + 1, tenure_height);
last_tenture_height = tenure_height;
} else {
// tenure extend block should have the same tenure height as the last tenure height
assert_eq!(last_tenture_height, tenure_height);
}
} else {
// epoch2.x block tenure height is the same as the block height
assert_eq!(tenure_height, block_height);
last_tenture_height = block_height;
}
}

coord_channel
.lock()
.expect("Mutex poisoned")
Expand Down

0 comments on commit e272540

Please sign in to comment.