Skip to content

Commit

Permalink
fntest: tweaked rpc_recent_blocks to maybe make it flake less
Browse files Browse the repository at this point in the history
  • Loading branch information
delbonis committed Jan 7, 2025
1 parent 2eb4fbf commit 8f36017
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions functional-tests/tests/rpc_recent_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from envs import testenv

NUM_BLOCKS_TO_RECEIVE = 10
BLOCK_NUMBER = 4
CHECK_BLOCK_NUMBER = 6
TRY_LIMIT = 20


@flexitest.register
Expand All @@ -19,25 +20,27 @@ def main(self, ctx: flexitest.RunContext):
# create both btc and sequencer RPC
seqrpc = seq.create_rpc()
counter = 0
while counter <= 20:
while counter < TRY_LIMIT:
blk = seqrpc.strata_getHeadersAtIdx(NUM_BLOCKS_TO_RECEIVE)
if blk is None:
counter += 1
time.sleep(1)
else:
if blk is not None:
break

counter += 1
time.sleep(1)

assert counter < TRY_LIMIT, "seem to be not making progress"

recent_blks = seqrpc.strata_getRecentBlockHeaders(NUM_BLOCKS_TO_RECEIVE)
assert len(recent_blks) == NUM_BLOCKS_TO_RECEIVE
assert len(recent_blks) == NUM_BLOCKS_TO_RECEIVE, f"got {len(recent_blks)} blocks back, asked for {NUM_BLOCKS_TO_RECEIVE}"

# check if they are in order by verifying if N-1 block is parent of N block
for idx in reversed(range(0, NUM_BLOCKS_TO_RECEIVE)):
if idx != NUM_BLOCKS_TO_RECEIVE - 1:
assert recent_blks[idx]["prev_block"] == recent_blks[idx + 1]["block_id"]

l2_blk = seqrpc.strata_getHeadersAtIdx(recent_blks[BLOCK_NUMBER]["block_idx"])
l2_blk = seqrpc.strata_getHeadersAtIdx(recent_blks[CHECK_BLOCK_NUMBER]["block_idx"])

assert recent_blks[BLOCK_NUMBER]["block_idx"] == l2_blk[0]["block_idx"]
assert recent_blks[CHECK_BLOCK_NUMBER]["block_idx"] == l2_blk[0]["block_idx"]

second_blk_from_id = seqrpc.strata_getHeaderById(l2_blk[0]["block_id"])

Expand Down

0 comments on commit 8f36017

Please sign in to comment.