From fea7e91666775dc173f5339c91bae45ae37519f5 Mon Sep 17 00:00:00 2001 From: clabby Date: Thu, 3 Aug 2023 12:47:15 -0400 Subject: [PATCH] Use time travel clock over sleeping the test thread --- op-e2e/e2eutils/disputegame/deploy.go | 5 +++-- op-e2e/e2eutils/disputegame/helper.go | 5 +++-- op-e2e/faultproof_test.go | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/op-e2e/e2eutils/disputegame/deploy.go b/op-e2e/e2eutils/disputegame/deploy.go index 0b5d1c52d157..424c505f1989 100644 --- a/op-e2e/e2eutils/disputegame/deploy.go +++ b/op-e2e/e2eutils/disputegame/deploy.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum-optimism/optimism/op-e2e/config" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils" "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/ethclient" "github.com/stretchr/testify/require" @@ -19,7 +20,7 @@ import ( // 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 // 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) defer cancel() // Deploy the proxy @@ -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. // 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 tx, err = blockHashOracle.Checkpoint(opts) diff --git a/op-e2e/e2eutils/disputegame/helper.go b/op-e2e/e2eutils/disputegame/helper.go index 843ae84d8b9a..fc360c2d1005 100644 --- a/op-e2e/e2eutils/disputegame/helper.go +++ b/op-e2e/e2eutils/disputegame/helper.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/fault/types" "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/clock" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -47,14 +48,14 @@ type FactoryHelper struct { 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) chainID, err := client.ChainID(ctx) require.NoError(err) opts, err := bind.NewKeyedTransactorWithChainID(deployer.TestKey, chainID) require.NoError(err) - factory, l1Head := deployDisputeGameContracts(require, ctx, client, opts, gameDuration) + factory, l1Head := deployDisputeGameContracts(require, ctx, clock, client, opts, gameDuration) return &FactoryHelper{ t: t, diff --git a/op-e2e/faultproof_test.go b/op-e2e/faultproof_test.go index f4f55f7c034c..41908a091dc9 100644 --- a/op-e2e/faultproof_test.go +++ b/op-e2e/faultproof_test.go @@ -21,7 +21,7 @@ func TestResolveDisputeGame(t *testing.T) { t.Cleanup(sys.Close) 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") require.NotNil(t, game) @@ -119,7 +119,7 @@ func TestChallengerCompleteDisputeGame(t *testing.T) { t.Cleanup(sys.Close) 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) require.NotNil(t, game)