itest: refactor testWumboChannels

This commit is contained in:
yyforyongyu committed 2023-01-16 16:49:17 +08:00
1 parent 638872520e
commit ec3e1561b6
3 files changed
+21 -39

No files matched your search

+4
View File
@@ -247,4 +247,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "maximum channel size", Name: "maximum channel size",
TestFunc: testMaxChannelSize, TestFunc: testMaxChannelSize,
}, },
{
Name: "wumbo channels",
TestFunc: testWumboChannels,
},
} }
-4
View File
@@ -182,10 +182,6 @@ var allTestCases = []*testCase{
name: "forward interceptor dedup htlcs", name: "forward interceptor dedup htlcs",
test: testForwardInterceptorDedupHtlc, test: testForwardInterceptorDedupHtlc,
}, },
{
name: "wumbo channels",
test: testWumboChannels,
},
{ {
name: "stateless init", name: "stateless init",
test: testStatelessInit, test: testStatelessInit,
+17 -35
View File
@@ -1,70 +1,52 @@
package itest package itest
import ( import (
"strings"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/funding" "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 // testWumboChannels tests that only a node that signals wumbo channel
// acceptances will allow a wumbo channel to be created. Additionally, if a // 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 // node is running with mini channels only enabled, then they should reject any
// inbound wumbo channel requests. // 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 // With all the channel types exercised, we'll now make sure the wumbo
// signalling support works properly. // signalling support works properly.
// //
// We'll make two new nodes, with one of them signalling support for // We'll make two new nodes, with one of them signalling support for
// wumbo channels while the other doesn't. // wumbo channels while the other doesn't.
wumboNode := net.NewNode( wumboNode := ht.NewNode("wumbo", []string{"--protocol.wumbo-channels"})
t.t, "wumbo", []string{"--protocol.wumbo-channels"}, miniNode := ht.NewNode("mini", nil)
)
defer shutdownAndAssert(net, t, wumboNode)
miniNode := net.NewNode(t.t, "mini", nil)
defer shutdownAndAssert(net, t, miniNode)
// We'll send coins to the wumbo node, as it'll be the one imitating // We'll send coins to the wumbo node, as it'll be the one imitating
// the channel funding. // 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 // 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 // funding request to the mini node we created above. The wumbo request
// should fail as the node isn't advertising wumbo channels. // should fail as the node isn't advertising wumbo channels.
net.EnsureConnected(t.t, wumboNode, miniNode) ht.EnsureConnected(wumboNode, miniNode)
chanAmt := funding.MaxBtcFundingAmount + 1 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 // The test should indicate a failure due to the channel being too
// large. // large.
if !strings.Contains(err.Error(), "exceeds maximum chan size") { ht.OpenChannelAssertErr(
t.Fatalf("channel should be rejected due to size, instead "+ wumboNode, miniNode, lntemp.OpenChannelParams{Amt: chanAmt},
"error was: %v", err) lnwallet.ErrChanTooLarge(chanAmt, funding.MaxBtcFundingAmount),
} )
// We'll now make another wumbo node to accept our wumbo channel // We'll now make another wumbo node to accept our wumbo channel
// funding. // funding.
wumboNode2 := net.NewNode( wumboNode2 := ht.NewNode(
t.t, "wumbo2", []string{"--protocol.wumbo-channels"}, "wumbo2", []string{"--protocol.wumbo-channels"},
) )
defer shutdownAndAssert(net, t, wumboNode2)
// Creating a wumbo channel between these two nodes should succeed. // Creating a wumbo channel between these two nodes should succeed.
net.EnsureConnected(t.t, wumboNode, wumboNode2) ht.EnsureConnected(wumboNode, wumboNode2)
chanPoint := openChannelAndAssert( chanPoint := ht.OpenChannel(
t, net, wumboNode, wumboNode2, wumboNode, wumboNode2, lntemp.OpenChannelParams{Amt: chanAmt},
lntest.OpenChannelParams{
Amt: chanAmt,
},
) )
closeChannelAndAssert(t, net, wumboNode, chanPoint, false) ht.CloseChannel(wumboNode, chanPoint)
} }