ethtesting

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBlockGeneratorOffsetTime = int64(5)
)

Variables

View Source
var (
	MockPrivateKey1 = MustHexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
	MockPrivateKey2 = MustHexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
	MockPrivateKey3 = MustHexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
	MockPrivateKey4 = MustHexToECDSA("e238eb8e04fee6511ab04c6dd3c89ce097b11f25d584863ac2b6d5b35b1847e4")
)

Functions

func MustGenerateKey

func MustGenerateKey() *ecdsa.PrivateKey

func MustHexToECDSA

func MustHexToECDSA(hexkey string) *ecdsa.PrivateKey

MustHexToECDSA returns the result of HexToECDSA on hexkey, or panics if error.

func NewSimulatedClient

func NewSimulatedClient(sim *backends.SimulatedBackend) ethhelpers.Client

func PendingLogHandler

func PendingLogHandler(h log.Handler) (log.Handler, func())

PendingLogHandler returns a new log.Handler that buffers records until the returned commit function is called.

func PendingLogHandlerForTesting

func PendingLogHandlerForTesting(t *testing.T, logger log.Logger) func()

func SimulatedChainID

func SimulatedChainID() *big.Int

Types

type BlockGenerator

type BlockGenerator interface {
	Generator() (func(int, *core.BlockGen), int, error)
}

type CanceledMockCallOption added in v0.1.3

type CanceledMockCallOption struct{}

func CanceledMockCall added in v0.1.3

func CanceledMockCall() CanceledMockCallOption

type ClientWithMock added in v0.1.2

type ClientWithMock interface {
	ethhelpers.Client
	Mock() *mock.Mock
	Test(t mock.TestingT)
}

func NewClientWithMock added in v0.1.2

func NewClientWithMock() ClientWithMock

Newethhelpers.Client creates a new client with *testing.Mock.

func NewClientWithMockAndClient added in v0.1.2

func NewClientWithMockAndClient(client ethhelpers.Client) ClientWithMock

NewClientWithMockAndClient creates a new client with *testing.Mock and an underlying client.

Using PassthroughMockCall() as the assigned return value for mocked calls will pass the call to the underlying client.

type GenesisAccountWithPrivateKey

type GenesisAccountWithPrivateKey struct {
	*ecdsa.PrivateKey
	core.GenesisAccount
}

type PassthroughMockCallOption added in v0.1.3

type PassthroughMockCallOption struct{}

func PassthroughMockCall added in v0.1.3

func PassthroughMockCall() PassthroughMockCallOption

type SimpleBlockGenerator

type SimpleBlockGenerator struct {
	// Expected block height of the chain if it contains a non-zero
	// value, otherwise the last block with a transaction is
	// used.
	//
	// Results in an error if set to a non-zero value that is less
	// than the last block number with a transaction.
	ExpectedHeight int

	// Offset time of the block in seconds.
	OffsetTime int64

	// Generate a byte array for the extraData generator parameter field.
	ExtraGenerator func(int, *core.BlockGen) []byte

	Transactions []TransactionWithHeight
}

func (*SimpleBlockGenerator) Generator

func (g *SimpleBlockGenerator) Generator() (func(int, *core.BlockGen), int, error)

type SimulatedAccount

type SimulatedAccount struct {
	PrivateKey *ecdsa.PrivateKey
	Address    common.Address
	Nonce      uint64
}

func NewSimulatedAccount

func NewSimulatedAccount(privateKey *ecdsa.PrivateKey) *SimulatedAccount

func NewSimulatedAccountWithNonce

func NewSimulatedAccountWithNonce(privateKey *ecdsa.PrivateKey, nonce uint64) *SimulatedAccount

func (*SimulatedAccount) NonceAndIncrement

func (a *SimulatedAccount) NonceAndIncrement() (n uint64)

NextNonce increments SimulatedAccount.Nonce and returns its old value.

func (*SimulatedAccount) SendNewTransaction

func (a *SimulatedAccount) SendNewTransaction(ctx context.Context, client ethhelpers.ChainReaderAndTransactionSender, nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, data []byte) (*types.Transaction, error)

type SimulatedBackendWithAccounts

type SimulatedBackendWithAccounts struct {
	Backend  *backends.SimulatedBackend
	Accounts []*SimulatedAccount
}

func NewSimulatedBackendWithAccounts

func NewSimulatedBackendWithAccounts(genesisAccounts ...GenesisAccountWithPrivateKey) *SimulatedBackendWithAccounts

NewSimulatedBackendWithAccounts creates a new simulated backend with provided simulated accounts.

If GenesisAccount.Balance is nil then big.NewInt(0) is used.

func (*SimulatedBackendWithAccounts) GenerateCallableContract

func (b *SimulatedBackendWithAccounts) GenerateCallableContract() (*bind.BoundContract, error)

GenerateCallableContract creates a callable contract on the simulated backend.

The transaction must be commited by the caller.

pragma solidity >=0.7.0 <0.9.0;
contract Callable {
    event Called();
    function Call() public { emit Called(); }
}

type TransactionWithHeight

type TransactionWithHeight struct {
	Height      int
	Transaction *types.Transaction
}

Jump to

Keyboard shortcuts

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