lntemp

package
v0.15.10001 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 43 Imported by: 0

README

lntest

lntest is a package which holds the components used for the lnd’s integration tests. It is responsible for managing lnd nodes, chain backends and miners, advancing nodes’ states and providing assertions.

Quick Start

A simple example to run the integration test.

func TestFoo(t *testing.T) {
	// Get the binary path and setup the harness test.
	//
	// TODO: define the binary path to lnd and the name of the database
	// backend.
	harnessTest := lntemp.SetupHarness(t, binary, *dbBackendFlag)
	defer harnessTest.Stop()

	// Setup standby nodes, Alice and Bob, which will be alive and shared
	// among all the test cases.
	harnessTest.SetupStandbyNodes()

	// Run the subset of the test cases selected in this tranche.
	//
	// TODO: define your own testCases.
	for _, tc := range testCases {
		tc := tc

		t.Run(tc.Name, func(st *testing.T) {
			// Create a separate harness test for the testcase to
			// avoid overwriting the external harness test that is
			// tied to the parent test.
			ht := harnessTest.Subtest(st)

			// Run the test cases.
			ht.RunTestCase(tc)
		})
	}
}
Package Structure

This package has four major components, HarnessTest, HarnessMiner, node.HarnessNode and rpc.HarnessRPC, with the following architecture,

+----------------------------------------------------------+
|                                                          |
|                        HarnessTest                       |
|                                                          |
| +----------------+  +----------------+  +--------------+ |
| |   HarnessNode  |  |   HarnessNode  |  | HarnessMiner | |
| |                |  |                |  +--------------+ |
| | +------------+ |  | +------------+ |                   |
| | | HarnessRPC | |  | | HarnessRPC | |  +--------------+ |
| | +------------+ |  | +------------+ |  | HarnessMiner | |
| +----------------+  +----------------+  +--------------+ |
+----------------------------------------------------------+
  • HarnessRPC holds all the RPC clients and adds a layer over all the RPC methods to assert no error happened at the RPC level.

  • HarnessNode builds on top of the HarnessRPC. It is responsible for managing the lnd node, including start and stop pf the lnd process, authentication of the gRPC connection, topology subscription(NodeWatcher) and maintains an internal state(NodeState).

  • HarnessMiner builds on top of btcd’s rcptest.Harness and is responsilbe for managing blocks and the mempool.

  • HarnessTest builds on top of testing.T and can be viewed as the assertion machine. It provides multiple ways to initialize a node, such as with/without seed, backups, etc. It also handles interactions between nodes like connecting nodes and opening/closing channels so it’s easier to acquire or validate a desired test states such as node’s balance, mempool condition, etc.

Standby Nodes

Standby nodes are HarnessNodes created when initializing the integration test and stay alive across all the test cases. Creating a new node is not without a cost. With block height increasing, it takes significantly longer to initialize a new node and wait for it to be synced. Standby nodes, however, don’t have this problem as they are digesting blocks all the time. Thus it’s encouraged to use standby nodes wherever possible.

Currently there are two standby nodes, Alice and Bob. Their internal states are recorded and taken into account when HarnessTest makes assertions. When making a new test case using Subtest, there’s a cleanup function which further validates the current test case has no dangling uncleaned states, such as transactions left in mempool, open channels, etc.

Documentation

Index

Constants

View Source
const (
	// NeutrinoBackendName is the name of the neutrino backend.
	NeutrinoBackendName = "neutrino"

	// TODO(yy): delete.
	DefaultTimeout = lntest.DefaultTimeout
)
View Source
const (

	// DefaultFeeRateSatPerKw specifies the default fee rate used in the
	// tests.
	DefaultFeeRateSatPerKw = 12500
)

Variables

This section is empty.

Functions

func ChanPointFromPendingUpdate

func ChanPointFromPendingUpdate(pu *lnrpc.PendingUpdate) *lnrpc.ChannelPoint

ChanPointFromPendingUpdate constructs a channel point from a lnrpc pending update.

func CopyFile

func CopyFile(dest, src string) error

CopyFile copies the file src to dest.

func ParseDerivationPath

func ParseDerivationPath(path string) ([]uint32, error)

parseDerivationPath parses a path in the form of m/x'/y'/z'/a/b into a slice of [x, y, z, a, b], meaning that the apostrophe is ignored and 2^31 is _not_ added to the numbers.

Types

type FeeService

type FeeService struct {
	*testing.T
	// contains filtered or unexported fields
}

FeeService runs a web service that provides fee estimation information.

func NewFeeService

func NewFeeService(t *testing.T) *FeeService

Start spins up a go-routine to serve fee estimates.

func (*FeeService) SetFeeRate

func (f *FeeService) SetFeeRate(fee chainfee.SatPerKWeight, conf uint32)

SetFeeRate sets a fee for the given confirmation target.

func (*FeeService) Start

func (f *FeeService) Start() error

Start starts the web server.

func (*FeeService) Stop

func (f *FeeService) Stop() error

Stop stops the web server.

func (*FeeService) URL

func (f *FeeService) URL() string

URL returns the service endpoint.

type HarnessMiner

type HarnessMiner struct {
	*testing.T
	*rpctest.Harness
	// contains filtered or unexported fields
}

func NewMiner

func NewMiner(ctxt context.Context, t *testing.T) *HarnessMiner

NewMiner creates a new miner using btcd backend with the default log file dir and name.

func (*HarnessMiner) AssertNumTxsInMempool

func (h *HarnessMiner) AssertNumTxsInMempool(n int) []*chainhash.Hash

AssertNumTxsInMempool polls until finding the desired number of transactions in the provided miner's mempool. It will asserrt if this number is not met after the given timeout.

func (*HarnessMiner) AssertOutpointInMempool

func (h *HarnessMiner) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx

AssertOutpointInMempool asserts a given outpoint can be found in the mempool.

func (*HarnessMiner) AssertTxInBlock

func (h *HarnessMiner) AssertTxInBlock(block *wire.MsgBlock,
	txid *chainhash.Hash)

AssertTxInBlock asserts that a given txid can be found in the passed block.

