test

package
v0.0.0-...-697f13e Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseEthConfig = &eth.Config{
		SyncMode:            downloader.FullSync,
		MinSyncPeers:        1,
		DatabaseCache:       256,
		DatabaseHandles:     256,
		TxPool:              core.DefaultTxPoolConfig,
		RPCEthCompatibility: true,
		Istanbul: istanbul.Config{
			Validator: true,

			AnnounceQueryEnodeGossipPeriod: 60,

			RequestTimeout:              200,
			TimeoutBackoffFactor:        200,
			MinResendRoundChangeTimeout: 200,
			MaxResendRoundChangeTimeout: 10000,
			Epoch:                       20,
			ProposerPolicy:              istanbul.ShuffledRoundRobin,
			DefaultLookbackWindow:       3,
			BlockPeriod:                 0,
		},
	}
)
View Source
var (
	ErrTrackerAlreadyStopped = errors.New("attempted to stop already stopped tracker")
)

Functions

func AccountConfig

func AccountConfig(numValidators, numExternal int) *env.AccountsConfig

func BuildConfig

func BuildConfig(accounts *env.AccountsConfig) (*genesis.Config, *ethconfig.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 GenerateGenesis

func GenerateGenesis(accounts *env.AccountsConfig, gc *genesis.Config, contractsBuildPath string) (*core.Genesis, error)

GenerateGenesis checks that the contractsBuildPath exists and if so proceeds to generate the genesis.

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.

func ValueTransferTransactionWithDynamicFee

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

ValueTransferTransactionWithDynamicFee builds a signed value transfer transaction from the sender to the recipient with the given value, nonce, gasFeeCap and gasTipCap.

Types

type Account

type Account struct {
	Address     common.Address
	Key         *ecdsa.PrivateKey
	ChainConfig *params.ChainConfig
	Nonce       *uint64
}

func Accounts

func Accounts(accts []env.Account, chainConfig *params.ChainConfig) []*Account

Accounts converts a slice of env.Account objects to Account objects.

func NewAccount

func NewAccount(key *ecdsa.PrivateKey, address common.Address, chainConfig *params.ChainConfig) *Account

func (*Account) SendCelo

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

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

func (*Account) SendCeloTracked

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

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

func (*Account) SendCeloWithDynamicFee

func (a *Account) SendCeloWithDynamicFee(ctx context.Context, recipient common.Address, value int64, gasFeeCap *big.Int, gasTipCap *big.Int, node *Node) (*types.Transaction, error)

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

type BalanceWatcher

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

BalanceWatcher is a helper to watch balance changes over addresses.

func NewBalanceWatcher

func NewBalanceWatcher(client *ethclient.Client, addresses []common.Address) *BalanceWatcher

NewBalanceWatcher creates a BalanceWatcher, records initial balances of the accounts.

func (*BalanceWatcher) Current

func (w *BalanceWatcher) Current(address common.Address) *big.Int

Current returns current balance of given address.

func (*BalanceWatcher) Delta

func (w *BalanceWatcher) Delta(address common.Address) *big.Int

Delta returns difference between current and initial balance of given address for given token.

func (*BalanceWatcher) Initial

func (w *BalanceWatcher) Initial(address common.Address) *big.Int

Initial returns initial balance of given address, or nil if address is not found.

func (*BalanceWatcher) Update

func (w *BalanceWatcher) Update()

Update updates current balances in the BalanceWatcher

type Balances

type Balances map[common.Address]*big.Int

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, func(), 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. A shutdown function is also returned which will shutdown and clean up the network when called. In the case that an error is returned the shutdown function will be nil and so no attempt should be made to call it.

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() []error

Shutdown closes all nodes in the network, any errors encountered when shutting down nodes are returned in a slice.

type Node

type Node struct {
	*node.Node
	Config        *node.Config
	P2PListenAddr string
	Enode         *enode.Node
	Eth           *eth.Ethereum
	EthConfig     *eth.Config
	WsClient      *ethclient.Client
	Key           *ecdsa.PrivateKey
	Address       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 *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) AddPeers

func (n *Node) AddPeers(nodes ...*Node)

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. It is assumed that this is only called after calling Start otherwise it will panic.

func (*Node) GossipEnodeCertificatge

func (n *Node) GossipEnodeCertificatge() error

GossipEnodeCertificatge gossips this nodes enode certificates to the rest of the network.

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) 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 Token

type Token int

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