lntemp+lntest: refactor testOpenChannelUpdateFeePolicy

This commit is contained in:
yyforyongyu committed 2023-01-18 10:53:58 +08:00
1 parent 1cb7ea1a0c
commit 0b0c0f12ee
4 files changed
+61 -42

No files matched your search

+24
View File
@@ -822,6 +822,26 @@ type OpenChannelParams struct {
// ScidAlias denotes whether the channel will be an option-scid-alias // ScidAlias denotes whether the channel will be an option-scid-alias
// channel type negotiation. // channel type negotiation.
ScidAlias bool ScidAlias bool
// BaseFee is the channel base fee applied during the channel
// announcement phase.
BaseFee uint64
// FeeRate is the channel fee rate in ppm applied during the channel
// announcement phase.
FeeRate uint64
// UseBaseFee, if set, instructs the downstream logic to apply the
// user-specified channel base fee to the channel update announcement.
// If set to false it avoids applying a base fee of 0 and instead
// activates the default configured base fee.
UseBaseFee bool
// UseFeeRate, if set, instructs the downstream logic to apply the
// user-specified channel fee rate to the channel update announcement.
// If set to false it avoids applying a fee rate of 0 and instead
// activates the default configured fee rate.
UseFeeRate bool
} }
// prepareOpenChannel waits for both nodes to be synced to chain and returns an // prepareOpenChannel waits for both nodes to be synced to chain and returns an
@@ -858,6 +878,10 @@ func (h *HarnessTest) prepareOpenChannel(srcNode, destNode *node.HarnessNode,
CommitmentType: p.CommitmentType, CommitmentType: p.CommitmentType,
ZeroConf: p.ZeroConf, ZeroConf: p.ZeroConf,
ScidAlias: p.ScidAlias, ScidAlias: p.ScidAlias,
BaseFee: p.BaseFee,
FeeRate: p.FeeRate,
UseBaseFee: p.UseBaseFee,
UseFeeRate: p.UseFeeRate,
} }
} }
+4
View File
@@ -493,4 +493,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "trackpayments", Name: "trackpayments",
TestFunc: testTrackPayments, TestFunc: testTrackPayments,
}, },
{
Name: "open channel fee policy",
TestFunc: testOpenChannelUpdateFeePolicy,
},
} }
+33 -38
View File
@@ -2,6 +2,7 @@ package itest
import ( import (
"fmt" "fmt"
"testing"
"github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -12,7 +13,6 @@ import (
"github.com/lightningnetwork/lnd/lntemp" "github.com/lightningnetwork/lnd/lntemp"
"github.com/lightningnetwork/lnd/lntemp/node" "github.com/lightningnetwork/lnd/lntemp/node"
"github.com/lightningnetwork/lnd/lntemp/rpc" "github.com/lightningnetwork/lnd/lntemp/rpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -172,9 +172,7 @@ func testOpenChannelAfterReorg(ht *lntemp.HarnessTest) {
// ChannelUpdate --> defaultBaseFee, provided FeeRate // ChannelUpdate --> defaultBaseFee, provided FeeRate
// 4.) baseFee and feeRate provided to OpenChannelRequest // 4.) baseFee and feeRate provided to OpenChannelRequest
// ChannelUpdate --> provided baseFee, provided feeRate. // ChannelUpdate --> provided baseFee, provided feeRate.
func testOpenChannelUpdateFeePolicy(net *lntest.NetworkHarness, func testOpenChannelUpdateFeePolicy(ht *lntemp.HarnessTest) {
t *harnessTest) {
const ( const (
defaultBaseFee = 1000 defaultBaseFee = 1000
defaultFeeRate = 1 defaultFeeRate = 1
@@ -189,7 +187,7 @@ func testOpenChannelUpdateFeePolicy(net *lntest.NetworkHarness,
chanAmt := funding.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := chanAmt / 2 pushAmt := chanAmt / 2
feeScenarios := []lntest.OpenChannelParams{ feeScenarios := []lntemp.OpenChannelParams{
{ {
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -259,51 +257,48 @@ func testOpenChannelUpdateFeePolicy(net *lntest.NetworkHarness,
MaxHtlcMsat: defaultMaxHtlc, MaxHtlcMsat: defaultMaxHtlc,
} }
for i, feeScenario := range feeScenarios { alice, bob := ht.Alice, ht.Bob
runTestCase := func(ht *lntemp.HarnessTest,
fs lntemp.OpenChannelParams,
alicePolicy, bobPolicy *lnrpc.RoutingPolicy) {
// Create a channel Alice->Bob. // Create a channel Alice->Bob.
chanPoint := openChannelAndAssert( chanPoint := ht.OpenChannel(alice, bob, fs)
t, net, net.Alice, net.Bob, defer ht.CloseChannel(alice, chanPoint)
feeScenario,
)
defer closeChannelAndAssert(t, net, net.Alice, chanPoint, false) // We add all the nodes' update channels to a slice, such that
// we can make sure they all receive the expected updates.
nodes := []*node.HarnessNode{alice, bob}
// We add all the nodes' update channels to a slice, such that we can // Alice and Bob should see each other's ChannelUpdates,
// make sure they all receive the expected updates. // advertising the preferred routing policies.
nodes := []*lntest.HarnessNode{net.Alice, net.Bob} assertNodesPolicyUpdate(
ht, nodes, alice, alicePolicy, chanPoint,
// Alice and Bob should see each other's ChannelUpdates, advertising
// the preferred routing policies.
assertPolicyUpdate(
t, nodes, net.Alice.PubKeyStr,
&expectedPolicies[i], chanPoint,
)
assertPolicyUpdate(
t, nodes, net.Bob.PubKeyStr,
&bobExpectedPolicy, chanPoint,
) )
assertNodesPolicyUpdate(ht, nodes, bob, bobPolicy, chanPoint)
// They should now know about the default policies. // They should now know about the default policies.
for _, node := range nodes { for _, node := range nodes {
assertChannelPolicy( ht.AssertChannelPolicy(
t, node, net.Alice.PubKeyStr, node, alice.PubKeyStr, alicePolicy, chanPoint,
&expectedPolicies[i], chanPoint,
) )
assertChannelPolicy( ht.AssertChannelPolicy(
t, node, net.Bob.PubKeyStr, node, bob.PubKeyStr, bobPolicy, chanPoint,
&bobExpectedPolicy, chanPoint,
) )
} }
}
require.NoError( for i, feeScenario := range feeScenarios {
t.t, net.Alice.WaitForNetworkChannelOpen(chanPoint), ht.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
"alice reports channel opening", st := ht.Subtest(t)
) ht.EnsureConnected(alice, bob)
require.NoError( runTestCase(
t.t, net.Bob.WaitForNetworkChannelOpen(chanPoint), st, feeScenario,
"bob reports channel opening", &expectedPolicies[i], &bobExpectedPolicy,
) )
})
} }
} }
-4
View File
@@ -8,10 +8,6 @@ var allTestCases = []*testCase{
name: "async bidirectional payments", name: "async bidirectional payments",
test: testBidirectionalAsyncPayments, test: testBidirectionalAsyncPayments,
}, },
{
name: "open channel fee policy",
test: testOpenChannelUpdateFeePolicy,
},
{ {
name: "custom messaging", name: "custom messaging",
test: testCustomMessage, test: testCustomMessage,