op_e2e

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 84 Imported by: 0

README

op-e2e

The end to end tests in this repo depend on genesis state that is created with the kroma-devnet package. To create this state, run the following commands from the root of the repository:

make install-geth
make cannon-prestate
make devnet-allocs

This will leave artifacts in the .devnet directory that will be read into op-e2e at runtime. The default deploy configuration used for starting all op-e2e based tests can be found in packages/contracts/deploy-config/devnetL1.json. There are some values that are safe to change in memory in op-e2e at runtime, but others cannot be changed or else it will result in broken tests. Any changes to devnetL1.json should result in rebuilding the .devnet artifacts before the new values will be present in the op-e2e tests.

Running tests

Consult the Makefile in this directory. Run, e.g.:

make test-http
Troubleshooting

If you encounter errors:

  • ensure you have the latest version of foundry installed: pnpm update:foundry
  • try deleting the packages/contracts/forge-artifacts directory
  • if the above step doesn't fix the error, try pnpm clean

Documentation

Index

Constants

View Source
const (
	DummyHashSepolia = "0xaf01bc158f9b35867aea1517e84cf67eedc6a397c0df380b4b139eb570ddb2fc"
	DummyHashDev     = "0xa1235b834d6f1f78f78bc4db856fbc49302cce2c519921347600693021e087f7"
)
View Source
const (
	Sequencer1Name = "sequencer1"
	Sequencer2Name = "sequencer2"
	Sequencer3Name = "sequencer3"
	VerifierName   = "verifier"
)

Variables

View Source
var (
	// ErrForkChoiceUpdatedNotValid is returned when a forkChoiceUpdated returns a status other than Valid
	ErrForkChoiceUpdatedNotValid = errors.New("forkChoiceUpdated status was not valid")
	// ErrNewPayloadNotValid is returned when a newPayload call returns a status other than Valid, indicating the new block is invalid
	ErrNewPayloadNotValid = errors.New("newPayload status was not valid")
)

Functions

func FinalizeWithdrawal

func FinalizeWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client, privKey *ecdsa.PrivateKey, withdrawalProofReceipt *types.Receipt, params withdrawals.ProvenWithdrawalParameters) *types.Receipt

func InitParallel

func InitParallel(t e2eutils.TestingBase, args ...func(t e2eutils.TestingBase))

func ProveAndFinalizeWithdrawal

func ProveAndFinalizeWithdrawal(t *testing.T, cfg SystemConfig, clients ClientProvider, l2NodeName string, ethPrivKey *ecdsa.PrivateKey, l2WithdrawalReceipt *types.Receipt) (*types.Receipt, *types.Receipt)

func ProveWithdrawal

func ProveWithdrawal(t *testing.T, cfg SystemConfig, clients ClientProvider, l2NodeName string, ethPrivKey *ecdsa.PrivateKey, l2WithdrawalReceipt *types.Receipt) (withdrawals.ProvenWithdrawalParameters, *types.Receipt)

func ProveWithdrawalParameters added in v1.4.0

func ProveWithdrawalParameters(ctx context.Context, proofCl withdrawals.ProofClient, l2ReceiptCl withdrawals.ReceiptClient, l2BlockCl withdrawals.BlockClient, txHash common.Hash, header *types.Header, l2OutputOracleContract *bindings.L2OutputOracleCaller) (withdrawals.ProvenWithdrawalParameters, error)

func SendDepositTx

func SendDepositTx(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client, l2Client *ethclient.Client, l1Opts *bind.TransactOpts, applyL2Opts DepositTxOptsFn) *types.Receipt

SendDepositTx creates and sends a deposit transaction. The L1 transaction, including sender, is configured by the l1Opts param. The L2 transaction options can be configured by modifying the DepositTxOps value supplied to applyL2Opts Will verify that the transaction is included with the expected status on L1 and L2 Returns the receipt of the L2 transaction

func SendL2Tx

func SendL2Tx(t *testing.T, cfg SystemConfig, l2Client *ethclient.Client, privKey *ecdsa.PrivateKey, applyTxOpts TxOptsFn) *types.Receipt

SendL2Tx creates and sends a transaction. The supplied privKey is used to specify the account to send from and the transaction is sent to the supplied l2Client Transaction options and expected status can be configured in the applyTxOpts function by modifying the supplied TxOpts Will verify that the transaction is included with the expected status on l2Client and any clients added to TxOpts.VerifyClients

func SendWithdrawal

