framework

package
v0.0.0-...-dd56834 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	DefaultTimeout = time.Minute
)

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(t *testing.T, address types.Address, rpcClient *jsonrpc.Client) *big.Int

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

func GetStakedAmount

func GetStakedAmount(from types.Address, rpcClient *jsonrpc.Client) (*big.Int, error)

GetStakedAmount is a helper function for getting the staked amount on the Staking SC

func GetValidatorSet

func GetValidatorSet(from types.Address, rpcClient *jsonrpc.Client) ([]types.Address, error)

GetValidatorSet returns the validator set from the SC

func MethodSig

func MethodSig(name string) []byte

MethodSig returns the signature of a non-parametrized function

func MethodSigWithParams

func MethodSigWithParams(nameWithParams string) []byte

MethodSigWithParams returns the signature of a function

func MultiJoin

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

func MultiJoinSerial

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

func StakeAmount

func StakeAmount(
	from types.Address,
	senderKey *ecdsa.PrivateKey,
	amount *big.Int,
	srv *TestServer,
) error

StakeAmount is a helper function for staking an amount on the Staking SC

func ToLocalIPv4LibP2pAddr

func ToLocalIPv4LibP2pAddr(port int, nodeID string) string

func UnstakeAmount

func UnstakeAmount(
	from types.Address,
	senderKey *ecdsa.PrivateKey,
	srv *TestServer,
) (*ethgo.Receipt, error)

UnstakeAmount is a helper function for unstaking the entire amount on the Staking SC

func WaitForServersToSeal

func WaitForServersToSeal(servers []*TestServer, desiredHeight uint64) []error

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 AtomicErrors

type AtomicErrors struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewAtomicErrors

func NewAtomicErrors(capacity int) AtomicErrors

func (*AtomicErrors) Append

func (a *AtomicErrors) Append(err error)

func (*AtomicErrors) Errors

func (a *AtomicErrors) Errors() []error

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 PredeployParams

type PredeployParams struct {
	ArtifactsPath    string
	PredeployAddress string
	ConstructorArgs  []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) CallJSONRPC

func (t *TestServer) CallJSONRPC(req map[string]interface{}) map[string]interface{}

func (*TestServer) DeployContract

func (t *TestServer) DeployContract(
	ctx context.Context,
	binary string,
	privateKey *ecdsa.PrivateKey,
) (ethgo.Address, error)

DeployContract deploys a contract with account 0 and returns the address

func (*TestServer) GenerateGenesis

func (t *TestServer) GenerateGenesis() error

func (*TestServer) GenesisPredeploy

func (t *TestServer) GenesisPredeploy() error

func (*TestServer) GetGasTotal

func (t *TestServer) GetGasTotal(txHashes []ethgo.Hash) uint64

GetGasTotal waits for the total gas used sum for the passed in transactions

func (*TestServer) GetLatestBlockHeight

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

func (*TestServer) GetStdout

func (t *TestServer) GetStdout() io.Writer

GetStdout returns the combined stdout writers of the server

func (*TestServer) GrpcAddr

func (t *TestServer) GrpcAddr() string

func (*TestServer) HTTPJSONRPCURL

func (t *TestServer) HTTPJSONRPCURL() string

func (*TestServer) IBFTOperator

func (t *TestServer) IBFTOperator() ibftOp.IbftOperatorClient

func (*TestServer) InvokeMethod

func (t *TestServer) InvokeMethod(
	ctx context.Context,
	contractAddress types.Address,
	method string,
	fromKey *ecdsa.PrivateKey,
) *ethgo.Receipt

func (*TestServer) JSONRPC

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

func (*TestServer) JSONRPCAddr

func (t *TestServer) JSONRPCAddr() string

func (*TestServer) LibP2PAddr

func (t *TestServer) LibP2PAddr() string

func (*TestServer) Operator

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

func (*TestServer) ReleaseReservedPorts

func (t *TestServer) ReleaseReservedPorts()

func (*TestServer) SecretsInit

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

func (*TestServer) SendRawTx

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

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

func (*TestServer) SignTx

func (t *TestServer) SignTx(
	transaction *types.Transaction,
	privateKey *ecdsa.PrivateKey,
) (*types.Transaction, error)

SignTx is a helper method for signing transactions

func (*TestServer) Start

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

func (*TestServer) Stop

func (t *TestServer) Stop()

func (*TestServer) SwitchIBFTType

func (t *TestServer) SwitchIBFTType(typ fork.IBFTType, from uint64, to, deployment *uint64) error

func (*TestServer) Txn

func (t *TestServer) Txn(key *wallet.Key) *Txn

func (*TestServer) TxnPoolOperator

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

func (*TestServer) WSJSONRPCURL

func (t *TestServer) WSJSONRPCURL() string

func (*TestServer) WaitForReady

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

func (*TestServer) WaitForReceipt

