Documentation ¶
Overview ¶
The ethtest package provides helpers for testing Ethereum smart contracts.
Index ¶
- Variables
- func Comparers() []cmp.Option
- func ExecutionErrData(err error) (interface{}, bool)
- func LogGas(tb testing.TB, tx *types.Transaction, prefix string)
- func RevertDiff(got error, want string) string
- type SimulatedBackend
- func (sb *SimulatedBackend) Acc(account int) *bind.TransactOpts
- func (sb *SimulatedBackend) BalanceOf(ctx context.Context, tb testing.TB, addr common.Address) *big.Int
- func (sb *SimulatedBackend) BlockNumber() *big.Int
- func (sb *SimulatedBackend) CallFrom(account int) *bind.CallOpts
- func (sb *SimulatedBackend) FastForward(blockNumber *big.Int) bool
- func (sb *SimulatedBackend) GasSpent(ctx context.Context, tb testing.TB, tx *types.Transaction) *big.Int
- func (sb *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (sb *SimulatedBackend) WithValueFrom(account int, value *big.Int) *bind.TransactOpts
Constants ¶
This section is empty.
Variables ¶
var GasPrice uint64 = 200
GasPrice is the assumed gas price, in GWei, when logging transaction costs.
Functions ¶
func ExecutionErrData ¶
ExecutionErrData checks if err is both an rpc.Error and rpc.DataError, and returns err.ErrorData() iff err.ErrorCode()==3 (i.e. an Execution error under the JSON RPC error codes IP).
func LogGas ¶
func LogGas(tb testing.TB, tx *types.Transaction, prefix string)
LogGas logs the amount and cost of the Transaction's gas. See GasPrice.
func RevertDiff ¶
RevertDiff compares the error from a transaction by extracting its data, confirming that it carries a string, and comparing it to `want`.
Types ¶
type SimulatedBackend ¶
type SimulatedBackend struct { *backends.SimulatedBackend AutoCommit bool // contains filtered or unexported fields }
A SimulatedBackend embeds a go-ethereum SimulatedBackend and extends its functionality to simplify standard testing.
func NewSimulatedBackend ¶
func NewSimulatedBackend(numAccounts int) (*SimulatedBackend, error)
NewSimulatedBackend returns a new simulated ETH backend with the specified number of accounts. Transactions are automatically committed unless. Close() must be called to free resources after use.
func NewSimulatedBackendTB ¶
func NewSimulatedBackendTB(tb testing.TB, numAccounts int) *SimulatedBackend
NewSimulatedBackendT calls NewSimulatedBackend(), reports any errors with tb.Fatal, and calls Close() with tb.Cleanup().
func (*SimulatedBackend) Acc ¶
func (sb *SimulatedBackend) Acc(account int) *bind.TransactOpts
Acc returns a TransactOpts signing as the specified account number.
func (*SimulatedBackend) BalanceOf ¶
func (sb *SimulatedBackend) BalanceOf(ctx context.Context, tb testing.TB, addr common.Address) *big.Int
BalanceOf returns the current balance of the address, calling tb.Fatalf on error.
func (*SimulatedBackend) BlockNumber ¶
func (sb *SimulatedBackend) BlockNumber() *big.Int
BlockNumber returns the current block number.
func (*SimulatedBackend) CallFrom ¶
func (sb *SimulatedBackend) CallFrom(account int) *bind.CallOpts
CallFrom returns a CallOpts from the specified account number.
func (*SimulatedBackend) FastForward ¶
func (sb *SimulatedBackend) FastForward(blockNumber *big.Int) bool
FastForward calls sb.Commit() until sb.BlockNumber() >= blockNumber. It returns whether fast-forwarding was required; i.e. false if the requested block number is current or in the past.
NOTE: FastForward is O(curr - requested).
func (*SimulatedBackend) GasSpent ¶
func (sb *SimulatedBackend) GasSpent(ctx context.Context, tb testing.TB, tx *types.Transaction) *big.Int
GasSpent returns the gas spent (i.e. used*cost) by the transaction.
func (*SimulatedBackend) SendTransaction ¶
func (sb *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error
SendTransaction functions pipes its parameters to the embedded backend and also calls Commit() if sb.AutoCommit==true.
func (*SimulatedBackend) WithValueFrom ¶
func (sb *SimulatedBackend) WithValueFrom(account int, value *big.Int) *bind.TransactOpts
WithValueFrom returns a TransactOpts that sends the specified value from the account. If value==0, sb.Acc(account) can be used directly.