func SendWithdrawal(t *testing.T, cfg SystemConfig, l2Client *ethclient.Client, privKey *ecdsa.PrivateKey, applyOpts WithdrawalTxOptsFn) (*types.Transaction, *types.Receipt)

func SkipOnFPAC added in v1.4.0

func SkipOnFPAC(t e2eutils.TestingBase)

func SkipOnNotFPAC added in v1.4.0

func SkipOnNotFPAC(t e2eutils.TestingBase)

func UseHTTP added in v1.2.0

func UseHTTP() bool

func UsesCannon added in v1.2.0

func UsesCannon(t e2eutils.TestingBase)

Types

type ClientProvider added in v1.4.0

type ClientProvider interface {
	NodeClient(name string) *ethclient.Client
}

type DepositContractConfig

type DepositContractConfig struct {
	L2Oracle           common.Address
	FinalizationPeriod *big.Int
}

type DepositTxOpts

type DepositTxOpts struct {
	ToAddr         common.Address
	Value          *big.Int
	GasLimit       uint64
	IsCreation     bool
	Data           []byte
	ExpectedStatus uint64
}

type DepositTxOptsFn

type DepositTxOptsFn func(l2Opts *DepositTxOpts)

type EthInstance

type EthInstance interface {
	HTTPEndpoint() string
	WSEndpoint() string
	HTTPAuthEndpoint() string
	WSAuthEndpoint() string
	Close() error
}

EthInstance is either an in process Geth or external process exposing its endpoints over the network

type ExternalEthClient added in v1.2.0

type ExternalEthClient struct {
	Session   *gexec.Session
	Endpoints external.Endpoints
}

func (*ExternalEthClient) Close added in v1.2.0

func (eec *ExternalEthClient) Close() error

func (*ExternalEthClient) HTTPAuthEndpoint added in v1.2.0

func (eec *ExternalEthClient) HTTPAuthEndpoint() string

func (*ExternalEthClient) HTTPEndpoint added in v1.2.0

func (eec *ExternalEthClient) HTTPEndpoint() string

func (*ExternalEthClient) WSAuthEndpoint added in v1.2.0

func (eec *ExternalEthClient) WSAuthEndpoint() string

func (*ExternalEthClient) WSEndpoint added in v1.2.0

func (eec *ExternalEthClient) WSEndpoint() string

type ExternalRunner added in v1.2.0

type ExternalRunner struct {
	Name    string
	BinPath string
	Genesis *core.Genesis
	JWTPath string
	// 4844: a datadir specifically for tx-pool blobs
	BlobPoolPath string
}

func (*ExternalRunner) Run added in v1.2.0

type FnTracer

type FnTracer struct {
	OnNewL1HeadFn        func(ctx context.Context, sig eth.L1BlockRef)
	OnUnsafeL2PayloadFn  func(ctx context.Context, from peer.ID, payload *eth.ExecutionPayloadEnvelope)
	OnPublishL2PayloadFn func(ctx context.Context, payload *eth.ExecutionPayloadEnvelope)
}

func (*FnTracer) OnNewL1Head

func (n *FnTracer) OnNewL1Head(ctx context.Context, sig eth.L1BlockRef)

func (*FnTracer) OnPublishL2Payload

func (n *FnTracer) OnPublishL2Payload(ctx context.Context, payload *eth.ExecutionPayloadEnvelope)

func (*FnTracer) OnUnsafeL2Payload

func (n *FnTracer) OnUnsafeL2Payload(ctx context.Context, from peer.ID, payload *eth.ExecutionPayloadEnvelope)

type GethInstance

type GethInstance struct {
	Backend *geth_eth.Ethereum
	Node    *node.Node
}

func (*GethInstance) Close

func (gi *GethInstance) Close() error

func (*GethInstance) HTTPAuthEndpoint

func (gi *GethInstance) HTTPAuthEndpoint() string

func (*GethInstance) HTTPEndpoint

func (gi *GethInstance) HTTPEndpoint() string

func (*GethInstance) WSAuthEndpoint

func (gi *GethInstance) WSAuthEndpoint() string

func (*GethInstance) WSEndpoint

func (gi *GethInstance) WSEndpoint() string

type OpGeth added in v1.2.0

type OpGeth struct {
	L2Client      *ethclient.Client
	SystemConfig  eth.SystemConfig
	L1ChainConfig *params.ChainConfig
	L2ChainConfig *params.ChainConfig
	L1Head        eth.BlockInfo
	L2Head        *eth.ExecutionPayload
	// contains filtered or unexported fields
}