func (*HarnessMiner) AssertTxInMempool

func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx

AssertTxInMempool asserts a given transaction can be found in the mempool.

func (*HarnessMiner) CreateTransaction

func (h *HarnessMiner) CreateTransaction(outputs []*wire.TxOut,
	feeRate btcutil.Amount) *wire.MsgTx

CreateTransaction uses the miner to create a transaction using the given outputs using the specified fee rate and returns the transaction.

func (*HarnessMiner) GenerateBlocks

func (h *HarnessMiner) GenerateBlocks(num uint32) []*chainhash.Hash

GenerateBlocks mine 'num' of blocks and returns them.

func (*HarnessMiner) GetBestBlock

func (h *HarnessMiner) GetBestBlock() (*chainhash.Hash, int32)

GetBestBlock makes a RPC request to miner and asserts.

func (*HarnessMiner) GetBlock

func (h *HarnessMiner) GetBlock(blockHash *chainhash.Hash) *wire.MsgBlock

GetBlock gets a block using its block hash.

func (*HarnessMiner) GetNumTxsFromMempool

func (h *HarnessMiner) GetNumTxsFromMempool(n int) []*wire.MsgTx

GetNumTxsFromMempool polls until finding the desired number of transactions in the miner's mempool and returns the full transactions to the caller.

func (*HarnessMiner) GetRawMempool

func (h *HarnessMiner) GetRawMempool() []*chainhash.Hash

GetRawMempool makes a RPC call to the miner's GetRawMempool and asserts.

func (*HarnessMiner) GetRawTransaction

func (h *HarnessMiner) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx

GetRawTransaction makes a RPC call to the miner's GetRawTransaction and asserts.

func (*HarnessMiner) MineBlocks

func (h *HarnessMiner) MineBlocks(num uint32) []*wire.MsgBlock

MineBlocks mine 'num' of blocks and check that blocks are present in node blockchain.

func (*HarnessMiner) MineBlocksAndAssertNumTxes

func (h *HarnessMiner) MineBlocksAndAssertNumTxes(num uint32,
	numTxs int) []*wire.MsgBlock

MineBlocksAndAssertNumTxes mine 'num' of blocks and check that blocks are present in node blockchain. numTxs should be set to the number of transactions (excluding the coinbase) we expect to be included in the first mined block.

func (*HarnessMiner) MineBlocksSlow

func (h *HarnessMiner) MineBlocksSlow(num uint32) []*wire.MsgBlock

MineBlocksSlow mines 'num' of blocks. Between each mined block an artificial delay is introduced to give all network participants time to catch up.

func (*HarnessMiner) NewMinerAddress

func (h *HarnessMiner) NewMinerAddress() btcutil.Address

NewMinerAddress creates a new address for the miner and asserts.

func (*HarnessMiner) SendOutput

func (h *HarnessMiner) SendOutput(newOutput *wire.TxOut,
	feeRate btcutil.Amount) *chainhash.Hash

SendOutput creates, signs, and finally broadcasts a transaction spending the harness' available mature coinbase outputs to create the new output.

func (*HarnessMiner) SendOutputsWithoutChange

func (h *HarnessMiner) SendOutputsWithoutChange(outputs []*wire.TxOut,
	feeRate btcutil.Amount) *chainhash.Hash

SendOutputsWithoutChange uses the miner to send the given outputs using the specified fee rate and returns the txid.

func (*HarnessMiner) Stop

func (h *HarnessMiner) Stop()

Stop shuts down the miner and saves its logs.

type HarnessTest

type HarnessTest struct {
	*testing.T

	// Miner is a reference to a running full node that can be used to
	// create new blocks on the network.
	Miner *HarnessMiner
	// contains filtered or unexported fields
}

HarnessTest builds on top of a testing.T with enhanced error detection. It is responsible for managing the interactions among different nodes, and providing easy-to-use assertions.

func NewHarnessTest

func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
	dbBackend lntest.DatabaseBackend) *HarnessTest

NewHarnessTest creates a new instance of a harnessTest from a regular testing.T instance.

func SetupHarness

func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
	feeService WebFeeService) *HarnessTest

SetupHarness creates a new HarnessTest with a series of setups such that the instance is ready for usage. The setups are, 1. create the directories to hold lnd files. 2. start a btcd miner. 3. start a chain backend(btcd, bitcoind, or neutrino). 4. connect the miner and the chain backend. 5. start the HarnessTest.

func (*HarnessTest) AssertActiveHtlcs

func (h *HarnessTest) AssertActiveHtlcs(hn *node.HarnessNode,
	payHashes ...[]byte)

AssertActiveHtlcs makes sure the node has the _exact_ HTLCs matching payHashes on _all_ their channels.

func (*HarnessTest) AssertActiveNodesSynced

func (h *HarnessTest) AssertActiveNodesSynced()

AssertActiveNodesSynced asserts all active nodes have synced to the chain.

func (*HarnessTest) AssertActiveNodesSyncedTo

func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock *wire.MsgBlock)

AssertActiveNodesSyncedTo asserts all active nodes have synced to the provided bestBlock.

func (*HarnessTest) AssertAllTxesSpendFrom

func (h *HarnessTest) AssertAllTxesSpendFrom(txes []*wire.MsgTx,
	prevTxid chainhash.Hash)

assertAllTxesSpendFrom asserts that all txes in the list spend from the given tx.

func (*HarnessTest) AssertAmountPaid

func (h *HarnessTest) AssertAmountPaid(channelName string, hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint, amountSent, amountReceived int64)

AssertAmountPaid checks that the ListChannels command of the provided node list the total amount sent and received as expected for the provided channel.

func (*HarnessTest) AssertChannelBalanceResp

func (h *HarnessTest) AssertChannelBalanceResp(hn *node.HarnessNode,
	expected *lnrpc.ChannelBalanceResponse)

AssertChannelBalanceResp makes a ChannelBalance request and checks the returned response matches the expected.

func (*HarnessTest) AssertChannelExists

func (h *HarnessTest) AssertChannelExists(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint) *lnrpc.Channel

