testutils

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigEqual

func BigEqual(a, b *big.Int) bool

func FakeGenesis

func FakeGenesis(l1 rune, l2 rune, l1GenesisNumber int) rollup.Genesis

func GenerateDeposit

func GenerateDeposit(sourceHash common.Hash, rng *rand.Rand) *types.DepositTx

Returns a DepositEvent customized on the basis of the id parameter.

func GenerateLog

func GenerateLog(addr common.Address, topics []common.Hash, data []byte) *types.Log

Generates an EVM log entry with the given topics and data.

func MakeBlockInfo

func MakeBlockInfo(fn func(l *MockBlockInfo)) func(rng *rand.Rand) *MockBlockInfo

func NextRandomL2Ref

func NextRandomL2Ref(rng *rand.Rand, l2BlockTime uint64, parent eth.L2BlockRef, origin eth.BlockID) eth.L2BlockRef

func NextRandomRef

func NextRandomRef(rng *rand.Rand, parent eth.L1BlockRef) eth.L1BlockRef

func RandomAddress

func RandomAddress(rng *rand.Rand) (out common.Address)

func RandomBlockID

func RandomBlockID(rng *rand.Rand) eth.BlockID

func RandomBlockRef

func RandomBlockRef(rng *rand.Rand) eth.L1BlockRef

func RandomData

func RandomData(rng *rand.Rand, size int) []byte

func RandomETH

func RandomETH(rng *rand.Rand, max int64) *big.Int

func RandomHash

func RandomHash(rng *rand.Rand) (out common.Hash)

func RandomKey

func RandomKey() *ecdsa.PrivateKey

func RandomL2BlockRef

func RandomL2BlockRef(rng *rand.Rand) eth.L2BlockRef

func RequireBigEqual

func RequireBigEqual(t *testing.T, exp, actual *big.Int)

Types

type FakeChainSource

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

FakeChainSource implements the ChainSource interface with the ability to control what the head block is of the L1 and L2 chains. In addition, it enables re-orgs to easily be implemented

func NewFakeChainSource

func NewFakeChainSource(l1 []string, l2 []string, l1GenesisNumber int, log log.Logger) *FakeChainSource

func (*FakeChainSource) AdvanceL1

func (m *FakeChainSource) AdvanceL1() eth.L1BlockRef

func (*FakeChainSource) ForkchoiceUpdate

func (*FakeChainSource) L1BlockRefByHash

func (m *FakeChainSource) L1BlockRefByHash(ctx context.Context, l1Hash common.Hash) (eth.L1BlockRef, error)

func (*FakeChainSource) L1BlockRefByLabel

func (m *FakeChainSource) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error)

func (*FakeChainSource) L1BlockRefByNumber

func (m *FakeChainSource) L1BlockRefByNumber(ctx context.Context, l1Num uint64) (eth.L1BlockRef, error)

func (*FakeChainSource) L1Head

func (m *FakeChainSource) L1Head() eth.L1BlockRef

func (*FakeChainSource) L1Range

func (m *FakeChainSource) L1Range(ctx context.Context, base eth.BlockID, max uint64) ([]eth.BlockID, error)

func (*FakeChainSource) L2BlockRefByHash

func (m *FakeChainSource) L2BlockRefByHash(ctx context.Context, l2Hash common.Hash) (eth.L2BlockRef, error)

func (*FakeChainSource) L2BlockRefByLabel

func (m *FakeChainSource) L2BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L2BlockRef, error)

func (*FakeChainSource) L2BlockRefByNumber

func (m *FakeChainSource) L2BlockRefByNumber(ctx context.Context, l2Num *big.Int) (eth.L2BlockRef, error)

func (*FakeChainSource) ReorgL1

func (m *FakeChainSource) ReorgL1()

func (*FakeChainSource) SetL2Finalized

func (m *FakeChainSource) SetL2Finalized(finalized common.Hash)

