lnd/lntemp
2023-01-17 07:26:56 +08:00
..
node lntemp+itest: refactor node restart process 2023-01-17 07:26:56 +08:00
rpc lntemp+itest: refactor testRPCMiddlewareInterceptor 2023-01-17 07:26:56 +08:00
fee_service.go lntemp+itest: create interface WebFeeService 2022-10-14 15:45:25 +08:00
harness_assertion.go itest: refactor testSendToRouteErrorPropagation 2023-01-17 07:26:55 +08:00
harness_miner.go lntemp+itest: refactor testOpenChannelAfterReorg 2023-01-16 16:49:18 +08:00
harness_node_manager.go lntemp+itest: refactor node restart process 2023-01-17 07:26:56 +08:00
harness_setup.go lntemp+itest: create interface WebFeeService 2022-10-14 15:45:25 +08:00
harness.go lntemp+itest: refactor node restart process 2023-01-17 07:26:56 +08:00
README.md lntemp+lntest: use t.Cleanup to register cleanup functions 2022-10-27 01:11:34 +08:00
utils.go multi: refactor testUpdateChannelPolicy 2022-11-17 20:58:05 +08:00

lntest

lntest is a package which holds the components used for the lnds 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 btcds 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 its easier to acquire or validate a desired test states such as nodes 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, dont have this problem as they are digesting blocks all the time. Thus its 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, theres a cleanup function which further validates the current test case has no dangling uncleaned states, such as transactions left in mempool, open channels, etc.