func (t *TestServer) WaitForReceipt(ctx context.Context, hash ethgo.Hash) (*ethgo.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
	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)
	GenesisValidatorBalance *big.Int                 // Genesis the balance for the validators
	DevStakers              []types.Address          // List of initial staking addresses for the staking SC
	Consensus               ConsensusType            // Consensus MechanismType
	ValidatorType           validators.ValidatorType // Validator Type
	Bootnodes               []string                 // Bootnode Addresses
	PriceLimit              *uint64                  // Minimum gas price limit to enforce for acceptance into the pool
	DevInterval             int                      // Dev consensus update interval [s]
	EpochSize               uint64                   // The epoch size in blocks for the IBFT layer
	BlockGasLimit           uint64                   // Block gas limit
	BlockGasTarget          uint64                   // Gas target for new blocks
	ShowsLog                bool                     // Flag specifying if logs are shown
	Name                    string                   // Name of the server
	SaveLogs                bool                     // Flag specifying if logs are saved
	LogsDir                 string                   // Directory where logs are saved
	IsPos                   bool                     // Specifies the mechanism used for IBFT (PoA / PoS)
	Signer                  *crypto.EIP155Signer     // Signer used for transactions
	MinValidatorCount       uint64                   // Min validator count
	MaxValidatorCount       uint64                   // Max validator count
	BlockTime               uint64                   // Minimum block generation time (in s)
	IBFTBaseTimeout         uint64                   // Base Timeout in seconds for IBFT
	PredeployParams         *PredeployParams
}

TestServerConfig for the test server

func (*TestServerConfig) DataDir

func (t *TestServerConfig) DataDir() string

DataDir returns path of data directory server uses

func (*TestServerConfig) Premine

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

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

func (*TestServerConfig) PremineValidatorBalance

func (t *TestServerConfig) PremineValidatorBalance(balance *big.Int)

PremineValidatorBalance callback sets the genesis balance of the validator the server manages (in WEI)

func (*TestServerConfig) PrivateKey

func (t *TestServerConfig) PrivateKey() (*ecdsa.PrivateKey, error)

PrivateKey returns a private key in data directory

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

func (t *TestServerConfig) SetBlockTime(blockTime uint64)

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

func (t *TestServerConfig) SetDevStakingAddresses(stakingAddresses []types.Address)

SetDevStakingAddresses sets the Staking smart contract staker addresses for the dev mode. These addresses should be passed into the `ibft-validator` flag in genesis generation. Since invoking the dev consensus will not generate the ibft base folders, this is the only way to signalize to the genesis creation process who the validators are

func (*TestServerConfig) SetEpochSize

func (t *TestServerConfig) SetEpochSize(epochSize uint64)

SetEpochSize sets the epoch size for the consensus layer. It controls the rate at which the validator set is updated

func (*TestServerConfig) SetIBFTBaseTimeout

func (t *TestServerConfig) SetIBFTBaseTimeout(baseTimeout uint64)

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

func (t *TestServerConfig) SetIBFTPoS(value bool)

SetIBFTPoS sets the flag indicating the IBFT mechanism

func (*TestServerConfig) SetLogsDir

func (t *TestServerConfig) SetLogsDir(dir string)

SetLogsDir sets the directory where logs are saved

func (*TestServerConfig) SetMaxValidatorCount

func (t *TestServerConfig) SetMaxValidatorCount(val uint64)

SetMaxValidatorCount sets the max validator count

func (*TestServerConfig) SetMinValidatorCount

func (t *TestServerConfig) SetMinValidatorCount(val uint64)

SetMinValidatorCount sets the min validator count

func (*TestServerConfig) SetName

func (t *TestServerConfig) SetName(name string)

SetName sets the name of the server

func (*TestServerConfig) SetPredeployParams

func (t *TestServerConfig) SetPredeployParams(params *PredeployParams)

func (*TestServerConfig) SetPriceLimit

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

SetPriceLimit sets the gas price limit

func (*TestServerConfig) SetSaveLogs

func (t *TestServerConfig) SetSaveLogs(f bool)

SetSaveLogs sets flag for saving logs

func (*TestServerConfig) SetShowsLog

func (t *TestServerConfig) SetShowsLog(f bool)

SetShowsLog sets flag for logging

func (*TestServerConfig) SetSigner

func (t *TestServerConfig) SetSigner(signer *crypto.EIP155Signer)

func (*TestServerConfig) SetValidatorType

func (t *TestServerConfig) SetValidatorType(vt validators.ValidatorType)

SetValidatorType callback sets validator type

type TestServerConfigCallback

type TestServerConfigCallback func(*TestServerConfig)

type Txn

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

func (*Txn) Complete

func (t *Txn) Complete() bool

func (*Txn) Deploy

func (t *Txn) Deploy(input []byte) *Txn

func (*Txn) GasLimit

func (t *Txn) GasLimit(gas uint64) *Txn

func (*Txn) GasPrice

func (t *Txn) GasPrice(price uint64) *Txn

func (*Txn) NoFail

func (t *Txn) NoFail(tt *testing.T)

func (*Txn) Nonce

func (t *Txn) Nonce(nonce uint64) *Txn

func (*Txn) Receipt

func (t *Txn) Receipt() *ethgo.Receipt

func (*Txn) Send

func (t *Txn) Send() (*Txn, error)

func (*Txn) To

func (t *Txn) To(to ethgo.Address) *Txn

func (*Txn) Transfer

func (t *Txn) Transfer(to ethgo.Address, value *big.Int) *Txn

func (*Txn) Value

func (t *Txn) Value(value *big.Int) *Txn

func (*Txn) Wait

func (t *Txn) Wait()

Jump to

Keyboard shortcuts

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