Commit cfa5e24a authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6970 from ethereum-optimism/aj/delete-files-e2e

op-e2e: Assert deletion of game data in fault proof e2e tests
parents 85f8e844 0cc332d7
...@@ -23,9 +23,11 @@ import ( ...@@ -23,9 +23,11 @@ import (
) )
type Helper struct { type Helper struct {
log log.Logger log log.Logger
cancel func() require *require.Assertions
errors chan error dir string
cancel func()
errors chan error
} }
type Option func(config2 *config.Config) type Option func(config2 *config.Config)
...@@ -105,9 +107,11 @@ func NewChallenger(t *testing.T, ctx context.Context, l1Endpoint string, name st ...@@ -105,9 +107,11 @@ func NewChallenger(t *testing.T, ctx context.Context, l1Endpoint string, name st
errCh <- op_challenger.Main(ctx, log, cfg) errCh <- op_challenger.Main(ctx, log, cfg)
}() }()
return &Helper{ return &Helper{
log: log, log: log,
cancel: cancel, require: require.New(t),
errors: errCh, dir: cfg.Datadir,
cancel: cancel,
errors: errCh,
} }
} }
...@@ -155,3 +159,25 @@ func (h *Helper) Close() error { ...@@ -155,3 +159,25 @@ func (h *Helper) Close() error {
return nil return nil
} }
} }
type GameAddr interface {
Addr() common.Address
}
func (h *Helper) VerifyGameDataExists(games ...GameAddr) {
for _, game := range games {
addr := game.Addr()
h.require.DirExistsf(h.gameDataDir(addr), "should have data for game %v", addr)
}
}
func (h *Helper) VerifyNoGameDataExists(games ...GameAddr) {
for _, game := range games {
addr := game.Addr()
h.require.NoDirExistsf(h.gameDataDir(addr), "should have data for game %v", addr)
}
}
func (h *Helper) gameDataDir(addr common.Address) string {
return filepath.Join(h.dir, addr.Hex())
}
...@@ -26,6 +26,10 @@ type FaultGameHelper struct { ...@@ -26,6 +26,10 @@ type FaultGameHelper struct {
addr common.Address addr common.Address
} }
func (g *FaultGameHelper) Addr() common.Address {
return g.addr
}
func (g *FaultGameHelper) GameDuration(ctx context.Context) time.Duration { func (g *FaultGameHelper) GameDuration(ctx context.Context) time.Duration {
duration, err := g.game.GAMEDURATION(&bind.CallOpts{Context: ctx}) duration, err := g.game.GAMEDURATION(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "failed to get game duration") g.require.NoError(err, "failed to get game duration")
......
...@@ -58,7 +58,7 @@ func TestMultipleCannonGames(t *testing.T) { ...@@ -58,7 +58,7 @@ func TestMultipleCannonGames(t *testing.T) {
gameFactory := disputegame.NewFactoryHelper(t, ctx, sys.cfg.L1Deployments, l1Client) gameFactory := disputegame.NewFactoryHelper(t, ctx, sys.cfg.L1Deployments, l1Client)
// Start a challenger with the correct alphabet trace // Start a challenger with the correct alphabet trace
gameFactory.StartChallenger(ctx, sys.NodeEndpoint("l1"), "TowerDefense", challenger := gameFactory.StartChallenger(ctx, sys.NodeEndpoint("l1"), "TowerDefense",
challenger.WithCannon(t, sys.RollupConfig, sys.L2GenesisCfg, sys.NodeEndpoint("sequencer")), challenger.WithCannon(t, sys.RollupConfig, sys.L2GenesisCfg, sys.NodeEndpoint("sequencer")),
challenger.WithPrivKey(sys.cfg.Secrets.Alice), challenger.WithPrivKey(sys.cfg.Secrets.Alice),
challenger.WithAgreeProposedOutput(true), challenger.WithAgreeProposedOutput(true),
...@@ -74,6 +74,9 @@ func TestMultipleCannonGames(t *testing.T) { ...@@ -74,6 +74,9 @@ func TestMultipleCannonGames(t *testing.T) {
game2Claim := game2.GetClaimValue(ctx, 1) game2Claim := game2.GetClaimValue(ctx, 1)
require.NotEqual(t, game1Claim, game2Claim, "games should have different cannon traces") require.NotEqual(t, game1Claim, game2Claim, "games should have different cannon traces")
// Check that the helper finds the game directories correctly
challenger.VerifyGameDataExists(game1, game2)
// Push both games down to the step function // Push both games down to the step function
maxDepth := game1.MaxDepth(ctx) maxDepth := game1.MaxDepth(ctx)
for claimCount := int64(1); claimCount <= maxDepth; { for claimCount := int64(1); claimCount <= maxDepth; {
...@@ -97,8 +100,9 @@ func TestMultipleCannonGames(t *testing.T) { ...@@ -97,8 +100,9 @@ func TestMultipleCannonGames(t *testing.T) {
game1.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) game1.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game2.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) game2.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game1.LogGameData(ctx)
game2.LogGameData(ctx) // Check that the game directories are removed
challenger.VerifyNoGameDataExists(game1, game2)
} }
func TestResolveDisputeGame(t *testing.T) { func TestResolveDisputeGame(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment