Commit fea7e916 authored by clabby's avatar clabby

Use time travel clock over sleeping the test thread

parent 9ce2a4c7
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-e2e/config" "github.com/ethereum-optimism/optimism/op-e2e/config"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-service/client/utils" "github.com/ethereum-optimism/optimism/op-service/client/utils"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -19,7 +20,7 @@ import ( ...@@ -19,7 +20,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, *big.Int) { func deployDisputeGameContracts(require *require.Assertions, ctx context.Context, clock *clock.AdvancingClock, client *ethclient.Client, opts *bind.TransactOpts, gameDuration uint64) (*bindings.DisputeGameFactory, *big.Int) {
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
...@@ -108,7 +109,7 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context ...@@ -108,7 +109,7 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context
// Wait for the block hash oracle to be ready to receive the checkpoint. // Wait for the block hash oracle to be ready to receive the checkpoint.
// The block time is hard coded at 13 seconds, should parameterize. // The block time is hard coded at 13 seconds, should parameterize.
time.Sleep(15 * time.Second) clock.AdvanceTime(13 * time.Second)
// Store the current block in the oracle // Store the current block in the oracle
tx, err = blockHashOracle.Checkpoint(opts) tx, err = blockHashOracle.Checkpoint(opts)
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/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-service/client/utils" "github.com/ethereum-optimism/optimism/op-service/client/utils"
"github.com/ethereum-optimism/optimism/op-service/clock"
"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/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
...@@ -47,14 +48,14 @@ type FactoryHelper struct { ...@@ -47,14 +48,14 @@ type FactoryHelper struct {
l1Head *big.Int l1Head *big.Int
} }
func NewFactoryHelper(t *testing.T, ctx context.Context, client *ethclient.Client, gameDuration uint64) *FactoryHelper { func NewFactoryHelper(t *testing.T, ctx context.Context, clock *clock.AdvancingClock, client *ethclient.Client, gameDuration uint64) *FactoryHelper {
require := require.New(t) require := require.New(t)
chainID, err := client.ChainID(ctx) chainID, err := client.ChainID(ctx)
require.NoError(err) require.NoError(err)
opts, err := bind.NewKeyedTransactorWithChainID(deployer.TestKey, chainID) opts, err := bind.NewKeyedTransactorWithChainID(deployer.TestKey, chainID)
require.NoError(err) require.NoError(err)
factory, l1Head := deployDisputeGameContracts(require, ctx, client, opts, gameDuration) factory, l1Head := deployDisputeGameContracts(require, ctx, clock, client, opts, gameDuration)
return &FactoryHelper{ return &FactoryHelper{
t: t, t: t,
......
...@@ -21,7 +21,7 @@ func TestResolveDisputeGame(t *testing.T) { ...@@ -21,7 +21,7 @@ func TestResolveDisputeGame(t *testing.T) {
t.Cleanup(sys.Close) t.Cleanup(sys.Close)
gameDuration := 24 * time.Hour gameDuration := 24 * time.Hour
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, l1Client, uint64(gameDuration.Seconds())) disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys.TimeTravelClock, l1Client, uint64(gameDuration.Seconds()))
game := disputeGameFactory.StartAlphabetGame(ctx, "zyxwvut") game := disputeGameFactory.StartAlphabetGame(ctx, "zyxwvut")
require.NotNil(t, game) require.NotNil(t, game)
...@@ -119,7 +119,7 @@ func TestChallengerCompleteDisputeGame(t *testing.T) { ...@@ -119,7 +119,7 @@ func TestChallengerCompleteDisputeGame(t *testing.T) {
t.Cleanup(sys.Close) t.Cleanup(sys.Close)
gameDuration := 24 * time.Hour gameDuration := 24 * time.Hour
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, l1Client, uint64(gameDuration.Seconds())) disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys.TimeTravelClock, l1Client, uint64(gameDuration.Seconds()))
game := disputeGameFactory.StartAlphabetGame(ctx, test.rootClaimAlphabet) game := disputeGameFactory.StartAlphabetGame(ctx, test.rootClaimAlphabet)
require.NotNil(t, game) require.NotNil(t, game)
......
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