Skip to content

Commit

Permalink
op-e2e: Separate actions tests into different packages (#11921)
Browse files Browse the repository at this point in the history
* op-e2e: Move most action tests into a package based on what they test

* op-e2e: Move batch_queue_test.go to derivation package

* op-e2e: Move eip4844_test.go to batcher package

* op-e2e: Move actions helper code to helpers package

* update makefile

* op-e2e: Fix typo

---------

Co-authored-by: clabby <[email protected]>
  • Loading branch information
ajsutton and clabby authored Sep 17, 2024
1 parent 66bfe67 commit 994f634
Show file tree
Hide file tree
Showing 43 changed files with 808 additions and 760 deletions.
2 changes: 1 addition & 1 deletion op-e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test-ws: pre-test
.PHONY: test-ws

test-actions: pre-test
$(go_test) $(go_test_flags) ./actions
$(go_test) $(go_test_flags) ./actions/...
.PHONY: test-actions

test-http: pre-test
Expand Down
82 changes: 41 additions & 41 deletions op-e2e/actions/altda_test.go → op-e2e/actions/altda/altda_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package actions
package altda

import (
"math/big"
"math/rand"
"testing"

"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -32,21 +33,21 @@ type L2AltDA struct {
daMgr *altda.DA
altDACfg altda.Config
contract *bindings.DataAvailabilityChallenge
batcher *L2Batcher
sequencer *L2Sequencer
engine *L2Engine
batcher *helpers.L2Batcher
sequencer *helpers.L2Sequencer
engine *helpers.L2Engine
engCl *sources.EngineClient
sd *e2eutils.SetupData
dp *e2eutils.DeployParams
miner *L1Miner
alice *CrossLayerUser
miner *helpers.L1Miner
alice *helpers.CrossLayerUser
lastComm []byte
lastCommBn uint64
}

type AltDAParam func(p *e2eutils.TestParams)

func NewL2AltDA(t Testing, params ...AltDAParam) *L2AltDA {
func NewL2AltDA(t helpers.Testing, params ...AltDAParam) *L2AltDA {
p := &e2eutils.TestParams{
MaxSequencerDrift: 40,
SequencerWindowSize: 12,
Expand All @@ -60,15 +61,15 @@ func NewL2AltDA(t Testing, params ...AltDAParam) *L2AltDA {
log := testlog.Logger(t, log.LvlDebug)

dp := e2eutils.MakeDeployParams(t, p)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)

require.True(t, sd.RollupCfg.AltDAEnabled())

miner := NewL1Miner(t, log, sd.L1Cfg)
miner := helpers.NewL1Miner(t, log, sd.L1Cfg)
l1Client := miner.EthClient()

jwtPath := e2eutils.WriteDefaultJWT(t)
engine := NewL2Engine(t, log, sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath)
engine := helpers.NewL2Engine(t, log, sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath)
engCl := engine.EngineClient(t, sd.RollupCfg)

storage := &altda.DAErrFaker{Client: altda.NewMockDAClient(log)}
Expand All @@ -81,21 +82,21 @@ func NewL2AltDA(t Testing, params ...AltDAParam) *L2AltDA {

daMgr := altda.NewAltDAWithStorage(log, altDACfg, storage, &altda.NoopMetrics{})

sequencer := NewL2Sequencer(t, log, l1F, miner.BlobStore(), daMgr, engCl, sd.RollupCfg, 0, nil)
sequencer := helpers.NewL2Sequencer(t, log, l1F, miner.BlobStore(), daMgr, engCl, sd.RollupCfg, 0, nil)
miner.ActL1SetFeeRecipient(common.Address{'A'})
sequencer.ActL2PipelineFull(t)

batcher := NewL2Batcher(log, sd.RollupCfg, AltDABatcherCfg(dp, storage), sequencer.RollupClient(), l1Client, engine.EthClient(), engCl)
batcher := helpers.NewL2Batcher(log, sd.RollupCfg, helpers.AltDABatcherCfg(dp, storage), sequencer.RollupClient(), l1Client, engine.EthClient(), engCl)

addresses := e2eutils.CollectAddresses(sd, dp)
cl := engine.EthClient()
l2UserEnv := &BasicUserEnv[*L2Bindings]{
l2UserEnv := &helpers.BasicUserEnv[*helpers.L2Bindings]{
EthCl: cl,
Signer: types.LatestSigner(sd.L2Cfg.Config),
AddressCorpora: addresses,
Bindings: NewL2Bindings(t, cl, engine.GethClient()),
Bindings: helpers.NewL2Bindings(t, cl, engine.GethClient()),
}
alice := NewCrossLayerUser(log, dp.Secrets.Alice, rand.New(rand.NewSource(0xa57b)))
alice := helpers.NewCrossLayerUser(log, dp.Secrets.Alice, rand.New(rand.NewSource(0xa57b)))
alice.L2.SetUserEnv(l2UserEnv)

contract, err := bindings.NewDataAvailabilityChallenge(sd.RollupCfg.AltDAConfig.DAChallengeAddress, l1Client)
Expand Down Expand Up @@ -130,21 +131,21 @@ func (a *L2AltDA) StorageClient() *altda.DAErrFaker {
return a.storage
}

func (a *L2AltDA) NewVerifier(t Testing) *L2Verifier {
func (a *L2AltDA) NewVerifier(t helpers.Testing) *helpers.L2Verifier {
jwtPath := e2eutils.WriteDefaultJWT(t)
engine := NewL2Engine(t, a.log, a.sd.L2Cfg, a.sd.RollupCfg.Genesis.L1, jwtPath)
engine := helpers.NewL2Engine(t, a.log, a.sd.L2Cfg, a.sd.RollupCfg.Genesis.L1, jwtPath)
engCl := engine.EngineClient(t, a.sd.RollupCfg)
l1F, err := sources.NewL1Client(a.miner.RPCClient(), a.log, nil, sources.L1ClientDefaultConfig(a.sd.RollupCfg, false, sources.RPCKindBasic))
require.NoError(t, err)

daMgr := altda.NewAltDAWithStorage(a.log, a.altDACfg, a.storage, &altda.NoopMetrics{})

verifier := NewL2Verifier(t, a.log, l1F, a.miner.BlobStore(), daMgr, engCl, a.sd.RollupCfg, &sync.Config{}, safedb.Disabled, nil)
verifier := helpers.NewL2Verifier(t, a.log, l1F, a.miner.BlobStore(), daMgr, engCl, a.sd.RollupCfg, &sync.Config{}, safedb.Disabled, nil)

return verifier
}

func (a *L2AltDA) ActSequencerIncludeTx(t Testing) {
func (a *L2AltDA) ActSequencerIncludeTx(t helpers.Testing) {
a.alice.L2.ActResetTxOpts(t)
a.alice.L2.ActSetTxToAddr(&a.dp.Addresses.Bob)(t)
a.alice.L2.ActMakeTx(t)
Expand All @@ -156,7 +157,7 @@ func (a *L2AltDA) ActSequencerIncludeTx(t Testing) {
a.sequencer.ActL2EndBlock(t)
}

func (a *L2AltDA) ActNewL2Tx(t Testing) {
func (a *L2AltDA) ActNewL2Tx(t helpers.Testing) {
a.ActSequencerIncludeTx(t)

a.batcher.ActL2BatchBuffer(t)
Expand All @@ -170,20 +171,20 @@ func (a *L2AltDA) ActNewL2Tx(t Testing) {
a.miner.ActL1IncludeTx(a.dp.Addresses.Batcher)(t)
a.miner.ActL1EndBlock(t)

a.lastCommBn = a.miner.l1Chain.CurrentBlock().Number.Uint64()
a.lastCommBn = a.miner.L1Chain().CurrentBlock().Number.Uint64()
}

func (a *L2AltDA) ActDeleteLastInput(t Testing) {
func (a *L2AltDA) ActDeleteLastInput(t helpers.Testing) {
require.NoError(t, a.storage.Client.DeleteData(a.lastComm))
}

func (a *L2AltDA) ActChallengeLastInput(t Testing) {
func (a *L2AltDA) ActChallengeLastInput(t helpers.Testing) {
a.ActChallengeInput(t, a.lastComm, a.lastCommBn)

a.log.Info("challenged last input", "block", a.lastCommBn)
}

func (a *L2AltDA) ActChallengeInput(t Testing, comm []byte, bn uint64) {
func (a *L2AltDA) ActChallengeInput(t helpers.Testing, comm []byte, bn uint64) {
bondValue, err := a.contract.BondSize(&bind.CallOpts{})
require.NoError(t, err)

Expand All @@ -209,15 +210,15 @@ func (a *L2AltDA) ActChallengeInput(t Testing, comm []byte, bn uint64) {
a.miner.ActL1EndBlock(t)
}

func (a *L2AltDA) ActExpireLastInput(t Testing) {
func (a *L2AltDA) ActExpireLastInput(t helpers.Testing) {
reorgWindow := a.altDACfg.ResolveWindow + a.altDACfg.ChallengeWindow
for a.miner.l1Chain.CurrentBlock().Number.Uint64() <= a.lastCommBn+reorgWindow {
for a.miner.L1Chain().CurrentBlock().Number.Uint64() <= a.lastCommBn+reorgWindow {
a.miner.ActL1StartBlock(12)(t)
a.miner.ActL1EndBlock(t)
}
}

func (a *L2AltDA) ActResolveInput(t Testing, comm []byte, input []byte, bn uint64) {
func (a *L2AltDA) ActResolveInput(t helpers.Testing, comm []byte, input []byte, bn uint64) {
txOpts, err := bind.NewKeyedTransactorWithChainID(a.dp.Secrets.Alice, a.sd.L1Cfg.Config.ChainID)
require.NoError(t, err)

Expand All @@ -229,31 +230,30 @@ func (a *L2AltDA) ActResolveInput(t Testing, comm []byte, input []byte, bn uint6
a.miner.ActL1EndBlock(t)
}

func (a *L2AltDA) ActResolveLastChallenge(t Testing) {
func (a *L2AltDA) ActResolveLastChallenge(t helpers.Testing) {
// remove derivation byte prefix
input, err := a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(a.lastComm[1:]))
require.NoError(t, err)

a.ActResolveInput(t, a.lastComm, input, a.lastCommBn)
}

func (a *L2AltDA) ActL1Blocks(t Testing, n uint64) {
func (a *L2AltDA) ActL1Blocks(t helpers.Testing, n uint64) {
for i := uint64(0); i < n; i++ {
a.miner.ActL1StartBlock(12)(t)
a.miner.ActL1EndBlock(t)
}
}

func (a *L2AltDA) GetLastTxBlock(t Testing) *types.Block {
rcpt, err := a.engine.EthClient().TransactionReceipt(t.Ctx(), a.alice.L2.lastTxHash)
require.NoError(t, err)
func (a *L2AltDA) GetLastTxBlock(t helpers.Testing) *types.Block {
rcpt := a.alice.L2.LastTxReceipt(t)
blk, err := a.engine.EthClient().BlockByHash(t.Ctx(), rcpt.BlockHash)
require.NoError(t, err)
return blk
}

func (a *L2AltDA) ActL1Finalized(t Testing) {
latest := a.miner.l1Chain.CurrentBlock().Number.Uint64()
func (a *L2AltDA) ActL1Finalized(t helpers.Testing) {
latest := a.miner.L1Chain().CurrentBlock().Number.Uint64()
a.miner.ActL1Safe(t, latest)
a.miner.ActL1Finalize(t, latest)
a.sequencer.ActL1FinalizedSignal(t)
Expand All @@ -265,7 +265,7 @@ func TestAltDA_ChallengeExpired(gt *testing.T) {
gt.Skip("AltDA is not enabled")
}

t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
harness := NewL2AltDA(t)

// generate enough initial l1 blocks to have a finalized head.
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestAltDA_ChallengeResolved(gt *testing.T) {
gt.Skip("AltDA is not enabled")
}

t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
harness := NewL2AltDA(t)

// include a new l2 transaction, submitting an input commitment to the l1.
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestAltDA_StorageError(gt *testing.T) {
gt.Skip("AltDA is not enabled")
}

t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
harness := NewL2AltDA(t)

// include a new l2 transaction, submitting an input commitment to the l1.
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestAltDA_ChallengeReorg(gt *testing.T) {
gt.Skip("AltDA is not enabled")
}

t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
harness := NewL2AltDA(t)

// New L2 tx added to a batch and committed to L1
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestAltDA_SequencerStalledMultiChallenges(gt *testing.T) {
gt.Skip("AltDA is not enabled")
}

t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
a := NewL2AltDA(t)

// create a new tx on l2 and commit it to l1
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestAltDA_SequencerStalledMultiChallenges(gt *testing.T) {
comm2 := a.lastComm
_, err = a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(comm2[1:]))
require.NoError(t, err)
a.lastCommBn = a.miner.l1Chain.CurrentBlock().Number.Uint64()
a.lastCommBn = a.miner.L1Chain().CurrentBlock().Number.Uint64()

// ensure the second commitment is distinct from the first
require.NotEqual(t, comm1, comm2)
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestAltDA_Finalization(gt *testing.T) {
if !e2eutils.UseAltDA() {
gt.Skip("AltDA is not enabled")
}
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
a := NewL2AltDA(t)

// build L1 block #1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package actions
package batcher

import (
"testing"

"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -16,26 +17,26 @@ import (
"github.com/ethereum-optimism/optimism/op-service/testlog"
)

func setupEIP4844Test(t Testing, log log.Logger) (*e2eutils.SetupData, *e2eutils.DeployParams, *L1Miner, *L2Sequencer, *L2Engine, *L2Verifier, *L2Engine) {
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
func setupEIP4844Test(t helpers.Testing, log log.Logger) (*e2eutils.SetupData, *e2eutils.DeployParams, *helpers.L1Miner, *helpers.L2Sequencer, *helpers.L2Engine, *helpers.L2Verifier, *helpers.L2Engine) {
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
genesisActivation := hexutil.Uint64(0)
dp.DeployConfig.L1CancunTimeOffset = &genesisActivation
dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisActivation
dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisActivation
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisActivation

sd := e2eutils.Setup(t, dp, DefaultAlloc)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
miner, seqEngine, sequencer := helpers.SetupSequencerTest(t, sd, log)
miner.ActL1SetFeeRecipient(common.Address{'A'})
sequencer.ActL2PipelineFull(t)
verifEngine, verifier := setupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{})
verifEngine, verifier := helpers.SetupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{})
return sd, dp, miner, sequencer, seqEngine, verifier, verifEngine
}

func setupBatcher(t Testing, log log.Logger, sd *e2eutils.SetupData, dp *e2eutils.DeployParams, miner *L1Miner,
sequencer *L2Sequencer, engine *L2Engine, daType batcherFlags.DataAvailabilityType,
) *L2Batcher {
return NewL2Batcher(log, sd.RollupCfg, &BatcherCfg{
func setupBatcher(t helpers.Testing, log log.Logger, sd *e2eutils.SetupData, dp *e2eutils.DeployParams, miner *helpers.L1Miner,
sequencer *helpers.L2Sequencer, engine *helpers.L2Engine, daType batcherFlags.DataAvailabilityType,
) *helpers.L2Batcher {
return helpers.NewL2Batcher(log, sd.RollupCfg, &helpers.BatcherCfg{
MinL1TxSize: 0,
MaxL1TxSize: 128_000,
BatcherKey: dp.Secrets.Batcher,
Expand All @@ -44,7 +45,7 @@ func setupBatcher(t Testing, log log.Logger, sd *e2eutils.SetupData, dp *e2eutil
}

func TestEIP4844DataAvailability(gt *testing.T) {
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)

log := testlog.Logger(t, log.LevelDebug)
sd, dp, miner, sequencer, seqEngine, verifier, _ := setupEIP4844Test(t, log)
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestEIP4844DataAvailability(gt *testing.T) {
}

func TestEIP4844MultiBlobs(gt *testing.T) {
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)

log := testlog.Logger(t, log.LevelDebug)
sd, dp, miner, sequencer, seqEngine, verifier, _ := setupEIP4844Test(t, log)
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestEIP4844MultiBlobs(gt *testing.T) {
}

func TestEIP4844DataAvailabilitySwitch(gt *testing.T) {
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)

log := testlog.Logger(t, log.LevelDebug)
sd, dp, miner, sequencer, seqEngine, verifier, _ := setupEIP4844Test(t, log)
Expand Down
Loading

0 comments on commit 994f634

Please sign in to comment.