Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request ethereum-optimism#6711 from ethereum-optimism/aj/u…
Browse files Browse the repository at this point in the history
…se-l2-block-number

op-e2e: Specify correct l2 block number when create dispute games
  • Loading branch information
OptimismBot authored Aug 11, 2023
2 parents 595d591 + 8b07245 commit 4804504
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
40 changes: 25 additions & 15 deletions op-e2e/e2eutils/disputegame/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewFactoryHelper(t *testing.T, ctx context.Context, deployments *genesis.L1
}

func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet string) *AlphabetGameHelper {
h.waitForProposals(ctx)
l2BlockNumber := h.waitForProposals(ctx)
l1Head := h.checkpointL1Block(ctx)

ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
Expand All @@ -94,7 +94,7 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s
rootClaim, err := trace.Get(ctx, lastAlphabetTraceIndex)
h.require.NoError(err, "get root claim")
extraData := make([]byte, 64)
binary.BigEndian.PutUint64(extraData[24:], uint64(8))
binary.BigEndian.PutUint64(extraData[24:], l2BlockNumber)
binary.BigEndian.PutUint64(extraData[56:], l1Head.Uint64())
tx, err := h.factory.Create(h.opts, alphabetGameType, rootClaim, extraData)
h.require.NoError(err, "create fault dispute game")
Expand All @@ -120,14 +120,14 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s
}

func (h *FactoryHelper) StartCannonGame(ctx context.Context, rootClaim common.Hash) *CannonGameHelper {
h.waitForProposals(ctx)
l2BlockNumber := h.waitForProposals(ctx)
l1Head := h.checkpointL1Block(ctx)

ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

extraData := make([]byte, 64)
binary.BigEndian.PutUint64(extraData[24:], uint64(8))
binary.BigEndian.PutUint64(extraData[24:], l2BlockNumber)
binary.BigEndian.PutUint64(extraData[56:], l1Head.Uint64())
tx, err := h.factory.Create(h.opts, cannonGameType, rootClaim, extraData)
h.require.NoError(err, "create fault dispute game")
Expand All @@ -153,20 +153,30 @@ func (h *FactoryHelper) StartCannonGame(ctx context.Context, rootClaim common.Ha

// waitForProposals waits until there are at least two proposals in the output oracle
// This is the minimum required for creating a game.
func (h *FactoryHelper) waitForProposals(ctx context.Context) {

// Returns the l2 block number of the latest available proposal
func (h *FactoryHelper) waitForProposals(ctx context.Context) uint64 {
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()
err := utils.WaitFor(ctx, time.Second, func() (bool, error) {
index, err := h.l2oo.LatestOutputIndex(&bind.CallOpts{Context: ctx})
if err != nil {
h.t.Logf("Could not get latest output index: %v", err.Error())
return false, nil
}
h.t.Logf("Latest output index: %v", index)
return index.Cmp(big.NewInt(1)) >= 0, nil
})
opts := &bind.CallOpts{Context: ctx}
latestOutputIndex, err := utils.WaitAndGet(
ctx,
time.Second,
func() (*big.Int, error) {
index, err := h.l2oo.LatestOutputIndex(opts)
if err != nil {
h.t.Logf("Could not get latest output index: %v", err.Error())
return nil, nil
}
h.t.Logf("Latest output index: %v", index)
return index, nil
},
func(index *big.Int) bool {
return index != nil && index.Cmp(big.NewInt(1)) >= 0
})
h.require.NoError(err, "Did not get two output roots")
output, err := h.l2oo.GetL2Output(opts, latestOutputIndex)
h.require.NoErrorf(err, "Could not get latst output root index: %v", latestOutputIndex)
return output.L2BlockNumber.Uint64()
}

// checkpointL1Block stores the current L1 block in the oracle
Expand Down
1 change: 1 addition & 0 deletions op-e2e/faultproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestResolveDisputeGame(t *testing.T) {
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys.cfg.L1Deployments, l1Client)

game := disputeGameFactory.StartAlphabetGame(ctx, "zyxwvut")
require.NotNil(t, game)
gameDuration := game.GameDuration(ctx)
Expand Down

0 comments on commit 4804504

Please sign in to comment.