Documentation ¶
Index ¶
- Constants
- Variables
- func EcrecoverFromBlockhash(hash types.Hash, signature []byte) (types.Address, error)
- func EthToWei(ethValue int64) *big.Int
- func EthToWeiPrecise(ethValue int64, decimals int64) *big.Int
- func GetAccountBalance(t *testing.T, address types.Address, rpcClient *jsonrpc.Client) *big.Int
- func MethodSig(name string) []byte
- func MultiJoin(t *testing.T, srvs ...*TestServer)
- func MultiJoinSerial(t *testing.T, srvs []*TestServer)
- func StakeAmount(from types.Address, senderKey *ecdsa.PrivateKey, amount *big.Int, ...) error
- func ToLocalIPv4LibP2pAddr(port int, nodeID string) string
- func UnstakeAmount(from types.Address, senderKey *ecdsa.PrivateKey, srv *TestServer) (*web3.Receipt, error)
- func WaitForServersToSeal(servers []*TestServer, desiredHeight uint64) []error
- func WaitUntilBlockMined(ctx context.Context, srv *TestServer, desiredHeight uint64) (uint64, error)
- func WaitUntilPeerConnects(ctx context.Context, srv *TestServer, requiredNum int) (*proto.PeersListResponse, error)
- func WaitUntilTxPoolFilled(ctx context.Context, srv *TestServer, requiredNum uint64) (*txpoolProto.TxnPoolStatusResp, error)
- type ConsensusType
- type IBFTServerConfigCallback
- type IBFTServersManager
- type InitIBFTResult
- type PreparedTransaction
- type ReservedPort
- type SrvAccount
- type TestServer
- func (t *TestServer) DeployContract(ctx context.Context, binary string, privateKey *ecdsa.PrivateKey) (web3.Address, error)
- func (t *TestServer) GenerateGenesis() error
- func (t *TestServer) GetLatestBlockHeight() (uint64, error)
- func (t *TestServer) GrpcAddr() string
- func (t *TestServer) HTTPJSONRPCURL() string
- func (t *TestServer) IBFTOperator() ibftOp.IbftOperatorClient
- func (t *TestServer) InvokeMethod(ctx context.Context, contractAddress types.Address, method string, ...) *web3.Receipt
- func (t *TestServer) JSONRPC() *jsonrpc.Client
- func (t *TestServer) JSONRPCAddr() string
- func (t *TestServer) LibP2PAddr() string
- func (t *TestServer) Operator() proto.SystemClient
- func (t *TestServer) ReleaseReservedPorts()
- func (t *TestServer) SecretsInit() (*InitIBFTResult, error)
- func (t *TestServer) SendRawTx(ctx context.Context, tx *PreparedTransaction, signerKey *ecdsa.PrivateKey) (*web3.Receipt, error)
- func (t *TestServer) SignTx(transaction *types.Transaction, privateKey *ecdsa.PrivateKey) (*types.Transaction, error)
- func (t *TestServer) Start(ctx context.Context) error
- func (t *TestServer) Stop()
- func (t *TestServer) SwitchIBFTType(typ ibft.MechanismType, from uint64, to, deployment *uint64) error
- func (t *TestServer) TxnPoolOperator() txpoolProto.TxnPoolOperatorClient
- func (t *TestServer) WSJSONRPCURL() string
- func (t *TestServer) WaitForReady(ctx context.Context) error
- func (t *TestServer) WaitForReceipt(ctx context.Context, hash web3.Hash) (*web3.Receipt, error)
- type TestServerConfig
- func (t *TestServerConfig) DataDir() string
- func (t *TestServerConfig) EnableWebSocket()
- func (t *TestServerConfig) Premine(addr types.Address, amount *big.Int)
- func (t *TestServerConfig) PremineValidatorBalance(balance *big.Int)
- func (t *TestServerConfig) PrivateKey() (*ecdsa.PrivateKey, error)
- func (t *TestServerConfig) SetBlockGasTarget(target uint64)
- func (t *TestServerConfig) SetBlockLimit(limit uint64)
- func (t *TestServerConfig) SetBlockTime(blockTime uint64)
- func (t *TestServerConfig) SetBootnodes(bootnodes []string)
- func (t *TestServerConfig) SetBridgeOwner(owner types.Address)
- func (t *TestServerConfig) SetBridgeSigners(signers []types.Address)
- func (t *TestServerConfig) SetConsensus(c ConsensusType)
- func (t *TestServerConfig) SetDevInterval(interval int)
- func (t *TestServerConfig) SetDevStakingAddresses(stakingAddresses []types.Address)
- func (t *TestServerConfig) SetEpochSize(epochSize uint64)
- func (t *TestServerConfig) SetIBFTDir(ibftDir string)
- func (t *TestServerConfig) SetIBFTDirPrefix(ibftDirPrefix string)
- func (t *TestServerConfig) SetIBFTPoS(value bool)
- func (t *TestServerConfig) SetPriceLimit(priceLimit *uint64)
- func (t *TestServerConfig) SetRestoreFile(path string)
- func (t *TestServerConfig) SetSeal(state bool)
- func (t *TestServerConfig) SetShowsLog(f bool)
- func (t *TestServerConfig) SetSigner(signer *crypto.EIP155Signer)
- func (t *TestServerConfig) SetValidatorSetOwner(owner types.Address)
- type TestServerConfigCallback
Constants ¶
const ( DefaultGasPrice = 1879048192 // 0x70000000 DefaultGasLimit = 5242880 // 0x500000 )
Variables ¶
var (
DefaultTimeout = time.Minute
)
Functions ¶
func EcrecoverFromBlockhash ¶
func GetAccountBalance ¶
GetAccountBalance is a helper method for fetching the Balance field of an account
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 ValidatorSet SC
func ToLocalIPv4LibP2pAddr ¶
func UnstakeAmount ¶
func UnstakeAmount( from types.Address, senderKey *ecdsa.PrivateKey, srv *TestServer, ) (*web3.Receipt, error)
UnstakeAmount is a helper function for unstaking the entire amount on the ValidatorSet 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 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 PreparedTransaction ¶
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 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, privateKey *ecdsa.PrivateKey, ) (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) 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, ) *web3.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, ) (*web3.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) Stop ¶
func (t *TestServer) Stop()
func (*TestServer) SwitchIBFTType ¶
func (t *TestServer) SwitchIBFTType(typ ibft.MechanismType, from uint64, to, deployment *uint64) error
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 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) GenesisValidatorBalance *big.Int // Genesis the balance for the validators // List of initial staking addresses for the ValidatorSet SC with dev consensus DevStakers []types.Address Consensus ConsensusType // Consensus MechanismType 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 IsPos bool // Specifies the mechanism used for IBFT (PoA / PoS) Signer *crypto.EIP155Signer // Signer used for transactions ValidatorSetOwner types.Address // validatorset contract owner BridgeOwner types.Address // bridge contract owner BridgeSigners []types.Address // bridge contract signers IsWSEnable bool // enable websocket or not RestoreFile string // blockchain restore file BlockTime uint64 // minimum block generation time (in s) }
TestServerConfig for the test server
func (*TestServerConfig) DataDir ¶
func (t *TestServerConfig) DataDir() string
DataDir returns path of data directory server uses
func (*TestServerConfig) EnableWebSocket ¶ added in v1.1.3
func (t *TestServerConfig) EnableWebSocket()
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 ¶ added in v1.1.4
func (t *TestServerConfig) SetBlockTime(blockTime uint64)
func (*TestServerConfig) SetBootnodes ¶
func (t *TestServerConfig) SetBootnodes(bootnodes []string)
SetBootnodes sets bootnodes
func (*TestServerConfig) SetBridgeOwner ¶
func (t *TestServerConfig) SetBridgeOwner(owner types.Address)
func (*TestServerConfig) SetBridgeSigners ¶
func (t *TestServerConfig) SetBridgeSigners(signers []types.Address)
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 ValidatorSet 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) 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) SetPriceLimit ¶
func (t *TestServerConfig) SetPriceLimit(priceLimit *uint64)
SetPriceLimit sets the gas price limit
func (*TestServerConfig) SetRestoreFile ¶ added in v1.1.4
func (t *TestServerConfig) SetRestoreFile(path string)
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
func (*TestServerConfig) SetSigner ¶
func (t *TestServerConfig) SetSigner(signer *crypto.EIP155Signer)
func (*TestServerConfig) SetValidatorSetOwner ¶ added in v1.1.4
func (t *TestServerConfig) SetValidatorSetOwner(owner types.Address)
type TestServerConfigCallback ¶
type TestServerConfigCallback func(*TestServerConfig)