itest: refactor testMaxChannelSize

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

No files matched your search

+4
View File
@@ -243,4 +243,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "hold invoice sender persistence", Name: "hold invoice sender persistence",
TestFunc: testHoldInvoicePersistence, TestFunc: testHoldInvoicePersistence,
}, },
{
Name: "maximum channel size",
TestFunc: testMaxChannelSize,
},
} }
+31 -64
View File
@@ -5,79 +5,50 @@ package itest
import ( import (
"fmt" "fmt"
"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"
) )
// testMaxChannelSize tests that lnd handles --maxchansize parameter // testMaxChannelSize tests that lnd handles --maxchansize parameter correctly.
// correctly. Wumbo nodes should enforce a default soft limit of 10 BTC by // Wumbo nodes should enforce a default soft limit of 10 BTC by default. This
// default. This limit can be adjusted with --maxchansize config option // limit can be adjusted with --maxchansize config option.
func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) { func testMaxChannelSize(ht *lntemp.HarnessTest) {
// We'll make two new nodes, both wumbo but with the default // We'll make two new nodes, both wumbo but with the default limit on
// limit on maximum channel size (10 BTC) // maximum channel size (10 BTC)
wumboNode := net.NewNode( wumboNode := ht.NewNode(
t.t, "wumbo", []string{"--protocol.wumbo-channels"}, "wumbo", []string{"--protocol.wumbo-channels"},
) )
defer shutdownAndAssert(net, t, wumboNode) wumboNode2 := ht.NewNode(
"wumbo2", []string{"--protocol.wumbo-channels"},
wumboNode2 := net.NewNode(
t.t, "wumbo2", []string{"--protocol.wumbo-channels"},
) )
defer shutdownAndAssert(net, t, wumboNode2)
// We'll send 11 BTC to the wumbo node so it can test the wumbo soft limit. // We'll send 11 BTC to the wumbo node so it can test the wumbo soft
net.SendCoins(t.t, 11*btcutil.SatoshiPerBitcoin, wumboNode) // limit.
ht.FundCoins(11*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, which should fail as it exceeds the default wumbo // funding request, which should fail as it exceeds the default wumbo
// soft limit of 10 BTC. // soft limit of 10 BTC.
net.EnsureConnected(t.t, wumboNode, wumboNode2) ht.EnsureConnected(wumboNode, wumboNode2)
chanAmt := funding.MaxBtcFundingAmountWumbo + 1 chanAmt := funding.MaxBtcFundingAmountWumbo + 1
_, err := net.OpenChannel( // The test should show failure due to the channel exceeding our max
wumboNode, wumboNode2, lntest.OpenChannelParams{ // size.
Amt: chanAmt, expectedErr := lnwallet.ErrChanTooLarge(
}, chanAmt, funding.MaxBtcFundingAmountWumbo,
) )
if err == nil { ht.OpenChannelAssertErr(
t.Fatalf("expected channel funding to fail as it exceeds 10 BTC limit") wumboNode, wumboNode2,
} lntemp.OpenChannelParams{Amt: chanAmt}, expectedErr,
// The test should show failure due to the channel exceeding our max size.
if !strings.Contains(err.Error(), "exceeds maximum chan size") {
t.Fatalf("channel should be rejected due to size, instead "+
"error was: %v", err)
}
// Next we'll create a non-wumbo node to verify that it enforces the
// BOLT-02 channel size limit and rejects our funding request.
miniNode := net.NewNode(t.t, "mini", nil)
defer shutdownAndAssert(net, t, miniNode)
net.EnsureConnected(t.t, wumboNode, miniNode)
_, err = net.OpenChannel(
wumboNode, miniNode, lntest.OpenChannelParams{
Amt: chanAmt,
},
) )
if err == nil {
t.Fatalf("expected channel funding to fail as it exceeds 0.16 BTC limit")
}
// The test should show failure due to the channel exceeding our max size. // We'll now make another wumbo node with appropriate maximum channel
if !strings.Contains(err.Error(), "exceeds maximum chan size") { // size to accept our wumbo channel funding.
t.Fatalf("channel should be rejected due to size, instead "+ wumboNode3 := ht.NewNode(
"error was: %v", err) "wumbo3", []string{
}
// We'll now make another wumbo node with appropriate maximum channel size
// to accept our wumbo channel funding.
wumboNode3 := net.NewNode(
t.t, "wumbo3", []string{
"--protocol.wumbo-channels", "--protocol.wumbo-channels",
fmt.Sprintf( fmt.Sprintf(
"--maxchansize=%v", "--maxchansize=%v",
@@ -85,16 +56,12 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
), ),
}, },
) )
defer shutdownAndAssert(net, t, wumboNode3)
// 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, wumboNode3) ht.EnsureConnected(wumboNode, wumboNode3)
chanPoint := openChannelAndAssert( chanPoint := ht.OpenChannel(
t, net, wumboNode, wumboNode3, wumboNode, wumboNode3, lntemp.OpenChannelParams{Amt: chanAmt},
lntest.OpenChannelParams{
Amt: chanAmt,
},
) )
closeChannelAndAssert(t, net, wumboNode, chanPoint, false)
ht.CloseChannel(wumboNode, chanPoint)
} }
-4
View File
@@ -186,10 +186,6 @@ var allTestCases = []*testCase{
name: "wumbo channels", name: "wumbo channels",
test: testWumboChannels, test: testWumboChannels,
}, },
{
name: "maximum channel size",
test: testMaxChannelSize,
},
{ {
name: "stateless init", name: "stateless init",
test: testStatelessInit, test: testStatelessInit,