From 8f472bf063d8a27a3e2ed1e64da23be22613bdb5 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 4 Aug 2022 19:59:17 +0800 Subject: [PATCH] itest: refactor `testChannelBalance` --- lntest/itest/list_on_test.go | 4 +++ lntest/itest/lnd_channel_balance_test.go | 42 ++++++++---------------- lntest/itest/lnd_test_list_on_test.go | 4 --- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/lntest/itest/list_on_test.go b/lntest/itest/list_on_test.go index befa73514..ee402fe25 100644 --- a/lntest/itest/list_on_test.go +++ b/lntest/itest/list_on_test.go @@ -199,4 +199,8 @@ var allTestCasesTemp = []*lntemp.TestCase{ Name: "export channel backup", TestFunc: testExportChannelBackup, }, + { + Name: "channel balance", + TestFunc: testChannelBalance, + }, } diff --git a/lntest/itest/lnd_channel_balance_test.go b/lntest/itest/lnd_channel_balance_test.go index f33b26fdb..066492fd7 100644 --- a/lntest/itest/lnd_channel_balance_test.go +++ b/lntest/itest/lnd_channel_balance_test.go @@ -9,6 +9,8 @@ import ( "github.com/lightningnetwork/lnd/funding" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" + "github.com/lightningnetwork/lnd/lntemp" + "github.com/lightningnetwork/lnd/lntemp/node" "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lnwire" @@ -17,14 +19,14 @@ import ( // testChannelBalance creates a new channel between Alice and Bob, then checks // channel balance to be equal amount specified while creation of channel. -func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) { +func testChannelBalance(ht *lntemp.HarnessTest) { // Open a channel with 0.16 BTC between Alice and Bob, ensuring the // channel has been opened properly. amount := funding.MaxBtcFundingAmount // Creates a helper closure to be used below which asserts the proper // response to a channel balance RPC. - checkChannelBalance := func(node *lntest.HarnessNode, + checkChannelBalance := func(node *node.HarnessNode, local, remote btcutil.Amount) { expectedResponse := &lnrpc.ChannelBalanceResponse{ @@ -45,46 +47,28 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) { // Deprecated fields. Balance: int64(local), } - assertChannelBalanceResp(t, node, expectedResponse) + ht.AssertChannelBalanceResp(node, expectedResponse) } // Before beginning, make sure alice and bob are connected. - net.EnsureConnected(t.t, net.Alice, net.Bob) + alice, bob := ht.Alice, ht.Bob + ht.EnsureConnected(alice, bob) - chanPoint := openChannelAndAssert( - t, net, net.Alice, net.Bob, - lntest.OpenChannelParams{ - Amt: amount, - }, + chanPoint := ht.OpenChannel( + alice, bob, lntemp.OpenChannelParams{Amt: amount}, ) - - // Wait for both Alice and Bob to recognize this new channel. - err := net.Alice.WaitForNetworkChannelOpen(chanPoint) - if err != nil { - t.Fatalf("alice didn't advertise channel before "+ - "timeout: %v", err) - } - err = net.Bob.WaitForNetworkChannelOpen(chanPoint) - if err != nil { - t.Fatalf("bob didn't advertise channel before "+ - "timeout: %v", err) - } - - cType, err := channelCommitType(net.Alice, chanPoint) - if err != nil { - t.Fatalf("unable to get channel type: %v", err) - } + cType := ht.GetChannelCommitType(alice, chanPoint) // As this is a single funder channel, Alice's balance should be // exactly 0.5 BTC since now state transitions have taken place yet. - checkChannelBalance(net.Alice, amount-calcStaticFee(cType, 0), 0) + checkChannelBalance(alice, amount-calcStaticFee(cType, 0), 0) // Ensure Bob currently has no available balance within the channel. - checkChannelBalance(net.Bob, 0, amount-calcStaticFee(cType, 0)) + checkChannelBalance(bob, 0, amount-calcStaticFee(cType, 0)) // Finally close the channel between Alice and Bob, asserting that the // channel has been properly closed on-chain. - closeChannelAndAssert(t, net, net.Alice, chanPoint, false) + ht.CloseChannel(alice, chanPoint) } // testChannelUnsettledBalance will test that the UnsettledBalance field diff --git a/lntest/itest/lnd_test_list_on_test.go b/lntest/itest/lnd_test_list_on_test.go index d8d658309..4a7666569 100644 --- a/lntest/itest/lnd_test_list_on_test.go +++ b/lntest/itest/lnd_test_list_on_test.go @@ -12,10 +12,6 @@ var allTestCases = []*testCase{ name: "channel force closure", test: testChannelForceClosure, }, - { - name: "channel balance", - test: testChannelBalance, - }, { name: "channel unsettled balance", test: testChannelUnsettledBalance,