From 97093b4223d9a3b0cdecd99fb079a609d530b008 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 18 Sep 2019 12:46:44 +0200 Subject: [PATCH] lntest/itest: wait for on-chain balance restore We add a wait predicate to make sure the node's on-chain balance is restored before continuing the restore test case. This is needed since the DLP test scenario includes several restarts of the node, and if the node isn't done scanning for on-chain balance before the restart happens, it would be unlocked without a recovery window, causing funds to be left undiscovered. --- lntest/itest/lnd_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index dfd4be60..6c26b2a0 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -8121,7 +8121,9 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest, assertTxInBlock(t, block, forceClose) // Dave should sweep his funds immediately, as they are not timelocked. - daveSweep, err := waitForTxInMempool(net.Miner.Node, minerMempoolTimeout) + daveSweep, err := waitForTxInMempool( + net.Miner.Node, minerMempoolTimeout, + ) if err != nil { t.Fatalf("unable to find Dave's sweep tx in mempool: %v", err) } @@ -13559,6 +13561,27 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness, t.Fatalf("unable to restore node: %v", err) } + // First ensure that the on-chain balance is restored. + err = wait.NoError(func() error { + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) + balReq := &lnrpc.WalletBalanceRequest{} + daveBalResp, err := dave.WalletBalance(ctxt, balReq) + if err != nil { + return err + } + + daveBal := daveBalResp.ConfirmedBalance + if daveBal <= 0 { + return fmt.Errorf("expected positive balance, had %v", + daveBal) + } + + return nil + }, defaultTimeout) + if err != nil { + t.Fatalf("On-chain balance not restored: %v", err) + } + // Now that we have our new node up, we expect that it'll re-connect to // Carol automatically based on the restored backup. ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)