OpGeth is an actor that functions as a l2 op-geth node It provides useful functions for advancing and querying the chain

func NewOpGeth added in v1.2.0

func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, error)

func (*OpGeth) AddL2Block added in v1.2.0

func (d *OpGeth) AddL2Block(ctx context.Context, txs ...*types.Transaction) (*eth.ExecutionPayloadEnvelope, error)

AddL2Block Appends a new L2 block to the current chain including the specified transactions The L1Info transaction is automatically prepended to the created block

func (*OpGeth) Close added in v1.2.0

func (d *OpGeth) Close()

func (*OpGeth) CreatePayloadAttributes added in v1.2.0

func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.PayloadAttributes, error)

CreatePayloadAttributes creates a valid PayloadAttributes containing a L1Info deposit transaction followed by the supplied transactions.

func (*OpGeth) StartBlockBuilding added in v1.2.0

func (d *OpGeth) StartBlockBuilding(ctx context.Context, attrs *eth.PayloadAttributes) (*eth.ForkchoiceUpdatedResult, error)

StartBlockBuilding begins block building for the specified PayloadAttributes by sending a engine_forkChoiceUpdated call. The current L2Head is used as the parent of the new block. ErrForkChoiceUpdatedNotValid is returned if the forkChoiceUpdate call returns a status other than valid.

type System

type System struct {
	Cfg SystemConfig

	RollupConfig *rollup.Config

	L2GenesisCfg *core.Genesis

	// Connections to running nodes
	EthInstances   map[string]EthInstance
	Clients        map[string]*ethclient.Client
	RawClients     map[string]*rpc.Client
	RollupNodes    map[string]*rollupNode.OpNode
	Validator      *validator.Validator
	Challenger     *validator.Validator
	BatchSubmitter *bss.BatcherService
	Mocknet        mocknet.Mocknet

	L1BeaconAPIAddr string

	// TimeTravelClock is nil unless SystemConfig.SupportL1TimeTravel was set to true
	// It provides access to the clock instance used by the L1 node. Calling TimeTravelClock.AdvanceBy
	// allows tests to quickly time travel L1 into the future.
	// Note that this time travel may occur in a single block, creating a very large difference in the Time
	// on sequential blocks.
	TimeTravelClock *clock.AdvancingClock
	// contains filtered or unexported fields
}

func (*System) AdvanceTime added in v1.4.0

func (sys *System) AdvanceTime(d time.Duration)

AdvanceTime advances the system clock by the given duration. If the [System.TimeTravelClock] is nil, this is a no-op.

func (*System) BatcherHelper added in v1.4.0

func (sys *System) BatcherHelper() *batcher.Helper

func (*System) Close

func (sys *System) Close()

func (*System) L1BeaconEndpoint added in v1.4.0

func (sys *System) L1BeaconEndpoint() string

func (*System) L1BeaconHTTPClient added in v1.4.0

func (sys *System) L1BeaconHTTPClient() *sources.BeaconHTTPClient

func (*System) L1Deployments added in v1.4.0

func (sys *System) L1Deployments() *genesis.L1Deployments

func (*System) L1Slot added in v1.4.0

func (sys *System) L1Slot(l1Timestamp uint64) uint64

func (*System) L2Genesis added in v1.4.0

func (sys *System) L2Genesis() *core.Genesis

func (*System) NodeClient added in v1.4.0

func (sys *System) NodeClient(name string) *ethclient.Client

func (*System) NodeEndpoint

func (sys *System) NodeEndpoint(name string) string

func (*System) RollupCfg added in v1.4.0

func (sys *System) RollupCfg() *rollup.Config

func (*System) RollupClient added in v1.4.0

func (sys *System) RollupClient(name string) *sources.RollupClient

func (*System) RollupEndpoint added in v1.4.0

func (sys *System) RollupEndpoint(name string) string

type SystemConfig

