From 9e30ba17c749017fe0d712dd94fc83dbcc484b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tigerstr=C3=B6m?= Date: Tue, 14 May 2024 11:50:35 +0200 Subject: [PATCH] lntest: separate creation/start of watch-only node Update the harness to allow creating a watch-only node without starting it. This is useful for tests that need to create a watch-only node prior to starting it, such as tests that use an outbound remote signer. --- itest/lnd_remote_signer_test.go | 2 +- lntest/harness.go | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/itest/lnd_remote_signer_test.go b/itest/lnd_remote_signer_test.go index e18e5cb039..6a8d05bcbf 100644 --- a/itest/lnd_remote_signer_test.go +++ b/itest/lnd_remote_signer_test.go @@ -221,7 +221,7 @@ func testRemoteSigner(ht *lntest.HarnessTest) { // WatchOnly is the node that has a watch-only wallet and uses // the Signer node for any operation that requires access to // private keys. - watchOnly := st.NewNodeRemoteSigner( + watchOnly := st.NewNodeWatchOnly( "WatchOnly", append([]string{ "--remotesigner.enable", fmt.Sprintf( diff --git a/lntest/harness.go b/lntest/harness.go index e8996e9a64..ba0bcebad3 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -232,7 +232,7 @@ func (h *HarnessTest) setupWatchOnlyNode(name string, name) // Create a new watch-only node with remote signer configuration. - return h.NewNodeRemoteSigner( + return h.NewNodeWatchOnly( name, remoteSignerArgs, password, &lnrpc.WatchOnly{ MasterKeyBirthdayTimestamp: 0, @@ -812,15 +812,35 @@ func (h *HarnessTest) NewNodeWithSeedEtcd(name string, etcdCfg *etcd.Config, return h.newNodeWithSeed(name, extraArgs, req, statelessInit) } -// NewNodeRemoteSigner creates a new remote signer node and asserts its +// NewNodeWatchOnly creates a new watch-only node and asserts its // creation. -func (h *HarnessTest) NewNodeRemoteSigner(name string, extraArgs []string, +func (h *HarnessTest) NewNodeWatchOnly(name string, extraArgs []string, password []byte, watchOnly *lnrpc.WatchOnly) *node.HarnessNode { + hn := h.CreateNewNode(name, extraArgs, password) + + h.StartWatchOnly(hn, name, password, watchOnly) + + return hn +} + +// CreateNodeWatchOnly creates a new node and asserts its creation. The function +// will only create the node and will not start it. +func (h *HarnessTest) CreateNewNode(name string, extraArgs []string, + password []byte) *node.HarnessNode { + hn, err := h.manager.newNode(h.T, name, extraArgs, password, true) require.NoErrorf(h, err, "unable to create new node for %s", name) - err = hn.StartWithNoAuth(h.runCtx) + return hn +} + +// StartWatchOnly starts the passed node in watch-only mode. The function will +// assert that the node is started and that the initialization is successful. +func (h *HarnessTest) StartWatchOnly(hn *node.HarnessNode, name string, + password []byte, watchOnly *lnrpc.WatchOnly) { + + err := hn.StartWithNoAuth(h.runCtx) require.NoError(h, err, "failed to start node %s", name) // With the seed created, construct the init request to the node, @@ -834,8 +854,6 @@ func (h *HarnessTest) NewNodeRemoteSigner(name string, extraArgs []string, // will also initialize the macaroon-authenticated LightningClient. _, err = h.manager.initWalletAndNode(hn, initReq) require.NoErrorf(h, err, "failed to init node %s", name) - - return hn } // KillNode kills the node (but won't wait for the node process to stop).