From 3fd944e7e4169a96d85fa09117eaf1dd034da7ff Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Sat, 24 Oct 2020 23:18:56 +0200 Subject: [PATCH] lntest: allow node restore by extended root key To allow testing restoring a node from an extended master root key, we add an extra argument to the RestoreNodeWithSeed function. --- lntest/harness.go | 3 ++- lntest/itest/lnd_channel_backup_test.go | 13 +++++++------ lntest/itest/lnd_recovery_test.go | 11 +++++++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lntest/harness.go b/lntest/harness.go index 68ce2f83e..1c89bb123 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -426,7 +426,7 @@ func (n *NetworkHarness) newNodeWithSeed(name string, extraArgs []string, // will finish initializing the LightningClient such that the HarnessNode can // be used for regular rpc operations. func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string, - password []byte, mnemonic []string, recoveryWindow int32, + password []byte, mnemonic []string, rootKey string, recoveryWindow int32, chanBackups *lnrpc.ChanBackupSnapshot, opts ...NodeOption) (*HarnessNode, error) { @@ -441,6 +441,7 @@ func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string, WalletPassword: password, CipherSeedMnemonic: mnemonic, AezeedPassphrase: password, + ExtendedMasterKey: rootKey, RecoveryWindow: recoveryWindow, ChannelBackups: chanBackups, } diff --git a/lntest/itest/lnd_channel_backup_test.go b/lntest/itest/lnd_channel_backup_test.go index 7e273b602..abc14bf77 100644 --- a/lntest/itest/lnd_channel_backup_test.go +++ b/lntest/itest/lnd_channel_backup_test.go @@ -122,8 +122,8 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // obtained above. return func() (*lntest.HarnessNode, error) { return net.RestoreNodeWithSeed( - "dave", nil, password, - mnemonic, 1000, backupSnapshot, + "dave", nil, password, mnemonic, + "", 1000, backupSnapshot, copyPorts(oldNode), ) }, nil @@ -159,8 +159,8 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // restart it again using Unlock. return func() (*lntest.HarnessNode, error) { newNode, err := net.RestoreNodeWithSeed( - "dave", nil, password, - mnemonic, 1000, nil, + "dave", nil, password, mnemonic, + "", 1000, nil, copyPorts(oldNode), ) if err != nil { @@ -208,7 +208,8 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { return func() (*lntest.HarnessNode, error) { newNode, err := net.RestoreNodeWithSeed( "dave", nil, password, mnemonic, - 1000, nil, copyPorts(oldNode), + "", 1000, nil, + copyPorts(oldNode), ) if err != nil { return nil, fmt.Errorf("unable to "+ @@ -1322,7 +1323,7 @@ func chanRestoreViaRPC(net *lntest.NetworkHarness, password []byte, return func() (*lntest.HarnessNode, error) { newNode, err := net.RestoreNodeWithSeed( - "dave", nil, password, mnemonic, 1000, nil, + "dave", nil, password, mnemonic, "", 1000, nil, copyPorts(oldNode), ) if err != nil { diff --git a/lntest/itest/lnd_recovery_test.go b/lntest/itest/lnd_recovery_test.go index c48528d71..d287c9b29 100644 --- a/lntest/itest/lnd_recovery_test.go +++ b/lntest/itest/lnd_recovery_test.go @@ -34,7 +34,8 @@ func testGetRecoveryInfo(net *lntest.NetworkHarness, t *harnessTest) { // Restore Carol, passing in the password, mnemonic, and // desired recovery window. node, err := net.RestoreNodeWithSeed( - "Carol", nil, password, mnemonic, recoveryWindow, nil, + "Carol", nil, password, mnemonic, "", recoveryWindow, + nil, ) if err != nil { t.Fatalf("unable to restore node: %v", err) @@ -130,6 +131,11 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) { } shutdownAndAssert(net, t, carol) + // As long as the mnemonic is non-nil and the extended key is empty, the + // closure below will always restore the node from the seed. The tests + // need to manually overwrite this value to change that behavior. + rootKey := "" + // Create a closure for testing the recovery of Carol's wallet. This // method takes the expected value of Carol's balance when using the // given recovery window. Additionally, the caller can specify an action @@ -140,7 +146,8 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) { // Restore Carol, passing in the password, mnemonic, and // desired recovery window. node, err := net.RestoreNodeWithSeed( - "Carol", nil, password, mnemonic, recoveryWindow, nil, + "Carol", nil, password, mnemonic, rootKey, + recoveryWindow, nil, ) if err != nil { t.Fatalf("unable to restore node: %v", err)