Commit 994f6347 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-e2e: Separate actions tests into different packages (#11921)

* 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: default avatarclabby <ben@clab.by>
parent 66bfe678
......@@ -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
......
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"
......@@ -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,
......@@ -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)}
......@@ -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)
......@@ -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)
......@@ -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)
......@@ -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)
......@@ -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)
......@@ -229,7 +230,7 @@ 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)
......@@ -237,23 +238,22 @@ func (a *L2AltDA) ActResolveLastChallenge(t Testing) {
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)
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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
......@@ -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
......@@ -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)
......@@ -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
......
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"
......@@ -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,
......@@ -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)
......@@ -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)
......@@ -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)
......
package actions
package derivation
import (
"testing"
altda "github.com/ethereum-optimism/optimism/op-alt-da"
batcherFlags "github.com/ethereum-optimism/optimism/op-batcher/flags"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
upgradesHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/upgrades/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/node/safedb"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/log"
......@@ -20,7 +23,7 @@ import (
// This is a regression test, previously the pipeline encountered got stuck in a reset loop with the error:
// buffered L1 chain epoch %s in batch queue does not match safe head origin %s
func TestDeriveChainFromNearL1Genesis(gt *testing.T) {
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
p := &e2eutils.TestParams{
MaxSequencerDrift: 20, // larger than L1 block time we simulate in this test (12)
SequencerWindowSize: 24,
......@@ -29,22 +32,22 @@ func TestDeriveChainFromNearL1Genesis(gt *testing.T) {
}
dp := e2eutils.MakeDeployParams(t, p)
// do not activate Delta hardfork for verifier
applyDeltaTimeOffset(dp, nil)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
upgradesHelpers.ApplyDeltaTimeOffset(dp, nil)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
logger := testlog.Logger(t, log.LevelInfo)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, logger)
miner, seqEngine, sequencer := helpers.SetupSequencerTest(t, sd, logger)
miner.ActEmptyBlock(t)
require.EqualValues(gt, 1, miner.l1Chain.CurrentBlock().Number.Uint64())
require.EqualValues(gt, 1, miner.L1Chain().CurrentBlock().Number.Uint64())
ref, err := derive.L2BlockToBlockRef(sequencer.rollupCfg, seqEngine.l2Chain.Genesis())
ref, err := derive.L2BlockToBlockRef(sequencer.RollupCfg, seqEngine.L2Chain().Genesis())
require.NoError(gt, err)
require.EqualValues(gt, 0, ref.L1Origin.Number)
sequencer.ActL1HeadSignal(t)
sequencer.ActBuildToL1Head(t)
l2BlockNum := seqEngine.l2Chain.CurrentBlock().Number.Uint64()
ref, err = derive.L2BlockToBlockRef(sequencer.rollupCfg, seqEngine.l2Chain.GetBlockByNumber(l2BlockNum))
l2BlockNum := seqEngine.L2Chain().CurrentBlock().Number.Uint64()
ref, err = derive.L2BlockToBlockRef(sequencer.RollupCfg, seqEngine.L2Chain().GetBlockByNumber(l2BlockNum))
require.NoError(gt, err)
require.EqualValues(gt, 1, ref.L1Origin.Number)
......@@ -52,7 +55,7 @@ func TestDeriveChainFromNearL1Genesis(gt *testing.T) {
rollupSeqCl := sequencer.RollupClient()
// Force batcher to submit SingularBatches to L1.
batcher := NewL2Batcher(logger, sd.RollupCfg, &BatcherCfg{
batcher := helpers.NewL2Batcher(logger, sd.RollupCfg, &helpers.BatcherCfg{
MinL1TxSize: 0,
MaxL1TxSize: 128_000,
BatcherKey: dp.Secrets.Batcher,
......@@ -60,40 +63,40 @@ func TestDeriveChainFromNearL1Genesis(gt *testing.T) {
}, rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
batcher.ActSubmitAll(t)
require.EqualValues(gt, l2BlockNum, batcher.l2BufferedBlock.Number)
require.EqualValues(gt, l2BlockNum, batcher.L2BufferedBlock.Number)
// confirm batch on L1
miner.ActL1StartBlock(12)(t)
miner.ActL1IncludeTx(dp.Addresses.Batcher)(t)
miner.ActL1EndBlock(t)
bl := miner.l1Chain.CurrentBlock()
bl := miner.L1Chain().CurrentBlock()
logger.Info("Produced L1 block with batch",
"num", miner.l1Chain.CurrentBlock().Number.Uint64(),
"txs", len(miner.l1Chain.GetBlockByHash(bl.Hash()).Transactions()))
"num", miner.L1Chain().CurrentBlock().Number.Uint64(),
"txs", len(miner.L1Chain().GetBlockByHash(bl.Hash()).Transactions()))
// Process batches so safe head updates
sequencer.ActL1HeadSignal(t)
sequencer.ActL2PipelineFull(t)
require.EqualValues(gt, l2BlockNum, seqEngine.l2Chain.CurrentSafeBlock().Number.Uint64())
require.EqualValues(gt, l2BlockNum, seqEngine.L2Chain().CurrentSafeBlock().Number.Uint64())
// Finalize L1 and process so L2 finalized updates
miner.ActL1Safe(t, miner.l1Chain.CurrentBlock().Number.Uint64())
miner.ActL1Finalize(t, miner.l1Chain.CurrentBlock().Number.Uint64())
miner.ActL1Safe(t, miner.L1Chain().CurrentBlock().Number.Uint64())
miner.ActL1Finalize(t, miner.L1Chain().CurrentBlock().Number.Uint64())
sequencer.ActL1SafeSignal(t)
sequencer.ActL1FinalizedSignal(t)
sequencer.ActL2PipelineFull(t)
require.EqualValues(gt, l2BlockNum, seqEngine.l2Chain.CurrentFinalBlock().Number.Uint64())
require.EqualValues(gt, l2BlockNum, seqEngine.L2Chain().CurrentFinalBlock().Number.Uint64())
// Create a new verifier using the existing engine so it already has the safe and finalized heads set.
// This is the same situation as if op-node restarted at this point.
l2Cl, err := sources.NewEngineClient(seqEngine.RPCClient(), logger, nil, sources.EngineClientDefaultConfig(sd.RollupCfg))
require.NoError(gt, err)
verifier := NewL2Verifier(t, logger, sequencer.l1, miner.BlobStore(), altda.Disabled,
l2Cl, sequencer.rollupCfg, sequencer.syncCfg, safedb.Disabled, nil)
verifier := helpers.NewL2Verifier(t, logger, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), altda.Disabled,
l2Cl, sequencer.RollupCfg, &sync.Config{}, safedb.Disabled, nil)
verifier.ActL2PipelineFull(t) // Should not get stuck in a reset loop forever
require.EqualValues(gt, l2BlockNum, seqEngine.l2Chain.CurrentSafeBlock().Number.Uint64())
require.EqualValues(gt, l2BlockNum, seqEngine.l2Chain.CurrentFinalBlock().Number.Uint64())
syncStatus := verifier.syncStatus.SyncStatus()
require.EqualValues(gt, l2BlockNum, seqEngine.L2Chain().CurrentSafeBlock().Number.Uint64())
require.EqualValues(gt, l2BlockNum, seqEngine.L2Chain().CurrentFinalBlock().Number.Uint64())
syncStatus := verifier.SyncStatus()
require.EqualValues(gt, l2BlockNum, syncStatus.SafeL2.Number)
require.EqualValues(gt, l2BlockNum, syncStatus.FinalizedL2.Number)
}
package actions
package derivation
import (
"math/big"
"testing"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
upgradesHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/upgrades/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common/hexutil"
......@@ -44,16 +46,16 @@ func TestBlockTimeBatchType(t *testing.T) {
// window.
// This is a regression test against the bug fixed in PR #4566
func BatchInLastPossibleBlocks(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
applyDeltaTimeOffset(dp, deltaTimeOffset)
t := actionsHelpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, actionsHelpers.DefaultRollupTestParams)
upgradesHelpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
dp.DeployConfig.SequencerWindowSize = 4
dp.DeployConfig.L2BlockTime = 2
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, actionsHelpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
sd, _, miner, sequencer, sequencerEngine, _, _, batcher := setupReorgTestActors(t, dp, sd, log)
sd, _, miner, sequencer, sequencerEngine, _, _, batcher := actionsHelpers.SetupReorgTestActors(t, dp, sd, log)
signer := types.LatestSigner(sd.L2Cfg.Config)
cl := sequencerEngine.EthClient()
......@@ -63,7 +65,7 @@ func BatchInLastPossibleBlocks(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
ChainID: sd.L2Cfg.Config.ChainID,
Nonce: aliceNonce,
GasTipCap: big.NewInt(2 * params.GWei),
GasFeeCap: new(big.Int).Add(miner.l1Chain.CurrentBlock().BaseFee, big.NewInt(2*params.GWei)),
GasFeeCap: new(big.Int).Add(miner.L1Chain().CurrentBlock().BaseFee, big.NewInt(2*params.GWei)),
Gas: params.TxGas,
To: &dp.Addresses.Bob,
Value: e2eutils.Ether(2),
......@@ -78,7 +80,7 @@ func BatchInLastPossibleBlocks(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
sequencer.ActL2EndBlock(t)
}
verifyChainStateOnSequencer := func(l1Number, unsafeHead, unsafeHeadOrigin, safeHead, safeHeadOrigin uint64) {
require.Equal(t, l1Number, miner.l1Chain.CurrentHeader().Number.Uint64())
require.Equal(t, l1Number, miner.L1Chain().CurrentHeader().Number.Uint64())
require.Equal(t, unsafeHead, sequencer.L2Unsafe().Number)
require.Equal(t, unsafeHeadOrigin, sequencer.L2Unsafe().L1Origin.Number)
require.Equal(t, safeHead, sequencer.L2Safe().Number)
......@@ -155,8 +157,8 @@ func BatchInLastPossibleBlocks(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
// At this point it can verify that the batches where properly generated.
// Note: It batches submits when possible.
func LargeL1Gaps(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := actionsHelpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, actionsHelpers.DefaultRollupTestParams)
dp.DeployConfig.L1BlockTime = 4
dp.DeployConfig.L2BlockTime = 2
dp.DeployConfig.SequencerWindowSize = 4
......@@ -165,11 +167,11 @@ func LargeL1Gaps(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
// TODO(client-pod#831): The Ecotone (and Fjord) activation blocks don't include user txs,
// so disabling these forks for now.
applyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
upgradesHelpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, actionsHelpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
sd, _, miner, sequencer, sequencerEngine, verifier, _, batcher := setupReorgTestActors(t, dp, sd, log)
sd, _, miner, sequencer, sequencerEngine, verifier, _, batcher := actionsHelpers.SetupReorgTestActors(t, dp, sd, log)
signer := types.LatestSigner(sd.L2Cfg.Config)
cl := sequencerEngine.EthClient()
......@@ -180,7 +182,7 @@ func LargeL1Gaps(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
ChainID: sd.L2Cfg.Config.ChainID,
Nonce: aliceNonce,
GasTipCap: big.NewInt(2 * params.GWei),
GasFeeCap: new(big.Int).Add(miner.l1Chain.CurrentBlock().BaseFee, big.NewInt(2*params.GWei)),
GasFeeCap: new(big.Int).Add(miner.L1Chain().CurrentBlock().BaseFee, big.NewInt(2*params.GWei)),
Gas: params.TxGas,
To: &dp.Addresses.Bob,
Value: e2eutils.Ether(2),
......@@ -196,7 +198,7 @@ func LargeL1Gaps(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
}
verifyChainStateOnSequencer := func(l1Number, unsafeHead, unsafeHeadOrigin, safeHead, safeHeadOrigin uint64) {
require.Equal(t, l1Number, miner.l1Chain.CurrentHeader().Number.Uint64())
require.Equal(t, l1Number, miner.L1Chain().CurrentHeader().Number.Uint64())
require.Equal(t, unsafeHead, sequencer.L2Unsafe().Number)
require.Equal(t, unsafeHeadOrigin, sequencer.L2Unsafe().L1Origin.Number)
require.Equal(t, safeHead, sequencer.L2Safe().Number)
......@@ -204,7 +206,7 @@ func LargeL1Gaps(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
}
verifyChainStateOnVerifier := func(l1Number, unsafeHead, unsafeHeadOrigin, safeHead, safeHeadOrigin uint64) {
require.Equal(t, l1Number, miner.l1Chain.CurrentHeader().Number.Uint64())
require.Equal(t, l1Number, miner.L1Chain().CurrentHeader().Number.Uint64())
require.Equal(t, unsafeHead, verifier.L2Unsafe().Number)
require.Equal(t, unsafeHeadOrigin, verifier.L2Unsafe().L1Origin.Number)
require.Equal(t, safeHead, verifier.L2Safe().Number)
......
package actions
package derivation
import (
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/testlog"
)
func setupVerifier(t Testing, sd *e2eutils.SetupData, log log.Logger,
l1F derive.L1Fetcher, blobSrc derive.L1BlobsFetcher, syncCfg *sync.Config, opts ...VerifierOpt) (*L2Engine, *L2Verifier) {
cfg := DefaultVerifierCfg()
for _, opt := range opts {
opt(cfg)
}
jwtPath := e2eutils.WriteDefaultJWT(t)
engine := NewL2Engine(t, log.New("role", "verifier-engine"), sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath, EngineWithP2P())
engCl := engine.EngineClient(t, sd.RollupCfg)
verifier := NewL2Verifier(t, log.New("role", "verifier"), l1F, blobSrc, altda.Disabled, engCl, sd.RollupCfg, syncCfg, cfg.SafeHeadListener, cfg.InteropBackend)
return engine, verifier
}
func setupVerifierOnlyTest(t Testing, sd *e2eutils.SetupData, log log.Logger) (*L1Miner, *L2Engine, *L2Verifier) {
miner := NewL1Miner(t, log, sd.L1Cfg)
l1Cl := miner.L1Client(t, sd.RollupCfg)
engine, verifier := setupVerifier(t, sd, log, l1Cl, miner.BlobStore(), &sync.Config{})
return miner, engine, verifier
}
func TestL2Verifier_SequenceWindow(gt *testing.T) {
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
p := &e2eutils.TestParams{
MaxSequencerDrift: 10,
SequencerWindowSize: 24,
......@@ -43,26 +21,26 @@ func TestL2Verifier_SequenceWindow(gt *testing.T) {
L1BlockTime: 15,
}
dp := e2eutils.MakeDeployParams(t, p)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, engine, verifier := setupVerifierOnlyTest(t, sd, log)
miner, engine, verifier := helpers.SetupVerifierOnlyTest(t, sd, log)
miner.ActL1SetFeeRecipient(common.Address{'A'})
// Make two sequence windows worth of empty L1 blocks. After we pass the first sequence window, the L2 chain should get blocks
for miner.l1Chain.CurrentBlock().Number.Uint64() < sd.RollupCfg.SeqWindowSize*2 {
for miner.L1Chain().CurrentBlock().Number.Uint64() < sd.RollupCfg.SeqWindowSize*2 {
miner.ActL1StartBlock(10)(t)
miner.ActL1EndBlock(t)
verifier.ActL2PipelineFull(t)
l1Head := miner.l1Chain.CurrentBlock().Number.Uint64()
l1Head := miner.L1Chain().CurrentBlock().Number.Uint64()
expectedL1Origin := uint64(0)
// as soon as we complete the sequence window, we force-adopt the L1 origin
if l1Head >= sd.RollupCfg.SeqWindowSize {
expectedL1Origin = l1Head - sd.RollupCfg.SeqWindowSize
}
require.Equal(t, expectedL1Origin, verifier.SyncStatus().SafeL2.L1Origin.Number, "L1 origin is forced in, given enough L1 blocks pass by")
require.LessOrEqual(t, miner.l1Chain.GetBlockByNumber(expectedL1Origin).Time(), engine.l2Chain.CurrentBlock().Time, "L2 time higher than L1 origin time")
require.LessOrEqual(t, miner.L1Chain().GetBlockByNumber(expectedL1Origin).Time(), engine.L2Chain().CurrentBlock().Time, "L2 time higher than L1 origin time")
}
tip2N := verifier.SyncStatus()
......@@ -77,13 +55,13 @@ func TestL2Verifier_SequenceWindow(gt *testing.T) {
miner.ActL1SetFeeRecipient(common.Address{'B'})
miner.ActL1StartBlock(10)(t)
miner.ActL1EndBlock(t)
reorgL1Block := miner.l1Chain.CurrentBlock()
reorgL1Block := miner.L1Chain().CurrentBlock()
// Still no reorg, we need more L1 blocks first, before the reorged L1 block is forced in by sequence window
verifier.ActL2PipelineFull(t)
require.Equal(t, tip2N.SafeL2, verifier.SyncStatus().SafeL2)
for miner.l1Chain.CurrentBlock().Number.Uint64() < sd.RollupCfg.SeqWindowSize*2 {
for miner.L1Chain().CurrentBlock().Number.Uint64() < sd.RollupCfg.SeqWindowSize*2 {
miner.ActL1StartBlock(10)(t)
miner.ActL1EndBlock(t)
}
......@@ -95,6 +73,6 @@ func TestL2Verifier_SequenceWindow(gt *testing.T) {
// Now it will reorg
verifier.ActL2PipelineFull(t)
got := miner.l1Chain.GetBlockByHash(miner.l1Chain.GetBlockByHash(verifier.SyncStatus().SafeL2.L1Origin.Hash).Hash())
got := miner.L1Chain().GetBlockByHash(miner.L1Chain().GetBlockByHash(verifier.SyncStatus().SafeL2.L1Origin.Hash).Hash())
require.Equal(t, reorgL1Block.Hash(), got.Hash(), "must have reorged L2 chain to the new L1 chain")
}
package actions
package derivation
import (
"math/big"
"math/rand"
"testing"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
upgradesHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/upgrades/helpers"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
......@@ -49,27 +51,27 @@ func TestSystemConfigBatchType(t *testing.T) {
// BatcherKeyRotation tests that batcher A can operate, then be replaced with batcher B, then ignore old batcher A,
// and that the change to batcher B is reverted properly upon reorg of L1.
func BatcherKeyRotation(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
t := actionsHelpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
dp := e2eutils.MakeDeployParams(t, actionsHelpers.DefaultRollupTestParams)
dp.DeployConfig.L2BlockTime = 2
applyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
upgradesHelpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, actionsHelpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
miner, seqEngine, sequencer := actionsHelpers.SetupSequencerTest(t, sd, log)
miner.ActL1SetFeeRecipient(common.Address{'A'})
sequencer.ActL2PipelineFull(t)
_, verifier := setupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{})
_, verifier := actionsHelpers.SetupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{})
rollupSeqCl := sequencer.RollupClient()
// the default batcher
batcherA := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
batcherA := actionsHelpers.NewL2Batcher(log, sd.RollupCfg, actionsHelpers.DefaultBatcherCfg(dp),
rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
// a batcher with a new key
altCfg := *DefaultBatcherCfg(dp)
altCfg := *actionsHelpers.DefaultBatcherCfg(dp)
altCfg.BatcherKey = dp.Secrets.Bob
batcherB := NewL2Batcher(log, sd.RollupCfg, &altCfg,
batcherB := actionsHelpers.NewL2Batcher(log, sd.RollupCfg, &altCfg,
rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
sequencer.ActL2PipelineFull(t)
......@@ -114,7 +116,7 @@ func BatcherKeyRotation(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
receipt, err := miner.EthClient().TransactionReceipt(t.Ctx(), tx.Hash())
require.NoError(t, err)
cfgChangeL1BlockNum := miner.l1Chain.CurrentBlock().Number.Uint64()
cfgChangeL1BlockNum := miner.L1Chain().CurrentBlock().Number.Uint64()
require.Equal(t, cfgChangeL1BlockNum, receipt.BlockNumber.Uint64())
// sequence L2 blocks, and submit with new batcher
......@@ -225,9 +227,9 @@ func BatcherKeyRotation(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
// GPOParamsChange tests that the GPO params can be updated to adjust fees of L2 transactions,
// and that the L1 data fees to the L2 transaction are applied correctly before, during and after the GPO update in L2.
func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
applyDeltaTimeOffset(dp, deltaTimeOffset)
t := actionsHelpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, actionsHelpers.DefaultRollupTestParams)
upgradesHelpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
// activating Delta only, not Ecotone and further:
// the GPO change assertions here all apply only for the Delta transition.
......@@ -236,14 +238,14 @@ func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
dp.DeployConfig.L2GenesisGraniteTimeOffset = nil
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, actionsHelpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
batcher := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
miner, seqEngine, sequencer := actionsHelpers.SetupSequencerTest(t, sd, log)
batcher := actionsHelpers.NewL2Batcher(log, sd.RollupCfg, actionsHelpers.DefaultBatcherCfg(dp),
sequencer.RollupClient(), miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
alice := NewBasicUser[any](log, dp.Secrets.Alice, rand.New(rand.NewSource(1234)))
alice.SetUserEnv(&BasicUserEnv[any]{
alice := actionsHelpers.NewBasicUser[any](log, dp.Secrets.Alice, rand.New(rand.NewSource(1234)))
alice.SetUserEnv(&actionsHelpers.BasicUserEnv[any]{
EthCl: seqEngine.EthClient(),
Signer: types.LatestSigner(sd.L2Cfg.Config),
})
......@@ -254,7 +256,7 @@ func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
miner.ActEmptyBlock(t)
sequencer.ActL1HeadSignal(t)
sequencer.ActBuildToL1Head(t)
basefee := miner.l1Chain.CurrentBlock().BaseFee
basefee := miner.L1Chain().CurrentBlock().BaseFee
// alice makes a L2 tx, sequencer includes it
alice.ActResetTxOpts(t)
......@@ -299,7 +301,7 @@ func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
miner.ActL1StartBlock(12)(t)
miner.ActL1IncludeTx(dp.Addresses.SysCfgOwner)(t)
miner.ActL1EndBlock(t)
basefeeGPOUpdate := miner.l1Chain.CurrentBlock().BaseFee
basefeeGPOUpdate := miner.L1Chain().CurrentBlock().BaseFee
// build empty L2 chain, up to but excluding the L2 block with the L1 origin that processes the GPO change
sequencer.ActL1HeadSignal(t)
......@@ -336,7 +338,7 @@ func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
// build more L2 blocks, with new L1 origin
miner.ActEmptyBlock(t)
basefee = miner.l1Chain.CurrentBlock().BaseFee
basefee = miner.L1Chain().CurrentBlock().BaseFee
sequencer.ActL1HeadSignal(t)
sequencer.ActBuildToL1Head(t)
// and Alice makes a tx again
......@@ -360,13 +362,13 @@ func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
// and that the L2 changes the gas limit instantly at the exact block that adopts the L1 origin with
// the gas limit change event. And checks if a verifier node can reproduce the same gas limit change.
func GasLimitChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
applyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
t := actionsHelpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, actionsHelpers.DefaultRollupTestParams)
upgradesHelpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, actionsHelpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
batcher := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
miner, seqEngine, sequencer := actionsHelpers.SetupSequencerTest(t, sd, log)
batcher := actionsHelpers.NewL2Batcher(log, sd.RollupCfg, actionsHelpers.DefaultBatcherCfg(dp),
sequencer.RollupClient(), miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
sequencer.ActL2PipelineFull(t)
......@@ -374,7 +376,7 @@ func GasLimitChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
sequencer.ActL1HeadSignal(t)
sequencer.ActBuildToL1Head(t)
oldGasLimit := seqEngine.l2Chain.CurrentBlock().GasLimit
oldGasLimit := seqEngine.L2Chain().CurrentBlock().GasLimit
require.Equal(t, oldGasLimit, uint64(dp.DeployConfig.L2GenesisBlockGasLimit))
// change gas limit on L1 to triple what it was
......@@ -396,12 +398,12 @@ func GasLimitChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
sequencer.ActL1HeadSignal(t)
sequencer.ActBuildToL1HeadExcl(t)
require.Equal(t, oldGasLimit, seqEngine.l2Chain.CurrentBlock().GasLimit)
require.Equal(t, oldGasLimit, seqEngine.L2Chain().CurrentBlock().GasLimit)
require.Equal(t, uint64(1), sequencer.SyncStatus().UnsafeL2.L1Origin.Number)
// now include the L1 block with the gaslimit change, and see if it changes as expected
sequencer.ActBuildToL1Head(t)
require.Equal(t, oldGasLimit*3, seqEngine.l2Chain.CurrentBlock().GasLimit)
require.Equal(t, oldGasLimit*3, seqEngine.L2Chain().CurrentBlock().GasLimit)
require.Equal(t, uint64(2), sequencer.SyncStatus().UnsafeL2.L1Origin.Number)
// now submit all this to L1, and see if a verifier can sync and reproduce it
......@@ -410,7 +412,7 @@ func GasLimitChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
miner.ActL1IncludeTx(dp.Addresses.Batcher)(t)
miner.ActL1EndBlock(t)
_, verifier := setupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{})
_, verifier := actionsHelpers.SetupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{})
verifier.ActL2PipelineFull(t)
require.Equal(t, sequencer.L2Unsafe(), verifier.L2Safe(), "verifier stays in sync, even with gaslimit changes")
......
package actions
package helpers
import (
"context"
......
package actions
package helpers
import (
"math/big"
......@@ -33,9 +33,9 @@ type L1Miner struct {
// L1 block building data
l1BuildingHeader *types.Header // block header that we add txs to for block building
l1BuildingState *state.StateDB // state used for block building
l1GasPool *core.GasPool // track gas used of ongoing building
L1GasPool *core.GasPool // track gas used of ongoing building
pendingIndices map[common.Address]uint64 // per account, how many txs from the pool were already included in the block, since the pool is lagging behind block mining.
l1Transactions []*types.Transaction // collects txs that were successfully included into current block build
L1Transactions []*types.Transaction // collects txs that were successfully included into current block build
l1Receipts []*types.Receipt // collect receipts of ongoing building
l1Building bool
l1TxFailed []*types.Transaction // log of failed transactions which could not be included
......@@ -120,11 +120,11 @@ func (s *L1Miner) ActL1StartBlock(timeDelta uint64) Action {
s.l1BuildingHeader = header
s.l1BuildingState = statedb
s.l1Receipts = make([]*types.Receipt, 0)
s.l1Transactions = make([]*types.Transaction, 0)
s.L1Transactions = make([]*types.Transaction, 0)
s.pendingIndices = make(map[common.Address]uint64)
s.l1BuildingBlobSidecars = make([]*types.BlobTxSidecar, 0)
s.l1GasPool = new(core.GasPool).AddGas(header.GasLimit)
s.L1GasPool = new(core.GasPool).AddGas(header.GasLimit)
}
}
......@@ -138,7 +138,7 @@ func (s *L1Miner) ActL1IncludeTx(from common.Address) Action {
getPendingIndex := func(from common.Address) uint64 {
return s.pendingIndices[from]
}
tx := firstValidTx(t, from, getPendingIndex, s.eth.TxPool().ContentFrom, s.EthClient().NonceAt)
tx := firstValidTx(t, from, getPendingIndex, s.Eth.TxPool().ContentFrom, s.EthClient().NonceAt)
s.IncludeTx(t, tx)
s.pendingIndices[from] = s.pendingIndices[from] + 1 // won't retry the tx
}
......@@ -151,7 +151,7 @@ func (s *L1Miner) ActL1IncludeTxByHash(txHash common.Hash) Action {
t.InvalidAction("no tx inclusion when not building l1 block")
return
}
tx := s.eth.TxPool().Get(txHash)
tx := s.Eth.TxPool().Get(txHash)
require.NotNil(t, tx, "cannot find tx %s", txHash)
s.IncludeTx(t, tx)
from, err := s.l1Signer.Sender(tx)
......@@ -167,19 +167,19 @@ func (s *L1Miner) IncludeTx(t Testing, tx *types.Transaction) {
if tx.Gas() > s.l1BuildingHeader.GasLimit {
t.Fatalf("tx consumes %d gas, more than available in L1 block %d", tx.Gas(), s.l1BuildingHeader.GasLimit)
}
if tx.Gas() > uint64(*s.l1GasPool) {
t.InvalidAction("action takes too much gas: %d, only have %d", tx.Gas(), uint64(*s.l1GasPool))
if tx.Gas() > uint64(*s.L1GasPool) {
t.InvalidAction("action takes too much gas: %d, only have %d", tx.Gas(), uint64(*s.L1GasPool))
return
}
s.l1BuildingState.SetTxContext(tx.Hash(), len(s.l1Transactions))
s.l1BuildingState.SetTxContext(tx.Hash(), len(s.L1Transactions))
receipt, err := core.ApplyTransaction(s.l1Cfg.Config, s.l1Chain, &s.l1BuildingHeader.Coinbase,
s.l1GasPool, s.l1BuildingState, s.l1BuildingHeader, tx.WithoutBlobTxSidecar(), &s.l1BuildingHeader.GasUsed, *s.l1Chain.GetVMConfig())
s.L1GasPool, s.l1BuildingState, s.l1BuildingHeader, tx.WithoutBlobTxSidecar(), &s.l1BuildingHeader.GasUsed, *s.l1Chain.GetVMConfig())
if err != nil {
s.l1TxFailed = append(s.l1TxFailed, tx)
t.Fatalf("failed to apply transaction to L1 block (tx %d): %v", len(s.l1Transactions), err)
t.Fatalf("failed to apply transaction to L1 block (tx %d): %v", len(s.L1Transactions), err)
}
s.l1Receipts = append(s.l1Receipts, receipt)
s.l1Transactions = append(s.l1Transactions, tx.WithoutBlobTxSidecar())
s.L1Transactions = append(s.L1Transactions, tx.WithoutBlobTxSidecar())
if tx.Type() == types.BlobTxType {
require.True(t, s.l1Cfg.Config.IsCancun(s.l1BuildingHeader.Number, s.l1BuildingHeader.Time), "L1 must be cancun to process blob tx")
sidecar := tx.BlobTxSidecar()
......@@ -205,7 +205,7 @@ func (s *L1Miner) ActL1EndBlock(t Testing) {
}
s.l1Building = false
s.l1BuildingHeader.GasUsed = s.l1BuildingHeader.GasLimit - uint64(*s.l1GasPool)
s.l1BuildingHeader.GasUsed = s.l1BuildingHeader.GasLimit - uint64(*s.L1GasPool)
s.l1BuildingHeader.Root = s.l1BuildingState.IntermediateRoot(s.l1Cfg.Config.IsEIP158(s.l1BuildingHeader.Number))
var withdrawals []*types.Withdrawal
......@@ -213,7 +213,7 @@ func (s *L1Miner) ActL1EndBlock(t Testing) {
withdrawals = make([]*types.Withdrawal, 0)
}
block := types.NewBlock(s.l1BuildingHeader, &types.Body{Transactions: s.l1Transactions, Withdrawals: withdrawals}, s.l1Receipts, trie.NewStackTrie(nil))
block := types.NewBlock(s.l1BuildingHeader, &types.Body{Transactions: s.L1Transactions, Withdrawals: withdrawals}, s.l1Receipts, trie.NewStackTrie(nil))
if s.l1Cfg.Config.IsCancun(s.l1BuildingHeader.Number, s.l1BuildingHeader.Time) {
parent := s.l1Chain.GetHeaderByHash(s.l1BuildingHeader.ParentHash)
var (
......
package actions
package helpers
import (
"errors"
......@@ -38,7 +38,7 @@ type L1Replica struct {
log log.Logger
node *node.Node
eth *eth.Ethereum
Eth *eth.Ethereum
// L1 evm / chain
l1Chain *core.BlockChain
......@@ -90,7 +90,7 @@ func NewL1Replica(t Testing, log log.Logger, genesis *core.Genesis) *L1Replica {
return &L1Replica{
log: log,
node: n,
eth: backend,
Eth: backend,
l1Chain: backend.BlockChain(),
l1Database: backend.ChainDb(),
l1Cfg: genesis,
......
package actions
package helpers
import (
"bytes"
......@@ -106,12 +106,12 @@ type L2Batcher struct {
l1Signer types.Signer
l2ChannelOut ChannelOutIface
L2ChannelOut ChannelOutIface
l2Submitting bool // when the channel out is being submitted, and not safe to write to without resetting
l2BufferedBlock eth.L2BlockRef
L2BufferedBlock eth.L2BlockRef
l2SubmittedBlock eth.L2BlockRef
l2BatcherCfg *BatcherCfg
batcherAddr common.Address
BatcherAddr common.Address
LastSubmitted *types.Transaction
}
......@@ -126,7 +126,7 @@ func NewL2Batcher(log log.Logger, rollupCfg *rollup.Config, batcherCfg *BatcherC
engCl: engCl,
l2BatcherCfg: batcherCfg,
l1Signer: types.LatestSignerForChainID(rollupCfg.L1ChainID),
batcherAddr: crypto.PubkeyToAddress(batcherCfg.BatcherKey.PublicKey),
BatcherAddr: crypto.PubkeyToAddress(batcherCfg.BatcherKey.PublicKey),
}
}
......@@ -144,7 +144,7 @@ func (s *L2Batcher) ActL2BatchBuffer(t Testing) {
func (s *L2Batcher) Buffer(t Testing) error {
if s.l2Submitting { // break ongoing submitting work if necessary
s.l2ChannelOut = nil
s.L2ChannelOut = nil
s.l2Submitting = false
}
syncStatus, err := s.syncStatusAPI.SyncStatus(t.Ctx())
......@@ -153,38 +153,38 @@ func (s *L2Batcher) Buffer(t Testing) error {
if s.l2SubmittedBlock == (eth.L2BlockRef{}) {
s.log.Info("Starting batch-submitter work at safe-head", "safe", syncStatus.SafeL2)
s.l2SubmittedBlock = syncStatus.SafeL2
s.l2BufferedBlock = syncStatus.SafeL2
s.l2ChannelOut = nil
s.L2BufferedBlock = syncStatus.SafeL2
s.L2ChannelOut = nil
}
// If it's lagging behind, catch it up.
if s.l2SubmittedBlock.Number < syncStatus.SafeL2.Number {
s.log.Warn("last submitted block lagged behind L2 safe head: batch submission will continue from the safe head now", "last", s.l2SubmittedBlock, "safe", syncStatus.SafeL2)
s.l2SubmittedBlock = syncStatus.SafeL2
s.l2BufferedBlock = syncStatus.SafeL2
s.l2ChannelOut = nil
s.L2BufferedBlock = syncStatus.SafeL2
s.L2ChannelOut = nil
}
// Add the next unsafe block to the channel
if s.l2BufferedBlock.Number >= syncStatus.UnsafeL2.Number {
if s.l2BufferedBlock.Number > syncStatus.UnsafeL2.Number || s.l2BufferedBlock.Hash != syncStatus.UnsafeL2.Hash {
if s.L2BufferedBlock.Number >= syncStatus.UnsafeL2.Number {
if s.L2BufferedBlock.Number > syncStatus.UnsafeL2.Number || s.L2BufferedBlock.Hash != syncStatus.UnsafeL2.Hash {
s.log.Error("detected a reorg in L2 chain vs previous buffered information, resetting to safe head now", "safe_head", syncStatus.SafeL2)
s.l2SubmittedBlock = syncStatus.SafeL2
s.l2BufferedBlock = syncStatus.SafeL2
s.l2ChannelOut = nil
s.L2BufferedBlock = syncStatus.SafeL2
s.L2ChannelOut = nil
} else {
s.log.Info("nothing left to submit")
return nil
}
}
block, err := s.l2.BlockByNumber(t.Ctx(), big.NewInt(int64(s.l2BufferedBlock.Number+1)))
block, err := s.l2.BlockByNumber(t.Ctx(), big.NewInt(int64(s.L2BufferedBlock.Number+1)))
require.NoError(t, err, "need l2 block %d from sync status", s.l2SubmittedBlock.Number+1)
if block.ParentHash() != s.l2BufferedBlock.Hash {
if block.ParentHash() != s.L2BufferedBlock.Hash {
s.log.Error("detected a reorg in L2 chain vs previous submitted information, resetting to safe head now", "safe_head", syncStatus.SafeL2)
s.l2SubmittedBlock = syncStatus.SafeL2
s.l2BufferedBlock = syncStatus.SafeL2
s.l2ChannelOut = nil
s.L2BufferedBlock = syncStatus.SafeL2
s.L2ChannelOut = nil
}
// Create channel if we don't have one yet
if s.l2ChannelOut == nil {
if s.L2ChannelOut == nil {
var ch ChannelOutIface
if s.l2BatcherCfg.GarbageCfg != nil {
ch, err = NewGarbageChannelOut(s.l2BatcherCfg.GarbageCfg)
......@@ -210,29 +210,29 @@ func (s *L2Batcher) Buffer(t Testing) error {
}
}
require.NoError(t, err, "failed to create channel")
s.l2ChannelOut = ch
s.L2ChannelOut = ch
}
if err := s.l2ChannelOut.AddBlock(s.rollupCfg, block); err != nil {
if err := s.L2ChannelOut.AddBlock(s.rollupCfg, block); err != nil {
return err
}
ref, err := s.engCl.L2BlockRefByHash(t.Ctx(), block.Hash())
require.NoError(t, err, "failed to get L2BlockRef")
s.l2BufferedBlock = ref
s.L2BufferedBlock = ref
return nil
}
func (s *L2Batcher) ActL2ChannelClose(t Testing) {
// Don't run this action if there's no data to submit
if s.l2ChannelOut == nil {
if s.L2ChannelOut == nil {
t.InvalidAction("need to buffer data first, cannot batch submit with empty buffer")
return
}
require.NoError(t, s.l2ChannelOut.Close(), "must close channel before submitting it")
require.NoError(t, s.L2ChannelOut.Close(), "must close channel before submitting it")
}
func (s *L2Batcher) ReadNextOutputFrame(t Testing) []byte {
// Don't run this action if there's no data to submit
if s.l2ChannelOut == nil {
if s.L2ChannelOut == nil {
t.InvalidAction("need to buffer data first, cannot batch submit with empty buffer")
return nil
}
......@@ -240,8 +240,8 @@ func (s *L2Batcher) ReadNextOutputFrame(t Testing) []byte {
data := new(bytes.Buffer)
data.WriteByte(derive.DerivationVersion0)
// subtract one, to account for the version byte
if _, err := s.l2ChannelOut.OutputFrame(data, s.l2BatcherCfg.MaxL1TxSize-1); err == io.EOF {
s.l2ChannelOut = nil
if _, err := s.L2ChannelOut.OutputFrame(data, s.l2BatcherCfg.MaxL1TxSize-1); err == io.EOF {
s.L2ChannelOut = nil
s.l2Submitting = false
} else if err != nil {
s.l2Submitting = false
......@@ -263,7 +263,7 @@ func (s *L2Batcher) ActL2BatchSubmitRaw(t Testing, payload []byte, txOpts ...fun
payload = comm.TxData()
}
nonce, err := s.l1.PendingNonceAt(t.Ctx(), s.batcherAddr)
nonce, err := s.l1.PendingNonceAt(t.Ctx(), s.BatcherAddr)
require.NoError(t, err, "need batcher nonce")
gasTipCap := big.NewInt(2 * params.GWei)
......@@ -334,7 +334,7 @@ func (s *L2Batcher) ActL2BatchSubmitMultiBlob(t Testing, numBlobs int) {
}
// Don't run this action if there's no data to submit
if s.l2ChannelOut == nil {
if s.L2ChannelOut == nil {
t.InvalidAction("need to buffer data first, cannot batch submit with empty buffer")
return
}
......@@ -351,12 +351,12 @@ func (s *L2Batcher) ActL2BatchSubmitMultiBlob(t Testing, numBlobs int) {
// subtract one, to account for the version byte
l = s.l2BatcherCfg.MaxL1TxSize - 1
}
if _, err := s.l2ChannelOut.OutputFrame(data, l); err == io.EOF {
if _, err := s.L2ChannelOut.OutputFrame(data, l); err == io.EOF {
s.l2Submitting = false
if i < numBlobs-1 {
t.Fatalf("failed to fill up %d blobs, only filled %d", numBlobs, i+1)
}
s.l2ChannelOut = nil
s.L2ChannelOut = nil
} else if err != nil {
s.l2Submitting = false
t.Fatalf("failed to output channel data to frame: %v", err)
......@@ -366,7 +366,7 @@ func (s *L2Batcher) ActL2BatchSubmitMultiBlob(t Testing, numBlobs int) {
require.NoError(t, blobs[i].FromData(data.Bytes()), "must turn data into blob")
}
nonce, err := s.l1.PendingNonceAt(t.Ctx(), s.batcherAddr)
nonce, err := s.l1.PendingNonceAt(t.Ctx(), s.BatcherAddr)
require.NoError(t, err, "need batcher nonce")
gasTipCap := big.NewInt(2 * params.GWei)
......@@ -453,7 +453,7 @@ func (s *L2Batcher) ActL2BatchSubmitGarbageRaw(t Testing, outputFrame []byte, ki
func (s *L2Batcher) ActBufferAll(t Testing) {
stat, err := s.syncStatusAPI.SyncStatus(t.Ctx())
require.NoError(t, err)
for s.l2BufferedBlock.Number < stat.UnsafeL2.Number {
for s.L2BufferedBlock.Number < stat.UnsafeL2.Number {
s.ActL2BatchBuffer(t)
}
}
......
package actions
package helpers
import (
"errors"
......@@ -35,7 +35,7 @@ type L2Engine struct {
log log.Logger
node *node.Node
eth *geth.Ethereum
Eth *geth.Ethereum
rollupGenesis *rollup.Genesis
......@@ -43,9 +43,9 @@ type L2Engine struct {
l2Chain *core.BlockChain
l2Signer types.Signer
engineApi *engineapi.L2EngineAPI
EngineApi *engineapi.L2EngineAPI
failL2RPC func(call []rpc.BatchElem) error // mock error
FailL2RPC func(call []rpc.BatchElem) error // mock error
}
type EngineOption func(ethCfg *ethconfig.Config, nodeCfg *node.Config) error
......@@ -58,7 +58,7 @@ func NewL2Engine(t Testing, log log.Logger, genesis *core.Genesis, rollupGenesis
eng := &L2Engine{
log: log,
node: n,
eth: ethBackend,
Eth: ethBackend,
rollupGenesis: &rollup.Genesis{
L1: rollupGenesisL1,
L2: eth.BlockID{Hash: genesisBlock.Hash(), Number: genesisBlock.NumberU64()},
......@@ -66,14 +66,14 @@ func NewL2Engine(t Testing, log log.Logger, genesis *core.Genesis, rollupGenesis
},
l2Chain: chain,
l2Signer: types.LatestSigner(genesis.Config),
engineApi: engineApi,
EngineApi: engineApi,
}
// register the custom engine API, so we can serve engine requests while having more control
// over sequencing of individual txs.
n.RegisterAPIs([]rpc.API{
{
Namespace: "engine",
Service: eng.engineApi,
Service: eng.EngineApi,
Authenticated: true,
},
})
......@@ -172,10 +172,10 @@ func (e *L2Engine) RPCClient() client.RPC {
return testutils.RPCErrFaker{
RPC: client.NewBaseRPCClient(cl),
ErrFn: func(call []rpc.BatchElem) error {
if e.failL2RPC == nil {
if e.FailL2RPC == nil {
return nil
}
return e.failL2RPC(call)
return e.FailL2RPC(call)
},
}
}
......@@ -188,12 +188,12 @@ func (e *L2Engine) EngineClient(t Testing, cfg *rollup.Config) *sources.EngineCl
// ActL2RPCFail makes the next L2 RPC request fail with given error
func (e *L2Engine) ActL2RPCFail(t Testing, err error) {
if e.failL2RPC != nil { // already set to fail?
if e.FailL2RPC != nil { // already set to fail?
t.InvalidAction("already set a mock L2 rpc error")
return
}
e.failL2RPC = func(call []rpc.BatchElem) error {
e.failL2RPC = nil
e.FailL2RPC = func(call []rpc.BatchElem) error {
e.FailL2RPC = nil
return err
}
}
......@@ -201,13 +201,13 @@ func (e *L2Engine) ActL2RPCFail(t Testing, err error) {
// ActL2IncludeTx includes the next transaction from the given address in the block that is being built
func (e *L2Engine) ActL2IncludeTx(from common.Address) Action {
return func(t Testing) {
if e.engineApi.ForcedEmpty() {
if e.EngineApi.ForcedEmpty() {
e.log.Info("Skipping including a transaction because e.L2ForceEmpty is true")
return
}
tx := firstValidTx(t, from, e.engineApi.PendingIndices, e.eth.TxPool().ContentFrom, e.EthClient().NonceAt)
err := e.engineApi.IncludeTx(tx, from)
tx := firstValidTx(t, from, e.EngineApi.PendingIndices, e.Eth.TxPool().ContentFrom, e.EthClient().NonceAt)
err := e.EngineApi.IncludeTx(tx, from)
if errors.Is(err, engineapi.ErrNotBuildingBlock) {
t.InvalidAction(err.Error())
} else if errors.Is(err, engineapi.ErrUsesTooMuchGas) {
......
package actions
package helpers
import (
"context"
......@@ -89,7 +89,7 @@ func NewL2Sequencer(t Testing, log log.Logger, l1 derive.L1Fetcher, blobSrc deri
// ActL2StartBlock starts building of a new L2 block on top of the head
func (s *L2Sequencer) ActL2StartBlock(t Testing) {
if !s.l2PipelineIdle {
if !s.L2PipelineIdle {
t.InvalidAction("cannot start L2 build when derivation is not idle")
return
}
......@@ -191,22 +191,22 @@ func (s *L2Sequencer) ActBuildL2ToTime(t Testing, target uint64) {
}
func (s *L2Sequencer) ActBuildL2ToEcotone(t Testing) {
require.NotNil(t, s.rollupCfg.EcotoneTime, "cannot activate Ecotone when it is not scheduled")
for s.L2Unsafe().Time < *s.rollupCfg.EcotoneTime {
require.NotNil(t, s.RollupCfg.EcotoneTime, "cannot activate Ecotone when it is not scheduled")
for s.L2Unsafe().Time < *s.RollupCfg.EcotoneTime {
s.ActL2StartBlock(t)
s.ActL2EndBlock(t)
}
}
func (s *L2Sequencer) ActBuildL2ToFjord(t Testing) {
require.NotNil(t, s.rollupCfg.FjordTime, "cannot activate FjordTime when it is not scheduled")
for s.L2Unsafe().Time < *s.rollupCfg.FjordTime {
require.NotNil(t, s.RollupCfg.FjordTime, "cannot activate FjordTime when it is not scheduled")
for s.L2Unsafe().Time < *s.RollupCfg.FjordTime {
s.ActL2StartBlock(t)
s.ActL2EndBlock(t)
}
}
func (s *L2Sequencer) ActBuildL2ToGranite(t Testing) {
require.NotNil(t, s.rollupCfg.GraniteTime, "cannot activate GraniteTime when it is not scheduled")
for s.L2Unsafe().Time < *s.rollupCfg.GraniteTime {
require.NotNil(t, s.RollupCfg.GraniteTime, "cannot activate GraniteTime when it is not scheduled")
for s.L2Unsafe().Time < *s.RollupCfg.GraniteTime {
s.ActL2StartBlock(t)
s.ActL2EndBlock(t)
}
......
package actions
package helpers
import (
"context"
......@@ -40,7 +40,7 @@ type L2Verifier struct {
log log.Logger
eng L2API
Eng L2API
syncStatus driver.SyncStatusTracker
......@@ -57,10 +57,10 @@ type L2Verifier struct {
l1 derive.L1Fetcher
l2PipelineIdle bool
L2PipelineIdle bool
l2Building bool
rollupCfg *rollup.Config
RollupCfg *rollup.Config
rpc *rpc.Server
......@@ -160,7 +160,7 @@ func NewL2Verifier(t Testing, log log.Logger, l1 derive.L1Fetcher,
rollupNode := &L2Verifier{
eventSys: sys,
log: log,
eng: eng,
Eng: eng,
engine: ec,
derivation: pipeline,
safeHeadListener: safeHeadListener,
......@@ -168,9 +168,9 @@ func NewL2Verifier(t Testing, log log.Logger, l1 derive.L1Fetcher,
drainer: executor,
l1: l1,
syncStatus: syncStatusTracker,
l2PipelineIdle: true,
L2PipelineIdle: true,
l2Building: false,
rollupCfg: cfg,
RollupCfg: cfg,
rpc: rpc.NewServer(),
synchronousEvents: testActionEmitter,
}
......@@ -205,7 +205,7 @@ type l2VerifierBackend struct {
}
func (s *l2VerifierBackend) BlockRefWithStatus(ctx context.Context, num uint64) (eth.L2BlockRef, *eth.SyncStatus, error) {
ref, err := s.verifier.eng.L2BlockRefByNumber(ctx, num)
ref, err := s.verifier.Eng.L2BlockRefByNumber(ctx, num)
return ref, s.verifier.SyncStatus(), err
}
......@@ -345,9 +345,9 @@ func (s *L2Verifier) OnEvent(ev event.Event) bool {
case rollup.CriticalErrorEvent:
panic(fmt.Errorf("derivation failed critically: %w", x.Err))
case derive.DeriverIdleEvent:
s.l2PipelineIdle = true
s.L2PipelineIdle = true
case derive.PipelineStepEvent:
s.l2PipelineIdle = false
s.L2PipelineIdle = false
case driver.StepReqEvent:
s.synchronousEvents.Emit(driver.StepEvent{})
default:
......@@ -396,7 +396,7 @@ func (s *L2Verifier) ActL2UnsafeGossipReceive(payload *eth.ExecutionPayloadEnvel
// ActL2InsertUnsafePayload creates an action that can insert an unsafe execution payload
func (s *L2Verifier) ActL2InsertUnsafePayload(payload *eth.ExecutionPayloadEnvelope) Action {
return func(t Testing) {
ref, err := derive.PayloadToBlockRef(s.rollupCfg, payload.ExecutionPayload)
ref, err := derive.PayloadToBlockRef(s.RollupCfg, payload.ExecutionPayload)
require.NoError(t, err)
err = s.engine.InsertUnsafePayload(t.Ctx(), payload, ref)
require.NoError(t, err)
......
package helpers
import (
altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum-optimism/optimism/op-e2e/actions/upgrades/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
func SetupSequencerTest(t Testing, sd *e2eutils.SetupData, log log.Logger, opts ...SequencerOpt) (*L1Miner, *L2Engine, *L2Sequencer) {
jwtPath := e2eutils.WriteDefaultJWT(t)
cfg := DefaultSequencerConfig()
for _, opt := range opts {
opt(cfg)
}
miner := NewL1Miner(t, log.New("role", "l1-miner"), sd.L1Cfg)
l1F, err := sources.NewL1Client(miner.RPCClient(), log, nil, sources.L1ClientDefaultConfig(sd.RollupCfg, false, sources.RPCKindStandard))
require.NoError(t, err)
engine := NewL2Engine(t, log.New("role", "sequencer-engine"), sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath, EngineWithP2P())
l2Cl, err := sources.NewEngineClient(engine.RPCClient(), log, nil, sources.EngineClientDefaultConfig(sd.RollupCfg))
require.NoError(t, err)
sequencer := NewL2Sequencer(t, log.New("role", "sequencer"), l1F, miner.BlobStore(), altda.Disabled, l2Cl, sd.RollupCfg, 0, cfg.InteropBackend)
return miner, engine, sequencer
}
func SetupVerifier(t Testing, sd *e2eutils.SetupData, log log.Logger,
l1F derive.L1Fetcher, blobSrc derive.L1BlobsFetcher, syncCfg *sync.Config, opts ...VerifierOpt) (*L2Engine, *L2Verifier) {
cfg := DefaultVerifierCfg()
for _, opt := range opts {
opt(cfg)
}
jwtPath := e2eutils.WriteDefaultJWT(t)
engine := NewL2Engine(t, log.New("role", "verifier-engine"), sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath, EngineWithP2P())
engCl := engine.EngineClient(t, sd.RollupCfg)
verifier := NewL2Verifier(t, log.New("role", "verifier"), l1F, blobSrc, altda.Disabled, engCl, sd.RollupCfg, syncCfg, cfg.SafeHeadListener, cfg.InteropBackend)
return engine, verifier
}
func SetupVerifierOnlyTest(t Testing, sd *e2eutils.SetupData, log log.Logger) (*L1Miner, *L2Engine, *L2Verifier) {
miner := NewL1Miner(t, log, sd.L1Cfg)
l1Cl := miner.L1Client(t, sd.RollupCfg)
engine, verifier := SetupVerifier(t, sd, log, l1Cl, miner.BlobStore(), &sync.Config{})
return miner, engine, verifier
}
func SetupReorgTest(t Testing, config *e2eutils.TestParams, deltaTimeOffset *hexutil.Uint64) (*e2eutils.SetupData, *e2eutils.DeployParams, *L1Miner, *L2Sequencer, *L2Engine, *L2Verifier, *L2Engine, *L2Batcher) {
dp := e2eutils.MakeDeployParams(t, config)
helpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
return SetupReorgTestActors(t, dp, sd, log)
}
func SetupReorgTestActors(t Testing, dp *e2eutils.DeployParams, sd *e2eutils.SetupData, log log.Logger) (*e2eutils.SetupData, *e2eutils.DeployParams, *L1Miner, *L2Sequencer, *L2Engine, *L2Verifier, *L2Engine, *L2Batcher) {
miner, seqEngine, sequencer := 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{})
rollupSeqCl := sequencer.RollupClient()
batcher := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
return sd, dp, miner, sequencer, seqEngine, verifier, verifEngine, batcher
}
package actions
package helpers
import (
"context"
......
package actions
package helpers
import (
"fmt"
......@@ -131,7 +131,7 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
require.Equal(t, dp.Secrets.Addresses().Batcher, dp.DeployConfig.BatchSenderAddress)
require.Equal(t, dp.Secrets.Addresses().Proposer, dp.DeployConfig.L2OutputOracleProposer)
miner, seqEngine, seq := setupSequencerTest(t, sd, log)
miner, seqEngine, seq := SetupSequencerTest(t, sd, log)
batcher := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
seq.RollupClient(), miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
......@@ -199,7 +199,7 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
require.NoError(t, err)
require.True(t, infoTx.IsDepositTx())
// Should only be a system tx if regolith is not enabled
require.Equal(t, !seq.rollupCfg.IsRegolith(seq.L2Unsafe().Time), infoTx.IsSystemTx())
require.Equal(t, !seq.RollupCfg.IsRegolith(seq.L2Unsafe().Time), infoTx.IsSystemTx())
// regular L2 tx, in new L2 block
alice.L2.ActResetTxOpts(t)
......@@ -320,5 +320,5 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
require.NoError(t, err)
require.True(t, infoTx.IsDepositTx())
// Should only be a system tx if regolith is not enabled
require.Equal(t, !seq.rollupCfg.IsRegolith(seq.L2Unsafe().Time), infoTx.IsSystemTx())
require.Equal(t, !seq.RollupCfg.IsRegolith(seq.L2Unsafe().Time), infoTx.IsSystemTx())
}
package actions
package helpers
import (
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
......
package actions
package interop
import (
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/log"
......@@ -18,24 +19,24 @@ import (
var _ interop.InteropBackend = (*testutils.MockInteropBackend)(nil)
func TestInteropVerifier(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
// Temporary work-around: interop needs to be active, for cross-safety to not be instant.
// The state genesis in this test is pre-interop however.
sd.RollupCfg.InteropTime = new(uint64)
logger := testlog.Logger(t, log.LevelDebug)
seqMockBackend := &testutils.MockInteropBackend{}
l1Miner, seqEng, seq := setupSequencerTest(t, sd, logger,
WithVerifierOpts(WithInteropBackend(seqMockBackend)))
l1Miner, seqEng, seq := helpers.SetupSequencerTest(t, sd, logger,
helpers.WithVerifierOpts(helpers.WithInteropBackend(seqMockBackend)))
batcher := NewL2Batcher(logger, sd.RollupCfg, DefaultBatcherCfg(dp),
batcher := helpers.NewL2Batcher(logger, sd.RollupCfg, helpers.DefaultBatcherCfg(dp),
seq.RollupClient(), l1Miner.EthClient(), seqEng.EthClient(), seqEng.EngineClient(t, sd.RollupCfg))
verMockBackend := &testutils.MockInteropBackend{}
_, ver := setupVerifier(t, sd, logger,
_, ver := helpers.SetupVerifier(t, sd, logger,
l1Miner.L1Client(t, sd.RollupCfg), l1Miner.BlobStore(), &sync.Config{},
WithInteropBackend(verMockBackend))
helpers.WithInteropBackend(verMockBackend))
seq.ActL2PipelineFull(t)
ver.ActL2PipelineFull(t)
......
......@@ -3,7 +3,7 @@ package proofs
import (
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/actions/proofs/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-program/client/claim"
......@@ -21,7 +21,7 @@ import (
// 5. Instruct the sequencer to derive the L2 chain.
// 6. Run the FPP on the safe head.
func runChannelTimeoutTest(gt *testing.T, testCfg *helpers.TestCfg[any]) {
t := actions.NewDefaultTesting(gt)
t := actionsHelpers.NewDefaultTesting(gt)
tp := helpers.NewTestParams(func(tp *e2eutils.TestParams) {
// Set the channel timeout to 10 blocks, 12x lower than the sequencing window.
tp.ChannelTimeout = 10
......
......@@ -4,7 +4,7 @@ import (
"fmt"
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/actions/proofs/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-program/client/claim"
......@@ -15,19 +15,19 @@ import (
// garbageKinds is a list of garbage kinds to test. We don't use `INVALID_COMPRESSION` and `MALFORM_RLP` because
// they submit malformed frames always, and this test models a valid channel with a single invalid frame in the
// middle.
var garbageKinds = []actions.GarbageKind{
actions.STRIP_VERSION,
actions.RANDOM,
actions.TRUNCATE_END,
actions.DIRTY_APPEND,
var garbageKinds = []actionsHelpers.GarbageKind{
actionsHelpers.STRIP_VERSION,
actionsHelpers.RANDOM,
actionsHelpers.TRUNCATE_END,
actionsHelpers.DIRTY_APPEND,
}
// Run a test that submits garbage channel data in the middle of a channel.
//
// channel format ([]Frame):
// [f[0 - correct] f_x[1 - bad frame] f[1 - correct]]
func runGarbageChannelTest(gt *testing.T, testCfg *helpers.TestCfg[actions.GarbageKind]) {
t := actions.NewDefaultTesting(gt)
func runGarbageChannelTest(gt *testing.T, testCfg *helpers.TestCfg[actionsHelpers.GarbageKind]) {
t := actionsHelpers.NewDefaultTesting(gt)
tp := helpers.NewTestParams(func(tp *e2eutils.TestParams) {
// Set the channel timeout to 10 blocks, 12x lower than the sequencing window.
tp.ChannelTimeout = 10
......@@ -100,7 +100,7 @@ func runGarbageChannelTest(gt *testing.T, testCfg *helpers.TestCfg[actions.Garba
}
func Test_ProgramAction_GarbageChannel(gt *testing.T) {
matrix := helpers.NewMatrix[actions.GarbageKind]()
matrix := helpers.NewMatrix[actionsHelpers.GarbageKind]()
defer matrix.Run(gt)
for _, garbageKind := range garbageKinds {
......
......@@ -6,7 +6,7 @@ import (
altda "github.com/ethereum-optimism/optimism/op-alt-da"
batcherFlags "github.com/ethereum-optimism/optimism/op-batcher/flags"
"github.com/ethereum-optimism/optimism/op-e2e/actions"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-program/host"
"github.com/ethereum-optimism/optimism/op-program/host/config"
......@@ -25,17 +25,17 @@ import (
// L2FaultProofEnv is a test harness for a fault provable L2 chain.
type L2FaultProofEnv struct {
log log.Logger
Batcher *actions.L2Batcher
Sequencer *actions.L2Sequencer
Engine *actions.L2Engine
Batcher *helpers.L2Batcher
Sequencer *helpers.L2Sequencer
Engine *helpers.L2Engine
engCl *sources.EngineClient
sd *e2eutils.SetupData
dp *e2eutils.DeployParams
Miner *actions.L1Miner
Alice *actions.CrossLayerUser
Miner *helpers.L1Miner
Alice *helpers.CrossLayerUser
}
func NewL2FaultProofEnv[c any](t actions.Testing, testCfg *TestCfg[c], tp *e2eutils.TestParams, batcherCfg *actions.BatcherCfg) *L2FaultProofEnv {
func NewL2FaultProofEnv[c any](t helpers.Testing, testCfg *TestCfg[c], tp *e2eutils.TestParams, batcherCfg *helpers.BatcherCfg) *L2FaultProofEnv {
log := testlog.Logger(t, log.LvlDebug)
dp := NewDeployParams(t, func(dp *e2eutils.DeployParams) {
genesisBlock := hexutil.Uint64(0)
......@@ -59,44 +59,44 @@ func NewL2FaultProofEnv[c any](t actions.Testing, testCfg *TestCfg[c], tp *e2eut
dp.DeployConfig.L2GenesisGraniteTimeOffset = &genesisBlock
}
})
sd := e2eutils.Setup(t, dp, actions.DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
jwtPath := e2eutils.WriteDefaultJWT(t)
cfg := &actions.SequencerCfg{VerifierCfg: *actions.DefaultVerifierCfg()}
cfg := &helpers.SequencerCfg{VerifierCfg: *helpers.DefaultVerifierCfg()}
miner := actions.NewL1Miner(t, log.New("role", "l1-miner"), sd.L1Cfg)
miner := helpers.NewL1Miner(t, log.New("role", "l1-miner"), sd.L1Cfg)
l1Cl, err := sources.NewL1Client(miner.RPCClient(), log, nil, sources.L1ClientDefaultConfig(sd.RollupCfg, false, sources.RPCKindStandard))
require.NoError(t, err)
engine := actions.NewL2Engine(t, log.New("role", "sequencer-engine"), sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath, actions.EngineWithP2P())
engine := helpers.NewL2Engine(t, log.New("role", "sequencer-engine"), sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath, helpers.EngineWithP2P())
l2EngineCl, err := sources.NewEngineClient(engine.RPCClient(), log, nil, sources.EngineClientDefaultConfig(sd.RollupCfg))
require.NoError(t, err)
sequencer := actions.NewL2Sequencer(t, log.New("role", "sequencer"), l1Cl, miner.BlobStore(), altda.Disabled, l2EngineCl, sd.RollupCfg, 0, cfg.InteropBackend)
sequencer := helpers.NewL2Sequencer(t, log.New("role", "sequencer"), l1Cl, miner.BlobStore(), altda.Disabled, l2EngineCl, sd.RollupCfg, 0, cfg.InteropBackend)
miner.ActL1SetFeeRecipient(common.Address{0xCA, 0xFE, 0xBA, 0xBE})
sequencer.ActL2PipelineFull(t)
engCl := engine.EngineClient(t, sd.RollupCfg)
// Set the batcher key to the secret key of the batcher
batcherCfg.BatcherKey = dp.Secrets.Batcher
batcher := actions.NewL2Batcher(log, sd.RollupCfg, batcherCfg, sequencer.RollupClient(), miner.EthClient(), engine.EthClient(), engCl)
batcher := helpers.NewL2Batcher(log, sd.RollupCfg, batcherCfg, sequencer.RollupClient(), miner.EthClient(), engine.EthClient(), engCl)
addresses := e2eutils.CollectAddresses(sd, dp)
l1EthCl := miner.EthClient()
l2EthCl := engine.EthClient()
l1UserEnv := &actions.BasicUserEnv[*actions.L1Bindings]{
l1UserEnv := &helpers.BasicUserEnv[*helpers.L1Bindings]{
EthCl: l1EthCl,
Signer: types.LatestSigner(sd.L1Cfg.Config),
AddressCorpora: addresses,
Bindings: actions.NewL1Bindings(t, l1EthCl),
Bindings: helpers.NewL1Bindings(t, l1EthCl),
}
l2UserEnv := &actions.BasicUserEnv[*actions.L2Bindings]{
l2UserEnv := &helpers.BasicUserEnv[*helpers.L2Bindings]{
EthCl: l2EthCl,
Signer: types.LatestSigner(sd.L2Cfg.Config),
AddressCorpora: addresses,
Bindings: actions.NewL2Bindings(t, l2EthCl, engine.GethClient()),
Bindings: helpers.NewL2Bindings(t, l2EthCl, engine.GethClient()),
}
alice := actions.NewCrossLayerUser(log, dp.Secrets.Alice, rand.New(rand.NewSource(0xa57b)))
alice := helpers.NewCrossLayerUser(log, dp.Secrets.Alice, rand.New(rand.NewSource(0xa57b)))
alice.L1.SetUserEnv(l1UserEnv)
alice.L2.SetUserEnv(l2UserEnv)
......@@ -115,16 +115,16 @@ func NewL2FaultProofEnv[c any](t actions.Testing, testCfg *TestCfg[c], tp *e2eut
type FixtureInputParam func(f *FixtureInputs)
type CheckResult func(actions.Testing, error)
type CheckResult func(helpers.Testing, error)
func ExpectNoError() CheckResult {
return func(t actions.Testing, err error) {
return func(t helpers.Testing, err error) {
require.NoError(t, err, "fault proof program should have succeeded")
}
}
func ExpectError(expectedErr error) CheckResult {
return func(t actions.Testing, err error) {
return func(t helpers.Testing, err error) {
require.ErrorIs(t, err, expectedErr, "fault proof program should have failed with expected error")
}
}
......@@ -135,7 +135,7 @@ func WithL2Claim(claim common.Hash) FixtureInputParam {
}
}
func (env *L2FaultProofEnv) RunFaultProofProgram(t actions.Testing, l2ClaimBlockNum uint64, checkResult CheckResult, fixtureInputParams ...FixtureInputParam) {
func (env *L2FaultProofEnv) RunFaultProofProgram(t helpers.Testing, l2ClaimBlockNum uint64, checkResult CheckResult, fixtureInputParams ...FixtureInputParam) {
// Fetch the pre and post output roots for the fault proof.
preRoot, err := env.Sequencer.RollupClient().OutputAtBlock(t.Ctx(), l2ClaimBlockNum-1)
require.NoError(t, err)
......@@ -182,7 +182,7 @@ func (env *L2FaultProofEnv) RunFaultProofProgram(t actions.Testing, l2ClaimBlock
type TestParam func(p *e2eutils.TestParams)
func NewTestParams(params ...TestParam) *e2eutils.TestParams {
dfault := actions.DefaultRollupTestParams
dfault := helpers.DefaultRollupTestParams
for _, apply := range params {
apply(dfault)
}
......@@ -191,7 +191,7 @@ func NewTestParams(params ...TestParam) *e2eutils.TestParams {
type DeployParam func(p *e2eutils.DeployParams)
func NewDeployParams(t actions.Testing, params ...DeployParam) *e2eutils.DeployParams {
func NewDeployParams(t helpers.Testing, params ...DeployParam) *e2eutils.DeployParams {
dfault := e2eutils.MakeDeployParams(t, NewTestParams())
for _, apply := range params {
apply(dfault)
......@@ -199,10 +199,10 @@ func NewDeployParams(t actions.Testing, params ...DeployParam) *e2eutils.DeployP
return dfault
}
type BatcherCfgParam func(c *actions.BatcherCfg)
type BatcherCfgParam func(c *helpers.BatcherCfg)
func NewBatcherCfg(params ...BatcherCfgParam) *actions.BatcherCfg {
dfault := &actions.BatcherCfg{
func NewBatcherCfg(params ...BatcherCfgParam) *helpers.BatcherCfg {
dfault := &helpers.BatcherCfg{
MinL1TxSize: 0,
MaxL1TxSize: 128_000,
DataAvailabilityType: batcherFlags.BlobsType,
......@@ -216,7 +216,7 @@ func NewBatcherCfg(params ...BatcherCfgParam) *actions.BatcherCfg {
type OpProgramCfgParam func(p *config.Config)
func NewOpProgramCfg(
t actions.Testing,
t helpers.Testing,
env *L2FaultProofEnv,
fi *FixtureInputs,
params ...OpProgramCfgParam,
......
......@@ -10,7 +10,7 @@ import (
"regexp"
"strings"
"github.com/ethereum-optimism/optimism/op-e2e/actions"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-program/client/claim"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum/go-ethereum/common"
......@@ -48,7 +48,7 @@ type FixtureInputs struct {
// Dumps a `fp-tests` test fixture to disk if the `OP_E2E_DUMP_FIXTURES` environment variable is set.
//
// [fp-tests]: https://github.com/ethereum-optimism/fp-tests
func tryDumpTestFixture(t actions.Testing, result error, name string, env *L2FaultProofEnv, programCfg *config.Config) {
func tryDumpTestFixture(t helpers.Testing, result error, name string, env *L2FaultProofEnv, programCfg *config.Config) {
if !dumpFixtures {
return
}
......
......@@ -3,7 +3,7 @@ package proofs
import (
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/actions/proofs/helpers"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
......@@ -11,7 +11,7 @@ import (
// Run a test that proves a deposit-only block generated due to sequence window expiry.
func runSequenceWindowExpireTest(gt *testing.T, testCfg *helpers.TestCfg[any]) {
t := actions.NewDefaultTesting(gt)
t := actionsHelpers.NewDefaultTesting(gt)
tp := helpers.NewTestParams()
env := helpers.NewL2FaultProofEnv(t, testCfg, tp, helpers.NewBatcherCfg())
......
......@@ -3,7 +3,7 @@ package proofs
import (
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/actions/proofs/helpers"
"github.com/ethereum-optimism/optimism/op-program/client/claim"
"github.com/ethereum/go-ethereum/common"
......@@ -11,7 +11,7 @@ import (
)
func runSimpleProgramTest(gt *testing.T, testCfg *helpers.TestCfg[any]) {
t := actions.NewDefaultTesting(gt)
t := actionsHelpers.NewDefaultTesting(gt)
env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), helpers.NewBatcherCfg())
// Build an empty block on L2
......
package actions
package proposer
import (
"math/big"
"testing"
"time"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
upgradesHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/upgrades/helpers"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
......@@ -44,24 +46,24 @@ func TestProposerBatchType(t *testing.T) {
}
func RunProposerTest(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
applyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
t := actionsHelpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, actionsHelpers.DefaultRollupTestParams)
upgradesHelpers.ApplyDeltaTimeOffset(dp, deltaTimeOffset)
sd := e2eutils.Setup(t, dp, actionsHelpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
miner, seqEngine, sequencer := actionsHelpers.SetupSequencerTest(t, sd, log)
rollupSeqCl := sequencer.RollupClient()
batcher := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
batcher := actionsHelpers.NewL2Batcher(log, sd.RollupCfg, actionsHelpers.DefaultBatcherCfg(dp),
rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
var proposer *L2Proposer
var proposer *actionsHelpers.L2Proposer
if e2eutils.UseFaultProofs() {
optimismPortal2Contract, err := bindingspreview.NewOptimismPortal2(sd.DeploymentsL1.OptimismPortalProxy, miner.EthClient())
require.NoError(t, err)
respectedGameType, err := optimismPortal2Contract.RespectedGameType(&bind.CallOpts{})
require.NoError(t, err)
proposer = NewL2Proposer(t, log, &ProposerCfg{
proposer = actionsHelpers.NewL2Proposer(t, log, &actionsHelpers.ProposerCfg{
DisputeGameFactoryAddr: &sd.DeploymentsL1.DisputeGameFactoryProxy,
ProposalInterval: 6 * time.Second,
ProposalRetryInterval: 3 * time.Second,
......@@ -70,7 +72,7 @@ func RunProposerTest(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
AllowNonFinalized: true,
}, miner.EthClient(), rollupSeqCl)
} else {
proposer = NewL2Proposer(t, log, &ProposerCfg{
proposer = actionsHelpers.NewL2Proposer(t, log, &actionsHelpers.ProposerCfg{
OutputOracleAddr: &sd.DeploymentsL1.L2OutputOracleProxy,
ProposerKey: dp.Secrets.Proposer,
ProposalRetryInterval: 3 * time.Second,
......
package helpers
import (
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/node/safedb"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
func SetupSafeDBTest(t helpers.Testing, config *e2eutils.TestParams) (*e2eutils.SetupData, *helpers.L1Miner, *helpers.L2Sequencer, *helpers.L2Verifier, *helpers.L2Engine, *helpers.L2Batcher) {
dp := e2eutils.MakeDeployParams(t, config)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
logger := testlog.Logger(t, log.LevelDebug)
return SetupSafeDBTestActors(t, dp, sd, logger)
}
func SetupSafeDBTestActors(t helpers.Testing, dp *e2eutils.DeployParams, sd *e2eutils.SetupData, log log.Logger) (*e2eutils.SetupData, *helpers.L1Miner, *helpers.L2Sequencer, *helpers.L2Verifier, *helpers.L2Engine, *helpers.L2Batcher) {
dir := t.TempDir()
db, err := safedb.NewSafeDB(log, dir)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
})
miner, seqEngine, sequencer := helpers.SetupSequencerTest(t, sd, log)
miner.ActL1SetFeeRecipient(common.Address{'A'})
sequencer.ActL2PipelineFull(t)
verifEngine, verifier := helpers.SetupVerifier(t, sd, log, miner.L1Client(t, sd.RollupCfg), miner.BlobStore(), &sync.Config{}, helpers.WithSafeHeadListener(db))
rollupSeqCl := sequencer.RollupClient()
batcher := helpers.NewL2Batcher(log, sd.RollupCfg, helpers.DefaultBatcherCfg(dp),
rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
return sd, miner, sequencer, verifier, verifEngine, batcher
}
package actions
package safedb
import (
"context"
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/node/safedb"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-e2e/actions/safedb/helpers"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
func TestRecordSafeHeadUpdates(gt *testing.T) {
t := NewDefaultTesting(gt)
sd, miner, sequencer, verifier, verifierEng, batcher := setupSafeDBTest(t, DefaultRollupTestParams)
t := actionsHelpers.NewDefaultTesting(gt)
sd, miner, sequencer, verifier, verifierEng, batcher := helpers.SetupSafeDBTest(t, actionsHelpers.DefaultRollupTestParams)
verifEngClient := verifierEng.EngineClient(t, sd.RollupCfg)
sequencer.ActL2PipelineFull(t)
......@@ -36,7 +33,7 @@ func TestRecordSafeHeadUpdates(gt *testing.T) {
// new L1 block with L2 batch
miner.ActL1StartBlock(12)(t)
miner.ActL1IncludeTx(sd.RollupCfg.Genesis.SystemConfig.BatcherAddr)(t)
batchTx := miner.l1Transactions[0]
batchTx := miner.L1Transactions[0]
miner.ActL1EndBlock(t)
// verifier picks up the L2 chain that was submitted
......@@ -46,7 +43,7 @@ func TestRecordSafeHeadUpdates(gt *testing.T) {
require.NotEqual(t, sequencer.L2Safe(), sequencer.L2Unsafe(), "sequencer has not processed L1 yet")
// Verify the safe head is recorded
l1Head := miner.l1Chain.CurrentBlock()
l1Head := miner.L1Chain().CurrentBlock()
firstSafeHeadUpdateL1Block := l1Head.Number.Uint64()
response, err := verifier.RollupClient().SafeHeadAtL1Block(context.Background(), firstSafeHeadUpdateL1Block)
require.NoError(t, err)
......@@ -62,7 +59,7 @@ func TestRecordSafeHeadUpdates(gt *testing.T) {
// Only genesis is safe at this point
response, err = verifier.RollupClient().SafeHeadAtL1Block(context.Background(), firstSafeHeadUpdateL1Block-1)
require.NoError(t, err)
require.Equal(t, eth.HeaderBlockID(miner.l1Chain.Genesis().Header()), response.L1Block)
require.Equal(t, eth.HeaderBlockID(miner.L1Chain().Genesis().Header()), response.L1Block)
require.Equal(t, sd.RollupCfg.Genesis.L2, response.SafeHead)
// orphan the L1 block that included the batch tx, and build a new different L1 block
......@@ -83,7 +80,7 @@ func TestRecordSafeHeadUpdates(gt *testing.T) {
// The safe head has been reorged so the record should have been deleted, leaving us back with just genesis safe
response, err = verifier.RollupClient().SafeHeadAtL1Block(context.Background(), firstSafeHeadUpdateL1Block)
require.NoError(t, err)
require.Equal(t, eth.HeaderBlockID(miner.l1Chain.Genesis().Header()), response.L1Block)
require.Equal(t, eth.HeaderBlockID(miner.L1Chain().Genesis().Header()), response.L1Block)
require.Equal(t, sd.RollupCfg.Genesis.L2, response.SafeHead)
// Now replay the batch tx in a new L1 block
......@@ -91,7 +88,7 @@ func TestRecordSafeHeadUpdates(gt *testing.T) {
miner.ActL1SetFeeRecipient(common.Address{'C'})
// note: the geth tx pool reorgLoop is too slow (responds to chain head events, but async),
// and there's no way to manually trigger runReorg, so we re-insert it ourselves.
require.NoError(t, miner.eth.TxPool().Add([]*types.Transaction{batchTx}, true, true)[0])
require.NoError(t, miner.Eth.TxPool().Add([]*types.Transaction{batchTx}, true, true)[0])
// need to re-insert previously included tx into the block
miner.ActL1IncludeTx(sd.RollupCfg.Genesis.SystemConfig.BatcherAddr)(t)
miner.ActL1EndBlock(t)
......@@ -105,36 +102,10 @@ func TestRecordSafeHeadUpdates(gt *testing.T) {
require.Equal(t, verifier.L2Safe(), ref, "verifier engine matches rollup client")
// Verify the safe head is recorded again
l1Head = miner.l1Chain.CurrentBlock()
l1Head = miner.L1Chain().CurrentBlock()
firstSafeHeadUpdateL1Block = l1Head.Number.Uint64()
response, err = verifier.RollupClient().SafeHeadAtL1Block(context.Background(), firstSafeHeadUpdateL1Block)
require.NoError(t, err)
require.Equal(t, eth.HeaderBlockID(l1Head), response.L1Block)
require.Equal(t, verifier.L2Unsafe().ID(), response.SafeHead)
}
func setupSafeDBTest(t Testing, config *e2eutils.TestParams) (*e2eutils.SetupData, *L1Miner, *L2Sequencer, *L2Verifier, *L2Engine, *L2Batcher) {
dp := e2eutils.MakeDeployParams(t, config)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
logger := testlog.Logger(t, log.LevelDebug)
return setupSafeDBTestActors(t, dp, sd, logger)
}
func setupSafeDBTestActors(t Testing, dp *e2eutils.DeployParams, sd *e2eutils.SetupData, log log.Logger) (*e2eutils.SetupData, *L1Miner, *L2Sequencer, *L2Verifier, *L2Engine, *L2Batcher) {
dir := t.TempDir()
db, err := safedb.NewSafeDB(log, dir)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
})
miner, seqEngine, sequencer := 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{}, WithSafeHeadListener(db))
rollupSeqCl := sequencer.RollupClient()
batcher := NewL2Batcher(log, sd.RollupCfg, DefaultBatcherCfg(dp),
rollupSeqCl, miner.EthClient(), seqEngine.EthClient(), seqEngine.EngineClient(t, sd.RollupCfg))
return sd, miner, sequencer, verifier, verifEngine, batcher
}
package actions
package sequencer
import (
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
......@@ -11,33 +12,12 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/testlog"
)
func setupSequencerTest(t Testing, sd *e2eutils.SetupData, log log.Logger, opts ...SequencerOpt) (*L1Miner, *L2Engine, *L2Sequencer) {
jwtPath := e2eutils.WriteDefaultJWT(t)
cfg := DefaultSequencerConfig()
for _, opt := range opts {
opt(cfg)
}
miner := NewL1Miner(t, log.New("role", "l1-miner"), sd.L1Cfg)
l1F, err := sources.NewL1Client(miner.RPCClient(), log, nil, sources.L1ClientDefaultConfig(sd.RollupCfg, false, sources.RPCKindStandard))
require.NoError(t, err)
engine := NewL2Engine(t, log.New("role", "sequencer-engine"), sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath, EngineWithP2P())
l2Cl, err := sources.NewEngineClient(engine.RPCClient(), log, nil, sources.EngineClientDefaultConfig(sd.RollupCfg))
require.NoError(t, err)
sequencer := NewL2Sequencer(t, log.New("role", "sequencer"), l1F, miner.BlobStore(), altda.Disabled, l2Cl, sd.RollupCfg, 0, cfg.InteropBackend)
return miner, engine, sequencer
}
func TestL2Sequencer_SequencerDrift(gt *testing.T) {
t := NewDefaultTesting(gt)
t := helpers.NewDefaultTesting(gt)
p := &e2eutils.TestParams{
MaxSequencerDrift: 20, // larger than L1 block time we simulate in this test (12)
SequencerWindowSize: 24,
......@@ -45,9 +25,9 @@ func TestL2Sequencer_SequencerDrift(gt *testing.T) {
L1BlockTime: 12,
}
dp := e2eutils.MakeDeployParams(t, p)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, engine, sequencer := setupSequencerTest(t, sd, log)
miner, engine, sequencer := helpers.SetupSequencerTest(t, sd, log)
miner.ActL1SetFeeRecipient(common.Address{'A'})
sequencer.ActL2PipelineFull(t)
......@@ -61,7 +41,7 @@ func TestL2Sequencer_SequencerDrift(gt *testing.T) {
ChainID: sd.L2Cfg.Config.ChainID,
Nonce: n,
GasTipCap: big.NewInt(2 * params.GWei),
GasFeeCap: new(big.Int).Add(miner.l1Chain.CurrentBlock().BaseFee, big.NewInt(2*params.GWei)),
GasFeeCap: new(big.Int).Add(miner.L1Chain().CurrentBlock().BaseFee, big.NewInt(2*params.GWei)),
Gas: params.TxGas,
To: &dp.Addresses.Bob,
Value: e2eutils.Ether(2),
......@@ -79,7 +59,7 @@ func TestL2Sequencer_SequencerDrift(gt *testing.T) {
miner.ActL1StartBlock(12)(t)
miner.ActL1EndBlock(t)
sequencer.ActL1HeadSignal(t)
origin := miner.l1Chain.CurrentBlock()
origin := miner.L1Chain().CurrentBlock()
// L2 makes blocks to catch up
for sequencer.SyncStatus().UnsafeL2.Time+sd.RollupCfg.BlockTime < origin.Time {
......@@ -104,18 +84,18 @@ func TestL2Sequencer_SequencerDrift(gt *testing.T) {
// We passed the sequencer drift: we can still keep the old origin, but can't include any txs
sequencer.ActL2KeepL1Origin(t)
sequencer.ActL2StartBlock(t)
require.True(t, engine.engineApi.ForcedEmpty(), "engine should not be allowed to include anything after sequencer drift is surpassed")
require.True(t, engine.EngineApi.ForcedEmpty(), "engine should not be allowed to include anything after sequencer drift is surpassed")
}
// TestL2Sequencer_SequencerOnlyReorg regression-tests a Goerli halt where the sequencer
// would build an unsafe L2 block with a L1 origin that then gets reorged out,
// while the verifier-codepath only ever sees the valid post-reorg L1 chain.
func TestL2Sequencer_SequencerOnlyReorg(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, _, sequencer := setupSequencerTest(t, sd, log)
miner, _, sequencer := helpers.SetupSequencerTest(t, sd, log)
// Sequencer at first only recognizes the genesis as safe.
// The rest of the L1 chain will be incorporated as L1 origins into unsafe L2 blocks.
......
package actions
package upgrades
import (
"context"
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
......@@ -17,15 +18,15 @@ import (
)
func TestDencunL1ForkAfterGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
offset := hexutil.Uint64(24)
dp.DeployConfig.L1CancunTimeOffset = &offset
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, miner, sequencer, _, verifier, _, batcher := setupReorgTestActors(t, dp, sd, log)
_, _, miner, sequencer, _, verifier, _, batcher := helpers.SetupReorgTestActors(t, dp, sd, log)
l1Head := miner.l1Chain.CurrentBlock()
l1Head := miner.L1Chain().CurrentBlock()
require.False(t, sd.L1Cfg.Config.IsCancun(l1Head.Number, l1Head.Time), "Cancun not active yet")
require.Nil(t, l1Head.ExcessBlobGas, "Cancun blob gas not in header")
......@@ -39,7 +40,7 @@ func TestDencunL1ForkAfterGenesis(gt *testing.T) {
miner.ActEmptyBlock(t) // Cancun activates here
miner.ActEmptyBlock(t)
// verify Cancun is active
l1Head = miner.l1Chain.CurrentBlock()
l1Head = miner.L1Chain().CurrentBlock()
require.True(t, sd.L1Cfg.Config.IsCancun(l1Head.Number, l1Head.Time), "Cancun active")
require.NotNil(t, l1Head.ExcessBlobGas, "Cancun blob gas in header")
......@@ -48,7 +49,7 @@ func TestDencunL1ForkAfterGenesis(gt *testing.T) {
sequencer.ActBuildToL1Head(t)
miner.ActL1StartBlock(12)(t)
batcher.ActSubmitAll(t)
miner.ActL1IncludeTx(batcher.batcherAddr)(t)
miner.ActL1IncludeTx(batcher.BatcherAddr)(t)
miner.ActL1EndBlock(t)
// sync verifier
......@@ -60,14 +61,14 @@ func TestDencunL1ForkAfterGenesis(gt *testing.T) {
}
func TestDencunL1ForkAtGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
require.Zero(t, *dp.DeployConfig.L1CancunTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, miner, sequencer, _, verifier, _, batcher := setupReorgTestActors(t, dp, sd, log)
_, _, miner, sequencer, _, verifier, _, batcher := helpers.SetupReorgTestActors(t, dp, sd, log)
l1Head := miner.l1Chain.CurrentBlock()
l1Head := miner.L1Chain().CurrentBlock()
require.True(t, sd.L1Cfg.Config.IsCancun(l1Head.Number, l1Head.Time), "Cancun active at genesis")
require.NotNil(t, l1Head.ExcessBlobGas, "Cancun blob gas in header")
......@@ -81,7 +82,7 @@ func TestDencunL1ForkAtGenesis(gt *testing.T) {
miner.ActEmptyBlock(t)
// verify Cancun is still active
l1Head = miner.l1Chain.CurrentBlock()
l1Head = miner.L1Chain().CurrentBlock()
require.True(t, sd.L1Cfg.Config.IsCancun(l1Head.Number, l1Head.Time), "Cancun active")
require.NotNil(t, l1Head.ExcessBlobGas, "Cancun blob gas in header")
......@@ -90,7 +91,7 @@ func TestDencunL1ForkAtGenesis(gt *testing.T) {
sequencer.ActBuildToL1Head(t)
miner.ActL1StartBlock(12)(t)
batcher.ActSubmitAll(t)
miner.ActL1IncludeTx(batcher.batcherAddr)(t)
miner.ActL1IncludeTx(batcher.BatcherAddr)(t)
miner.ActL1EndBlock(t)
// sync verifier
......@@ -117,8 +118,8 @@ func verifyEcotoneBlock(gt *testing.T, header *types.Header) {
}
func TestDencunL2ForkAfterGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
require.Zero(t, *dp.DeployConfig.L1CancunTimeOffset)
// This test wil fork on the second block
offset := hexutil.Uint64(dp.DeployConfig.L2BlockTime * 2)
......@@ -127,56 +128,56 @@ func TestDencunL2ForkAfterGenesis(gt *testing.T) {
dp.DeployConfig.L2GenesisGraniteTimeOffset = nil
// New forks have to be added here, after changing the default deploy config!
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
_, _, _, sequencer, engine, verifier, _, _ := helpers.SetupReorgTestActors(t, dp, sd, log)
// start op-nodes
sequencer.ActL2PipelineFull(t)
verifier.ActL2PipelineFull(t)
// Genesis block is pre-ecotone
verifyPreEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyPreEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
// Block before fork block
sequencer.ActL2StartBlock(t)
sequencer.ActL2EndBlock(t)
verifyPreEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyPreEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
// Fork block is ecotone
sequencer.ActL2StartBlock(t)
sequencer.ActL2EndBlock(t)
verifyEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
// Blocks post fork have Ecotone properties
sequencer.ActL2StartBlock(t)
sequencer.ActL2EndBlock(t)
verifyEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
}
func TestDencunL2ForkAtGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
require.Zero(t, *dp.DeployConfig.L2GenesisEcotoneTimeOffset)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
_, _, _, sequencer, engine, verifier, _, _ := helpers.SetupReorgTestActors(t, dp, sd, log)
// start op-nodes
sequencer.ActL2PipelineFull(t)
verifier.ActL2PipelineFull(t)
// Genesis block has ecotone properties
verifyEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
// Blocks post fork have Ecotone properties
sequencer.ActL2StartBlock(t)
sequencer.ActL2EndBlock(t)
verifyEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
}
func aliceSimpleBlobTx(t Testing, dp *e2eutils.DeployParams) *types.Transaction {
func aliceSimpleBlobTx(t helpers.Testing, dp *e2eutils.DeployParams) *types.Transaction {
txData := transactions.CreateEmptyBlobTx(true, dp.DeployConfig.L2ChainID)
// Manual signer creation, so we can sign a blob tx on the chain,
// even though we have disabled cancun signer support in Ecotone.
......@@ -186,17 +187,17 @@ func aliceSimpleBlobTx(t Testing, dp *e2eutils.DeployParams) *types.Transaction
return tx
}
func newEngine(t Testing, sd *e2eutils.SetupData, log log.Logger) *L2Engine {
func newEngine(t helpers.Testing, sd *e2eutils.SetupData, log log.Logger) *helpers.L2Engine {
jwtPath := e2eutils.WriteDefaultJWT(t)
return NewL2Engine(t, log, sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath)
return helpers.NewL2Engine(t, log, sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath)
}
// TestDencunBlobTxRPC tries to send a Blob tx to the L2 engine via RPC, it should not be accepted.
func TestDencunBlobTxRPC(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
engine := newEngine(t, sd, log)
cl := engine.EthClient()
......@@ -207,31 +208,31 @@ func TestDencunBlobTxRPC(gt *testing.T) {
// TestDencunBlobTxInTxPool tries to insert a blob tx directly into the tx pool, it should not be accepted.
func TestDencunBlobTxInTxPool(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
engine := newEngine(t, sd, log)
tx := aliceSimpleBlobTx(t, dp)
errs := engine.eth.TxPool().Add([]*types.Transaction{tx}, true, true)
errs := engine.Eth.TxPool().Add([]*types.Transaction{tx}, true, true)
require.ErrorContains(t, errs[0], "transaction type not supported")
}
// TestDencunBlobTxInclusion tries to send a Blob tx to the L2 engine, it should not be accepted.
func TestDencunBlobTxInclusion(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, engine, sequencer := setupSequencerTest(t, sd, log)
_, engine, sequencer := helpers.SetupSequencerTest(t, sd, log)
sequencer.ActL2PipelineFull(t)
tx := aliceSimpleBlobTx(t, dp)
sequencer.ActL2StartBlock(t)
err := engine.engineApi.IncludeTx(tx, dp.Addresses.Alice)
err := engine.EngineApi.IncludeTx(tx, dp.Addresses.Alice)
require.ErrorContains(t, err, "invalid L2 block (tx 1): failed to apply transaction to L2 block (tx 1): transaction type not supported")
}
package actions
package upgrades
import (
"context"
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
......@@ -30,7 +31,7 @@ var (
// verifyCodeHashMatches checks that the has of the code at the given address matches the expected code-hash.
// It also sanity-checks that the code is not empty: we should never deploy empty contract codes.
// Returns the contract code
func verifyCodeHashMatches(t Testing, client *ethclient.Client, address common.Address, expectedCodeHash common.Hash) []byte {
func verifyCodeHashMatches(t helpers.Testing, client *ethclient.Client, address common.Address, expectedCodeHash common.Hash) []byte {
code, err := client.CodeAt(context.Background(), address, nil)
require.NoError(t, err)
require.NotEmpty(t, code)
......@@ -40,8 +41,8 @@ func verifyCodeHashMatches(t Testing, client *ethclient.Client, address common.A
}
func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
ecotoneOffset := hexutil.Uint64(4)
log := testlog.Logger(t, log.LevelDebug)
......@@ -54,8 +55,8 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
// New forks have to be added here...
require.NoError(t, dp.DeployConfig.Check(log), "must have valid config")
sd := e2eutils.Setup(t, dp, DefaultAlloc)
_, _, miner, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
_, _, miner, sequencer, engine, verifier, _, _ := helpers.SetupReorgTestActors(t, dp, sd, log)
ethCl := engine.EthClient()
// build a single block to move away from the genesis with 0-values in L1Block contract
......@@ -238,8 +239,8 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
// TestEcotoneBeforeL1 tests that the L2 Ecotone fork can activate before L1 Dencun does
func TestEcotoneBeforeL1(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
offset := hexutil.Uint64(0)
farOffset := hexutil.Uint64(10000)
dp.DeployConfig.L2GenesisRegolithTimeOffset = &offset
......@@ -248,19 +249,19 @@ func TestEcotoneBeforeL1(gt *testing.T) {
dp.DeployConfig.L2GenesisDeltaTimeOffset = &offset
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &offset
sd := e2eutils.Setup(t, dp, DefaultAlloc)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
_, _, _, sequencer, engine, verifier, _, _ := helpers.SetupReorgTestActors(t, dp, sd, log)
// start op-nodes
sequencer.ActL2PipelineFull(t)
verifier.ActL2PipelineFull(t)
// Genesis block has ecotone properties
verifyEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
// Blocks post fork have Ecotone properties
sequencer.ActL2StartBlock(t)
sequencer.ActL2EndBlock(t)
verifyEcotoneBlock(gt, engine.l2Chain.CurrentBlock())
verifyEcotoneBlock(gt, engine.L2Chain().CurrentBlock())
}
package actions
package upgrades
import (
"context"
......@@ -6,6 +6,7 @@ import (
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
......@@ -29,8 +30,8 @@ var (
)
func TestFjordNetworkUpgradeTransactions(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, DefaultRollupTestParams)
t := helpers.NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, helpers.DefaultRollupTestParams)
genesisBlock := hexutil.Uint64(0)
fjordOffset := hexutil.Uint64(2)
......@@ -46,8 +47,8 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) {
dp.DeployConfig.L2GenesisFjordTimeOffset = &fjordOffset
require.NoError(t, dp.DeployConfig.Check(log), "must have valid config")
sd := e2eutils.Setup(t, dp, DefaultAlloc)
_, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
sd := e2eutils.Setup(t, dp, helpers.DefaultAlloc)
_, _, _, sequencer, engine, verifier, _, _ := helpers.SetupReorgTestActors(t, dp, sd, log)
ethCl := engine.EthClient()
// start op-nodes
......
package helpers
import (
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum/go-ethereum/common/hexutil"
)
// ApplyDeltaTimeOffset adjusts fork configuration to not conflict with the delta overrides
func ApplyDeltaTimeOffset(dp *e2eutils.DeployParams, deltaTimeOffset *hexutil.Uint64) {
dp.DeployConfig.L2GenesisDeltaTimeOffset = deltaTimeOffset
// configure Ecotone to not be before Delta accidentally
if dp.DeployConfig.L2GenesisEcotoneTimeOffset != nil {
if deltaTimeOffset == nil {
dp.DeployConfig.L2GenesisEcotoneTimeOffset = nil
} else if *dp.DeployConfig.L2GenesisEcotoneTimeOffset < *deltaTimeOffset {
dp.DeployConfig.L2GenesisEcotoneTimeOffset = deltaTimeOffset
}
}
// configure Fjord to not be before Delta accidentally
if dp.DeployConfig.L2GenesisFjordTimeOffset != nil {
if deltaTimeOffset == nil {
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
} else if *dp.DeployConfig.L2GenesisFjordTimeOffset < *deltaTimeOffset {
dp.DeployConfig.L2GenesisFjordTimeOffset = deltaTimeOffset
}
}
}
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