framework

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: LGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGasPrice = 1879048192 // 0x70000000
	DefaultGasLimit = 5242880    // 0x500000
)

Variables

This section is empty.

Functions

func EcrecoverFromBlockhash

func EcrecoverFromBlockhash(hash types.Hash, signature []byte) (types.Address, error)

func EthToWei

func EthToWei(ethValue int64) *big.Int

func EthToWeiPrecise

func EthToWeiPrecise(ethValue int64, decimals int64) *big.Int

func GetAccountBalance

func GetAccountBalance(
	address types.Address,
	rpcClient *jsonrpc.Client,
	t *testing.T,
) *big.Int

GetAccountBalance is a helper method for fetching the Balance field of an account

func MethodSig

func MethodSig(name string) []byte

MethodSig returns the signature of a non-parametrized function

func MultiJoin

func MultiJoin(t *testing.T, srvs ...*TestServer)

func MultiJoinSerial

func MultiJoinSerial(t *testing.T, srvs []*TestServer)

func ToLocalIPv4LibP2pAddr

func ToLocalIPv4LibP2pAddr(port int, nodeID string) string

func WaitUntilBlockMined

func WaitUntilBlockMined(ctx context.Context, srv *TestServer, desiredHeight uint64) (uint64, error)

WaitUntilBlockMined waits until server mined block with bigger height than given height otherwise returns timeout

func WaitUntilPeerConnects

func WaitUntilPeerConnects(ctx context.Context, srv *TestServer, requiredNum int) (*proto.PeersListResponse, error)

WaitUntilPeerConnects waits until server connects to required number of peers otherwise returns timeout

func WaitUntilTxPoolFilled

func WaitUntilTxPoolFilled(ctx context.Context, srv *TestServer, requiredNum uint64) (*txpoolProto.TxnPoolStatusResp, error)

WaitUntilTxPoolFilled waits until node has required number of transactions in txpool, otherwise returns timeout

Types

type ConsensusType

type ConsensusType int
const (
	ConsensusIBFT ConsensusType = iota
	ConsensusDev
	ConsensusDummy
)

type IBFTServerConfigCallback

type IBFTServerConfigCallback func(index int, config *TestServerConfig)

type IBFTServersManager

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

func NewIBFTServersManager

func NewIBFTServersManager(t *testing.T, numNodes int, ibftDirPrefix string, callback IBFTServerConfigCallback) *IBFTServersManager

func (*IBFTServersManager) GetServer

func (m *IBFTServersManager) GetServer(i int) *TestServer

func (*IBFTServersManager) StartServers

func (m *IBFTServersManager) StartServers(ctx context.Context)

func (*IBFTServersManager) StopServers

func (m *IBFTServersManager) StopServers()

type InitIBFTResult

type InitIBFTResult struct {
	Address string
	NodeID  string
}

type PreparedTransaction

type PreparedTransaction struct {
	From     types.Address
	GasPrice *big.Int
	Gas      uint64
	To       *types.Address
	Value    *big.Int
	Input    []byte
}

type ReservedPort

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

ReservedPort keeps available port until use

func FindAvailablePort

func FindAvailablePort(from, to int) *ReservedPort

func FindAvailablePorts

func FindAvailablePorts(n, from, to int) ([]ReservedPort, error)

func (*ReservedPort) Close

func (p *ReservedPort) Close() error

func (*ReservedPort) IsClosed

func (p *ReservedPort) IsClosed() bool

func (*ReservedPort) Port

func (p *ReservedPort) Port() int

type SrvAccount

type SrvAccount struct {
	Addr    types.Address
	Balance *big.Int
}

type TestServer

type TestServer struct {
	Config *TestServerConfig
	// contains filtered or unexported fields
}

func NewTestServer

func NewTestServer(t *testing.T, rootDir string, callback TestServerConfigCallback) *TestServer

func NewTestServers

func NewTestServers(t *testing.T, num int, conf func(*TestServerConfig)) []*TestServer

func (*TestServer) DeployContract

func (t *TestServer) DeployContract(ctx context.Context, binary string) (web3.Address, error)

DeployContract deploys a contract with account 0 and returns the address

func (*TestServer) GenerateGenesis

func (t *TestServer) GenerateGenesis() error

func (*TestServer) GetLatestBlockHeight

func (t *TestServer) GetLatestBlockHeight() (uint64, error)

func (*TestServer) GrpcAddr

func (t *TestServer) GrpcAddr() string

func (*TestServer) InitIBFT

func (t *TestServer) InitIBFT() (*InitIBFTResult, error)

func (*TestServer) JSONRPC

func (t *TestServer) JSONRPC() *jsonrpc.Client

func (*TestServer) JsonRPCAddr

func (t *TestServer) JsonRPCAddr() string

func (*TestServer) Operator

