testutils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: ISC Imports: 54 Imported by: 0

Documentation

Overview

It is called by go generate and used to automatically generate pre-computed Copyright 2017-2022 The qitmeer developers This file is auto generate by : go run compile_solidity.go

Index

Constants

View Source
const DefaultMaxRpcConnRetries = 10
View Source
const ERC20Code = "" /* 8376-byte string literal not displayed */
View Source
const FACTORY = "" /* 21446-byte string literal not displayed */
View Source
const GAS_LIMIT = 8000000
View Source
const PAIR = "" /* 17954-byte string literal not displayed */
View Source
const RELEASECode = "" /* 2798-byte string literal not displayed */
View Source
const RELEASE_ADDR = "0xB191d00579ba344565637468e0CCbD6f161C0333"
View Source
const RELEASE_AMOUNT = "21387132742853980000000000"
View Source
const ROUTER = "" /* 32670-byte string literal not displayed */
View Source
const WETH = "" /* 4680-byte string literal not displayed */

Variables

View Source
var CHAIN_ID = params.QngPrivnetChainConfig.ChainID
View Source
var MAX_UINT256 = new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 255), common.Big1)

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 AssertMempoolTxNotify

func AssertMempoolTxNotify(t *testing.T, h *Harness, txid, addr string, timeout int)

func AssertScan

func AssertScan(t *testing.T, h *Harness, maxOrder, scanCount uint64)

func AssertTxConfirm

func AssertTxConfirm(t *testing.T, h *Harness, txid string, confirms uint64)

func AssertTxMinedUseNotifierAPI

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

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 AssertTxNotConfirm

func AssertTxNotConfirm(t *testing.T, h *Harness, txid string)

func CanNotSpend

func CanNotSpend(t *testing.T, h *Harness, amt types.Amount, preOutpoint *types.TxOutPoint, lockTime *int64) (*hash.Hash, types.Address)

Spend amount from the wallet of the test harness and return tx hash

func ConvertEthToMeer

func ConvertEthToMeer(amount *big.Int) *big.Int

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 PrivateKeyToAddr added in v1.2.0

func PrivateKeyToAddr(privKey []byte, params *params.Params) (types.Address, error)

convert the serialized private key into the p2pkh address

func PrivateKeyToETHAddress

func PrivateKeyToETHAddress(privB []byte) (common2.Address, error)

func PrivateKeyToPkAddress

func PrivateKeyToPkAddress(privB []byte, p *params.Params) (*address.SecpPubKeyAddress, error)

func PrivateKeyToPubK

func PrivateKeyToPubK(privB []byte, uncompressed bool) ([]byte, error)

func SendSelf

func SendSelf(t *testing.T, h *Harness, amt types.Amount, preOutpoint *types.TxOutPoint, lockTime *int64) *hash.Hash

Spend amount from the wallet of the test harness and return tx hash

func Spend

func Spend(t *testing.T, h *Harness, amt types.Amount, preOutpoint *types.TxOutPoint, lockTime *int64) (*hash.Hash, types.Address)

Spend amount from the wallet of the test harness and return tx hash

func TearDownAll

func TearDownAll() error

TearDownAll func teardown all Harness Instances

func TimeoutFunc

func TimeoutFunc(t *testing.T, f func() bool, timeout int)

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

func (c *Client) CreateExportRawTx(txid, pkaddress string, vout uint32, amount int64) (string, error)

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

func (*Client) TestSign

func (c *Client) TestSign(privateKey, rawStr, tokenPrivateKey string) (string, error)

type Complex

type Complex struct {
	X, Y int
	Name string
}

type EchoResult

type EchoResult struct {
	String  string
	Int     int
	Complex *Complex
}

type Harness

type Harness struct {

	// the qitmeer node process
	Node *node
	// the rpc client to the qitmeer node in the Harness instance.
	Client *Client
	// the rpc client to the qng evm node in the Harness instance.
	EVMClient *ethclient.Client

	// Notifier use rpc/client with web-socket notification support
	// TODO refactor & merge two rpc clients to the single one in the future.
	Notifier *client.Client
	// a simple in-memory test wallet works for the test harness node.
	// aka the wallet of the coinbase miner of the node of the harness
	// instance.
	Wallet *testWallet
	// 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 (*Harness) Id

func (h *Harness) Id() string

func (*Harness) NotifyNewTransactions

func (h *Harness) NotifyNewTransactions(verbose bool) error

Register NotifyNewTransactions

func (*Harness) NotifyTxsByAddr

func (h *Harness) NotifyTxsByAddr(reload bool, addr []string, outpoint []cmds.OutPoint) error

Register Addrs Filter

func (*Harness) NotifyTxsConfirmed

func (h *Harness) NotifyTxsConfirmed(txs []cmds.TxConfirm) error

Register NotifyTxsConfirmed

func (*Harness) Rescan

func (h *Harness) Rescan(beginBlock, endBlock uint64, addrs []string, op []cmds.OutPoint) error

Register Rescan by address

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

type TestService

type TestService struct{}

A dummy service for integrated-test of the rpc client with the test Harness

func (*TestService) Echo

func (s *TestService) Echo(str string, i int, comp *Complex) EchoResult

The Echo service will echo the input to the uppercase and return back

Directories

Path Synopsis
swap

Jump to

Keyboard shortcuts

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