type SystemConfig struct {
	Secrets                *e2eutils.Secrets
	L1InfoPredeployAddress common.Address

	DeployConfig  *genesis.DeployConfig
	L1Deployments *genesis.L1Deployments

	JWTFilePath string
	JWTSecret   [32]byte

	BlobsPath string

	Premine         map[common.Address]*big.Int
	Nodes           map[string]*rollupNode.Config // Per node config. Don't use populate rollup.Config
	Loggers         map[string]log.Logger
	GethOptions     map[string][]geth.GethOption
	ValidatorLogger log.Logger
	BatcherLogger   log.Logger

	ExternalL2Shim string

	// map of outbound connections to other nodes. Node names prefixed with "~" are unconnected but linked.
	// A nil map disables P2P completely.
	// Any node name not in the topology will not have p2p enabled.
	P2PTopology map[string][]string

	// Enables req-resp sync in the P2P nodes
	P2PReqRespSync bool

	// If the validator can make outputs for L2 blocks derived from L1 blocks which are not finalized on L1 yet.
	NonFinalizedOutputs bool

	// Explicitly disable batcher, for tests that rely on unsafe L2 payloads
	DisableBatcher bool

	// Configure data-availability type that is used by the batcher.
	DataAvailabilityType batcherFlags.DataAvailabilityType

	// Max L1 tx size for the batcher transactions
	BatcherMaxL1TxSizeBytes uint64

	// Target number of frames to create per channel. Can be used to create
	// multi-blob transactions.
	// Default is 1 if unset.
	BatcherTargetNumFrames int

	// whether to actually use BatcherMaxL1TxSizeBytes for blobs, insteaf of max blob size
	BatcherUseMaxTxSizeForBlobs bool

	// SupportL1TimeTravel determines if the L1 node supports quickly skipping forward in time
	SupportL1TimeTravel bool

	// MaxPendingTransactions determines how many transactions the batcher will try to send
	// concurrently. 0 means unlimited.
	MaxPendingTransactions uint64

	// [Kroma: START]
	// TODO(0xHansLee): temporal flag for malicious validator. If it is set true, the validator acts as a malicious one
	EnableMaliciousValidator bool
	EnableGuardian           bool
}

func DefaultSystemConfig

func DefaultSystemConfig(t *testing.T) SystemConfig

func (SystemConfig) DepositValidatorPool

func (cfg SystemConfig) DepositValidatorPool(l1Client *ethclient.Client, priv *ecdsa.PrivateKey, value *big.Int) error

func (SystemConfig) L1ChainIDBig

func (cfg SystemConfig) L1ChainIDBig() *big.Int

func (SystemConfig) L2ChainIDBig

func (cfg SystemConfig) L2ChainIDBig() *big.Int

func (SystemConfig) SendTransferTx

func (cfg SystemConfig) SendTransferTx(l2Seq *ethclient.Client, l2Sync *ethclient.Client) (*types.Receipt, error)

func (SystemConfig) Start

func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*System, error)

type SystemConfigOption

type SystemConfigOption struct {
	// contains filtered or unexported fields
}

type SystemConfigOptions

type SystemConfigOptions struct {
	// contains filtered or unexported fields
}

func NewSystemConfigOptions

func NewSystemConfigOptions(_opts []SystemConfigOption) (SystemConfigOptions, error)

func (*SystemConfigOptions) Get

func (s *SystemConfigOptions) Get(key, role string) (systemConfigHook, bool)

type TxOpts

type TxOpts struct {
	ToAddr         *common.Address
	Nonce          uint64
	Value          *big.Int
	Gas            uint64
	GasTipCap      *big.Int
	GasFeeCap      *big.Int
	Data           []byte
	ExpectedStatus uint64
	VerifyClients  []*ethclient.Client
}

func (*TxOpts) VerifyOnClients

func (o *TxOpts) VerifyOnClients(clients ...*ethclient.Client)

VerifyOnClients adds additional l2 clients that should sync the block the tx is included in Checks that the receipt received from these clients is equal to the receipt received from the sequencer

type TxOptsFn

type TxOptsFn func(opts *TxOpts)

type WSOrHTTPEndpoint

type WSOrHTTPEndpoint interface {
	WSAuthEndpoint() string
	HTTPAuthEndpoint() string
}

type WithdrawalTxOpts

type WithdrawalTxOpts struct {
	ToAddr         *common.Address
	Nonce          uint64
	Value          *big.Int
	Gas            uint64
	Data           []byte
	ExpectedStatus uint64
	VerifyClients  []*ethclient.Client
}

func (*WithdrawalTxOpts) VerifyOnClients

func (o *WithdrawalTxOpts) VerifyOnClients(clients ...*ethclient.Client)

VerifyOnClients adds additional l2 clients that should sync the block the tx is included in Checks that the receipt received from these clients is equal to the receipt received from the sequencer

type WithdrawalTxOptsFn

type WithdrawalTxOptsFn func(opts *WithdrawalTxOpts)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL