mock

package
v0.0.0-...-412688d Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type L1Client

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

L1Client represents a mock L1Client.

func NewL1Client

func NewL1Client(cfg L1ClientConfig) *L1Client

NewL1Client returns a new L1Client using the mocked methods in the L1ClientConfig.

func (*L1Client) BlockNumber

func (c *L1Client) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the most recent block number.

func (*L1Client) EstimateGas

func (c *L1Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

func (*L1Client) HeaderByNumber

func (c *L1Client) HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*L1Client) NonceAt

func (c *L1Client) NonceAt(ctx context.Context, addr common.Address, blockNumber *big.Int) (uint64, error)

NonceAt executes the mock NonceAt method.

func (*L1Client) SendTransaction

func (c *L1Client) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction executes the mock SendTransaction method.

func (*L1Client) SetBlockNumberFunc

func (c *L1Client) SetBlockNumberFunc(
	f func(context.Context) (uint64, error))

SetBlockNumberFunc overwrites the mock BlockNumber method.

func (*L1Client) SetEstimateGasFunc

func (c *L1Client) SetEstimateGasFunc(
	f func(context.Context, ethereum.CallMsg) (uint64, error))

SetEstimateGasFunc overwrites the mock EstimateGas method.

func (*L1Client) SetHeaderByNumberFunc

func (c *L1Client) SetHeaderByNumberFunc(
	f func(ctx context.Context, blockNumber *big.Int) (*types.Header, error))

SetHeaderByNumberFunc overwrites the mock HeaderByNumber method.

func (*L1Client) SetNonceAtFunc

func (c *L1Client) SetNonceAtFunc(
	f func(context.Context, common.Address, *big.Int) (uint64, error))

SetNonceAtFunc overwrites the mock NonceAt method.

func (*L1Client) SetSendTransactionFunc

func (c *L1Client) SetSendTransactionFunc(
	f func(context.Context, *types.Transaction) error)

SetSendTransactionFunc overwrites the mock SendTransaction method.

func (*L1Client) SetSuggestGasTipCapFunc

func (c *L1Client) SetSuggestGasTipCapFunc(
	f func(context.Context) (*big.Int, error))

SetSuggestGasTipCapFunc overwrites themock SuggestGasTipCap method.

func (*L1Client) SetTransactionReceiptFunc

func (c *L1Client) SetTransactionReceiptFunc(
	f func(context.Context, common.Hash) (*types.Receipt, error))

SetTransactionReceiptFunc overwrites the mock TransactionReceipt method.

func (*L1Client) SuggestGasTipCap

func (c *L1Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559 to allow a timely execution of a transaction.

func (*L1Client) TransactionReceipt

func (c *L1Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt executes the mock TransactionReceipt method.

type L1ClientConfig

type L1ClientConfig struct {
	// BlockNumber returns the most recent block number.
	BlockNumber func(context.Context) (uint64, error)

	// EstimateGas tries to estimate the gas needed to execute a specific
	// transaction based on the current pending state of the backend blockchain.
	// There is no guarantee that this is the true gas limit requirement as
	// other transactions may be added or removed by miners, but it should
	// provide a basis for setting a reasonable default.
	EstimateGas func(context.Context, ethereum.CallMsg) (uint64, error)

	// HeaderByNumber returns a block header from the current canonical chain.
	// If number is nil, the latest known header is returned.
	HeaderByNumber func(context.Context, *big.Int) (*types.Header, error)

	// NonceAt returns the account nonce of the given account. The block number
	// can be nil, in which case the nonce is taken from the latest known block.
	NonceAt func(context.Context, common.Address, *big.Int) (uint64, error)

	// SendTransaction injects a signed transaction into the pending pool for
	// execution.
	//
	// If the transaction was a contract creation use the TransactionReceipt
	// method to get the contract address after the transaction has been mined.
	SendTransaction func(context.Context, *types.Transaction) error

	// SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559
	// to allow a timely execution of a transaction.
	SuggestGasTipCap func(context.Context) (*big.Int, error)

	// TransactionReceipt returns the receipt of a transaction by transaction
	// hash. Note that the receipt is not available for pending transactions.
	TransactionReceipt func(context.Context, common.Hash) (*types.Receipt, error)
}

L1ClientConfig houses the internal methods that are executed by the mock L1Client. Any members left as nil will panic on execution.

Jump to

Keyboard shortcuts

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