Commit 9d51d103 authored by Adrian Sutton's avatar Adrian Sutton

op-e2e: Expect the challenger to resolve the game

parent 4bad280b
...@@ -2,6 +2,7 @@ package disputegame ...@@ -2,6 +2,7 @@ package disputegame
import ( import (
"context" "context"
"fmt"
"math" "math"
"math/big" "math/big"
"testing" "testing"
...@@ -134,10 +135,18 @@ func (g *FaultGameHelper) Resolve(ctx context.Context) { ...@@ -134,10 +135,18 @@ func (g *FaultGameHelper) Resolve(ctx context.Context) {
g.require.NoError(err) g.require.NoError(err)
} }
func (g *FaultGameHelper) AssertStatusEquals(ctx context.Context, expected Status) { func (g *FaultGameHelper) WaitForGameStatus(ctx context.Context, expected Status) {
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute) ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel() defer cancel()
status, err := g.game.Status(&bind.CallOpts{Context: ctx}) err := utils.WaitFor(ctx, 1*time.Second, func() (bool, error) {
g.require.NoError(err) ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
g.require.Equal(expected, Status(status)) defer cancel()
status, err := g.game.Status(&bind.CallOpts{Context: ctx})
if err != nil {
return false, fmt.Errorf("game status unavailable: %w", err)
}
return expected == Status(status), nil
})
g.require.NoError(err, "wait for game status")
} }
...@@ -32,7 +32,7 @@ func TestResolveDisputeGame(t *testing.T) { ...@@ -32,7 +32,7 @@ func TestResolveDisputeGame(t *testing.T) {
game := disputeGameFactory.StartAlphabetGame(ctx, "zyxwvut") game := disputeGameFactory.StartAlphabetGame(ctx, "zyxwvut")
require.NotNil(t, game) require.NotNil(t, game)
game.AssertStatusEquals(ctx, disputegame.StatusInProgress) game.WaitForGameStatus(ctx, disputegame.StatusInProgress)
honest := game.StartChallenger(ctx, sys.NodeEndpoint("l1"), "honestAlice", func(c *config.Config) { honest := game.StartChallenger(ctx, sys.NodeEndpoint("l1"), "honestAlice", func(c *config.Config) {
c.AgreeWithProposedOutput = true // Agree with the proposed output, so disagree with the root claim c.AgreeWithProposedOutput = true // Agree with the proposed output, so disagree with the root claim
...@@ -46,8 +46,7 @@ func TestResolveDisputeGame(t *testing.T) { ...@@ -46,8 +46,7 @@ func TestResolveDisputeGame(t *testing.T) {
sys.TimeTravelClock.AdvanceTime(gameDuration) sys.TimeTravelClock.AdvanceTime(gameDuration)
require.NoError(t, utils.WaitNextBlock(ctx, l1Client)) require.NoError(t, utils.WaitNextBlock(ctx, l1Client))
game.Resolve(ctx) // Challenger should resolve the game now that the clocks have expired.
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game.AssertStatusEquals(ctx, disputegame.StatusChallengerWins)
require.NoError(t, honest.Close()) require.NoError(t, honest.Close())
} }
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