AssertChannelExists asserts that an active channel identified by the specified channel point exists from the point-of-view of the node.

func (*HarnessTest) AssertChannelLocalBalance

func (h *HarnessTest) AssertChannelLocalBalance(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint, balance int64) *lnrpc.Channel

AssertChannelLocalBalance checks the local balance of the given channel is expected. The channel found using the specified channel point is returned.

func (*HarnessTest) AssertChannelNumUpdates

func (h *HarnessTest) AssertChannelNumUpdates(hn *node.HarnessNode,
	num uint64, cp *lnrpc.ChannelPoint)

AssertChannelNumUpdates checks the num of updates is expected from the given channel.

func (*HarnessTest) AssertChannelPendingForceClose

func (h *HarnessTest) AssertChannelPendingForceClose(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint) PendingForceClose

AssertChannelPendingForceClose asserts that the given channel found in the node is pending force close. Returns the PendingForceClose if found.

func (*HarnessTest) AssertChannelPolicy

func (h *HarnessTest) AssertChannelPolicy(hn *node.HarnessNode,
	advertisingNode string, expectedPolicy *lnrpc.RoutingPolicy,
	chanPoint *lnrpc.ChannelPoint)

AssertChannelPolicy asserts that the passed node's known channel policy for the passed chanPoint is consistent with the expected policy values.

func (*HarnessTest) AssertChannelPolicyUpdate

func (h *HarnessTest) AssertChannelPolicyUpdate(hn *node.HarnessNode,
	advertisingNode *node.HarnessNode, policy *lnrpc.RoutingPolicy,
	chanPoint *lnrpc.ChannelPoint, includeUnannounced bool)

AssertChannelPolicyUpdate checks that the required policy update has happened on the given node.

func (*HarnessTest) AssertChannelWaitingClose

func (h *HarnessTest) AssertChannelWaitingClose(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint) WaitingCloseChannel

AssertChannelWaitingClose asserts that the given channel found in the node is waiting close. Returns the WaitingCloseChannel if found.

func (*HarnessTest) AssertConnected

func (h *HarnessTest) AssertConnected(a, b *node.HarnessNode)

AssertConnected asserts that two peers are connected.

func (*HarnessTest) AssertFirstHTLCError

func (h *HarnessTest) AssertFirstHTLCError(hn *node.HarnessNode,
	code lnrpc.Failure_FailureCode)

AssertFirstHTLCError checks that the first HTLC of the last payment sent by the given node failed with the expected failure code.

func (*HarnessTest) AssertInvoiceSettled

func (h *HarnessTest) AssertInvoiceSettled(hn *node.HarnessNode, addr []byte)

AssertInvoiceSettled asserts a given invoice specified by its payment address is settled.

func (*HarnessTest) AssertInvoiceState

func (h *HarnessTest) AssertInvoiceState(stream rpc.SingleInvoiceClient,
	state lnrpc.Invoice_InvoiceState) *lnrpc.Invoice

AssertInvoiceState takes a single invoice subscription stream and asserts that a given invoice has became the desired state before timeout and returns the invoice found.

func (*HarnessTest) AssertLastHTLCError

func (h *HarnessTest) AssertLastHTLCError(hn *node.HarnessNode,
	code lnrpc.Failure_FailureCode)

AssertLastHTLCError checks that the last sent HTLC of the last payment sent by the given node failed with the expected failure code.

func (*HarnessTest) AssertNodeNumChannels

func (h *HarnessTest) AssertNodeNumChannels(hn *node.HarnessNode,
	numChannels int)

AssertNodeNumChannels polls the provided node's list channels rpc until it reaches the desired number of total channels.

func (*HarnessTest) AssertNodesNumPendingOpenChannels

func (h *HarnessTest) AssertNodesNumPendingOpenChannels(a, b *node.HarnessNode,
	expected int)

AssertNodesNumPendingOpenChannels asserts that both of the nodes have the expected number of pending open channels.

func (*HarnessTest) AssertNotConnected

func (h *HarnessTest) AssertNotConnected(a, b *node.HarnessNode)

AssertNotConnected asserts that two peers are not connected.

func (*HarnessTest) AssertNumActiveHtlcs

func (h *HarnessTest) AssertNumActiveHtlcs(hn *node.HarnessNode, num int)

AssertNumActiveHtlcs asserts that a given number of HTLCs are seen in the node's channels.

func (*HarnessTest) AssertNumChannelUpdates

func (h *HarnessTest) AssertNumChannelUpdates(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint, num int)

AssertNumChannelUpdates asserts that a given number of channel updates has been seen in the specified node's network topology.

func (*HarnessTest) AssertNumEdges

func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode,
	expected int, includeUnannounced bool) []*lnrpc.ChannelEdge

AssertNumEdges checks that an expected number of edges can be found in the node specified.

func (*HarnessTest) AssertNumHTLCsAndStage

func (h *HarnessTest) AssertNumHTLCsAndStage(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint, num int, stage uint32)

AssertNumHTLCsAndStage takes a pending force close channel's channel point and asserts the expected number of pending HTLCs and HTLC stage are matched.

func (*HarnessTest) AssertNumNodeAnns

func (h *HarnessTest) AssertNumNodeAnns(hn *node.HarnessNode,
	pubkey string, num int) []*lnrpc.NodeUpdate

AssertNumNodeAnns asserts that a given number of node announcements has been seen in the specified node.

func (*HarnessTest) AssertNumPayments

func (h *HarnessTest) AssertNumPayments(hn *node.HarnessNode,
	num int) []*lnrpc.Payment

AssertNumPayments asserts that the number of payments made within the test scope is as expected, including the incomplete ones.

func (*HarnessTest) AssertNumPendingForceClose

func (h *HarnessTest) AssertNumPendingForceClose(hn *node.HarnessNode,
	num int) []*lnrpc.PendingChannelsResponse_ForceClosedChannel

AssertNumPendingForceClose checks that a PendingChannels response from the node reports the expected number of pending force close channels.

func (*HarnessTest) AssertNumPendingOpenChannels

