From ec3e1561b64c2d5a47a0240260218665cc012dd3 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 5 Aug 2022 18:15:48 +0800 Subject: [PATCH] itest: refactor `testWumboChannels` --- lntest/itest/list_on_test.go | 4 ++ lntest/itest/lnd_test_list_on_test.go | 4 -- lntest/itest/lnd_wumbo_channels_test.go | 52 ++++++++----------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/lntest/itest/list_on_test.go b/lntest/itest/list_on_test.go index baa553f21..2bb5dcee6 100644 --- a/lntest/itest/list_on_test.go +++ b/lntest/itest/list_on_test.go @@ -247,4 +247,8 @@ var allTestCasesTemp = []*lntemp.TestCase{ Name: "maximum channel size", TestFunc: testMaxChannelSize, }, + { + Name: "wumbo channels", + TestFunc: testWumboChannels, + }, } diff --git a/lntest/itest/lnd_test_list_on_test.go b/lntest/itest/lnd_test_list_on_test.go index aefdb7b9b..dea3d20ef 100644 --- a/lntest/itest/lnd_test_list_on_test.go +++ b/lntest/itest/lnd_test_list_on_test.go @@ -182,10 +182,6 @@ var allTestCases = []*testCase{ name: "forward interceptor dedup htlcs", test: testForwardInterceptorDedupHtlc, }, - { - name: "wumbo channels", - test: testWumboChannels, - }, { name: "stateless init", test: testStatelessInit, diff --git a/lntest/itest/lnd_wumbo_channels_test.go b/lntest/itest/lnd_wumbo_channels_test.go index ddfd6d677..5a5ba6627 100644 --- a/lntest/itest/lnd_wumbo_channels_test.go +++ b/lntest/itest/lnd_wumbo_channels_test.go @@ -1,70 +1,52 @@ package itest import ( - "strings" - "github.com/btcsuite/btcd/btcutil" "github.com/lightningnetwork/lnd/funding" - "github.com/lightningnetwork/lnd/lntest" + "github.com/lightningnetwork/lnd/lntemp" + "github.com/lightningnetwork/lnd/lnwallet" ) // testWumboChannels tests that only a node that signals wumbo channel // acceptances will allow a wumbo channel to be created. Additionally, if a // node is running with mini channels only enabled, then they should reject any // inbound wumbo channel requests. -func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) { +func testWumboChannels(ht *lntemp.HarnessTest) { // With all the channel types exercised, we'll now make sure the wumbo // signalling support works properly. // // We'll make two new nodes, with one of them signalling support for // wumbo channels while the other doesn't. - wumboNode := net.NewNode( - t.t, "wumbo", []string{"--protocol.wumbo-channels"}, - ) - defer shutdownAndAssert(net, t, wumboNode) - miniNode := net.NewNode(t.t, "mini", nil) - defer shutdownAndAssert(net, t, miniNode) + wumboNode := ht.NewNode("wumbo", []string{"--protocol.wumbo-channels"}) + miniNode := ht.NewNode("mini", nil) // We'll send coins to the wumbo node, as it'll be the one imitating // the channel funding. - net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, wumboNode) + ht.FundCoins(btcutil.SatoshiPerBitcoin, wumboNode) // Next we'll connect both nodes, then attempt to make a wumbo channel // funding request to the mini node we created above. The wumbo request // should fail as the node isn't advertising wumbo channels. - net.EnsureConnected(t.t, wumboNode, miniNode) + ht.EnsureConnected(wumboNode, miniNode) chanAmt := funding.MaxBtcFundingAmount + 1 - _, err := net.OpenChannel( - wumboNode, miniNode, lntest.OpenChannelParams{ - Amt: chanAmt, - }, - ) - if err == nil { - t.Fatalf("expected wumbo channel funding to fail") - } - // The test should indicate a failure due to the channel being too // large. - if !strings.Contains(err.Error(), "exceeds maximum chan size") { - t.Fatalf("channel should be rejected due to size, instead "+ - "error was: %v", err) - } + ht.OpenChannelAssertErr( + wumboNode, miniNode, lntemp.OpenChannelParams{Amt: chanAmt}, + lnwallet.ErrChanTooLarge(chanAmt, funding.MaxBtcFundingAmount), + ) // We'll now make another wumbo node to accept our wumbo channel // funding. - wumboNode2 := net.NewNode( - t.t, "wumbo2", []string{"--protocol.wumbo-channels"}, + wumboNode2 := ht.NewNode( + "wumbo2", []string{"--protocol.wumbo-channels"}, ) - defer shutdownAndAssert(net, t, wumboNode2) // Creating a wumbo channel between these two nodes should succeed. - net.EnsureConnected(t.t, wumboNode, wumboNode2) - chanPoint := openChannelAndAssert( - t, net, wumboNode, wumboNode2, - lntest.OpenChannelParams{ - Amt: chanAmt, - }, + ht.EnsureConnected(wumboNode, wumboNode2) + chanPoint := ht.OpenChannel( + wumboNode, wumboNode2, lntemp.OpenChannelParams{Amt: chanAmt}, ) - closeChannelAndAssert(t, net, wumboNode, chanPoint, false) + ht.CloseChannel(wumboNode, chanPoint) }