lntemp+itest: refactor testGetRecoveryInfo
This commit is contained in:
4 files changed
+57
-71
No files matched your search
@@ -381,3 +381,21 @@ func (h *HarnessRPC) VerifyMessage(msg []byte,
|
|||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRecoveryInfo uses the specified node to make a RPC call to
|
||||||
|
// GetRecoveryInfo and asserts.
|
||||||
|
func (h *HarnessRPC) GetRecoveryInfo(
|
||||||
|
req *lnrpc.GetRecoveryInfoRequest) *lnrpc.GetRecoveryInfoResponse {
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
if req == nil {
|
||||||
|
req = &lnrpc.GetRecoveryInfoRequest{}
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.LN.GetRecoveryInfo(ctxt, req)
|
||||||
|
require.NoErrorf(h, err, "failed to GetRecoveryInfo")
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
@@ -111,4 +111,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "abandonchannel",
|
Name: "abandonchannel",
|
||||||
TestFunc: testAbandonChannel,
|
TestFunc: testAbandonChannel,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "recovery info",
|
||||||
|
TestFunc: testGetRecoveryInfo,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,14 @@ package itest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||||
"github.com/lightningnetwork/lnd/aezeed"
|
"github.com/lightningnetwork/lnd/aezeed"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -15,87 +17,53 @@ import (
|
|||||||
|
|
||||||
// testGetRecoveryInfo checks whether lnd gives the right information about
|
// testGetRecoveryInfo checks whether lnd gives the right information about
|
||||||
// the wallet recovery process.
|
// the wallet recovery process.
|
||||||
func testGetRecoveryInfo(net *lntest.NetworkHarness, t *harnessTest) {
|
func testGetRecoveryInfo(ht *lntemp.HarnessTest) {
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
// First, create a new node with strong passphrase and grab the mnemonic
|
// First, create a new node with strong passphrase and grab the mnemonic
|
||||||
// used for key derivation. This will bring up Carol with an empty
|
// used for key derivation. This will bring up Carol with an empty
|
||||||
// wallet, and such that she is synced up.
|
// wallet, and such that she is synced up.
|
||||||
password := []byte("The Magic Words are Squeamish Ossifrage")
|
password := []byte("The Magic Words are Squeamish Ossifrage")
|
||||||
carol, mnemonic, _, err := net.NewNodeWithSeed(
|
carol, mnemonic, _ := ht.NewNodeWithSeed("Carol", nil, password, false)
|
||||||
"Carol", nil, password, false,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to create node with seed; %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
shutdownAndAssert(net, t, carol)
|
|
||||||
|
|
||||||
checkInfo := func(expectedRecoveryMode, expectedRecoveryFinished bool,
|
checkInfo := func(expectedRecoveryMode, expectedRecoveryFinished bool,
|
||||||
expectedProgress float64, recoveryWindow int32) {
|
expectedProgress float64, recoveryWindow int32) {
|
||||||
|
|
||||||
// Restore Carol, passing in the password, mnemonic, and
|
// Restore Carol, passing in the password, mnemonic, and
|
||||||
// desired recovery window.
|
// desired recovery window.
|
||||||
node, err := net.RestoreNodeWithSeed(
|
node := ht.RestoreNodeWithSeed(
|
||||||
"Carol", nil, password, mnemonic, "", recoveryWindow,
|
carol.Name(), nil, password, mnemonic, "",
|
||||||
nil,
|
recoveryWindow, nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to restore node: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for Carol to sync to the chain.
|
|
||||||
_, minerHeight, err := net.Miner.Client.GetBestBlock()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to get current blockheight %v", err)
|
|
||||||
}
|
|
||||||
err = waitForNodeBlockHeight(node, minerHeight)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to sync to chain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query carol for her current wallet recovery progress.
|
// Query carol for her current wallet recovery progress.
|
||||||
var (
|
err := wait.NoError(func() error {
|
||||||
recoveryMode bool
|
|
||||||
recoveryFinished bool
|
|
||||||
progress float64
|
|
||||||
)
|
|
||||||
|
|
||||||
err = wait.Predicate(func() bool {
|
|
||||||
// Verify that recovery info gives the right response.
|
// Verify that recovery info gives the right response.
|
||||||
req := &lnrpc.GetRecoveryInfoRequest{}
|
resp := node.RPC.GetRecoveryInfo(nil)
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
resp, err := node.GetRecoveryInfo(ctxt, req)
|
mode := resp.RecoveryMode
|
||||||
if err != nil {
|
finished := resp.RecoveryFinished
|
||||||
t.Fatalf("unable to query recovery info: %v", err)
|
progress := resp.Progress
|
||||||
|
|
||||||
|
if mode != expectedRecoveryMode {
|
||||||
|
return fmt.Errorf("expected recovery mode %v "+
|
||||||
|
"got %v", expectedRecoveryMode, mode)
|
||||||
|
}
|
||||||
|
if finished != expectedRecoveryFinished {
|
||||||
|
return fmt.Errorf("expected finished %v "+
|
||||||
|
"got %v", expectedRecoveryFinished,
|
||||||
|
finished)
|
||||||
|
}
|
||||||
|
if progress != expectedProgress {
|
||||||
|
return fmt.Errorf("expected progress %v"+
|
||||||
|
"got %v", expectedProgress, progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
recoveryMode = resp.RecoveryMode
|
return nil
|
||||||
recoveryFinished = resp.RecoveryFinished
|
|
||||||
progress = resp.Progress
|
|
||||||
|
|
||||||
if recoveryMode != expectedRecoveryMode ||
|
|
||||||
recoveryFinished != expectedRecoveryFinished ||
|
|
||||||
progress != expectedProgress {
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}, defaultTimeout)
|
}, defaultTimeout)
|
||||||
if err != nil {
|
require.NoError(ht, err)
|
||||||
t.Fatalf("expected recovery mode to be %v, got %v, "+
|
|
||||||
"expected recovery finished to be %v, got %v, "+
|
|
||||||
"expected progress %v, got %v",
|
|
||||||
expectedRecoveryMode, recoveryMode,
|
|
||||||
expectedRecoveryFinished, recoveryFinished,
|
|
||||||
expectedProgress, progress,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lastly, shutdown this Carol so we can move on to the next
|
// Lastly, shutdown this Carol so we can move on to the next
|
||||||
// restoration.
|
// restoration.
|
||||||
shutdownAndAssert(net, t, node)
|
ht.Shutdown(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore Carol with a recovery window of 0. Since it's not in recovery
|
// Restore Carol with a recovery window of 0. Since it's not in recovery
|
||||||
@@ -103,15 +71,15 @@ func testGetRecoveryInfo(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// recoveryFinished=false, and progress=0
|
// recoveryFinished=false, and progress=0
|
||||||
checkInfo(false, false, 0, 0)
|
checkInfo(false, false, 0, 0)
|
||||||
|
|
||||||
// Change the recovery windown to be 1 to turn on recovery mode. Since the
|
// Change the recovery windown to be 1 to turn on recovery mode. Since
|
||||||
// current chain height is the same as the birthday height, it should
|
// the current chain height is the same as the birthday height, it
|
||||||
// indicate the recovery process is finished.
|
// should indicate the recovery process is finished.
|
||||||
checkInfo(true, true, 1, 1)
|
checkInfo(true, true, 1, 1)
|
||||||
|
|
||||||
// We now go ahead 5 blocks. Because the wallet's syncing process is
|
// We now go ahead 5 blocks. Because the wallet's syncing process is
|
||||||
// controlled by a goroutine in the background, it will catch up quickly.
|
// controlled by a goroutine in the background, it will catch up
|
||||||
// This makes the recovery progress back to 1.
|
// quickly. This makes the recovery progress back to 1.
|
||||||
mineBlocks(t, net, 5, 0)
|
ht.MineBlocks(5)
|
||||||
checkInfo(true, true, 1, 1)
|
checkInfo(true, true, 1, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,6 @@
|
|||||||
package itest
|
package itest
|
||||||
|
|
||||||
var allTestCases = []*testCase{
|
var allTestCases = []*testCase{
|
||||||
{
|
|
||||||
name: "recovery info",
|
|
||||||
test: testGetRecoveryInfo,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "onchain fund recovery",
|
name: "onchain fund recovery",
|
||||||
test: testOnchainFundRecovery,
|
test: testOnchainFundRecovery,
|
||||||
|
|||||||
Reference in new issue
Block a user