func (h *HarnessTest) AssertNumPendingOpenChannels(hn *node.HarnessNode,
	expected int) []*lnrpc.PendingChannelsResponse_PendingOpenChannel

AssertNumPendingOpenChannels asserts that a given node have the expected number of pending open channels.

func (*HarnessTest) AssertNumPolicyUpdates

func (h *HarnessTest) AssertNumPolicyUpdates(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint,
	advertisingNode *node.HarnessNode, num int)

AssertNumPolicyUpdates asserts that a given number of channel policy updates has been seen in the specified node.

func (*HarnessTest) AssertNumUTXOs

func (h *HarnessTest) AssertNumUTXOs(hn *node.HarnessNode,
	num int) []*lnrpc.Utxo

AssertNumUTXOs asserts the expected num of utxos are seen, including confirmed and unconfirmed outputs.

NOTE: for standby nodes(Alice and Bob), this method takes account of the previous state of the node's UTXOs. Check `AssertNumUTXOsWithConf` for details.

func (*HarnessTest) AssertNumUTXOsConfirmed

func (h *HarnessTest) AssertNumUTXOsConfirmed(hn *node.HarnessNode,
	num int) []*lnrpc.Utxo

AssertNumUTXOsConfirmed asserts the expected num of confirmed utxos are seen, which means the returned utxos have at least one confirmation.

NOTE: for standby nodes(Alice and Bob), this method takes account of the previous state of the node's UTXOs. Check `AssertNumUTXOsWithConf` for details.

func (*HarnessTest) AssertNumUTXOsUnconfirmed

func (h *HarnessTest) AssertNumUTXOsUnconfirmed(hn *node.HarnessNode,
	num int) []*lnrpc.Utxo

AssertNumUTXOsUnconfirmed asserts the expected num of unconfirmed utxos are seen.

NOTE: for standby nodes(Alice and Bob), this method takes account of the previous state of the node's UTXOs. Check `AssertNumUTXOsWithConf` for details.

func (*HarnessTest) AssertNumUTXOsWithConf

func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
	expectedUtxos int, max, min int32) []*lnrpc.Utxo

AssertNumUTXOsWithConf waits for the given number of UTXOs with the specified confirmations range to be available or fails if that isn't the case before the default timeout.

NOTE: for standby nodes(Alice and Bob), this method takes account of the previous state of the node's UTXOs. The previous state is snapshotted when finishing a previous test case via the cleanup function in `Subtest`. In other words, this assertion only checks the new changes made in the current test.

func (*HarnessTest) AssertNumWaitingClose

func (h *HarnessTest) AssertNumWaitingClose(hn *node.HarnessNode,
	num int) []*lnrpc.PendingChannelsResponse_WaitingCloseChannel

AssertNumWaitingClose checks that a PendingChannels response from the node reports the expected number of waiting close channels.

func (*HarnessTest) AssertPaymentStatus

func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
	preimage lntypes.Preimage,
	status lnrpc.Payment_PaymentStatus) *lnrpc.Payment

AssertPaymentStatus asserts that the given node list a payment with the given preimage has the expected status. It also checks that the payment has the expected preimage, which is empty when it's not settled and matches the given preimage when it's succeeded.

func (*HarnessTest) AssertPaymentStatusFromStream

func (h *HarnessTest) AssertPaymentStatusFromStream(stream rpc.PaymentClient,
	status lnrpc.Payment_PaymentStatus) *lnrpc.Payment

AssertPaymentStatusFromStream takes a client stream and asserts the payment is in desired status before default timeout. The payment found is returned once succeeded.

func (*HarnessTest) AssertPeerConnected

func (h *HarnessTest) AssertPeerConnected(a, b *node.HarnessNode)

AssertPeerConnected asserts that the given node b is connected to a.

func (*HarnessTest) AssertPeerNotConnected

func (h *HarnessTest) AssertPeerNotConnected(a, b *node.HarnessNode)

AssertPeerNotConnected asserts that the given node b is not connected to a.

func (*HarnessTest) AssertStreamChannelCoopClosed

func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint, anchors bool,
	stream rpc.CloseChanClient) *chainhash.Hash

AssertStreamChannelCoopClosed reads an update from the close channel client stream and asserts that the mempool state and node's topology match a coop close. In specific, - assert the channel is waiting close and has the expected ChanStatusFlags. - assert the mempool has the closing txes and anchor sweeps. - mine a block and assert the closing txid is mined. - assert the node has zero waiting close channels. - assert the node has seen the channel close update.

func (*HarnessTest) AssertStreamChannelForceClosed

func (h *HarnessTest) AssertStreamChannelForceClosed(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint, anchors bool,
	stream rpc.CloseChanClient) *chainhash.Hash

AssertStreamChannelForceClosed reads an update from the close channel client stream and asserts that the mempool state and node's topology match a local force close. In specific, - assert the channel is waiting close and has the expected ChanStatusFlags. - assert the mempool has the closing txes and anchor sweeps. - mine a block and assert the closing txid is mined. - assert the channel is pending force close. - assert the node has seen the channel close update.

func (*HarnessTest) AssertSweepFound

func (h *HarnessTest) AssertSweepFound(hn *node.HarnessNode,
	sweep string, verbose bool)

AssertSweepFound looks up a sweep in a nodes list of broadcast sweeps and asserts it's found.

NOTE: Does not account for node's internal state.

func (*HarnessTest) AssertTopologyChannelClosed

func (h *HarnessTest) AssertTopologyChannelClosed(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint) *lnrpc.ClosedChannelUpdate

AssertTopologyChannelClosed asserts a given channel is closed by checking the graph topology subscription of the specified node. Returns the closed channel update if found.

func (*HarnessTest) AssertTopologyChannelOpen

func (h *HarnessTest) AssertTopologyChannelOpen(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint)

AssertTopologyChannelOpen asserts that a given channel outpoint is seen by the passed node's network topology.

func (*HarnessTest) AssertTxAtHeight

func (h *HarnessTest) AssertTxAtHeight(hn *node.HarnessNode, height int32,
	txid *chainhash.Hash) *lnrpc.Transaction

