Skip to content

Commit e456b89

Browse files
committed
fix(test): wait for game of required type, not just any game
The previous fix waited for any game to exist, but the system may have a pre-existing permissioned game (type 0) from initialization. The FP proposer creates games of type 1 (respected game type), so the test needs to wait specifically for a game of that type before calling Prove. Add WaitForGameOfType helper that polls DGF for a game matching the specified type, and use it in the withdrawal test.
1 parent 2e91f8c commit e456b89

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

tests/e2e/faultproof/withdrawal/withdrawal_finalized_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func TestFaultProofProposer_WithdrawalFinalized(gt *testing.T) {
3636
l2User.VerifyBalanceExact(depositAmount)
3737

3838
// Log respected game type for debugging
39-
logger.Info("Using respected game type", "gameType", bridge.RespectedGameType())
39+
respectedGameType := bridge.RespectedGameType()
40+
logger.Info("Using respected game type", "gameType", respectedGameType)
4041

4142
// Phase 1: Initiate withdrawal on L2
4243
logger.Info("Phase 1: Initiating withdrawal on L2")
@@ -47,13 +48,14 @@ func TestFaultProofProposer_WithdrawalFinalized(gt *testing.T) {
4748
expectedL2UserBalance := depositAmount.Sub(withdrawAmount).Sub(withdrawal.InitiateGasCost())
4849
l2User.VerifyBalanceExact(expectedL2UserBalance)
4950

50-
// Wait for at least one game to be created before proving
51-
// The FP proposer needs time to batch L2 blocks and create games
51+
// Wait for a game of the required type to be created before proving.
52+
// The system may have games of other types (e.g., permissioned type 0),
53+
// but the FP proposer creates games of the respected type.
5254
dgf := sys.DgfClient(t)
5355
ctx, cancel := context.WithTimeout(t.Ctx(), utils.ShortTimeout())
5456
defer cancel()
55-
logger.Info("Waiting for dispute game creation")
56-
utils.WaitForGameCount(ctx, t, dgf, 1)
57+
logger.Info("Waiting for game of required type")
58+
utils.WaitForGameOfType(ctx, t, dgf, respectedGameType)
5759

5860
// Phase 2: Prove withdrawal on L1
5961
logger.Info("Phase 2: Proving withdrawal on L1")

tests/utils/adapters.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,37 @@ func WaitForGameCount(ctx context.Context, t devtest.T, dgf *DgfClient, min uint
185185
}
186186
}
187187

188+
// WaitForGameOfType waits until a dispute game of the specified type exists.
189+
// This is needed because the system may have games of other types (e.g., permissioned type 0)
190+
// while the FP proposer creates games of type 1.
191+
func WaitForGameOfType(ctx context.Context, t devtest.T, dgf *DgfClient, gameType uint32) {
192+
for {
193+
gameCount, err := dgf.GameCount(ctx)
194+
require.NoError(t, err, "failed to get game count from factory")
195+
196+
// Check all games (newest first) for matching type
197+
for i := int64(gameCount) - 1; i >= 0; i-- {
198+
game, err := dgf.GameAtIndex(ctx, uint64(i))
199+
if err != nil {
200+
continue
201+
}
202+
if game.GameType == gameType {
203+
t.Logger().Info("Found game of required type", "index", i, "gameType", gameType)
204+
return
205+
}
206+
}
207+
208+
t.Logger().Info("Waiting for game of required type...", "gameType", gameType, "totalGames", gameCount)
209+
210+
select {
211+
case <-ctx.Done():
212+
t.Errorf("timeout waiting for game of type %d", gameType)
213+
t.FailNow()
214+
case <-time.After(time.Second):
215+
}
216+
}
217+
}
218+
188219
// -------------------------------------------------------------
189220
// Fault Dispute Game Client
190221
// -------------------------------------------------------------

0 commit comments

Comments
 (0)