testutils

package
v0.0.0-...-5a930d7 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxRpcConnRetries = 10

Variables

This section is empty.

Functions

func AssertBlockOrderAndHeight

func AssertBlockOrderAndHeight(t *testing.T, h *Harness, order, total, height uint64)

AssertBlockOrderAndHeight will verify the current block order, total block number and current main-chain height of the appointed test harness and assert it ok or cause the test failed.

func AssertTxMinedUseSerializedBlock

func AssertTxMinedUseSerializedBlock(t *testing.T, h *Harness, txId *hash.Hash, blockHash *hash.Hash)

TODO, order and height not work for the SerializedBlock

func GenerateBlock

func GenerateBlock(t *testing.T, h *Harness, num uint64) []*hash.Hash

GenerateBlock will generate a number of blocks by the input number for the appointed test harness. It will return the hashes of the generated blocks or an error

func GetBlock

func GetBlock(h *Harness, order uint64) (*json.BlockVerboseResult, error)

func TearDownAll

func TearDownAll() error

TearDownAll func teardown all Harness Instances

Types

type Client

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

Client represents a connection to an RPC server.

func Dial

func Dial(URL, user, pass string, certs string) (*Client, error)

Dial connects to a JSON-RPC server at the specified url, return a new client which can perform rpc Call. the context controls the entire lifetime of the client.

func (*Client) BlockCount

func (c *Client) BlockCount() (uint64, error)

func (*Client) BlockTotal

func (c *Client) BlockTotal() (uint64, error)

func (*Client) Call

func (c *Client) Call(result interface{}, method string, args ...interface{}) error

Call wraps CallWithContext using the background context.

func (*Client) CallWithContext

func (c *Client) CallWithContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

CallWithContext performs a JSON-RPC call with the given arguments and unmarshalls into result if no error occurred.

func (*Client) Generate

func (c *Client) Generate(num uint64) ([]*hash.Hash, error)

func (*Client) GetBlock

func (c *Client) GetBlock(h *hash.Hash) (*json.BlockVerboseResult, error)

TODO, the api is not easy to use when doing the internal-test

func (*Client) GetBlockByOrder

func (c *Client) GetBlockByOrder(order uint64) (*json.BlockVerboseResult, error)

func (*Client) GetSerializedBlock

func (c *Client) GetSerializedBlock(h *hash.Hash) (*types.SerializedBlock, error)

TODO, the SerializedBlock not work for order and height

func (*Client) MainHeight

func (c *Client) MainHeight() (uint64, error)

func (*Client) NodeInfo

func (c *Client) NodeInfo() (json.InfoNodeResult, error)

func (*Client) SendRawTx

func (c *Client) SendRawTx(txHex string, allowHighFees bool) (*hash.Hash, error)

type Harness

type Harness struct {

	// the qitmeer node process
	Node *node
	// the rpc client to the qitmeer node in the Harness instance.
	Client *Client
	// contains filtered or unexported fields
}

Harness manage an embedded qitmeer node process for running the rpc driven integration tests. The active qitmeer node will typically be run in privnet mode in order to allow for easy block generation. Harness handles the node start/shutdown and any temporary directories need to be created.

func AllHarnesses

func AllHarnesses() []*Harness

AllHarnesses func get all Harness instances

func NewHarness

func NewHarness(t *testing.T, params *params.Params, args ...string) (*Harness, error)

NewHarness func creates an new instance of test harness with provided network params. The args is the arguments list that are used when setup a qitmeer node. In the most case, it should be set to nil if no extra args need to add on the default starting up.

func NewHarnessWithMnemonic

func NewHarnessWithMnemonic(t *testing.T, mnemonic, path string, usePkAddr bool, params *params.Params, args ...string) (*Harness, error)

NewHarness func creates an new instance of test harness with provided network params. The args is the arguments list that are used when setup a qitmeer node. In the most case, it should be set to nil if no extra args need to add on the default starting up.

func (*Harness) Id

func (h *Harness) Id() string

func (*Harness) Setup

func (h *Harness) Setup() error

Setup func initialize the test state. 1. start the qitmeer node according to the net params 2. setup the rpc clint so that the rpc call can be sent to the node 3. generate a test block dag by configuration (optional, may empty dag by config)

func (*Harness) Teardown

func (h *Harness) Teardown() error

Teardown func the concurrent safe wrapper of teardown func

func (*Harness) WaitWalletInit

func (h *Harness) WaitWalletInit()

type Wallet

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

func NewWallet

func NewWallet(cfg *config.Config, net protocol.Network, mnemonic, path string) (*Wallet, error)

func (*Wallet) Balance

func (w *Wallet) Balance(coin types.CoinID) (*wallet.Balance, error)

func (*Wallet) BalanceByAddr

func (w *Wallet) BalanceByAddr(coin types.CoinID, addr string) (*wallet.Balance, error)

func (*Wallet) EvmToAddress

func (w *Wallet) EvmToAddress(addr string, coin types.CoinID, amount uint64) (string, error)

func (*Wallet) GenerateAddress

func (w *Wallet) GenerateAddress(usePkAddr bool) (string, error)

func (*Wallet) SendToAddress

func (w *Wallet) SendToAddress(addr string, coin types.CoinID, amount uint64) (string, error)

func (*Wallet) Start

func (w *Wallet) Start() error

func (*Wallet) Stop

func (w *Wallet) Stop()

Jump to

Keyboard shortcuts

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