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:
- Start a new ucd process with a fresh SimNet chain.
- Create a new temporary wallet connected to the running node.
- Get a new address from the wallet for mining subsidy.
- Restart ucd with miningaddr set.
- 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:
- Ticket buyer enabled (--enableticketbuyer).
- Zero max ticket price.
- High balance to maintain (2000000 UC).
Thus, a harness wallet will automatically vote on owned tickets, but not automatically purchase tickets.
Index ¶
- type Harness
- func (h *Harness) FullNodeCommand() string
- func (h *Harness) FullWalletCommand() string
- func (h *Harness) GenerateBlock(startHeight uint32) ([]*chainhash.Hash, error)
- func (h *Harness) IsUp() bool
- func (h *Harness) RPCCertFile() string
- func (h *Harness) RPCConfig() rpc.ConnConfig
- func (h *Harness) RPCWalletCertFile() string
- func (h *Harness) RPCWalletConfig() rpc.ConnConfig
- func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error
- func (h *Harness) TearDown() error
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 ¶
FullNodeCommand returns the full command line of the node
func (*Harness) FullWalletCommand ¶
FullWalletCommand returns the full command line of the wallet
func (*Harness) GenerateBlock ¶
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) RPCCertFile ¶
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 ¶
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 ¶
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.