func (*FakeChainSource) SetL2Head

func (m *FakeChainSource) SetL2Head(head int) eth.L2BlockRef

func (*FakeChainSource) SetL2Safe

func (m *FakeChainSource) SetL2Safe(safe common.Hash)

type MockBlockInfo

type MockBlockInfo struct {
	InfoHash        common.Hash
	InfoParentHash  common.Hash
	InfoCoinbase    common.Address
	InfoRoot        common.Hash
	InfoNum         uint64
	InfoTime        uint64
	InfoMixDigest   [32]byte
	InfoBaseFee     *big.Int
	InfoReceiptRoot common.Hash
}

func RandomBlockInfo

func RandomBlockInfo(rng *rand.Rand) *MockBlockInfo

func (*MockBlockInfo) BaseFee

func (l *MockBlockInfo) BaseFee() *big.Int

func (*MockBlockInfo) BlockRef

func (l *MockBlockInfo) BlockRef() eth.L1BlockRef

func (*MockBlockInfo) Coinbase

func (l *MockBlockInfo) Coinbase() common.Address

func (*MockBlockInfo) Hash

func (l *MockBlockInfo) Hash() common.Hash

func (*MockBlockInfo) ID

func (l *MockBlockInfo) ID() eth.BlockID

func (*MockBlockInfo) MixDigest

func (l *MockBlockInfo) MixDigest() common.Hash

func (*MockBlockInfo) NumberU64

func (l *MockBlockInfo) NumberU64() uint64

func (*MockBlockInfo) ParentHash

func (l *MockBlockInfo) ParentHash() common.Hash

func (*MockBlockInfo) ReceiptHash

func (l *MockBlockInfo) ReceiptHash() common.Hash

func (*MockBlockInfo) Root

func (l *MockBlockInfo) Root() common.Hash

func (*MockBlockInfo) Time

func (l *MockBlockInfo) Time() uint64

type MockEngine

type MockEngine struct {
	MockL2Client
}

func (*MockEngine) ExpectForkchoiceUpdate

func (m *MockEngine) ExpectForkchoiceUpdate(state *eth.ForkchoiceState, attr *eth.PayloadAttributes, result *eth.ForkchoiceUpdatedResult, err error)

func (*MockEngine) ExpectGetPayload

func (m *MockEngine) ExpectGetPayload(payloadId eth.PayloadID, payload *eth.ExecutionPayload, err error)

func (*MockEngine) ExpectNewPayload

func (m *MockEngine) ExpectNewPayload(payload *eth.ExecutionPayload, result *eth.PayloadStatusV1, err error)

func (*MockEngine) ForkchoiceUpdate

func (m *MockEngine) ForkchoiceUpdate(ctx context.Context, state *eth.ForkchoiceState, attr *eth.PayloadAttributes) (*eth.ForkchoiceUpdatedResult, error)

func (*MockEngine) GetPayload

func (m *MockEngine) GetPayload(ctx context.Context, payloadId eth.PayloadID) (*eth.ExecutionPayload, error)

func (*MockEngine) NewPayload

func (m *MockEngine) NewPayload(ctx context.Context, payload *eth.ExecutionPayload) (*eth.PayloadStatusV1, error)

type MockEthClient

type MockEthClient struct {
	mock.Mock
}

func (*MockEthClient) ExpectFetch added in v0.6.0

func (m *MockEthClient) ExpectFetch(hash common.Hash, info eth.BlockInfo, transactions types.Transactions, receipts types.Receipts, err error)

func (*MockEthClient) ExpectGetProof

func (m *MockEthClient) ExpectGetProof(address common.Address, blockTag string, result *eth.AccountResult, err error)

func (*MockEthClient) ExpectInfoAndTxsByHash

func (m *MockEthClient) ExpectInfoAndTxsByHash(hash common.Hash, info eth.BlockInfo, transactions types.Transactions, err error)

