Skip to content

Commit 28ab2c0

Browse files
committed
refactor(functional-tests): extract wait_for_l1_commitment helper
Move inline wait_until_with_value calls for L1 header commitments into a dedicated StrataService.wait_for_l1_commitment() method, consistent with existing wait_for_block_height/wait_for_block patterns.
1 parent 78a73f2 commit 28ab2c0

4 files changed

Lines changed: 48 additions & 32 deletions

File tree

functional-tests-new/common/services/strata.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,45 @@ def wait_for_additional_blocks(
195195
)
196196
return self.get_cur_block_height(rpc)
197197

198+
def wait_for_l1_commitment(
199+
self,
200+
height: int,
201+
rpc: JsonRpcClient | None = None,
202+
timeout: int = 60,
203+
poll_interval: float = 0.5,
204+
differs_from: object | None = None,
205+
) -> object:
206+
"""Wait for an L1 header commitment at a given height.
207+
208+
Args:
209+
height: L1 block height to check.
210+
rpc: Optional RPC client. If None, creates a new one.
211+
timeout: Maximum time to wait in seconds.
212+
poll_interval: How often to poll.
213+
differs_from: If set, also require the commitment to differ
214+
from this value (useful for reorg detection).
215+
216+
Returns:
217+
The L1 header commitment value.
218+
"""
219+
if rpc is None:
220+
rpc = self.create_rpc()
221+
222+
def predicate(v):
223+
if v is None:
224+
return False
225+
if differs_from is not None and v == differs_from:
226+
return False
227+
return True
228+
229+
return wait_until_with_value(
230+
lambda: rpc.strata_getL1HeaderCommitment(height),
231+
predicate,
232+
error_with=f"No L1 header commitment at height {height}",
233+
timeout=timeout,
234+
step=poll_interval,
235+
)
236+
198237
def check_block_generation_in_range(self, rpc: JsonRpcClient, start: int, end: int) -> int:
199238
"""Checks for range of blocks produced and returns current block height"""
200239
logger.info(f"Waiting for blocks from {start} to {end} be produced...")

functional-tests-new/tests/btcio/test_l1_connected.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from common.base_test import StrataNodeTest
88
from common.config import ServiceType
9-
from common.wait import wait_until_with_value
109

1110
logger = logging.getLogger(__name__)
1211

@@ -45,12 +44,7 @@ def main(self, ctx):
4544
check_height = tip_height - 2
4645
logger.info(f"Checking L1 header commitment at height {check_height}")
4746

48-
commitment = wait_until_with_value(
49-
lambda: rpc.strata_getL1HeaderCommitment(check_height),
50-
lambda v: v is not None,
51-
timeout=30,
52-
error_with=f"No L1 header commitment at height {check_height}",
53-
)
47+
commitment = strata.wait_for_l1_commitment(check_height, rpc=rpc, timeout=30)
5448

5549
logger.info(f"L1 header commitment at {check_height}: {commitment}")
5650
return True

functional-tests-new/tests/btcio/test_l1_reorg.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from common.base_test import StrataNodeTest
88
from common.config import ServiceType
9-
from common.wait import wait_until_with_value
109
from envconfigs.strata import StrataEnvConfig
1110

1211
logger = logging.getLogger(__name__)
@@ -45,11 +44,8 @@ def main(self, ctx):
4544
logger.info(f"Will invalidate from height {invalidate_height}")
4645

4746
# wait for strata to have processed the block at this height
48-
pre_reorg_commitment = wait_until_with_value(
49-
lambda: rpc.strata_getL1HeaderCommitment(invalidate_height),
50-
lambda v: v is not None,
51-
timeout=60,
52-
error_with=f"Strata not caught up to height {invalidate_height}",
47+
pre_reorg_commitment = strata.wait_for_l1_commitment(
48+
invalidate_height, rpc=rpc, timeout=60
5349
)
5450
logger.info(f"Pre-reorg commitment at {invalidate_height}: {pre_reorg_commitment}")
5551

@@ -75,13 +71,11 @@ def main(self, ctx):
7571

7672
# wait for strata to pick up the new chain; the commitment
7773
# at invalidate_height must differ from the pre-reorg value
78-
post_reorg_commitment = wait_until_with_value(
79-
lambda: rpc.strata_getL1HeaderCommitment(invalidate_height),
80-
lambda v: v is not None and v != pre_reorg_commitment,
74+
post_reorg_commitment = strata.wait_for_l1_commitment(
75+
invalidate_height,
76+
rpc=rpc,
8177
timeout=60,
82-
error_with=(
83-
f"Strata did not update commitment at height {invalidate_height} after reorg"
84-
),
78+
differs_from=pre_reorg_commitment,
8579
)
8680
logger.info(f"Post-reorg commitment at {invalidate_height}: {post_reorg_commitment}")
8781

functional-tests-new/tests/btcio/test_l1_tracking.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from common.base_test import StrataNodeTest
88
from common.config import ServiceType
9-
from common.wait import wait_until_with_value
109

1110
logger = logging.getLogger(__name__)
1211

@@ -38,12 +37,7 @@ def main(self, ctx):
3837
logger.info(f"Bitcoin tip before mining: {pre_tip}")
3938

4039
# Wait for strata to have caught up to pre_tip
41-
wait_until_with_value(
42-
lambda: rpc.strata_getL1HeaderCommitment(pre_tip),
43-
lambda v: v is not None,
44-
timeout=60,
45-
error_with=f"Strata not caught up to L1 height {pre_tip}",
46-
)
40+
strata.wait_for_l1_commitment(pre_tip, rpc=rpc, timeout=60)
4741

4842
# Mine additional blocks
4943
addr = btc_rpc.proxy.getnewaddress()
@@ -55,12 +49,7 @@ def main(self, ctx):
5549
raise AssertionError(f"Expected tip {pre_tip + self.EXTRA_BLOCKS}, got {post_tip}")
5650

5751
# Wait for strata to pick up the new blocks
58-
commitment = wait_until_with_value(
59-
lambda: rpc.strata_getL1HeaderCommitment(post_tip),
60-
lambda v: v is not None,
61-
timeout=60,
62-
error_with=f"Strata did not track new L1 blocks up to height {post_tip}",
63-
)
52+
commitment = strata.wait_for_l1_commitment(post_tip, rpc=rpc, timeout=60)
6453
logger.info(f"L1 header commitment at new tip {post_tip}: {commitment}")
6554

6655
# Verify intermediate heights also have commitments

0 commit comments

Comments
 (0)