func (t *TestServer) Operator() proto.SystemClient

func (*TestServer) ReleaseReservedPorts

func (t *TestServer) ReleaseReservedPorts()

func (*TestServer) SendRawTx

func (t *TestServer) SendRawTx(ctx context.Context, tx *PreparedTransaction, signerKey *ecdsa.PrivateKey) (*web3.Receipt, error)

SendRawTx signs the transaction with the provided private key, executes it, and returns the receipt

func (*TestServer) SendTxn

func (t *TestServer) SendTxn(ctx context.Context, txn *web3.Transaction) (*web3.Receipt, error)

func (*TestServer) Start

func (t *TestServer) Start(ctx context.Context) error

func (*TestServer) Stop

func (t *TestServer) Stop()

func (*TestServer) TxnPoolOperator

func (t *TestServer) TxnPoolOperator() txpoolProto.TxnPoolOperatorClient

func (*TestServer) TxnTo

func (t *TestServer) TxnTo(ctx context.Context, address web3.Address, method string) *web3.Receipt

func (*TestServer) WaitForReady

func (t *TestServer) WaitForReady(ctx context.Context) error

func (*TestServer) WaitForReceipt

func (t *TestServer) WaitForReceipt(ctx context.Context, hash web3.Hash) (*web3.Receipt, error)

type TestServerConfig

type TestServerConfig struct {
	ReservedPorts  []ReservedPort
	JsonRPCPort    int           // The JSON RPC endpoint port
	GRPCPort       int           // The GRPC endpoint port
	LibP2PPort     int           // The Libp2p endpoint port
	Seal           bool          // Flag indicating if blocks should be sealed
	RootDir        string        // The root directory for test environment
	IBFTDirPrefix  string        // The prefix of data directory for IBFT
	IBFTDir        string        // The name of data directory for IBFT
	PremineAccts   []*SrvAccount // Accounts with existing balances (genesis accounts)
	Consensus      ConsensusType // Consensus Type
	Bootnodes      []string      // Bootnode Addresses
	Locals         []string      // Accounts whose transactions are treated as locals
	NoLocals       bool          // Flag to disable price exemptions for locally transactions
	PriceLimit     *uint64       // Minimum gas price limit to enforce for acceptance into the pool
	DevInterval    int           // Dev consensus update interval [s]
	BlockGasLimit  uint64        // Block gas limit
	BlockGasTarget uint64        // Gas target for new blocks
	ShowsLog       bool
}

TestServerConfig for the test server

func (*TestServerConfig) Premine

func (t *TestServerConfig) Premine(addr types.Address, amount *big.Int)

CALLBACKS // Premine callback specifies an account with a balance (in WEI)

func (*TestServerConfig) SetBlockGasTarget

func (t *TestServerConfig) SetBlockGasTarget(target uint64)

SetBlockGasTarget sets the gas target for the test server

func (*TestServerConfig) SetBlockLimit

func (t *TestServerConfig) SetBlockLimit(limit uint64)

SetBlockLimit sets the block gas limit

func (*TestServerConfig) SetBootnodes

func (t *TestServerConfig) SetBootnodes(bootnodes []string)

SetBootnodes sets bootnodes

func (*TestServerConfig) SetConsensus

func (t *TestServerConfig) SetConsensus(c ConsensusType)

SetConsensus callback sets consensus

func (*TestServerConfig) SetDevInterval

func (t *TestServerConfig) SetDevInterval(interval int)

SetDevInterval sets the update interval for the dev consensus

func (*TestServerConfig) SetIBFTDir

func (t *TestServerConfig) SetIBFTDir(ibftDir string)

SetIBFTDir callback sets the name of data directory for IBFT

func (*TestServerConfig) SetIBFTDirPrefix

func (t *TestServerConfig) SetIBFTDirPrefix(ibftDirPrefix string)

SetIBFTDirPrefix callback sets prefix of IBFT directories

func (*TestServerConfig) SetLocals

func (t *TestServerConfig) SetLocals(locals []string)

SetLocals sets locals

func (*TestServerConfig) SetNoLocals

func (t *TestServerConfig) SetNoLocals(noLocals bool)

SetLocals sets NoLocals flag

func (*TestServerConfig) SetPriceLimit

func (t *TestServerConfig) SetPriceLimit(priceLimit *uint64)

SetLocals sets PriceLimit

func (*TestServerConfig) SetSeal

func (t *TestServerConfig) SetSeal(state bool)

SetSeal callback toggles the seal mode

func (*TestServerConfig) SetShowsLog

func (t *TestServerConfig) SetShowsLog(f bool)

SetShowsLog sets flag for logging

type TestServerConfigCallback

type TestServerConfigCallback func(*TestServerConfig)

Jump to

Keyboard shortcuts

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