func (*MockEthClient) ExpectInfoAndTxsByLabel

func (m *MockEthClient) ExpectInfoAndTxsByLabel(label eth.BlockLabel, info eth.BlockInfo, transactions types.Transactions, err error)

func (*MockEthClient) ExpectInfoAndTxsByNumber

func (m *MockEthClient) ExpectInfoAndTxsByNumber(number uint64, info eth.BlockInfo, transactions types.Transactions, err error)

func (*MockEthClient) ExpectInfoByHash

func (m *MockEthClient) ExpectInfoByHash(hash common.Hash, info eth.BlockInfo, err error)

func (*MockEthClient) ExpectInfoByLabel

func (m *MockEthClient) ExpectInfoByLabel(label eth.BlockLabel, info eth.BlockInfo, err error)

func (*MockEthClient) ExpectInfoByNumber

func (m *MockEthClient) ExpectInfoByNumber(number uint64, info eth.BlockInfo, err error)

func (*MockEthClient) ExpectInfoByRpcNumber added in v0.6.0

func (m *MockEthClient) ExpectInfoByRpcNumber(num rpc.BlockNumber, info eth.BlockInfo, err error)

func (*MockEthClient) ExpectPayloadByHash

func (m *MockEthClient) ExpectPayloadByHash(hash common.Hash, payload *eth.ExecutionPayload, err error)

func (*MockEthClient) ExpectPayloadByLabel

func (m *MockEthClient) ExpectPayloadByLabel(label eth.BlockLabel, payload *eth.ExecutionPayload, err error)

func (*MockEthClient) ExpectPayloadByNumber

func (m *MockEthClient) ExpectPayloadByNumber(hash common.Hash, payload *eth.ExecutionPayload, err error)

func (*MockEthClient) Fetch added in v0.6.0

func (*MockEthClient) GetProof

func (m *MockEthClient) GetProof(ctx context.Context, address common.Address, blockTag string) (*eth.AccountResult, error)

func (*MockEthClient) InfoAndTxsByHash

func (m *MockEthClient) InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error)

func (*MockEthClient) InfoAndTxsByLabel

func (m *MockEthClient) InfoAndTxsByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, types.Transactions, error)

func (*MockEthClient) InfoAndTxsByNumber

func (m *MockEthClient) InfoAndTxsByNumber(ctx context.Context, number uint64) (eth.BlockInfo, types.Transactions, error)

func (*MockEthClient) InfoByHash

func (m *MockEthClient) InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error)

func (*MockEthClient) InfoByLabel

func (m *MockEthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, error)

func (*MockEthClient) InfoByNumber

func (m *MockEthClient) InfoByNumber(ctx context.Context, number uint64) (eth.BlockInfo, error)

func (*MockEthClient) InfoByRpcNumber added in v0.6.0

func (m *MockEthClient) InfoByRpcNumber(ctx context.Context, num rpc.BlockNumber) (eth.BlockInfo, error)

func (*MockEthClient) PayloadByHash

func (m *MockEthClient) PayloadByHash(ctx context.Context, hash common.Hash) (*eth.ExecutionPayload, error)

func (*MockEthClient) PayloadByLabel

func (m *MockEthClient) PayloadByLabel(ctx context.Context, label eth.BlockLabel) (*eth.ExecutionPayload, error)

func (*MockEthClient) PayloadByNumber

func (m *MockEthClient) PayloadByNumber(ctx context.Context, n uint64) (*eth.ExecutionPayload, error)

type MockL1Source

type MockL1Source struct {
	MockEthClient
}

func (*MockL1Source) ExpectL1BlockRefByHash

func (m *MockL1Source) ExpectL1BlockRefByHash(hash common.Hash, ref eth.L1BlockRef, err error)

func (*MockL1Source) ExpectL1BlockRefByLabel

func (m *MockL1Source) ExpectL1BlockRefByLabel(label eth.BlockLabel, ref eth.L1BlockRef, err error)

