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
- type Backend
- func (s *Backend) AdjustTime(adjustment time.Duration) error
- func (s *Backend) BackendName() string
- func (s *Backend) ChainConfig() *params.ChainConfig
- func (s *Backend) Commit()
- func (s *Backend) EmptyBlock(blockTime time.Time)
- func (s *Backend) EnableTenderly() (enabled bool)
- func (s *Backend) FundAccount(ctx context.Context, address common.Address, amount big.Int)
- func (s *Backend) GetAccount(address common.Address) *keystore.Key
- func (s *Backend) GetFundedAccount(ctx context.Context, requestBalance *big.Int) *keystore.Key
- func (s *Backend) GetTxContext(ctx context.Context, address *common.Address) (res commonBackend.AuthType)
- func (s *Backend) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (s *Backend) SetT(t *testing.T)
- func (s *Backend) Signer() types.Signer
- func (s *Backend) T() *testing.T
- type Client
- func (s Client) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
- func (s Client) BatchContext(ctx context.Context, calls ...w3types.Caller) error
- func (s Client) BlockNumber(ctx context.Context) (uint64, error)
- func (s Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
- func (s Client) ChainConfig() *params.ChainConfig
- func (s Client) ChainID(_ context.Context) (*big.Int, error)
- func (s Client) Close()
- func (s Client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, ...) (*ethereum.FeeHistory, error)
- func (s Client) NetworkID(ctx context.Context) (*big.Int, error)
- func (s Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
- func (s Client) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
- func (s Client) PendingTransactionCount(ctx context.Context) (uint, error)
- func (s Client) SuggestGasPrice(ctx context.Context) (gasPrice *big.Int, err error)
- func (s Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
Constants ¶
const BackendName = "SimulatedBackend"
BackendName is the name of the simulated backend.
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 ¶
NewSimulatedBackend gets a simulated backend from geth for testing and creates an account with balance. ChainID is 1337.
func NewSimulatedBackendWithChainID ¶
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 ¶
AdjustTime adjusts the time of the most recent block.
func (*Backend) BackendName ¶
BackendName gets the name of SimulatedBackend.
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 ¶
EmptyBlock mines an empty block.
func (*Backend) EnableTenderly ¶
EnableTenderly tells the user tenderly is not currently enabled for simulated backend type.
func (*Backend) FundAccount ¶
FundAccount fundsa new account.
func (*Backend) GetAccount ¶
GetAccount gets the private key for an account nil if the account doesn't exist.
func (*Backend) GetFundedAccount ¶
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 ¶
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().
type Client ¶
type Client struct {
*multibackend.SimulatedBackend
}
Client is a simulated client for a simulated backend.
func (Client) BatchCallContext ¶
BatchCallContext panics here to bypass interface requirements for testing.
func (Client) BatchContext ¶ added in v0.0.20
BatchContext panics here to bypass interface requirements for testing.
func (Client) BlockNumber ¶
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) FeeHistory ¶ added in v0.0.21
func (s Client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)
FeeHistory is not implemented on this backend.
func (Client) PendingBalanceAt ¶ added in v0.0.21
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
PendingTransactionCount always returns 0 since simulated backends cannot have pending transactions.
func (Client) SuggestGasPrice ¶
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.
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. |