blockchain

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 29 Imported by: 25

README

Blockchain Clients

Contains code to connect and command blockchains

Documentation

Overview

Package blockchain handles connections to various blockchains

Index

Constants

View Source
const (
	// GWei one giga-wei used for gas calculations
	GWei = 1e9
	// ETH one eth in wei
	ETH = 1e18
)

Variables

View Source
var (
	// SimulatedEVMNetwork ensures that the test will use a default simulated geth instance
	SimulatedEVMNetwork = EVMNetwork{
		Name:                 "Simulated Geth",
		ClientImplementation: EthereumClientImplementation,
		Simulated:            true,
		ChainID:              1337,
		URLs:                 []string{"ws://geth:8546"},
		HTTPURLs:             []string{"http://geth:8544"},
		PrivateKeys: []string{
			"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
			"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
			"5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
			"8d351f5fc88484c65c15d44c7d3aa8779d12383373fb42d802e4576a50f765e5",
			"44fd8327d465031c71b20d7a5ba60bb01d33df8256fba406467bcb04e6f7262c",
			"809871f5c72d01a953f44f65d8b7bd0f3e39aee084d8cd0bc17ba3c386391814",
			"f29f5fda630ac9c0e39a8b05ec5b4b750a2e6ef098e612b177c6641bb5a675e1",
			"99b256477c424bb0102caab28c1792a210af906b901244fa67e2b704fac5a2bb",
			"bb74c3a9439ca83d09bcb4d3e5e65d8bc4977fc5b94be4db73772b22c3ff3d1a",
			"58845406a51d98fb2026887281b4e91b8843bbec5f16b89de06d5b9a62b231e8",
		},
		ChainlinkTransactionLimit: 500000,
		Timeout:                   JSONStrDuration{2 * time.Minute},
		MinimumConfirmations:      1,
		GasEstimationBuffer:       10000,
	}
)

Functions

func LogRevertReason added in v1.6.0

func LogRevertReason(err error, abiString string) error

LogRevertReason prints the revert reason for the transaction error by parsing through abi defined error list

Types

type ArbitrumClient added in v1.5.3

type ArbitrumClient struct {
	*EthereumClient
}

ArbitrumClient represents a single node, EVM compatible client for the Arbitrum network

func (*ArbitrumClient) Fund added in v1.5.3

func (a *ArbitrumClient) Fund(toAddress string, amount *big.Float) error

Fund sends some ARB to an address using the default wallet

func (*ArbitrumClient) ReturnFunds added in v1.7.0

func (a *ArbitrumClient) ReturnFunds(fromKey *ecdsa.PrivateKey) error

type ArbitrumMultinodeClient added in v1.5.3

type ArbitrumMultinodeClient struct {
	*EthereumMultinodeClient
}

ArbitrumMultinodeClient represents a multi-node, EVM compatible client for the Arbitrum network

type CeloClient added in v1.10.10

type CeloClient struct {
	*EthereumClient
}

CeloClient represents a single node, EVM compatible client for the Celo network

func (*CeloClient) DeployContract added in v1.10.10

func (e *CeloClient) DeployContract(
	contractName string,
	deployer ContractDeployer,
) (*common.Address, *types.Transaction, interface{}, error)

DeployContract uses legacy txs for Celo to bypass Geth checking Celo headers which do not have a required sha3Uncles field

func (*CeloClient) TransactionOpts added in v1.10.10

func (e *CeloClient) TransactionOpts(from *EthereumWallet) (*bind.TransactOpts, error)

type CeloMultinodeClient added in v1.10.10

type CeloMultinodeClient struct {
	*EthereumMultinodeClient
}

CeloMultinodeClient represents a multi-node, EVM compatible client for the Celo network

type ClientImplementation added in v1.7.0

type ClientImplementation string
const (
	// Ethereum uses the standard EVM implementation, and is considered default
	EthereumClientImplementation ClientImplementation = "Ethereum"
	// MetisClientImplementation uses a client tailored for Metis EVM networks
	MetisClientImplementation ClientImplementation = "Metis"
	// KlaytnClientImplementation uses a client tailored for Klaytn EVM networks
	KlaytnClientImplementation ClientImplementation = "Klaytn"
	// OptimismClientImplementation uses a client tailored for Optimism EVM networks
	OptimismClientImplementation ClientImplementation = "Optimism"
	// ArbitrumClientImplementation uses a client tailored for Arbitrum EVM networks
	ArbitrumClientImplementation ClientImplementation = "Arbitrum"
	// PolygonClientImplementation uses a client tailored for Polygon EVM networks
	PolygonClientImplementation ClientImplementation = "Polygon"
	// RSKClientImplementation uses a client tailored for RSK EVM networks
	RSKClientImplementation ClientImplementation = "RSK"
	// CeloClientImplementation uses a client tailored for Celo EVM networks
	CeloClientImplementation ClientImplementation = "Celo"
)

type ContractDeployer

type ContractDeployer func(auth *bind.TransactOpts, backend bind.ContractBackend) (
	common.Address,
	*types.Transaction,
	interface{},
	error,
)

ContractDeployer acts as a go-between function for general contract deployment

type ContractLoader added in v1.7.0

