Commit 3adecb93 authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Update e2e tests for multiple trace types.

parent 672adac1
...@@ -42,9 +42,6 @@ func WithFactoryAddress(addr common.Address) Option { ...@@ -42,9 +42,6 @@ func WithFactoryAddress(addr common.Address) Option {
func WithGameAddress(addr common.Address) Option { func WithGameAddress(addr common.Address) Option {
return func(c *config.Config) { return func(c *config.Config) {
if c.GameAllowlist == nil {
c.GameAllowlist = make([]common.Address, 0)
}
c.GameAllowlist = append(c.GameAllowlist, addr) c.GameAllowlist = append(c.GameAllowlist, addr)
} }
} }
...@@ -63,7 +60,7 @@ func WithAgreeProposedOutput(agree bool) Option { ...@@ -63,7 +60,7 @@ func WithAgreeProposedOutput(agree bool) Option {
func WithAlphabet(alphabet string) Option { func WithAlphabet(alphabet string) Option {
return func(c *config.Config) { return func(c *config.Config) {
c.TraceType = config.TraceTypeAlphabet c.TraceTypes = append(c.TraceTypes, config.TraceTypeAlphabet)
c.AlphabetTrace = alphabet c.AlphabetTrace = alphabet
} }
} }
...@@ -82,7 +79,7 @@ func WithCannon( ...@@ -82,7 +79,7 @@ func WithCannon(
) Option { ) Option {
return func(c *config.Config) { return func(c *config.Config) {
require := require.New(t) require := require.New(t)
c.TraceType = config.TraceTypeCannon c.TraceTypes = append(c.TraceTypes, config.TraceTypeCannon)
c.CannonL2 = l2Endpoint c.CannonL2 = l2Endpoint
c.CannonBin = "../cannon/bin/cannon" c.CannonBin = "../cannon/bin/cannon"
c.CannonServer = "../op-program/bin/op-program" c.CannonServer = "../op-program/bin/op-program"
...@@ -126,7 +123,7 @@ func NewChallenger(t *testing.T, ctx context.Context, l1Endpoint string, name st ...@@ -126,7 +123,7 @@ func NewChallenger(t *testing.T, ctx context.Context, l1Endpoint string, name st
func NewChallengerConfig(t *testing.T, l1Endpoint string, options ...Option) *config.Config { func NewChallengerConfig(t *testing.T, l1Endpoint string, options ...Option) *config.Config {
// Use the NewConfig method to ensure we pick up any defaults that are set. // Use the NewConfig method to ensure we pick up any defaults that are set.
cfg := config.NewConfig(common.Address{}, l1Endpoint, true, t.TempDir(), config.TraceTypeAlphabet) cfg := config.NewConfig(common.Address{}, l1Endpoint, true, t.TempDir())
cfg.TxMgrConfig.NumConfirmations = 1 cfg.TxMgrConfig.NumConfirmations = 1
cfg.TxMgrConfig.ReceiptQueryInterval = 1 * time.Second cfg.TxMgrConfig.ReceiptQueryInterval = 1 * time.Second
if cfg.MaxConcurrency > 4 { if cfg.MaxConcurrency > 4 {
......
...@@ -3,11 +3,8 @@ package disputegame ...@@ -3,11 +3,8 @@ package disputegame
import ( import (
"context" "context"
"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/alphabet" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/alphabet"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger"
"github.com/ethereum/go-ethereum/common"
) )
type AlphabetGameHelper struct { type AlphabetGameHelper struct {
...@@ -17,15 +14,12 @@ type AlphabetGameHelper struct { ...@@ -17,15 +14,12 @@ type AlphabetGameHelper struct {
func (g *AlphabetGameHelper) StartChallenger(ctx context.Context, l1Endpoint string, name string, options ...challenger.Option) *challenger.Helper { func (g *AlphabetGameHelper) StartChallenger(ctx context.Context, l1Endpoint string, name string, options ...challenger.Option) *challenger.Helper {
opts := []challenger.Option{ opts := []challenger.Option{
func(c *config.Config) { challenger.WithFactoryAddress(g.factoryAddr),
c.GameFactoryAddress = g.factoryAddr challenger.WithGameAddress(g.addr),
c.GameAllowlist = []common.Address{g.addr} // By default the challenger agrees with the root claim (thus disagrees with the proposed output)
c.TraceType = config.TraceTypeAlphabet // This can be overridden by passing in options
// By default the challenger agrees with the root claim (thus disagrees with the proposed output) challenger.WithAlphabet(g.claimedAlphabet),
// This can be overridden by passing in options challenger.WithAgreeProposedOutput(false),
c.AlphabetTrace = g.claimedAlphabet
c.AgreeWithProposedOutput = false
},
} }
opts = append(opts, options...) opts = append(opts, options...)
c := challenger.NewChallenger(g.t, ctx, l1Endpoint, name, opts...) c := challenger.NewChallenger(g.t, ctx, l1Endpoint, name, opts...)
......
...@@ -2,9 +2,12 @@ package op_e2e ...@@ -2,9 +2,12 @@ package op_e2e
import ( import (
"context" "context"
"math/big"
"testing" "testing"
"time" "time"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/alphabet"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame"
l2oo2 "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/l2oo" l2oo2 "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/l2oo"
...@@ -74,6 +77,41 @@ func TestMultipleCannonGames(t *testing.T) { ...@@ -74,6 +77,41 @@ func TestMultipleCannonGames(t *testing.T) {
challenger.WaitForGameDataDeletion(ctx, game1, game2) challenger.WaitForGameDataDeletion(ctx, game1, game2)
} }
func TestMultipleGameTypes(t *testing.T) {
InitParallel(t)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
gameFactory := disputegame.NewFactoryHelper(t, ctx, sys.cfg.L1Deployments, l1Client)
// Start a challenger with both cannon and alphabet support
gameFactory.StartChallenger(ctx, sys.NodeEndpoint("l1"), "TowerDefense",
challenger.WithCannon(t, sys.RollupConfig, sys.L2GenesisCfg, sys.NodeEndpoint("sequencer")),
challenger.WithAlphabet(disputegame.CorrectAlphabet),
challenger.WithPrivKey(sys.cfg.Secrets.Alice),
challenger.WithAgreeProposedOutput(true),
)
game1 := gameFactory.StartCannonGame(ctx, common.Hash{0x01, 0xaa})
game2 := gameFactory.StartAlphabetGame(ctx, "xyzabc")
// Wait for the challenger to respond to both games
game1.WaitForClaimCount(ctx, 2)
game2.WaitForClaimCount(ctx, 2)
game1Response := game1.GetClaimValue(ctx, 1)
game2Response := game2.GetClaimValue(ctx, 1)
// The alphabet game always posts the same traces, so if they're different they can't both be from the alphabet.
require.NotEqual(t, game1Response, game2Response, "should have posted different claims")
// Now check they aren't both just from different cannon games by confirming the alphabet value.
correctAlphabet := alphabet.NewTraceProvider(disputegame.CorrectAlphabet, uint64(game2.MaxDepth(ctx)))
expectedClaim, err := correctAlphabet.Get(ctx, types.NewPositionFromGIndex(big.NewInt(1)).Attack())
require.NoError(t, err)
require.Equal(t, expectedClaim, game2Response)
// We don't confirm the cannon value because generating the correct claim is expensive
// Just being different is enough to confirm the challenger isn't just playing two alphabet games incorrectly
}
func TestChallengerCompleteDisputeGame(t *testing.T) { func TestChallengerCompleteDisputeGame(t *testing.T) {
InitParallel(t) InitParallel(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