AssertTxAtHeight gets all of the transactions that a node's wallet has a record of at the target height, and finds and returns the tx with the target txid, failing if it is not found.

func (*HarnessTest) AssertTxSpendFrom

func (h *HarnessTest) AssertTxSpendFrom(tx *wire.MsgTx,
	prevTxid chainhash.Hash)

AssertTxSpendFrom asserts that a given tx is spent from a previous tx.

func (*HarnessTest) AssertZombieChannel

func (h *HarnessTest) AssertZombieChannel(hn *node.HarnessNode, chanID uint64)

AssertZombieChannel asserts that a given channel found using the chanID is marked as zombie.

func (*HarnessTest) BackupDB

func (h *HarnessTest) BackupDB(hn *node.HarnessNode)

BackupDB creates a backup of the current database. It will stop the node first, copy the database files, and restart the node.

func (*HarnessTest) CalculateTxFee

func (h *HarnessTest) CalculateTxFee(tx *wire.MsgTx) btcutil.Amount

CalculateTxFee retrieves parent transactions and reconstructs the fee paid.

func (*HarnessTest) CalculateTxesFeeRate

func (h *HarnessTest) CalculateTxesFeeRate(txns []*wire.MsgTx) int64

CalculateTxesFeeRate takes a list of transactions and estimates the fee rate used to sweep them.

NOTE: only used in current test file.

func (*HarnessTest) ChainBackendName

func (h *HarnessTest) ChainBackendName() string

ChainBackendName returns the chain backend name used in the test.

func (*HarnessTest) CleanupForceClose

func (h *HarnessTest) CleanupForceClose(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint)

CleanupForceClose mines a force close commitment found in the mempool and the following sweep transaction from the force closing node.

func (*HarnessTest) CloseChannel

func (h *HarnessTest) CloseChannel(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint) *chainhash.Hash

CloseChannel attempts to coop close a non-anchored channel identified by the passed channel point owned by the passed harness node. The following items are asserted,

  1. a close pending event is sent from the close channel client.
  2. the closing tx is found in the mempool.
  3. the node reports the channel being waiting to close.
  4. a block is mined and the closing tx should be found in it.
  5. the node reports zero waiting close channels.
  6. the node receives a topology update regarding the channel close.

func (*HarnessTest) CloseChannelAssertErr

func (h *HarnessTest) CloseChannelAssertErr(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint, force bool) error

CloseChannelAssertErr closes the given channel and asserts an error returned.

func (*HarnessTest) CloseChannelAssertPending

func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint,
	force bool) (rpc.CloseChanClient, *chainhash.Hash)

CloseChannelAssertPending attempts to close the channel indicated by the passed channel point, initiated by the passed node. Once the CloseChannel rpc is called, it will consume one event and assert it's a close pending event. In addition, it will check that the closing tx can be found in the mempool.

func (*HarnessTest) CompletePaymentRequests

func (h *HarnessTest) CompletePaymentRequests(hn *node.HarnessNode,
	paymentRequests []string)

CompletePaymentRequests sends payments from a node to complete all payment requests. This function does not return until all payments successfully complete without errors.

func (*HarnessTest) CompletePaymentRequestsNoWait

func (h *HarnessTest) CompletePaymentRequestsNoWait(hn *node.HarnessNode,
	paymentRequests []string, chanPoint *lnrpc.ChannelPoint)

CompletePaymentRequestsNoWait sends payments from a node to complete all payment requests without waiting for the results. Instead, it checks the number of updates in the specified channel has increased.

func (*HarnessTest) ConnectNodes

func (h *HarnessTest) ConnectNodes(a, b *node.HarnessNode)

ConnectNodes creates a connection between the two nodes and asserts the connection is succeeded.

func (*HarnessTest) ConnectNodesPerm

func (h *HarnessTest) ConnectNodesPerm(a, b *node.HarnessNode)

ConnectNodesPerm creates a persistent connection between the two nodes and asserts the connection is succeeded.

func (*HarnessTest) CreateBurnAddr

func (h *HarnessTest) CreateBurnAddr(addrType lnrpc.AddressType) ([]byte,
	btcutil.Address)

CreateBurnAddr creates a random burn address of the given type.

func (*HarnessTest) CreatePayReqs

func (h *HarnessTest) CreatePayReqs(hn *node.HarnessNode,
	paymentAmt btcutil.Amount, numInvoices int) ([]string,
	[][]byte, []*lnrpc.Invoice)

CreatePayReqs is a helper method that will create a slice of payment requests for the given node.

func (*HarnessTest) DecodeAddress

func (h *HarnessTest) DecodeAddress(addr string) btcutil.Address

DecodeAddress decodes a given address and asserts there's no error.

func (*HarnessTest) DisconnectNodes

func (h *HarnessTest) DisconnectNodes(a, b *node.HarnessNode)

DisconnectNodes disconnects the given two nodes and asserts the disconnection is succeeded. The request is made from node a and sent to node b.

func (*HarnessTest) EnsureConnected

func (h *HarnessTest) EnsureConnected(a, b *node.HarnessNode)

EnsureConnected will try to connect to two nodes, returning no error if they are already connected. If the nodes were not connected previously, this will behave the same as ConnectNodes. If a pending connection request has already been made, the method will block until the two nodes appear in each other's peers list, or until the DefaultTimeout expires.

func (*HarnessTest) FindCommitAndAnchor

func (h *HarnessTest) FindCommitAndAnchor(sweepTxns []*wire.MsgTx,
	closeTx string) (*SweptOutput, *SweptOutput)

FindCommitAndAnchor looks for a commitment sweep and anchor sweep in the mempool. Our anchor output is identified by having multiple inputs in its sweep transition, because we have to bring another input to add fees to the anchor. Note that the anchor swept output may be nil if the channel did not have anchors.

func (*HarnessTest) ForceCloseChannel

func (h *HarnessTest) ForceCloseChannel(hn *node.HarnessNode,
	cp *lnrpc.ChannelPoint) *chainhash.Hash

