From 6f5b7a9fd33393f4ea36f76ef826d3c0b10358fb Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 20 Mar 2024 06:35:37 +0800 Subject: [PATCH] lntest+itest: fix `testOpenChannelLockedBalance` --- itest/lnd_open_channel_test.go | 22 ++++++++++++++-------- lntest/harness_assertion.go | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/itest/lnd_open_channel_test.go b/itest/lnd_open_channel_test.go index 919e6ae97..d28a211db 100644 --- a/itest/lnd_open_channel_test.go +++ b/itest/lnd_open_channel_test.go @@ -829,12 +829,19 @@ func testSimpleTaprootChannelActivation(ht *lntest.HarnessTest) { // up as locked balance in the WalletBalance response. func testOpenChannelLockedBalance(ht *lntest.HarnessTest) { var ( - alice = ht.Alice - bob = ht.Bob - req *lnrpc.ChannelAcceptRequest - err error + bob = ht.Bob + req *lnrpc.ChannelAcceptRequest + err error ) + // Create a new node so we can assert exactly how much fund has been + // locked later. + alice := ht.NewNode("alice", nil) + ht.FundCoins(btcutil.SatoshiPerBitcoin, alice) + + // Connect the nodes. + ht.EnsureConnected(alice, bob) + // We first make sure Alice has no locked wallet balance. balance := alice.RPC.WalletBalance() require.EqualValues(ht, 0, balance.LockedBalance) @@ -851,6 +858,7 @@ func testOpenChannelLockedBalance(ht *lntest.HarnessTest) { openChannelReq := &lnrpc.OpenChannelRequest{ NodePubkey: bob.PubKey[:], LocalFundingAmount: int64(funding.MaxBtcFundingAmount), + TargetConf: 6, } _ = alice.RPC.OpenChannel(openChannelReq) @@ -862,8 +870,7 @@ func testOpenChannelLockedBalance(ht *lntest.HarnessTest) { }, defaultTimeout) require.NoError(ht, err) - balance = alice.RPC.WalletBalance() - require.NotEqualValues(ht, 0, balance.LockedBalance) + ht.AssertWalletLockedBalance(alice, btcutil.SatoshiPerBitcoin) // Next, we let Bob deny the request. resp := &lnrpc.ChannelAcceptResponse{ @@ -876,6 +883,5 @@ func testOpenChannelLockedBalance(ht *lntest.HarnessTest) { require.NoError(ht, err) // Finally, we check to make sure the balance is unlocked again. - balance = alice.RPC.WalletBalance() - require.EqualValues(ht, 0, balance.LockedBalance) + ht.AssertWalletLockedBalance(alice, 0) } diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index 2a19cd85d..2f4ebeb7f 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -2572,3 +2572,22 @@ func (h *HarnessTest) MineClosingTx(cp *lnrpc.ChannelPoint, return closeTx } + +// AssertWalletLockedBalance asserts the expected amount has been marked as +// locked in the node's WalletBalance response. +func (h *HarnessTest) AssertWalletLockedBalance(hn *node.HarnessNode, + balance int64) { + + err := wait.NoError(func() error { + balanceResp := hn.RPC.WalletBalance() + got := balanceResp.LockedBalance + + if got != balance { + return fmt.Errorf("want %d, got %d", balance, got) + } + + return nil + }, wait.DefaultTimeout) + require.NoError(h, err, "%s: timeout checking locked balance", + hn.Name()) +}