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.
This commit is contained in:
Oliver Gugger 2020-10-24 23:18:56 +02:00
parent bbd5980d42
commit 3fd944e7e4
No known key found for this signature in database
GPG key ID: 8E4256593F177720
3 changed files with 18 additions and 9 deletions

View file

@ -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,
}

View file

@ -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 {

View file

@ -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)