ForceCloseChannel attempts to force close a non-anchored channel identified by the passed channel point owned by the passed harness node. The following items are asserted,

  1. a close pending event is sent from the close channel client.
  2. the closing tx is found in the mempool.
  3. the node reports the channel being waiting to close.
  4. a block is mined and the closing tx should be found in it.
  5. the node reports zero waiting close channels.
  6. the node receives a topology update regarding the channel close.
  7. mine DefaultCSV-1 blocks.
  8. the node reports zero pending force close channels.

func (*HarnessTest) FundCoins

func (h *HarnessTest) FundCoins(amt btcutil.Amount, hn *node.HarnessNode)

FundCoins attempts to send amt satoshis from the internal mining node to the targeted lightning node using a P2WKH address. 2 blocks are mined after in order to confirm the transaction.

func (*HarnessTest) FundCoinsNP2WKH

func (h *HarnessTest) FundCoinsNP2WKH(amt btcutil.Amount,
	target *node.HarnessNode)

FundCoinsNP2WKH attempts to send amt satoshis from the internal mining node to the targeted lightning node using a NP2WKH address.

func (*HarnessTest) FundCoinsP2TR

func (h *HarnessTest) FundCoinsP2TR(amt btcutil.Amount,
	target *node.HarnessNode)

FundCoinsP2TR attempts to send amt satoshis from the internal mining node to the targeted lightning node using a P2TR address.

func (*HarnessTest) FundCoinsUnconfirmed

func (h *HarnessTest) FundCoinsUnconfirmed(amt btcutil.Amount,
	hn *node.HarnessNode)

FundCoinsUnconfirmed attempts to send amt satoshis from the internal mining node to the targeted lightning node using a P2WKH address. No blocks are mined after and the UTXOs are unconfirmed.

func (*HarnessTest) GetChanPointFundingTxid

func (h *HarnessTest) GetChanPointFundingTxid(
	cp *lnrpc.ChannelPoint) *chainhash.Hash

GetChanPointFundingTxid takes a channel point and converts it into a chain hash.

func (*HarnessTest) GetChannelByChanPoint

func (h *HarnessTest) GetChannelByChanPoint(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint) *lnrpc.Channel

GetChannelByChanPoint tries to find a channel matching the channel point and asserts. It returns the channel found.

func (*HarnessTest) GetChannelCommitType

func (h *HarnessTest) GetChannelCommitType(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint) lnrpc.CommitmentType

GetChannelCommitType retrieves the active channel commitment type for the given chan point.

func (*HarnessTest) IsNeutrinoBackend

func (h *HarnessTest) IsNeutrinoBackend() bool

IsNeutrinoBackend returns a bool indicating whether the node is using a neutrino as its backend. This is useful when we want to skip certain tests which cannot be done with a neutrino backend.

func (*HarnessTest) MineBlocks

func (h *HarnessTest) MineBlocks(num uint32) []*wire.MsgBlock

MineBlocks mines blocks and asserts all active nodes have synced to the chain.

NOTE: this differs from miner's `MineBlocks` as it requires the nodes to be synced.

func (*HarnessTest) MineBlocksAndAssertNumTxes

func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
	numTxs int) []*wire.MsgBlock

MineBlocksAndAssertNumTxes mines blocks and asserts the number of transactions are found in the first block. It also asserts all active nodes have synced to the chain.

NOTE: this differs from miner's `MineBlocks` as it requires the nodes to be synced.

func (*HarnessTest) NewNode

func (h *HarnessTest) NewNode(name string,
	extraArgs []string) *node.HarnessNode

NewNode creates a new node and asserts its creation. The node is guaranteed to have finished its initialization and all its subservers are started.

func (*HarnessTest) NewNodeWithSeed

func (h *HarnessTest) NewNodeWithSeed(name string,
	extraArgs []string, password []byte,
	statelessInit bool) (*node.HarnessNode, []string, []byte)

NewNodeWithSeed fully initializes a new HarnessNode after creating a fresh aezeed. The provided password is used as both the aezeed password and the wallet password. The generated mnemonic is returned along with the initialized harness node.

func (*HarnessTest) OpenChannel

func (h *HarnessTest) OpenChannel(alice, bob *node.HarnessNode,
	p OpenChannelParams) *lnrpc.ChannelPoint

OpenChannel attempts to open a channel with the specified parameters extended from Alice to Bob. Additionally, the following items are asserted,

  • 6 blocks will be mined so the channel will be announced if it's public.
  • the funding transaction should be found in the first block.
  • both nodes should see the channel edge update in their network graph.
  • both nodes can report the status of the new channel from ListChannels.

func (*HarnessTest) OpenChannelAssertErr

func (h *HarnessTest) OpenChannelAssertErr(srcNode, destNode *node.HarnessNode,
	p OpenChannelParams, expectedErr error)

OpenChannelAssertErr opens a channel between node srcNode and destNode, asserts that the expected error is returned from the channel opening.

func (*HarnessTest) OpenChannelAssertPending

func (h *HarnessTest) OpenChannelAssertPending(srcNode,
	destNode *node.HarnessNode, p OpenChannelParams) *lnrpc.PendingUpdate

OpenChannelAssertPending attempts to open a channel between srcNode and destNode with the passed channel funding parameters. Once the `OpenChannel` is called, it will consume the first event it receives from the open channel client and asserts it's a channel pending event. It returns the `PendingUpdate`.

func (*HarnessTest) OpenChannelAssertStream

func (h *HarnessTest) OpenChannelAssertStream(srcNode,
	destNode *node.HarnessNode, p OpenChannelParams) rpc.OpenChanClient

OpenChannelAssertStream attempts to open a channel between srcNode and destNode with the passed channel funding parameters. Once the `OpenChannel` is called, it will consume the first event it receives from the open channel client and asserts it's a channel pending event. It returns the open channel stream.

func (*HarnessTest) OpenChannelPsbt

func (h *HarnessTest) OpenChannelPsbt(srcNode, destNode *node.HarnessNode,
	p OpenChannelParams) (rpc.OpenChanClient, []byte)