type ContractLoader func(address common.Address, backend bind.ContractBackend) (
	interface{},
	error,
)

ContractLoader helps loading already deployed contracts

type EVMClient

type EVMClient interface {
	// Getters
	Get() interface{}
	GetNetworkName() string
	NetworkSimulated() bool
	GetChainID() *big.Int
	GetClients() []EVMClient
	GetDefaultWallet() *EthereumWallet
	GetWallets() []*EthereumWallet
	GetNetworkConfig() *EVMNetwork
	GetNonceSetting() NonceSettings

	// Setters
	SetID(id int)
	SetDefaultWallet(num int) error
	SetWallets([]*EthereumWallet)
	LoadWallets(ns EVMNetwork) error
	SwitchNode(node int) error
	SyncNonce(c EVMClient)

	// On-chain Operations
	BalanceAt(ctx context.Context, address common.Address) (*big.Int, error)
	HeaderHashByNumber(ctx context.Context, bn *big.Int) (string, error)
	HeaderTimestampByNumber(ctx context.Context, bn *big.Int) (uint64, error)
	LatestBlockNumber(ctx context.Context) (uint64, error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	Fund(toAddress string, amount *big.Float) error
	ReturnFunds(fromKey *ecdsa.PrivateKey) error
	DeployContract(
		contractName string,
		deployer ContractDeployer,
	) (*common.Address, *types.Transaction, interface{}, error)
	LoadContract(contractName string, address common.Address, loader ContractLoader) (interface{}, error)
	TransactionOpts(from *EthereumWallet) (*bind.TransactOpts, error)
	ProcessTransaction(tx *types.Transaction) error
	ProcessEvent(name string, event *types.Log, confirmedChan chan bool, errorChan chan error) error
	IsEventConfirmed(event *types.Log) (confirmed, removed bool, err error)
	IsTxConfirmed(txHash common.Hash) (bool, error)
	GetTxReceipt(txHash common.Hash) (*types.Receipt, error)
	ParallelTransactions(enabled bool)
	Close() error
	Backend() bind.ContractBackend
	// Deal with wrapped headers
	SubscribeNewHeaders(ctx context.Context, headerChan chan *SafeEVMHeader) (ethereum.Subscription, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*SafeEVMHeader, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*SafeEVMHeader, error)

	// Gas Operations
	EstimateCostForChainlinkOperations(amountOfOperations int) (*big.Float, error)
	EstimateTransactionGasCost() (*big.Int, error)
	GasStats() *GasStats

	// Event Subscriptions
	AddHeaderEventSubscription(key string, subscriber HeaderEventSubscription)
	DeleteHeaderEventSubscription(key string)
	WaitForEvents() error
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
}

EVMClient is the interface that wraps a given client implementation for a blockchain, to allow for switching of network types within the test suite EVMClient can be connected to a single or multiple nodes,

func ConcurrentEVMClient added in v1.9.1

func ConcurrentEVMClient(networkSettings EVMNetwork, env *environment.Environment, existing EVMClient) (EVMClient, error)

ConcurrentEVMClient returns a multi-node EVM client connected to the specified network It is used for concurrent interactions from different threads with the same network and from same owner account. This ensures that correct nonce value is fetched when an instance of EVMClient is initiated using this method.

func NewEVMClient added in v1.5.0

func NewEVMClient(networkSettings EVMNetwork, env *environment.Environment) (EVMClient, error)

NewEVMClient returns a multi-node EVM client connected to the specified network

type EVMNetwork added in v1.4.0

type EVMNetwork struct {
	// Human-readable name of the network:
	Name string `envconfig:"evm_name" default:"Unnamed EVM Network" toml:"evm_name" json:"evm_name"`
	// Chain ID for the blockchain
	ChainID int64 `envconfig:"evm_chain_id" default:"1337" toml:"evm_chain_id" json:"evm_chain_id"`
	// List of websocket URLs you want to connect to
	URLs []string `envconfig:"evm_urls" default:"ws://example.url" toml:"evm_urls" json:"evm_urls"`
	// List of websocket URLs you want to connect to
	HTTPURLs []string `envconfig:"evm_http_urls" default:"http://example.url" toml:"evm_http_urls" json:"evm_http_urls"`
	// True if the network is simulated like a geth instance in dev mode. False if the network is a real test or mainnet
	Simulated bool `envconfig:"evm_simulated" default:"false" toml:"evm_simulated" json:"evm_simulated"`
	// List of private keys to fund the tests
	PrivateKeys []string `envconfig:"evm_keys" default:"examplePrivateKey" toml:"evm_keys" json:"evm_keys"`
	// Default gas limit to assume that Chainlink nodes will use. Used to try to estimate the funds that Chainlink
	// nodes require to run the tests.
	ChainlinkTransactionLimit uint64 `` /* 138-byte string literal not displayed */
	// How long to wait for on-chain operations before timing out an on-chain operation
	Timeout JSONStrDuration `envconfig:"evm_transaction_timeout" default:"2m" toml:"evm_transaction_timeout" json:"evm_transaction_timeout"`
	// How many block confirmations to wait to confirm on-chain events
	MinimumConfirmations int `envconfig:"evm_minimum_confirmations" default:"1" toml:"evm_minimum_confirmations" json:"evm_minimum_confirmations"`
	// How much WEI to add to gas estimations for sending transactions
	GasEstimationBuffer uint64 `envconfig:"evm_gas_estimation_buffer" default:"1000" toml:"evm_gas_estimation_buffer" json:"evm_gas_estimation_buffer"`
	// ClientImplementation is the blockchain client to use when interacting with the test chain
	ClientImplementation ClientImplementation `envconfig:"client_implementation" default:"Ethereum" toml:"client_implementation" json:"client_implementation"`

	// Only used internally, do not set
	URL string `ignored:"true"`
}

EVMNetwork configures all the data the test needs to connect and operate on an EVM compatible network

func LoadNetworkFromEnvironment added in v1.4.0

func LoadNetworkFromEnvironment() EVMNetwork

LoadNetworkFromEnvironment loads an EVM network from default environment variables. Helpful in soak tests

func (*EVMNetwork) MustChainlinkTOML added in v1.8.2

func (e *EVMNetwork) MustChainlinkTOML(networkDetails string) string

MustChainlinkTOML marshals EVM network values into a TOML setting snippet. Will fail if error is encountered Can provide more detailed config for the network if non-default behaviors are desired.

func (*EVMNetwork) ToMap added in v1.4.0

func (e *EVMNetwork) ToMap() map[string]interface{}

ToMap marshalls the network's values to a generic map, useful for setting env vars on instances like the remote runner Map Structure "envconfig_key": stringValue

type EthereumClient

type EthereumClient struct {
	ID     int
	Client *ethclient.Client

	NetworkConfig EVMNetwork
	Wallets       []*EthereumWallet
	DefaultWallet *EthereumWallet
	NonceSettings *NonceSettings
	// contains filtered or unexported fields
}

EthereumClient wraps the client and the BlockChain network to interact with an EVM based Blockchain

func (*EthereumClient) AddHeaderEventSubscription

func (e *EthereumClient) AddHeaderEventSubscription(key string, subscriber HeaderEventSubscription)

AddHeaderEventSubscription adds a new header subscriber within the client to receive new headers

func (*EthereumClient) Backend added in v1.9.1

func (e *EthereumClient) Backend() bind.ContractBackend

func (*EthereumClient) BalanceAt added in v1.2.3

func (e *EthereumClient) BalanceAt(ctx context.Context, address common.Address) (*big.Int, error)

BalanceAt returns the ETH balance of the specified address

func (*EthereumClient) Close

func (e *EthereumClient) Close() error

Close tears down the current open Ethereum client

func (*EthereumClient) DeleteHeaderEventSubscription

func (e *EthereumClient) DeleteHeaderEventSubscription(key string)

DeleteHeaderEventSubscription removes a header subscriber from the map

func (*EthereumClient) DeployContract

func (e *EthereumClient) DeployContract(
	contractName string,
	deployer ContractDeployer,
) (*common.Address, *types.Transaction, interface{}, error)

DeployContract acts as a general contract deployment tool to an ethereum chain

func (*EthereumClient) EstimateCostForChainlinkOperations

func (e *EthereumClient) EstimateCostForChainlinkOperations(amountOfOperations int) (*big.Float, error)

EstimateCostForChainlinkOperations calculates required amount of ETH for amountOfOperations Chainlink operations based on the network's suggested gas price and the chainlink gas limit. This is fairly imperfect and should be used as only a rough, upper-end estimate instead of an exact calculation. See https://ethereum.org/en/developers/docs/gas/#post-london for info on how gas calculation works

func (*EthereumClient) EstimateTransactionGasCost

func (e *EthereumClient) EstimateTransactionGasCost() (*big.Int, error)

EstimateTransactionGasCost estimates the current total gas cost for a simple transaction

func (*EthereumClient) Fund

func (e *EthereumClient) Fund(
	toAddress string,
	amount *big.Float,
) error

Fund sends some ETH to an address using the default wallet

func (*EthereumClient) GasStats

func (e *EthereumClient) GasStats() *GasStats

GasStats retrieves all information on gas spent by this client

func (*EthereumClient) Get

func (e *EthereumClient) Get() interface{}

Get returns the underlying client type to be used generically across the framework for switching network types

func (*EthereumClient) GetChainID

func (e *EthereumClient) GetChainID() *big.Int

GetChainID retrieves the ChainID of the network that the client interacts with

func (*EthereumClient) GetClients

func (e *EthereumClient) GetClients() []EVMClient

GetClients not used, only applicable to EthereumMultinodeClient

func (*EthereumClient) GetDefaultWallet

func (e *EthereumClient) GetDefaultWallet() *EthereumWallet

DefaultWallet returns the default wallet for the network

func (*EthereumClient) GetHeaderSubscriptions

func (e *EthereumClient) GetHeaderSubscriptions() map[string]HeaderEventSubscription

GetHeaderSubscriptions returns a duplicate map of the queued transactions

func (*EthereumClient) GetNetworkConfig

func (e *EthereumClient) GetNetworkConfig() *EVMNetwork

DefaultWallet returns the default wallet for the network

func (*EthereumClient) GetNetworkName

func (e *EthereumClient) GetNetworkName() string

GetNetworkName retrieves the ID of the network that the client interacts with

func (*EthereumClient) GetNonce

func (e *EthereumClient) GetNonce(ctx context.Context, addr common.Address) (uint64, error)

GetNonce keep tracking of nonces per address, add last nonce for addr if the map is empty

func (*EthereumClient) GetNonceSetting added in v1.9.1

func (e *EthereumClient) GetNonceSetting() NonceSettings

func (*EthereumClient) GetTxReceipt added in v1.2.4

func (e *EthereumClient) GetTxReceipt(txHash common.Hash) (*types.Receipt, error)

GetTxReceipt returns the receipt of the transaction if available, error otherwise

func (*EthereumClient) GetWallets

func (e *EthereumClient) GetWallets() []*EthereumWallet

DefaultWallet returns the default wallet for the network

func (*EthereumClient) HeaderByHash added in v1.10.10

func (e *EthereumClient) HeaderByHash(ctx context.Context, hash common.Hash) (*SafeEVMHeader, error)

HeaderByHash retrieves a Safe EVM header by hash

func (*EthereumClient) HeaderByNumber added in v1.10.10

func (e *EthereumClient) HeaderByNumber(
	ctx context.Context,
	number *big.Int,
) (*SafeEVMHeader, error)

HeaderByNumber retrieves a Safe EVM header by number, nil for latest

func (*EthereumClient) HeaderHashByNumber

func (e *EthereumClient) HeaderHashByNumber(ctx context.Context, bn *big.Int) (string, error)

HeaderHashByNumber gets header hash by block number

func (*EthereumClient) HeaderTimestampByNumber

func (e *EthereumClient) HeaderTimestampByNumber(ctx context.Context, bn *big.Int) (uint64, error)

HeaderTimestampByNumber gets header timestamp by number

func (*EthereumClient) IsEventConfirmed added in v1.5.6

func (e *EthereumClient) IsEventConfirmed(event *types.Log) (confirmed, removed bool, err error)

IsEventConfirmed returns if eth client can confirm that the event happened

func (*EthereumClient) IsTxConfirmed

func (e *EthereumClient) IsTxConfirmed(txHash common.Hash) (bool, error)

IsTxConfirmed checks if the transaction is confirmed on chain or not

func (*EthereumClient) LatestBlockNumber

func (e *EthereumClient) LatestBlockNumber(ctx context.Context) (uint64, error)

BlockNumber gets latest block number

func (*EthereumClient) LoadContract added in v1.7.0

func (e *EthereumClient) LoadContract(contractName string, contractAddress common.Address, loader ContractLoader) (interface{}, error)

LoadContract load already deployed contract instance

func (*EthereumClient) LoadWallets

func (e *EthereumClient) LoadWallets(cfg EVMNetwork) error

LoadWallets loads wallets from config

func (*EthereumClient) NetworkSimulated added in v1.4.0

func (e *EthereumClient) NetworkSimulated() bool

NetworkSimulated returns true if the network is a simulated geth instance, false otherwise

func (*EthereumClient) ParallelTransactions

func (e *EthereumClient) ParallelTransactions(enabled bool)

ParallelTransactions when enabled, sends the transaction without waiting for transaction confirmations. The hashes are then stored within the client and confirmations can be waited on by calling WaitForEvents.

func (*EthereumClient) PeekPendingNonce added in v1.9.3

func (e *EthereumClient) PeekPendingNonce(addr common.Address) (uint64, error)

PeekPendingNonce returns the current pending nonce for the address. Does not change any nonce settings state

func (*EthereumClient) ProcessEvent added in v1.5.6

func (e *EthereumClient) ProcessEvent(name string, event *types.Log, confirmedChan chan bool, errorChan chan error) error

ProcessTransaction will queue or wait on a transaction depending on whether parallel transactions are enabled

func (*EthereumClient) ProcessTransaction

func (e *EthereumClient) ProcessTransaction(tx *types.Transaction) error

ProcessTransaction will queue or wait on a transaction depending on whether parallel transactions are enabled

func (*EthereumClient) ReturnFunds added in v1.7.0

func (e *EthereumClient) ReturnFunds(fromKey *ecdsa.PrivateKey) error

func (*EthereumClient) SendTransaction added in v1.9.3

func (e *EthereumClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*EthereumClient) SetDefaultWallet

func (e *EthereumClient) SetDefaultWallet(num int) error

SetDefaultWallet sets default wallet

func (*EthereumClient) SetID

func (e *EthereumClient) SetID(id int)

SetID sets client id, only used for multi-node networks

func (*EthereumClient) SetWallets

func (e *EthereumClient) SetWallets(wallets []*EthereumWallet)

SetWallets sets all wallets to be used by the client

func (*EthereumClient) SubscribeFilterLogs added in v1.4.2

func (e *EthereumClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*EthereumClient) SubscribeNewHeaders added in v1.10.10

func (e *EthereumClient) SubscribeNewHeaders(
	ctx context.Context,
	headerChan chan *SafeEVMHeader,
) (ethereum.Subscription, error)

func (*EthereumClient) SwitchNode

func (e *EthereumClient) SwitchNode(_ int) error

SwitchNode not used, only applicable to EthereumMultinodeClient

func (*EthereumClient) SyncNonce added in v1.9.1

func (e *EthereumClient) SyncNonce(c EVMClient)

SyncNonce sets the NonceMu and Nonces value based on existing EVMClient it ensures the instance of EthereumClient is synced with passed EVMClient's nonce updates.

func (*EthereumClient) TransactionOpts

func (e *EthereumClient) TransactionOpts(from *EthereumWallet) (*bind.TransactOpts, error)

TransactionOpts returns the base Tx options for 'transactions' that interact with a smart contract. Since most contract interactions in this framework are designed to happen through abigen calls, it's intentionally quite bare.

func (*EthereumClient) WaitForEvents

func (e *EthereumClient) WaitForEvents() error

WaitForEvents is a blocking function that waits for all event subscriptions that have been queued within the client.

type EthereumMultinodeClient

type EthereumMultinodeClient struct {
	DefaultClient EVMClient
	Clients       []EVMClient
}

EthereumMultinodeClient wraps the client and the BlockChain network to interact with an EVM based Blockchain with multiple nodes

func (*EthereumMultinodeClient) AddHeaderEventSubscription

func (e *EthereumMultinodeClient) AddHeaderEventSubscription(key string, subscriber HeaderEventSubscription)

AddHeaderEventSubscription adds a new header subscriber within the client to receive new headers

func (*EthereumMultinodeClient) Backend added in v1.9.1

func (*EthereumMultinodeClient) BalanceAt added in v1.2.3

func (e *EthereumMultinodeClient) BalanceAt(ctx context.Context, address common.Address) (*big.Int, error)

BalanceAt returns the ETH balance of the specified address

func (*EthereumMultinodeClient) Close

func (e *EthereumMultinodeClient) Close() error

Close tears down the all the clients

func (*EthereumMultinodeClient) DeleteHeaderEventSubscription

func (e *EthereumMultinodeClient) DeleteHeaderEventSubscription(key string)

DeleteHeaderEventSubscription removes a header subscriber from the map

func (*EthereumMultinodeClient) DeployContract

func (e *EthereumMultinodeClient) DeployContract(
	contractName string,
	deployer ContractDeployer,
) (*common.Address, *types.Transaction, interface{}, error)

DeployContract deploys a specified contract

func (*EthereumMultinodeClient) EstimateCostForChainlinkOperations

func (e *EthereumMultinodeClient) EstimateCostForChainlinkOperations(amountOfOperations int) (*big.Float, error)

EstimateCostForChainlinkOperations calculates TXs cost as a dirty estimation based on transactionLimit for that network

func (*EthereumMultinodeClient) EstimateTransactionGasCost

func (e *EthereumMultinodeClient) EstimateTransactionGasCost() (*big.Int, error)

func (*EthereumMultinodeClient) Fund

func (e *EthereumMultinodeClient) Fund(toAddress string, nativeAmount *big.Float) error

Fund funds a specified address with ETH from the given wallet

func (*EthereumMultinodeClient) GasStats

func (e *EthereumMultinodeClient) GasStats() *GasStats

GasStats gets gas stats instance

func (*EthereumMultinodeClient) Get

func (e *EthereumMultinodeClient) Get() interface{}

Get gets default client as an interface{}

func (*EthereumMultinodeClient) GetChainID

func (e *EthereumMultinodeClient) GetChainID() *big.Int

GetChainID retrieves the ChainID of the network that the client interacts with

func (*EthereumMultinodeClient) GetClients

func (e *EthereumMultinodeClient) GetClients() []EVMClient

GetClients gets clients for all nodes connected

func (*EthereumMultinodeClient) GetDefaultWallet

func (e *EthereumMultinodeClient) GetDefaultWallet() *EthereumWallet

GetDefaultWallet returns the default wallet for the network

func (*EthereumMultinodeClient) GetNetworkConfig

func (e *EthereumMultinodeClient) GetNetworkConfig() *EVMNetwork

GetNetworkConfig return the network config

func (*EthereumMultinodeClient) GetNetworkName

func (e *EthereumMultinodeClient) GetNetworkName() string

GetNetworkName gets the ID of the chain that the clients are connected to

func (*EthereumMultinodeClient) GetNonceSetting added in v1.9.1

func (e *EthereumMultinodeClient) GetNonceSetting() NonceSettings

func (*EthereumMultinodeClient) GetTxReceipt added in v1.2.4

func (e *EthereumMultinodeClient) GetTxReceipt(txHash common.Hash) (*types.Receipt, error)

GetTxReceipt returns the receipt of the transaction if available, error otherwise

func (*EthereumMultinodeClient) GetWallets

func (e *EthereumMultinodeClient) GetWallets() []*EthereumWallet

GetWallets returns the default wallet for the network

func (*EthereumMultinodeClient) HeaderByHash added in v1.10.10

func (e *EthereumMultinodeClient) HeaderByHash(ctx context.Context, hash common.Hash) (*SafeEVMHeader, error)

HeaderByHash retrieves a Safe EVM header by hash

func (*EthereumMultinodeClient) HeaderByNumber added in v1.10.10

func (e *EthereumMultinodeClient) HeaderByNumber(
	ctx context.Context,
	number *big.Int,
) (*SafeEVMHeader, error)

HeaderByNumber retrieves a Safe EVM header by number, nil for latest

func (*EthereumMultinodeClient) HeaderHashByNumber

func (e *EthereumMultinodeClient) HeaderHashByNumber(ctx context.Context, bn *big.Int) (string, error)

HeaderHashByNumber gets header hash by block number

func (*EthereumMultinodeClient) HeaderTimestampByNumber

func (e *EthereumMultinodeClient) HeaderTimestampByNumber(ctx context.Context, bn *big.Int) (uint64, error)

HeaderTimestampByNumber gets header timestamp by number

func (*EthereumMultinodeClient) IsEventConfirmed added in v1.5.6

func (e *EthereumMultinodeClient) IsEventConfirmed(event *types.Log) (confirmed, removed bool, err error)

IsEventConfirmed returns if the default client can confirm the event has happened

func (*EthereumMultinodeClient) IsTxConfirmed

func (e *EthereumMultinodeClient) IsTxConfirmed(txHash common.Hash) (bool, error)

IsTxConfirmed returns the default client's transaction confirmations

func (*EthereumMultinodeClient) LatestBlockNumber

func (e *EthereumMultinodeClient) LatestBlockNumber(ctx context.Context) (uint64, error)

LatestBlockNumber gets the latest block number from the default client

func (*EthereumMultinodeClient) LoadContract added in v1.7.0

func (e *EthereumMultinodeClient) LoadContract(contractName string, address common.Address, loader ContractLoader) (interface{}, error)

LoadContract load already deployed contract instance

func (*EthereumMultinodeClient) LoadWallets

func (e *EthereumMultinodeClient) LoadWallets(cfg EVMNetwork) error

LoadWallets loads wallets using private keys provided in the config

func (*EthereumMultinodeClient) NetworkSimulated added in v1.4.0

func (e *EthereumMultinodeClient) NetworkSimulated() bool

GetNetworkType retrieves the type of network this is running on

func (*EthereumMultinodeClient) ParallelTransactions

func (e *EthereumMultinodeClient) ParallelTransactions(enabled bool)

ParallelTransactions when enabled, sends the transaction without waiting for transaction confirmations. The hashes are then stored within the client and confirmations can be waited on by calling WaitForEvents. When disabled, the minimum confirmations are waited on when the transaction is sent, so parallelisation is disabled.

func (*EthereumMultinodeClient) ProcessEvent added in v1.5.6

func (e *EthereumMultinodeClient) ProcessEvent(name string, event *types.Log, confirmedChan chan bool, errorChan chan error) error

ProcessEvent returns the result of the default client's processed event

func (*EthereumMultinodeClient) ProcessTransaction

func (e *EthereumMultinodeClient) ProcessTransaction(tx *types.Transaction) error

ProcessTransaction returns the result of the default client's processed transaction

func (*EthereumMultinodeClient) ReturnFunds added in v1.7.0

func (e *EthereumMultinodeClient) ReturnFunds(fromKey *ecdsa.PrivateKey) error

func (*EthereumMultinodeClient) SendTransaction added in v1.9.3

func (e *EthereumMultinodeClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction wraps ethereum's SendTransaction to make it safe with instant transaction types

func (*EthereumMultinodeClient) SetDefaultWallet

func (e *EthereumMultinodeClient) SetDefaultWallet(num int) error

SetDefaultWallet sets default wallet

func (*EthereumMultinodeClient) SetID

func (e *EthereumMultinodeClient) SetID(id int)

SetID sets client ID in a multi-node environment

func (*EthereumMultinodeClient) SetWallets

func (e *EthereumMultinodeClient) SetWallets(wallets []*EthereumWallet)

SetWallets sets the default client's wallets

func (*EthereumMultinodeClient) SubscribeFilterLogs added in v1.4.2

func (e *EthereumMultinodeClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, logs chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*EthereumMultinodeClient) SubscribeNewHeaders added in v1.10.10

func (e *EthereumMultinodeClient) SubscribeNewHeaders(
	ctx context.Context,
	headerChan chan *SafeEVMHeader,
) (ethereum.Subscription, error)

func (*EthereumMultinodeClient) SwitchNode

func (e *EthereumMultinodeClient) SwitchNode(clientID int) error

SwitchNode sets default client to perform calls to the network

func (*EthereumMultinodeClient) SyncNonce added in v1.9.1

func (e *EthereumMultinodeClient) SyncNonce(c EVMClient)

func (*EthereumMultinodeClient) TransactionOpts

func (e *EthereumMultinodeClient) TransactionOpts(from *EthereumWallet) (*bind.TransactOpts, error)

TransactionOpts returns the base Tx options for 'transactions' that interact with a smart contract. Since most contract interactions in this framework are designed to happen through abigen calls, it's intentionally quite bare.

func (*EthereumMultinodeClient) WaitForEvents

func (e *EthereumMultinodeClient) WaitForEvents() error

WaitForEvents is a blocking function that waits for all event subscriptions for all clients

type EthereumWallet

type EthereumWallet struct {
	// contains filtered or unexported fields
}

EthereumWallet is the implementation to allow testing with ETH based wallets

func NewEthereumWallet

func NewEthereumWallet(pk string) (*EthereumWallet, error)

NewEthereumWallet returns the instantiated ETH wallet based on a given private key

func (*EthereumWallet) Address

func (e *EthereumWallet) Address() string

Address returns the ETH address for a given wallet

func (*EthereumWallet) PrivateKey

func (e *EthereumWallet) PrivateKey() string

PrivateKey returns the private key for a given Ethereum wallet

func (*EthereumWallet) RawPrivateKey

func (e *EthereumWallet) RawPrivateKey() interface{}

RawPrivateKey returns raw private key if it has some encoding or in bytes

type EventConfirmer added in v1.5.6

type EventConfirmer struct {
	// contains filtered or unexported fields
}

EventConfirmer confirms that an event is confirmed by a certain amount of headers

func NewEventConfirmer added in v1.5.6

func NewEventConfirmer(
	eventName string,
	client EVMClient,
	event *types.Log,
	minConfirmations int,
	confirmedChan chan bool,
	errorChan chan error,
) *EventConfirmer

NewEventConfirmer returns a new instance of the event confirmer that waits for on-chain minimum confirmations

func (*EventConfirmer) Complete added in v1.5.6

func (e *EventConfirmer) Complete() bool

Complete returns if the confirmer is done, whether confirmation was successful or not

func (*EventConfirmer) ReceiveHeader added in v1.5.12

func (e *EventConfirmer) ReceiveHeader(header NodeHeader) error

ReceiveHeader will attempt to confirm an event for the chain's configured minimum confirmed headers. Errors encountered are sent along the eventErrorChan, and the result of confirming the event is sent to eventConfirmedChan.

func (*EventConfirmer) Wait added in v1.5.6

func (e *EventConfirmer) Wait() error

Wait until the event fully presents as complete

type GasStats

type GasStats struct {
	NodeID       int
	TotalGasUsed int64
	SeenHashes   map[string]bool
	ClientTXs    []TXGasData
	// contains filtered or unexported fields
}

GasStats helper struct to determine gas metrics across all txs of a test

func NewGasStats

func NewGasStats(nodeID int) *GasStats

NewGasStats creates new gas stats collector

func (*GasStats) AddClientTXData

func (g *GasStats) AddClientTXData(data TXGasData)

AddClientTXData adds client TX data

func (*GasStats) PrintStats

func (g *GasStats) PrintStats()

PrintStats prints gas stats and total TXs cost

type HeaderEventSubscription

type HeaderEventSubscription interface {
	ReceiveHeader(header NodeHeader) error
	Wait() error
	Complete() bool
}

HeaderEventSubscription is an interface for allowing callbacks when the client receives a new header

type InstantConfirmer added in v1.5.12

type InstantConfirmer struct {
	// contains filtered or unexported fields
}

InstantConfirmer is a near-instant confirmation method, primarily for optimistic L2s that have near-instant finalization

func NewInstantConfirmer added in v1.5.12

func NewInstantConfirmer(
	client EVMClient,
	txHash common.Hash,
	confirmedChan chan bool,
	errorChan chan error,
) *InstantConfirmer

func (*InstantConfirmer) Complete added in v1.5.12

func (l *InstantConfirmer) Complete() bool

Complete returns if the transaction is complete or not

func (*InstantConfirmer) ReceiveHeader added in v1.5.12

func (l *InstantConfirmer) ReceiveHeader(_ NodeHeader) error

ReceiveHeader does a quick check on if the tx is confirmed already

func (*InstantConfirmer) Wait added in v1.5.12

func (l *InstantConfirmer) Wait() error

Wait checks every header if the tx has been included on chain or not

type JSONStrDuration added in v1.9.3

type JSONStrDuration struct {
	time.Duration
}

JSONStrDuration is JSON friendly duration that can be parsed from "1h2m0s" Go format

func (*JSONStrDuration) MarshalJSON added in v1.9.3

func (d *JSONStrDuration) MarshalJSON() ([]byte, error)

func (*JSONStrDuration) UnmarshalJSON added in v1.9.3

func (d *JSONStrDuration) UnmarshalJSON(b []byte) error

type KlaytnClient

type KlaytnClient struct {
	*EthereumClient
}

KlaytnClient represents a single node, EVM compatible client for the Klaytn network

func (*KlaytnClient) DeployContract

func (k *KlaytnClient) DeployContract(
	contractName string,
	deployer ContractDeployer,
) (*common.Address, *types.Transaction, interface{}, error)

DeployContract acts as a general contract deployment tool to an ethereum chain

func (*KlaytnClient) Fund

func (k *KlaytnClient) Fund(
	toAddress string,
	amount *big.Float,
) error

Fund overrides ethereum's fund to account for Klaytn's gas specifications https://docs.klaytn.com/klaytn/design/transaction-fees#unit-price

func (*KlaytnClient) ReturnFunds added in v1.7.0

func (k *KlaytnClient) ReturnFunds(fromPrivateKey *ecdsa.PrivateKey) error

type KlaytnMultinodeClient

type KlaytnMultinodeClient struct {
	*EthereumMultinodeClient
}

KlaytnMultinodeClient represents a multi-node, EVM compatible client for the Klaytn network

type MetisClient

type MetisClient struct {
	*EthereumClient
}

MetisClient represents a single node, EVM compatible client for the Metis network

func (*MetisClient) DeployContract

func (m *MetisClient) DeployContract(
	contractName string,
	deployer ContractDeployer,
) (*common.Address, *types.Transaction, interface{}, error)

DeployContract acts as a general contract deployment tool to an EVM chain

func (*MetisClient) Fund

func (m *MetisClient) Fund(toAddress string, amount *big.Float) error

Fund sends some ETH to an address using the default wallet

func (*MetisClient) ReturnFunds added in v1.7.0

func (m *MetisClient) ReturnFunds(fromPrivateKey *ecdsa.PrivateKey) error

Fund sends some ARB to an address using the default wallet

type MetisMultinodeClient

type MetisMultinodeClient struct {
	*EthereumMultinodeClient
}

MetisMultinodeClient represents a multi-node, EVM compatible client for the Metis network

type NodeHeader added in v1.5.12

type NodeHeader struct {
	NodeID int
	SafeEVMHeader
}

NodeHeader header with the ID of the node that received it

type NonceSettings added in v1.9.1

type NonceSettings struct {
	NonceMu *sync.Mutex
	Nonces  map[string]uint64
	// contains filtered or unexported fields
}

NonceSettings is a convenient wrapper for holding nonce state

type OptimismClient added in v1.6.4

type OptimismClient struct {
	*EthereumClient
}

OptimismClient represents a single node, EVM compatible client for the Optimism network

func (*OptimismClient) Fund added in v1.6.4

func (o *OptimismClient) Fund(
	toAddress string,
	amount *big.Float,
) error

Fund sends some ETH to an address using the default wallet

func (*OptimismClient) ReturnFunds added in v1.7.0

func (o *OptimismClient) ReturnFunds(fromKey *ecdsa.PrivateKey) error

type OptimismMultinodeClient added in v1.6.4

type OptimismMultinodeClient struct {
	*EthereumMultinodeClient
}

OptimismMultinodeClient represents a multi-node, EVM compatible client for the Optimism network

type PolygonClient added in v1.8.5

type PolygonClient struct {
	*EthereumClient
}

PolygonClient represents a single node, EVM compatible client for the Polygon network

type PolygonMultinodeClient added in v1.8.5

type PolygonMultinodeClient struct {
	*EthereumMultinodeClient
}

PolygonMultinodeClient represents a multi-node, EVM compatible client for the Klaytn network

type RSKClient added in v1.7.9

type RSKClient struct {
	*EthereumClient
}

RSKClient represents a single node, EVM compatible client for the RSK network

func (*RSKClient) DeployContract added in v1.7.9

func (r *RSKClient) DeployContract(
	contractName string,
	deployer ContractDeployer,
) (*common.Address, *types.Transaction, interface{}, error)

DeployContract acts as a general contract deployment tool to an EVM chain

func (*RSKClient) Fund added in v1.7.9

func (r *RSKClient) Fund(toAddress string, amount *big.Float) error

Fund sends some ETH to an address using the default wallet

func (*RSKClient) ReturnFunds added in v1.7.9

func (r *RSKClient) ReturnFunds(fromPrivateKey *ecdsa.PrivateKey) error

Fund sends some ARB to an address using the default wallet

type RSKMultinodeClient added in v1.7.9

type RSKMultinodeClient struct {
	*EthereumMultinodeClient
}

RSKMultinodeClient represents a multi-node, EVM compatible client for the RSK network

type SafeEVMHeader added in v1.10.10

type SafeEVMHeader struct {
	Hash      common.Hash
	Number    *big.Int
	Timestamp time.Time
	BaseFee   *big.Int
}

SafeEVMHeader is a wrapper for the EVM header, to allow for the addition/removal of fields without breaking the interface

func (*SafeEVMHeader) UnmarshalJSON added in v1.10.10

func (h *SafeEVMHeader) UnmarshalJSON(bs []byte) error

UnmarshalJSON enables Geth to unmarshal block headers into our custom type

type TXGasData

type TXGasData struct {
	TXHash            string
	Value             uint64
	GasLimit          uint64
	GasUsed           uint64
	GasPrice          uint64
	CumulativeGasUsed uint64
}

TXGasData transaction gas data

type TransactionConfirmer

type TransactionConfirmer struct {
	// contains filtered or unexported fields
}

TransactionConfirmer is an implementation of HeaderEventSubscription that checks whether tx are confirmed

func NewTransactionConfirmer

func NewTransactionConfirmer(client EVMClient, tx *types.Transaction, minConfirmations int) *TransactionConfirmer

NewTransactionConfirmer returns a new instance of the transaction confirmer that waits for on-chain minimum confirmations

func (*TransactionConfirmer) Complete added in v1.5.6

func (t *TransactionConfirmer) Complete() bool

Complete returns if the confirmer has completed or not

func (*TransactionConfirmer) ReceiveHeader added in v1.5.12

func (t *TransactionConfirmer) ReceiveHeader(header NodeHeader) error

ReceiveHeader the implementation of the HeaderEventSubscription that receives each header and checks tx confirmation

func (*TransactionConfirmer) Wait

func (t *TransactionConfirmer) Wait() error

Wait is a blocking function that waits until the transaction is complete

Jump to

Keyboard shortcuts

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