Skip to content

Commit 70cacf0

Browse files
committed
itest: add NewNodeWithSeed
This will be used in our stateless init tests to initialise a LiT node in stateless init mode. This method handles the creation of the wallet and returns the LND admin macaroon that we can use.
1 parent 28b8f2a commit 70cacf0

File tree

1 file changed

+64
-7
lines changed

1 file changed

+64
-7
lines changed

itest/network_harness.go

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,8 @@ func (n *NetworkHarness) Stop() {
269269
n.autopilotServer.Stop()
270270
}
271271

272-
// NewNode initializes a new HarnessNode.
273-
func (n *NetworkHarness) NewNode(t *testing.T, name string, extraArgs []string,
274-
remoteMode bool, wait bool) (*HarnessNode, error) {
275-
276-
litArgs := []string{
272+
func (n *NetworkHarness) litArgs() []string {
273+
return []string{
277274
fmt.Sprintf("--loop.server.host=%s", n.server.ServerHost),
278275
fmt.Sprintf("--loop.server.tlspath=%s", n.server.CertFile),
279276
fmt.Sprintf("--pool.auctionserver=%s", n.server.ServerHost),
@@ -284,10 +281,15 @@ func (n *NetworkHarness) NewNode(t *testing.T, name string, extraArgs []string,
284281
n.autopilotServer.GetPort(),
285282
),
286283
}
284+
}
285+
286+
// NewNode initializes a new HarnessNode.
287+
func (n *NetworkHarness) NewNode(t *testing.T, name string, extraArgs []string,
288+
remoteMode bool, wait bool) (*HarnessNode, error) {
287289

288290
return n.newNode(
289-
t, name, extraArgs, litArgs, false, remoteMode, nil, wait,
290-
false,
291+
t, name, extraArgs, n.litArgs(), false, remoteMode, nil,
292+
wait, false,
291293
)
292294
}
293295

@@ -348,6 +350,61 @@ func (n *NetworkHarness) newNode(t *testing.T, name string, extraArgs,
348350
return node, nil
349351
}
350352

353+
// NewNodeWithSeed fully initializes a new HarnessNode after creating a fresh
354+
// aezeed. The provided password is used as both the aezeed password and the
355+
// wallet password. The harness node is returned along with an admin macaroon
356+
// for the LND node.
357+
func (n *NetworkHarness) NewNodeWithSeed(t *testing.T, name string,
358+
extraArgs []string, walletPassword []byte, remoteMode,
359+
statelessInit bool) (*HarnessNode, []byte) {
360+
361+
node, err := n.newNode(
362+
t, name, extraArgs, n.litArgs(), true, remoteMode,
363+
walletPassword, false, true,
364+
)
365+
require.NoError(t, err)
366+
367+
conn, err := node.ConnectRPC(false)
368+
require.NoError(t, err)
369+
370+
// Initially, we just care about LND's wallet being ready for unlock.
371+
err = node.WaitForLNDWalletReady()
372+
require.NoError(t, err)
373+
374+
// Set the wallet unlocker client.
375+
node.WalletUnlockerClient = lnrpc.NewWalletUnlockerClient(conn)
376+
377+
ctxt, cancel := context.WithTimeout(
378+
context.Background(), defaultTimeout,
379+
)
380+
defer cancel()
381+
382+
// Generate a new seed.
383+
genSeedResp, err := node.GenSeed(ctxt, &lnrpc.GenSeedRequest{
384+
AezeedPassphrase: walletPassword,
385+
})
386+
require.NoError(t, err)
387+
388+
// With the seed created, construct the init request to the node,
389+
// including the newly generated seed.
390+
initReq := &lnrpc.InitWalletRequest{
391+
WalletPassword: walletPassword,
392+
CipherSeedMnemonic: genSeedResp.CipherSeedMnemonic,
393+
AezeedPassphrase: walletPassword,
394+
StatelessInit: statelessInit,
395+
}
396+
397+
// Create the wallet and obtain the admin macaroon.
398+
resp, err := node.Init(ctxt, initReq)
399+
require.NoError(t, err)
400+
401+
// Now wait for the full LiT node to start.
402+
err = node.WaitUntilStarted(conn, defaultTimeout)
403+
require.NoError(t, err)
404+
405+
return node, resp.AdminMacaroon
406+
}
407+
351408
// RegisterNode records a new HarnessNode in the NetworkHarnesses map of known
352409
// nodes. This method should only be called with nodes that have successfully
353410
// retrieved their public keys via FetchNodeInfo.

0 commit comments

Comments
 (0)