OpenChannelPsbt attempts to open a channel between srcNode and destNode with the passed channel funding parameters. It will assert if the expected step of funding the PSBT is not received from the source node.

func (*HarnessTest) OpenMultiChannelsAsync

func (h *HarnessTest) OpenMultiChannelsAsync(
	reqs []*OpenChannelRequest) []*lnrpc.ChannelPoint

OpenMultiChannelsAsync takes a list of OpenChannelRequest and opens them in batch. The channel points are returned in same the order of the requests once all of the channel open succeeded.

NOTE: compared to open multiple channel sequentially, this method will be faster as it doesn't need to mine 6 blocks for each channel open. However, it does make debugging the logs more difficult as messages are intertwined.

func (*HarnessTest) OutPointFromChannelPoint

func (h *HarnessTest) OutPointFromChannelPoint(
	cp *lnrpc.ChannelPoint) wire.OutPoint

OutPointFromChannelPoint creates an outpoint from a given channel point.

func (*HarnessTest) PayToAddrScript

func (h *HarnessTest) PayToAddrScript(addr btcutil.Address) []byte

PayToAddrScript creates a new script from the given address and asserts there's no error.

func (*HarnessTest) QueryChannelByChanPoint

func (h *HarnessTest) QueryChannelByChanPoint(hn *node.HarnessNode,
	chanPoint *lnrpc.ChannelPoint) *lnrpc.Channel

QueryChannelByChanPoint tries to find a channel matching the channel point and asserts. It returns the channel found.

func (*HarnessTest) Random32Bytes

func (h *HarnessTest) Random32Bytes() []byte

Random32Bytes generates a random 32 bytes which can be used as a pay hash, preimage, etc.

func (*HarnessTest) ReceiveCloseChannelUpdate

func (h *HarnessTest) ReceiveCloseChannelUpdate(
	stream rpc.CloseChanClient) (*lnrpc.CloseStatusUpdate, error)

ReceiveCloseChannelUpdate waits until a message or an error is received on the subscribe channel close stream or the timeout is reached.

func (*HarnessTest) ReceiveInvoiceUpdate

func (h *HarnessTest) ReceiveInvoiceUpdate(
	stream rpc.InvoiceUpdateClient) *lnrpc.Invoice

ReceiveInvoiceUpdate waits until a message is received on the subscribe invoice stream or the timeout is reached.

func (*HarnessTest) ReceiveOpenChannelUpdate

func (h *HarnessTest) ReceiveOpenChannelUpdate(
	stream rpc.OpenChanClient) *lnrpc.OpenStatusUpdate

ReceiveOpenChannelUpdate waits until a message is received on the stream or the timeout is reached.

func (*HarnessTest) ReceivePaymentUpdate

func (h *HarnessTest) ReceivePaymentUpdate(
	stream rpc.PaymentClient) *lnrpc.Payment

ReceivePaymentUpdate waits until a message is received on the payment client stream or the timeout is reached.

func (*HarnessTest) ReceiveSingleInvoice

func (h *HarnessTest) ReceiveSingleInvoice(
	stream rpc.SingleInvoiceClient) *lnrpc.Invoice

ReceiveSingleInvoice waits until a message is received on the subscribe single invoice stream or the timeout is reached.

func (*HarnessTest) RestartNode

func (h *HarnessTest) RestartNode(hn *node.HarnessNode,
	chanBackups ...*lnrpc.ChanBackupSnapshot)

RestartNode restarts a given node and asserts.

func (*HarnessTest) RestartNodeAndRestoreDB

func (h *HarnessTest) RestartNodeAndRestoreDB(hn *node.HarnessNode)

RestartNodeAndRestoreDB restarts a given node with a callback to restore the db.

func (*HarnessTest) RestartNodeWithExtraArgs

func (h *HarnessTest) RestartNodeWithExtraArgs(hn *node.HarnessNode,
	extraArgs []string)

RestartNodeWithExtraArgs updates the node's config and restarts it.

func (*HarnessTest) RestoreNodeWithSeed

func (h *HarnessTest) RestoreNodeWithSeed(name string, extraArgs []string,
	password []byte, mnemonic []string, rootKey string,
	recoveryWindow int32, chanBackups *lnrpc.ChanBackupSnapshot,
	opts ...node.Option) *node.HarnessNode

RestoreNodeWithSeed fully initializes a HarnessNode using a chosen mnemonic, password, recovery window, and optionally a set of static channel backups. After providing the initialization request to unlock the node, this method will finish initializing the LightningClient such that the HarnessNode can be used for regular rpc operations.

func (*HarnessTest) RunTestCase

func (h *HarnessTest) RunTestCase(testCase *TestCase)

RunTestCase executes a harness test case. Any errors or panics will be represented as fatal.

func (*HarnessTest) SendPaymentAndAssertStatus

func (h *HarnessTest) SendPaymentAndAssertStatus(hn *node.HarnessNode,
	req *routerrpc.SendPaymentRequest,
	status lnrpc.Payment_PaymentStatus) *lnrpc.Payment

SendPaymentAndAssertStatus sends a payment from the passed node and asserts the desired status is reached.

func (*HarnessTest) SendPaymentAssertFail

func (h *HarnessTest) SendPaymentAssertFail(hn *node.HarnessNode,
	req *routerrpc.SendPaymentRequest,
	reason lnrpc.PaymentFailureReason) *lnrpc.Payment

SendPaymentAssertFail sends a payment from the passed node and asserts the payment is failed with the specified failure reason .

func (*HarnessTest) SetFeeEstimate

func (h *HarnessTest) SetFeeEstimate(fee chainfee.SatPerKWeight)

SetFeeEstimate sets a fee rate to be returned from fee estimator.

NOTE: this method will set the fee rate for a conf target of 1, which is the fallback fee rate for a `WebAPIEstimator` if a higher conf target's fee rate is not set. This means if the fee rate for conf target 6 is set, the fee estimator will use that value instead.

func (*HarnessTest) SetFeeEstimateWithConf

func (h *HarnessTest) SetFeeEstimateWithConf(
	fee chainfee.SatPerKWeight, conf uint32)

