Documentation
¶
Index ¶
- Variables
- func DepositBalance(t *testing.T, receiver types.Address, amount *big.Int, ...)
- func GenFaucetSignKey() *ecdsa.PrivateKey
- func GetAccountFromPrivateKey(key *ecdsa.PrivateKey) types.Address
- func GetHeadBlock(t *testing.T, blockchain *blockchain.Blockchain) *types.Block
- func NewAccount(t *testing.T) (types.Address, *ecdsa.PrivateKey)
- func NewBlockchain(verifier blockchain.Verifier, basepath string) (*state.Executor, *blockchain.Blockchain, error)
- func NewBlockchainWithTxPool(chainSpec *chain.Chain, verifier blockchain.Verifier) (*state.Executor, *blockchain.Blockchain, *txpool.TxPool, error)
- func NewChain(basepath string) (*chain.Chain, error)
- func NewInMemExecutor(c *chain.Chain) *state.Executor
- func NewTxpoolHub(s state.State, bc *blockchain.Blockchain) *txpoolHub
- func RandomBytes(t *testing.T, size int) []byte
Constants ¶
This section is empty.
Variables ¶
var ( FaucetSignKey *ecdsa.PrivateKey = GenFaucetSignKey() FaucetAccount types.Address = GetAccountFromPrivateKey(FaucetSignKey) )
FaucetAccount and FaucetSignKey are used as a pair for an account with a plentiful balance for test purposes.
var ( // Seed is a global variable used in functions that generate random data. // It's value can be specified via a command-line flag `-seed`. // By default, it uses the current Unix time. Seed = flag.Int64("seed", time.Now().Unix(), "random seed used in tests") )
Functions ¶
func DepositBalance ¶
func DepositBalance(t *testing.T, receiver types.Address, amount *big.Int, blockchain *blockchain.Blockchain, executor *state.Executor)
DepositBalance is a test helper function that deposits a specified balance to a given account on a blockchain. It takes a pointer to a testing.T object, receiver address, deposit amount, blockchain and executor as arguments. This function should be used within tests to make a deposit of tokens to an account. Example usage (within a test, assuming receiver, amount, blockchain and executor are already defined): DepositBalance(t, receiver, amount, blockchain, executor)
func GenFaucetSignKey ¶
func GenFaucetSignKey() *ecdsa.PrivateKey
GenFaucetSignKey generates a new ECDSA private key which is used for the FaucetAccount. It panics if the key generation fails.
func GetAccountFromPrivateKey ¶
func GetAccountFromPrivateKey(key *ecdsa.PrivateKey) types.Address
GetAccountFromPrivateKey takes an ECDSA private key and returns the associated account address.
func GetHeadBlock ¶
func GetHeadBlock(t *testing.T, blockchain *blockchain.Blockchain) *types.Block
GetHeadBlock retrieves the head block from the provided blockchain instance. If the head block is not available, it retrieves the genesis block. It may fail the test if it's unable to fetch the head block.
func NewAccount ¶
NewAccount is a test helper function that creates a new account with a private key and returns its address and private key. It takes a pointer to a testing.T object as argument. This function should be used within tests to generate a new account. Example usage (within a test): address, privateKey := NewAccount(t)
func NewBlockchain ¶
func NewBlockchain(verifier blockchain.Verifier, basepath string) (*state.Executor, *blockchain.Blockchain, error)
NewBlockchain creates a new in-memory blockchain with a specified verifier and basepath. It returns an executor, a blockchain, and an error if any occurred during the initialization.
func NewBlockchainWithTxPool ¶
func NewBlockchainWithTxPool(chainSpec *chain.Chain, verifier blockchain.Verifier) (*state.Executor, *blockchain.Blockchain, *txpool.TxPool, error)
NewBlockchainWithTxPool creates a new in-memory blockchain with a specified chain specification and verifier. It also initializes a transaction pool with default parameters. It returns an executor, a blockchain, a transaction pool, and an error if any occurred during the initialization.
func NewChain ¶
NewChain creates a new Chain instance with a predefined genesis account (FaucetAccount) and staking contract. The function takes a basepath as an argument, which is used to locate the staking contract's bytecode. It returns a Chain instance and an error if any occurred during the initialization.
func NewInMemExecutor ¶
NewInMemExecutor creates a new executor with an in-memory state and returns it.
func NewTxpoolHub ¶
func NewTxpoolHub(s state.State, bc *blockchain.Blockchain) *txpoolHub
NewTxpoolHub creates a new txpoolHub instance with the provided state and blockchain. s is the current state of the blockchain. bc is the current blockchain instance. Returns a pointer to the newly created txpoolHub instance.
Example usage:
func TestNewTxpoolHub(t *testing.T) {
state := ... // initialize state
bc := ... // initialize blockchain
hub := NewTxpoolHub(state, bc)
// hub now holds a new txpoolHub instance
}
func RandomBytes ¶
RandomBytes generates a slice of random bytes of the specified size. This function uses the global Seed variable for random number generation. It's used to produce deterministic results when Seed is specified.
t is a pointer to testing.T, which is the parallel testing interface. size is the number of random bytes to generate.
Returns a slice of random bytes.
Example usage:
func TestRandomBytes(t *testing.T) {
bytes := RandomBytes(t, 10)
// bytes now holds a slice of 10 random bytes
}
Types ¶
This section is empty.