test

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accounts

func Accounts(numValidators int) *env.AccountsConfig

func BuildConfig

func BuildConfig(accounts *env.AccountsConfig) (*genesis.Config, *eth.Config, error)

BuildConfig generates genesis and eth config instances, that can be modified before passing to NewNetwork or NewNode.

NOTE: Do not edit the Istanbul field of the returned genesis config it will be overwritten with the corresponding config from the Istanbul field of the returned eth config.

func ValueTransferTransaction

func ValueTransferTransaction(
	client *ethclient.Client,
	senderKey *ecdsa.PrivateKey,
	sender,
	recipient common.Address,
	nonce uint64,
	value *big.Int,
	signer types.Signer,
) (*types.Transaction, error)

ValueTransferTransaction builds a signed value transfer transaction from the sender to the recipient with the given value and nonce, it uses the client to suggest a gas price and to estimate the gas.

Types

type MarshalableECDSAPrivateKey

type MarshalableECDSAPrivateKey ecdsa.PrivateKey

func (*MarshalableECDSAPrivateKey) MarshalJSON

func (k *MarshalableECDSAPrivateKey) MarshalJSON() ([]byte, error)

func (*MarshalableECDSAPrivateKey) UnmarshalJSON

func (k *MarshalableECDSAPrivateKey) UnmarshalJSON(b []byte) error

type MarshalableNodeConfig

type MarshalableNodeConfig struct {
	node.Config
	P2P MarshalableP2PConfig
}

type MarshalableP2PConfig

type MarshalableP2PConfig struct {
	p2p.Config
	PrivateKey *MarshalableECDSAPrivateKey
}

type Network

type Network []*Node

Network represents a network of nodes and provides functionality to easily create, start and stop a collection of nodes.

func NewNetwork

func NewNetwork(accounts *env.AccountsConfig, gc *genesis.Config, ec *eth.Config) (Network, error)

NewNetwork generates a network of nodes that are running and mining. For each provided validator account a corresponding node is created and each node is also assigned a developer account, there must be at least as many developer accounts provided as validator accounts. If there is an error it will be returned immediately, meaning that some nodes may be running and others not.

func (Network) AwaitBlock

func (n Network) AwaitBlock(ctx context.Context, num uint64) error

AwaitBlock ensures that the entire network has processed a block with the given num.

func (Network) AwaitTransactions

func (n Network) AwaitTransactions(ctx context.Context, txs ...*types.Transaction) error

AwaitTransactions ensures that the entire network has processed the provided transactions.

func (Network) Shutdown

func (n Network) Shutdown()

Shutdown closes all nodes in the network, any errors that are encountered are printed to stdout.

type Node

type Node struct {
	*node.Node
	Config        *node.Config
	P2PListenAddr string
	Eth           *eth.Ethereum
	EthConfig     *eth.Config
	WsClient      *ethclient.Client
	Nonce         uint64
	Key           *ecdsa.PrivateKey
	Address       common.Address
	DevKey        *ecdsa.PrivateKey
	DevAddress    common.Address
	Tracker       *Tracker
	// The transactions that this node has sent.
	SentTxs []*types.Transaction
}

Node provides an enhanced interface to node.Node with useful additions, the *node.Node is embedded so that its api is available through Node.

func NewNode

func NewNode(
	validatorAccount,
	devAccount *env.Account,
	nc *node.Config,
	ec *eth.Config,
	genesis *core.Genesis,
) (*Node, error)

NewNode creates a new running node with the provided config.

func (*Node) AwaitSentTransactions

func (n *Node) AwaitSentTransactions(ctx context.Context) error

AwaitSentTransactions awaits all the transactions that this node has sent via SendCelo.

func (*Node) AwaitTransactions

func (n *Node) AwaitTransactions(ctx context.Context, txs ...*types.Transaction) error

AwaitTransactions awaits all the provided transactions.

func (*Node) Close

func (n *Node) Close() error

Close shuts down the node and releases all resources and removes the datadir unless an error is returned, in which case there is no guarantee that all resources are released.

func (*Node) ProcessedTxBlock

func (n *Node) ProcessedTxBlock(tx *types.Transaction) *types.Block

ProcessedTxBlock returns the block that the given transaction was processed in, nil will be retuned if the transaction has not been processed by this node.

func (*Node) SendCelo

func (n *Node) SendCelo(ctx context.Context, recipient common.Address, value int64) (*types.Transaction, error)

SendCelo submits a value transfer transaction to the network to send celo to the recipient. The submitted transaction is returned.

func (*Node) SendCeloTracked

func (n *Node) SendCeloTracked(ctx context.Context, recipient common.Address, value int64) (*types.Transaction, error)

SendCeloTracked functions like SendCelo but also waits for the transaction to be processed.

func (*Node) Start

func (n *Node) Start() error

Start creates the node.Node and eth.Ethereum and starts the node.Node and starts eth.Ethereum mining.

func (*Node) TxFee

func (n *Node) TxFee(ctx context.Context, tx *types.Transaction) (*big.Int, error)

TxFee returns the gas fee for the given transaction.

type Tracker

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

Tracker tracks processed blocks and transactions through a subscription with an ethclient. It provides the ability to check whether blocks or transactions have been processed and to wait till those blocks or transactions have been processed.

func NewTracker

func NewTracker() *Tracker

NewTracker creates a new tracker.

func (*Tracker) AwaitBlock

func (tr *Tracker) AwaitBlock(ctx context.Context, num uint64) error

AwaitBlock waits for a block with the given num to be processed, it will return the ctx.Err() if ctx expires before a block with that number has been processed or ErrStopped if StopTracking is called before a block with that number is processed.

func (*Tracker) AwaitTransactions

func (tr *Tracker) AwaitTransactions(ctx context.Context, hashes []common.Hash) error

AwaitTransactions waits for the transactions listed in hashes to be processed, it will return the ctx.Err() if ctx expires before all the transactions in hashes were processed or ErrStopped if StopTracking is called before all the transactions in hashes were processed.

func (*Tracker) GetProcessedBlock

func (tr *Tracker) GetProcessedBlock(num uint64) *types.Block

GetProcessedBlock returns processed block with the given num or nil if the tracker has not seen a processed block with that num.

func (*Tracker) GetProcessedBlockForTx

func (tr *Tracker) GetProcessedBlockForTx(hash common.Hash) *types.Block

GetProcessedBlockForTx returns the block that a transaction with the given hash was processed in or nil if the tracker has not seen a processed transaction with the given hash.

func (*Tracker) GetProcessedTx

func (tr *Tracker) GetProcessedTx(hash common.Hash) *types.Transaction

GetProcessedTx returns the processed transaction with the given hash or nil if the tracker has not seen a processed transaction with the given hash.

func (*Tracker) StartTracking

func (tr *Tracker) StartTracking(client *ethclient.Client) error

StartTracking subscribes to new head events on the client and starts processing the events in a goroutine.

func (*Tracker) StopTracking

func (tr *Tracker) StopTracking() error

StopTracking shuts down all the goroutines in the tracker.

Jump to

Keyboard shortcuts

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