simulated

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 26 Imported by: 1

Documentation

Overview

Package simulated represents a simulated backend. It complies to the standard chain backend and is used for any tests that don't require a websocket (see https://github.com/ethereum/go-ethereum/issues/21457) It's relatively useful for any tests that don't require a full backend (often integration tests). Beyond the very real limitations fo this backend (json rpc, different mempool mechanics, etc) that make it differ from geth, geth also introduces some superficial limitations on us that we want to get around. Geth isn't made for multichain mocking so they require the use of chain id 1337. ToAddress get around this we use go:generate to copy the backend using multichainsimulation.

We don't make any changes to the fundamental backend simulation, but we do use the

Index

Constants

View Source
const BackendName = "SimulatedBackend"

BackendName is the name of the simulated backend.

View Source
const BlockGasLimit = uint64(91712388)

BlockGasLimit is the gas limit used for the block.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {

	// base backend is the base backend
	*base.Backend
	// contains filtered or unexported fields
}

Backend is the simulated backend.

func NewSimulatedBackend

func NewSimulatedBackend(ctx context.Context, t *testing.T) *Backend

NewSimulatedBackend gets a simulated backend from geth for testing and creates an account with balance. ChainID is 1337.

func NewSimulatedBackendWithChainID

func NewSimulatedBackendWithChainID(ctx context.Context, t *testing.T, chainID *big.Int) *Backend

NewSimulatedBackendWithChainID gets a simulated backend from geth for testing and creates an account with balance.

func NewSimulatedBackendWithConfig

func NewSimulatedBackendWithConfig(ctx context.Context, t *testing.T, config *params.ChainConfig) *Backend

NewSimulatedBackendWithConfig gets a simulated backend from geth for testing and creates an account with balance.

func (*Backend) AdjustTime

func (s *Backend) AdjustTime(adjustment time.Duration) error

AdjustTime adjusts the time of the most recent block.

func (*Backend) BackendName

func (s *Backend) BackendName() string

BackendName gets the name of SimulatedBackend.

func (*Backend) BatchWithContext added in v0.1.7

func (s *Backend) BatchWithContext(_ context.Context, _ ...w3types.Caller) error

func (*Backend) ChainConfig

func (s *Backend) ChainConfig() *params.ChainConfig

ChainConfig gets the chain config for the simulated backend.

func (*Backend) Commit

func (s *Backend) Commit()

Commit commits pending txes to the backend. Does not thing if no txes are pending.

func (*Backend) EmptyBlock

func (s *Backend) EmptyBlock(blockTime time.Time)

EmptyBlock mines an empty block.

func (*Backend) FundAccount

func (s *Backend) FundAccount(ctx context.Context, address common.Address, amount big.Int)

FundAccount fundsa new account.

func (*Backend) GetFundedAccount

func (s *Backend) GetFundedAccount(ctx context.Context, requestBalance *big.Int) *keystore.Key

GetFundedAccount returns an account with the requested balance. (Note: if genesis acount has an insufficient balance, blocks may be mined here).

func (*Backend) GetTxContext

func (s *Backend) GetTxContext(ctx context.Context, address *common.Address) (res commonBackend.AuthType)

GetTxContext gets a signed transaction from full backend.

func (*Backend) SendTransaction

func (s *Backend) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction sends a transaction and commits it mining a new block in cases where you would not like to commit automatically, you can run s.Client().SendTransaction().

func (*Backend) SetT

func (s *Backend) SetT(t *testing.T)

SetT sets the testing object on the backend.

func (*Backend) Signer

func (s *Backend) Signer() types.Signer

Signer gets the signer for the backend.

func (*Backend) T

func (s *Backend) T() *testing.T

T gets the testing object for the backend.

type Client

type Client struct {
	*multibackend.SimulatedBackend
}

Client is a simulated client for a simulated backend.

func (Client) BatchCallContext

func (s Client) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

BatchCallContext panics here to bypass interface requirements for testing.

func (Client) BatchContext added in v0.0.20

func (s Client) BatchContext(ctx context.Context, calls ...w3types.Caller) error

BatchContext panics here to bypass interface requirements for testing.

func (Client) BlockNumber

func (s Client) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber gets the latest block number.

func (Client) CallContext

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

CallContext panics here to bypass interface requirements for testing.

func (Client) ChainConfig

func (s Client) ChainConfig() *params.ChainConfig

ChainConfig gets the chain config for the backend.

func (Client) ChainID

func (s Client) ChainID(_ context.Context) (*big.Int, error)

ChainID returns the chain id.

func (Client) Close

func (s Client) Close()

Close closes the connection with the chain.

func (Client) FeeHistory added in v0.0.21

func (s Client) FeeHistory(_ context.Context, _ uint64, _ *big.Int, _ []float64) (*ethereum.FeeHistory, error)

FeeHistory is not implemented on this backend.

func (Client) NetworkID added in v0.0.21

func (s Client) NetworkID(ctx context.Context) (*big.Int, error)

NetworkID wraps network id on underlying backend.

func (Client) PendingBalanceAt added in v0.0.21

func (s Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)

PendingBalanceAt calls balance at since simulated backends are monotonic.

func (Client) PendingStorageAt added in v0.0.21

func (s Client) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)

PendingStorageAt gets the storage at since simulated backends cannot have non-final storage.

func (Client) PendingTransactionCount added in v0.0.21

func (s Client) PendingTransactionCount(ctx context.Context) (uint, error)

PendingTransactionCount always returns 0 since simulated backends cannot have pending transactions.

func (Client) SuggestGasPrice

func (s Client) SuggestGasPrice(ctx context.Context) (gasPrice *big.Int, err error)

SuggestGasPrice follows the rpc behavior for SuggestGasPrice. Because we rely on the legacy behavior of eth_sendTransaction and don't utilize the base fee (we need to figure out a way to do this cross-chain), we emulate the rpc eth_sugestGasPrice behavior here. TODO: find out if not emulating the rpc here is intended behavior on geth's end, patch via pr if not.

func (Client) SyncProgress added in v0.0.21

func (s Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)

SyncProgress panics since this state is not accessible on the simulated backend.

func (Client) Web3Version added in v0.7.0

func (s Client) Web3Version(_ context.Context) (version string, err error)

Web3Version is not implemented on this backend.

Directories

Path Synopsis
Package multibackend contains a copy of https://github.com/ethereum/go-ethereum/blob/master/accounts/abi/bind/backends/simulated.go that allows use with multiple chains by exporting new methods.
Package multibackend contains a copy of https://github.com/ethereum/go-ethereum/blob/master/accounts/abi/bind/backends/simulated.go that allows use with multiple chains by exporting new methods.

Jump to

Keyboard shortcuts

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