Commit e0c0f867 authored by clabby's avatar clabby

E2E dispute test fix

parent ae7c2740
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer" "github.com/ethereum-optimism/optimism/op-chain-ops/deployer"
"github.com/ethereum-optimism/optimism/op-service/client/utils" "github.com/ethereum-optimism/optimism/op-service/client/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -18,7 +17,7 @@ import ( ...@@ -18,7 +17,7 @@ import (
// It configures the alphabet fault game as game type 0 (faultGameType) // It configures the alphabet fault game as game type 0 (faultGameType)
// If/when the dispute game factory becomes a predeployed contract this can be removed and just use the // If/when the dispute game factory becomes a predeployed contract this can be removed and just use the
// predeployed version // predeployed version
func deployDisputeGameContracts(require *require.Assertions, ctx context.Context, client *ethclient.Client, opts *bind.TransactOpts, gameDuration uint64) *bindings.DisputeGameFactory { func deployDisputeGameContracts(require *require.Assertions, ctx context.Context, client *ethclient.Client, opts *bind.TransactOpts, gameDuration uint64) (*bindings.DisputeGameFactory, uint64) {
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel() defer cancel()
// Deploy the proxy // Deploy the proxy
...@@ -60,17 +59,50 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context ...@@ -60,17 +59,50 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context
blockHashOracle, err := bindings.NewBlockOracle(blockHashOracleAddr, client) blockHashOracle, err := bindings.NewBlockOracle(blockHashOracleAddr, client)
require.NoError(err) require.NoError(err)
// Deploy the L2 output oracle
_, tx, _, err = bindings.DeployL2OutputOracle(
opts,
client,
big.NewInt(1800),
big.NewInt(2),
big.NewInt(0),
big.NewInt(0),
opts.From,
opts.From,
big.NewInt(3600),
)
require.NoError(err)
l2OutputOracleAddr, err := bind.WaitDeployed(ctx, client, tx)
require.NoError(err)
l2OutputOracle, err := bindings.NewL2OutputOracle(l2OutputOracleAddr, client)
require.NoError(err)
// Deploy the fault dispute game implementation // Deploy the fault dispute game implementation
_, tx, _, err = bindings.DeployFaultDisputeGame(opts, client, alphabetVMAbsolutePrestateClaim, big.NewInt(alphabetGameDepth), gameDuration, alphaVMAddr, common.Address{0xBE, 0xEF}, blockHashOracleAddr) _, tx, _, err = bindings.DeployFaultDisputeGame(opts, client, alphabetVMAbsolutePrestateClaim, big.NewInt(alphabetGameDepth), gameDuration, alphaVMAddr, l2OutputOracleAddr, blockHashOracleAddr)
require.NoError(err) require.NoError(err)
faultDisputeGameAddr, err := bind.WaitDeployed(ctx, client, tx) faultDisputeGameAddr, err := bind.WaitDeployed(ctx, client, tx)
require.NoError(err) require.NoError(err)
// Store the genesis block hash in the oracle // Propose 2 outputs
tx, err = blockHashOracle.Store(opts, big.NewInt(0)) for i := uint8(0); i < 2; i++ {
nextBlockNumber, err := l2OutputOracle.NextBlockNumber(nil)
require.NoError(err)
block, err := client.BlockByNumber(ctx, big.NewInt(int64(i)))
require.NoError(err)
tx, err = l2OutputOracle.ProposeL2Output(opts, [32]byte{i + 1}, nextBlockNumber, block.Hash(), block.Number())
require.NoError(err)
_, err = utils.WaitReceiptOK(ctx, client, tx.Hash())
require.NoError(err)
}
// Store the current block in the oracle
blockNo, err := client.BlockNumber(ctx)
require.NoError(err)
tx, err = blockHashOracle.Store(opts, big.NewInt(int64(blockNo)))
require.NoError(err) require.NoError(err)
_, err = utils.WaitReceiptOK(ctx, client, tx.Hash()) _, err = utils.WaitReceiptOK(ctx, client, tx.Hash())
require.NoError(err, "failed to store genesis block hash in oracle") require.NoError(err, "failed to store block in blockoracle")
// Set the fault game type implementation // Set the fault game type implementation
tx, err = factory.SetImplementation(opts, faultGameType, faultDisputeGameAddr) tx, err = factory.SetImplementation(opts, faultGameType, faultDisputeGameAddr)
...@@ -78,5 +110,5 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context ...@@ -78,5 +110,5 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context
_, err = utils.WaitReceiptOK(ctx, client, tx.Hash()) _, err = utils.WaitReceiptOK(ctx, client, tx.Hash())
require.NoError(err, "wait for final transaction to be included and OK") require.NoError(err, "wait for final transaction to be included and OK")
return factory return factory, blockNo
} }
...@@ -2,6 +2,7 @@ package disputegame ...@@ -2,6 +2,7 @@ package disputegame
import ( import (
"context" "context"
"encoding/binary"
"fmt" "fmt"
"math/big" "math/big"
"testing" "testing"
...@@ -33,7 +34,6 @@ const ( ...@@ -33,7 +34,6 @@ const (
StatusDefenderWins StatusDefenderWins
) )
var alphaExtraData = common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000")
var alphabetVMAbsolutePrestate = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000060") var alphabetVMAbsolutePrestate = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000060")
var alphabetVMAbsolutePrestateClaim = crypto.Keccak256Hash(alphabetVMAbsolutePrestate) var alphabetVMAbsolutePrestateClaim = crypto.Keccak256Hash(alphabetVMAbsolutePrestate)
var CorrectAlphabet = "abcdefghijklmnop" var CorrectAlphabet = "abcdefghijklmnop"
...@@ -44,6 +44,7 @@ type FactoryHelper struct { ...@@ -44,6 +44,7 @@ type FactoryHelper struct {
client *ethclient.Client client *ethclient.Client
opts *bind.TransactOpts opts *bind.TransactOpts
factory *bindings.DisputeGameFactory factory *bindings.DisputeGameFactory
l1Head uint64
} }
func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Client, gameDuration uint64) *FactoryHelper { func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Client, gameDuration uint64) *FactoryHelper {
...@@ -53,7 +54,7 @@ func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Clien ...@@ -53,7 +54,7 @@ func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Clien
opts, err := bind.NewKeyedTransactorWithChainID(deployer.TestKey, chainID) opts, err := bind.NewKeyedTransactorWithChainID(deployer.TestKey, chainID)
require.NoError(err) require.NoError(err)
factory := deployDisputeGameContracts(require, ctx, client, opts, gameDuration) factory, l1Head := deployDisputeGameContracts(require, ctx, client, opts, gameDuration)
return &FactoryHelper{ return &FactoryHelper{
t: t, t: t,
...@@ -61,6 +62,7 @@ func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Clien ...@@ -61,6 +62,7 @@ func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Clien
client: client, client: client,
opts: opts, opts: opts,
factory: factory, factory: factory,
l1Head: l1Head,
} }
} }
...@@ -70,7 +72,10 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s ...@@ -70,7 +72,10 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s
trace := alphabet.NewTraceProvider(claimedAlphabet, 4) trace := alphabet.NewTraceProvider(claimedAlphabet, 4)
rootClaim, err := trace.Get(ctx, lastAlphabetTraceIndex) rootClaim, err := trace.Get(ctx, lastAlphabetTraceIndex)
h.require.NoError(err, "get root claim") h.require.NoError(err, "get root claim")
tx, err := h.factory.Create(h.opts, faultGameType, rootClaim, alphaExtraData) extraData := make([]byte, 64)
binary.BigEndian.PutUint64(extraData[24:], uint64(3600))
binary.BigEndian.PutUint64(extraData[56:], h.l1Head)
tx, err := h.factory.Create(h.opts, faultGameType, rootClaim, extraData)
h.require.NoError(err, "create fault dispute game") h.require.NoError(err, "create fault dispute game")
rcpt, err := utils.WaitReceiptOK(ctx, h.client, tx.Hash()) rcpt, err := utils.WaitReceiptOK(ctx, h.client, tx.Hash())
h.require.NoError(err, "wait for create fault dispute game receipt to be OK") h.require.NoError(err, "wait for create fault dispute game receipt to be OK")
......
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