Skip to content

Commit e3f9dfe

Browse files
committed
test: reduce flakiness in retry_proposal
1 parent b746bef commit e3f9dfe

File tree

1 file changed

+20
-6
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12165,6 +12165,20 @@ fn repeated_rejection() {
1216512165
signer_test.shutdown();
1216612166
}
1216712167

12168+
fn transfers_in_block(block: &serde_json::Value) -> usize {
12169+
let transactions = block["transactions"].as_array().unwrap();
12170+
let mut count = 0;
12171+
for tx in transactions {
12172+
let raw_tx = tx["raw_tx"].as_str().unwrap();
12173+
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
12174+
let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap();
12175+
if let TransactionPayload::TokenTransfer(..) = &parsed.payload {
12176+
count += 1;
12177+
}
12178+
}
12179+
count
12180+
}
12181+
1216812182
#[test]
1216912183
#[ignore]
1217012184
/// This test verifies that a miner will re-propose the same block if it times
@@ -12270,13 +12284,14 @@ fn retry_proposal() {
1227012284
submit_tx(&http_origin, &transfer_tx);
1227112285

1227212286
info!("Disable signer 1 from ignoring proposals");
12273-
test_observer::clear();
1227412287
TEST_IGNORE_ALL_BLOCK_PROPOSALS.set(vec![]);
1227512288

1227612289
info!("Waiting for the block to be approved");
1227712290
wait_for(60, || {
12278-
let info = get_chain_info(&signer_test.running_nodes.conf);
12279-
if info.stacks_tip_height > block_height_before {
12291+
let blocks = test_observer::get_blocks();
12292+
let last_block = blocks.last().expect("No blocks found");
12293+
let height = last_block["block_height"].as_u64().unwrap();
12294+
if height > block_height_before {
1228012295
return Ok(true);
1228112296
}
1228212297
Ok(false)
@@ -12285,9 +12300,8 @@ fn retry_proposal() {
1228512300

1228612301
// Ensure that the block was the original block with just 1 transfer
1228712302
let blocks = test_observer::get_blocks();
12288-
let block = blocks.first().expect("No blocks found");
12289-
let transactions = block["transactions"].as_array().unwrap();
12290-
assert_eq!(transactions.len(), 1);
12303+
let block = blocks.last().expect("No blocks found");
12304+
assert_eq!(transfers_in_block(block), 1);
1229112305

1229212306
signer_test.shutdown();
1229312307
}

0 commit comments

Comments
 (0)