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) 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) SuggestGasPrice(ctx context.Context) (gasPrice *big.Int, err 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 calls the batch call method on the underlying client.
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 calls the call context method on the underlying client.
func (Client) ChainConfig ¶
func (s Client) ChainConfig() *params.ChainConfig
ChainConfig gets the chain config for the backend.
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. |