SetFeeEstimateWithConf sets a fee rate of a specified conf target to be returned from fee estimator.

func (*HarnessTest) SetTestName

func (h *HarnessTest) SetTestName(name string)

SetTestName set the test case name.

func (*HarnessTest) SetupStandbyNodes

func (h *HarnessTest) SetupStandbyNodes()

SetUp starts the initial seeder nodes within the test harness. The initial node's wallets will be funded wallets with 10x10 BTC outputs each.

func (*HarnessTest) Shutdown

func (h *HarnessTest) Shutdown(node *node.HarnessNode)

Shutdown shuts down the given node and asserts that no errors occur.

func (*HarnessTest) Start

func (h *HarnessTest) Start(chain node.BackendConfig, miner *HarnessMiner)

Start will assemble the chain backend and the miner for the HarnessTest. It also starts the fee service and watches lnd process error.

func (*HarnessTest) Stop

func (h *HarnessTest) Stop()

Stop stops the test harness.

func (*HarnessTest) Subtest

func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest

Subtest creates a child HarnessTest, which inherits the harness net and stand by nodes created by the parent test. It will return a cleanup function which resets all the standby nodes' configs back to its original state and create snapshots of each nodes' internal state.

func (*HarnessTest) SuspendNode

func (h *HarnessTest) SuspendNode(node *node.HarnessNode) func() error

SuspendNode stops the given node and returns a callback that can be used to start it again.

func (*HarnessTest) WaitForBalanceConfirmed

func (h *HarnessTest) WaitForBalanceConfirmed(hn *node.HarnessNode,
	expected btcutil.Amount)

WaitForBalanceConfirmed waits until the node sees the expected confirmed balance in its wallet.

func (*HarnessTest) WaitForBalanceUnconfirmed

func (h *HarnessTest) WaitForBalanceUnconfirmed(hn *node.HarnessNode,
	expected btcutil.Amount)

WaitForBalanceUnconfirmed waits until the node sees the expected unconfirmed balance in its wallet.

func (*HarnessTest) WaitForBlockchainSync

func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode)

WaitForBlockchainSync waits until the node is synced to chain.

func (*HarnessTest) WaitForBlockchainSyncTo

func (h *HarnessTest) WaitForBlockchainSyncTo(hn *node.HarnessNode,
	bestBlock *wire.MsgBlock)

WaitForBlockchainSyncTo waits until the node is synced to bestBlock.

func (HarnessTest) WaitForChannelCloseEvent

func (h HarnessTest) WaitForChannelCloseEvent(
	stream rpc.CloseChanClient) *chainhash.Hash

WaitForChannelCloseEvent waits for a notification that a channel is closed by consuming a message from the passed close channel stream. Returns the closing txid if found.

func (HarnessTest) WaitForChannelOpenEvent

func (h HarnessTest) WaitForChannelOpenEvent(
	stream rpc.OpenChanClient) *lnrpc.ChannelPoint

WaitForChannelOpenEvent waits for a notification that a channel is open by consuming a message from the passed open channel stream.

func (*HarnessTest) WaitForGraphSync

func (h *HarnessTest) WaitForGraphSync(hn *node.HarnessNode)

WaitForGraphSync waits until the node is synced to graph or times out.

type OpenChannelParams

type OpenChannelParams struct {
	// Amt is the local amount being put into the channel.
	Amt btcutil.Amount

	// PushAmt is the amount that should be pushed to the remote when the
	// channel is opened.
	PushAmt btcutil.Amount

	// Private is a boolan indicating whether the opened channel should be
	// private.
	Private bool

	// SpendUnconfirmed is a boolean indicating whether we can utilize
	// unconfirmed outputs to fund the channel.
	SpendUnconfirmed bool

	// MinHtlc is the htlc_minimum_msat value set when opening the channel.
	MinHtlc lnwire.MilliSatoshi

	// RemoteMaxHtlcs is the remote_max_htlcs value set when opening the
	// channel, restricting the number of concurrent HTLCs the remote party
	// can add to a commitment.
	RemoteMaxHtlcs uint16

	// FundingShim is an optional funding shim that the caller can specify
	// in order to modify the channel funding workflow.
	FundingShim *lnrpc.FundingShim

	// SatPerVByte is the amount of satoshis to spend in chain fees per
	// virtual byte of the transaction.
	SatPerVByte btcutil.Amount

	// CommitmentType is the commitment type that should be used for the
	// channel to be opened.
	CommitmentType lnrpc.CommitmentType

	// ZeroConf is used to determine if the channel will be a zero-conf
	// channel. This only works if the explicit negotiation is used with
	// anchors or script enforced leases.
	ZeroConf bool

	// ScidAlias denotes whether the channel will be an option-scid-alias
	// channel type negotiation.
	ScidAlias bool
}

OpenChannelParams houses the params to specify when opening a new channel.

type OpenChannelRequest

type OpenChannelRequest struct {
	// Local is the funding node.
	Local *node.HarnessNode

	// Remote is the receiving node.
	Remote *node.HarnessNode

	// Param is the open channel params.
	Param OpenChannelParams
	// contains filtered or unexported fields
}

OpenChannelRequest is used to open a channel using the method OpenMultiChannelsAsync.

type SweptOutput

type SweptOutput struct {
	OutPoint wire.OutPoint
	SweepTx  *wire.MsgTx
}

type TestCase

type TestCase struct {
	// Name specifies the test name.
	Name string

	// TestFunc is the test case wrapped in a function.
	TestFunc func(t *HarnessTest)
}

TestCase defines a test case that's been used in the integration test.

type WebFeeService

type WebFeeService interface {
	// Start starts the service.
	Start() error

	// Stop stops the service.
	Stop() error

	// URL returns the service's endpoint.
	URL() string

	// SetFeeRate sets the estimated fee rate for a given confirmation
	// target.
	SetFeeRate(feeRate chainfee.SatPerKWeight, conf uint32)
}

WebFeeService defines an interface that's used to provide fee estimation service used in the integration tests. It must provide an URL so that a lnd node can be started with the flag `--feeurl` and uses the customized fee estimator.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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