rpctest

package
v0.0.0-...-9e8562e Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: ISC Imports: 21 Imported by: 0

Documentation

Overview

Package rpctest contains tests for ucwallet's RPC server and a harness used to facilitate the tests by setting up a temporary Simnet node and wallet. The RPC client implementation in ucrpcclient is used exclusively to test the RPC server. A single test function, TestMain, is executed by go test, and is responsible for setting up test harnesses and running the individual RPC test functions.

A Harness, as defined in rpcharness.go, manages a SimNet node and a wallet that connects to the node. (*Harness).SetUp does the following:

  1. Start a new ucd process with a fresh SimNet chain.
  2. Create a new temporary wallet connected to the running node.
  3. Get a new address from the wallet for mining subsidy.
  4. Restart ucd with miningaddr set.
  5. Generate a number of blocks so that testing starts with a spendable balance.

Multiple harnesses may be run concurrently. Temporary folders are created for each harness, and cleaned up on shutdown.

The default settings for a harness wallet are:

  1. Ticket buyer enabled (--enableticketbuyer).
  2. Zero max ticket price.
  3. High balance to maintain (2000000 UC).

Thus, a harness wallet will automatically vote on owned tickets, but not automatically purchase tickets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	ActiveNet *chaincfg.Params

	Node      *rpc.Client
	WalletRPC *rpc.Client
	// contains filtered or unexported fields
}

Harness fully encapsulates an active ucd process, along with an embedded ucwallet to provide a unified platform for creating RPC-driven integration tests involving ucd. The active ucd node will typically be run in simnet mode to allow for easy generation of test blockchains. Additionally, a special method is provided which allows one to easily generate coinbase spends. The active ucd process is fully managed by Harness, which handles the necessary initialization, and teardown of the process along with any temporary directories created as a result. Multiple Harness instances may be run concurrently, to allow for testing complex scenarios involving multuple nodes.

func NewHarness

func NewHarness(activeNet *chaincfg.Params, handlers *rpc.NotificationHandlers,
	extraArgs []string) (*Harness, error)

NewHarness creates and initializes a new instance of the rpc test harness. Optionally, websocket handlers and a specified configuration may be passed. In the case that a nil configuration is passed, a default configuration will be used.

NOTE: This function is safe for concurrent access.

func (*Harness) FullNodeCommand

func (h *Harness) FullNodeCommand() string

FullNodeCommand returns the full command line of the node

func (*Harness) FullWalletCommand

func (h *Harness) FullWalletCommand() string

FullWalletCommand returns the full command line of the wallet

func (*Harness) GenerateBlock

func (h *Harness) GenerateBlock(startHeight uint32) ([]*chainhash.Hash, error)

GenerateBlock is a helper function to ensure that the chain has actually incremented due to FORK blocks after stake voting height that may occur.

func (*Harness) IsUp

func (h *Harness) IsUp() bool

IsUp checks if the harness is still being tracked by rpctest

func (*Harness) RPCCertFile

func (h *Harness) RPCCertFile() string

RPCCertFile returns the full path the node RPC's TLS certifiate

func (*Harness) RPCConfig

func (h *Harness) RPCConfig() rpc.ConnConfig

RPCConfig returns the harnesses current rpc configuration. This allows other potential RPC clients created within tests to connect to a given test harness instance.

func (*Harness) RPCWalletCertFile

func (h *Harness) RPCWalletCertFile() string

RPCWalletCertFile returns the full path the wallet RPC's TLS certifiate

func (*Harness) RPCWalletConfig

func (h *Harness) RPCWalletConfig() rpc.ConnConfig

RPCWalletConfig returns the harnesses current rpc configuration. This allows other potential RPC clients created within tests to connect to a given test harness instance.

func (*Harness) SetUp

func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error

SetUp initializes the rpc test state. Initialization includes: starting up a simnet node, creating a websocket client and connecting to the started node, and finally: optionally generating and submitting a testchain with a configurable number of mature coinbase outputs coinbase outputs.

func (*Harness) TearDown

func (h *Harness) TearDown() error

TearDown stops the running RPC test instance. All created processes killed, and temporary directories removed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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