func (*MockL1Source) ExpectL1BlockRefByNumber

func (m *MockL1Source) ExpectL1BlockRefByNumber(num uint64, ref eth.L1BlockRef, err error)

func (*MockL1Source) L1BlockRefByHash

func (m *MockL1Source) L1BlockRefByHash(ctx context.Context, hash common.Hash) (eth.L1BlockRef, error)

func (*MockL1Source) L1BlockRefByLabel

func (m *MockL1Source) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error)

func (*MockL1Source) L1BlockRefByNumber

func (m *MockL1Source) L1BlockRefByNumber(ctx context.Context, num uint64) (eth.L1BlockRef, error)

type MockL2Client

type MockL2Client struct {
	MockEthClient
}

func (*MockL2Client) ExpectL2BlockRefByHash

func (m *MockL2Client) ExpectL2BlockRefByHash(hash common.Hash, ref eth.L2BlockRef, err error)

func (*MockL2Client) ExpectL2BlockRefByLabel

func (m *MockL2Client) ExpectL2BlockRefByLabel(label eth.BlockLabel, ref eth.L2BlockRef, err error)

func (*MockL2Client) ExpectL2BlockRefByNumber

func (m *MockL2Client) ExpectL2BlockRefByNumber(num uint64, ref eth.L2BlockRef, err error)

func (*MockL2Client) L2BlockRefByHash

func (c *MockL2Client) L2BlockRefByHash(ctx context.Context, hash common.Hash) (eth.L2BlockRef, error)

func (*MockL2Client) L2BlockRefByLabel

func (c *MockL2Client) L2BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L2BlockRef, error)

func (*MockL2Client) L2BlockRefByNumber

func (c *MockL2Client) L2BlockRefByNumber(ctx context.Context, num uint64) (eth.L2BlockRef, error)

type RPCErrFaker

type RPCErrFaker struct {
	// RPC to call when no ErrFn is set, or the ErrFn does not return an error
	RPC client.RPC
	// ErrFn returns an error when the RPC needs to return error upon a call, batch call or subscription.
	// The RPC operates without fake errors if the ErrFn is nil, or returns nil.
	ErrFn func() error
}

RPCErrFaker implements an RPC by wrapping one, but returns an error when prepared with one, to test RPC error handling.

func (RPCErrFaker) BatchCallContext

func (r RPCErrFaker) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

func (RPCErrFaker) CallContext

func (r RPCErrFaker) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (RPCErrFaker) Close

func (r RPCErrFaker) Close()

func (RPCErrFaker) EthSubscribe

func (r RPCErrFaker) EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)

type TestDerivationMetrics

type TestDerivationMetrics struct {
	FnRecordL1Ref          func(name string, ref eth.L1BlockRef)
	FnRecordL2Ref          func(name string, ref eth.L2BlockRef)
	FnRecordUnsafePayloads func(length uint64, memSize uint64, next eth.BlockID)
}

TestDerivationMetrics implements the metrics used in the derivation pipeline as no-op operations. Optionally a test may hook into the metrics

func (*TestDerivationMetrics) RecordL1Ref

func (t *TestDerivationMetrics) RecordL1Ref(name string, ref eth.L1BlockRef)

func (*TestDerivationMetrics) RecordL2Ref

func (t *TestDerivationMetrics) RecordL2Ref(name string, ref eth.L2BlockRef)

func (*TestDerivationMetrics) RecordUnsafePayloadsBuffer

func (t *TestDerivationMetrics) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID)

type TestID

type TestID string

TestID represents an eth.BlockID as string, and can be shortened for convenience in test definitions.

Format: <hash-characters>:<number> where the <hash-characters> are copied over (i.e. not hex) and <number> is in decimal.

Examples: "foobar:123", or "B:2"

func (TestID) ID

func (id TestID) ID() eth.BlockID

Jump to

Keyboard shortcuts

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