Skip to content

Commit

Permalink
lntest: separate creation/start of watch-only node
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ViktorTigerstrom committed Sep 2, 2024
1 parent 03b2f9d commit 9e30ba1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion itest/lnd_remote_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 24 additions & 6 deletions lntest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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).
Expand Down

0 comments on commit 9e30ba1

Please sign in to comment.