Skip to content

Commit 5817543

Browse files
committed
itest: call the rate limit and priv map itest
1 parent e2e5779 commit 5817543

File tree

2 files changed

+51
-56
lines changed

2 files changed

+51
-56
lines changed

autopilotserver/mock/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func (m *Server) SetFeatures(f map[string]*Feature) {
103103
m.featureSet = f
104104
}
105105

106+
// ResetDefaultFeatures resets the servers features set to the default set.
107+
func (m *Server) ResetDefaultFeatures() {
108+
m.featureSet = defaultFeatures
109+
}
110+
106111
// Terms returns any meta data from the autopilot server.
107112
//
108113
// Note: this is part of the autopilotrpc.AutopilotServer interface.

itest/litd_firewall_test.go

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"encoding/hex"
77
"fmt"
88
"io/ioutil"
9+
"os"
910
"strconv"
1011
"strings"
1112
"testing"
1213
"time"
1314

1415
"github.com/btcsuite/btcd/btcec/v2"
1516
"github.com/btcsuite/btcd/btcutil"
16-
"github.com/btcsuite/btcd/chaincfg/chainhash"
1717
"github.com/lightninglabs/lightning-node-connect/mailbox"
1818
"github.com/lightninglabs/lightning-terminal/autopilotserver/mock"
1919
"github.com/lightninglabs/lightning-terminal/firewall"
@@ -133,11 +133,16 @@ var (
133133
}
134134
)
135135

136-
// testFWRateLimitAndPrivacyMapper tests that an Autopilot session is forced to
137-
// adhere to the rate limits applied to the features of a session. Along the
138-
// way, the privacy mapper is also tested.
139-
func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
140-
ctx := context.Background()
136+
// assertStatusErr asserts that the given error contains the given status code.
137+
func assertStatusErr(t *testing.T, err error, code codes.Code) {
138+
require.Error(t, err)
139+
require.Contains(t, err.Error(), code.String())
140+
}
141+
142+
// testFirewallRules tests that the various firewall rules are enforced
143+
// correctly.
144+
func testFirewallRules(ctx context.Context, net *NetworkHarness,
145+
t *harnessTest) {
141146

142147
// Some very basic functionality tests to make sure lnd is working fine
143148
// in integrated mode.
@@ -158,22 +163,48 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
158163
)
159164
defer closeChannelAndAssert(t, net, net.Alice, channelOp, true)
160165

166+
t.t.Run("history limit rule", func(_ *testing.T) {
167+
testHistoryLimitRule(net, t)
168+
})
169+
170+
t.t.Run("channel policy bounds rule", func(_ *testing.T) {
171+
testChanPolicyBoundsRule(net, t)
172+
})
173+
174+
t.t.Run("peer and channel restrict rules", func(_ *testing.T) {
175+
testPeerAndChannelRestrictRules(net, t)
176+
})
177+
178+
t.t.Run("rate limit and privacy mapper", func(_ *testing.T) {
179+
testRateLimitAndPrivacyMapper(net, t)
180+
})
181+
}
182+
183+
// testRateLimitAndPrivacyMapper tests that an Autopilot session is forced to
184+
// adhere to the rate limits applied to the features of a session. Along the
185+
// way, the privacy mapper is also tested.
186+
func testRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
187+
ctx := context.Background()
188+
189+
// Fetch the channel that Alice has so that we can get the channel
190+
// point.
191+
resp, err := net.Alice.ListChannels(ctx, &lnrpc.ListChannelsRequest{})
192+
require.NoError(t.t, err)
193+
require.Len(t.t, resp.Channels, 1)
194+
161195
// We extract the txid of the channel so that we can use it later to
162196
// check that the autopilot's actions successfully completed and to
163197
// check that the txid that the autopilot server sees is not the same
164198
// as this one.
165-
realTxidBytes, err := getChanPointFundingTxid(channelOp)
166-
require.NoError(t.t, err)
167-
realTxid, err := chainhash.NewHash(realTxidBytes)
168-
require.NoError(t.t, err)
199+
realTxid := strings.Split(resp.Channels[0].ChannelPoint, ":")[0]
169200

170201
// We create a connection to the Alice node's RPC server.
171202
cfg := net.Alice.Cfg
172203
rawConn, err := connectRPC(ctx, cfg.LitAddr(), cfg.LitTLSCertPath)
173204
require.NoError(t.t, err)
174205
defer rawConn.Close()
175206

176-
macBytes, err := ioutil.ReadFile(cfg.LitMacPath)
207+
macBytes, err := os.ReadFile(cfg.LitMacPath)
177208
require.NoError(t.t, err)
178209
ctxm := macaroonContext(ctx, macBytes)
179210

@@ -186,6 +217,8 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
186217
require.NoError(t.t, err)
187218
require.NotEmpty(t.t, featResp)
188219

220+
net.autopilotServer.ResetDefaultFeatures()
221+
189222
// Add a new Autopilot session that subscribes to both a "HealthCheck",
190223
// and an "AutoFees" feature. Apply rate limits to the two features.
191224
// This call is expected to also result in Litd registering this session
@@ -305,7 +338,7 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
305338

306339
// Make sure that the txid returned by the call for Alice's channel is
307340
// not the same as the real txid of the channel.
308-
require.NotEqual(t.t, txid, realTxid.String())
341+
require.NotEqual(t.t, txid, realTxid)
309342

310343
chanPoint := &lnrpc.ChannelPoint{
311344
FundingTxid: &lnrpc.ChannelPoint_FundingTxidStr{
@@ -336,7 +369,7 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
336369

337370
txid2, _, err := decodeChannelPoint(feeResp.ChannelFees[0].ChannelPoint)
338371
require.NoError(t.t, err)
339-
require.Equal(t.t, realTxid.String(), txid2)
372+
require.Equal(t.t, realTxid, txid2)
340373
require.Equal(t.t, float64(8), feeResp.ChannelFees[0].FeeRate)
341374

342375
// Now we will check the same thing but from the PoV of the autopilot
@@ -371,49 +404,6 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
371404
assertStatusErr(t.t, err, codes.ResourceExhausted)
372405
}
373406

374-
// assertStatusErr asserts that the given error contains the given status code.
375-
func assertStatusErr(t *testing.T, err error, code codes.Code) {
376-
require.Error(t, err)
377-
require.True(t, strings.Contains(err.Error(), code.String()))
378-
}
379-
380-
// testFirewallRules tests that the various firewall rules are enforced
381-
// correctly.
382-
func testFirewallRules(ctx context.Context, net *NetworkHarness,
383-
t *harnessTest) {
384-
385-
// Some very basic functionality tests to make sure lnd is working fine
386-
// in integrated mode.
387-
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, net.Alice)
388-
389-
// We expect a non-empty alias (truncated node ID) to be returned.
390-
resp, err := net.Alice.GetInfo(ctx, &lnrpc.GetInfoRequest{})
391-
require.NoError(t.t, err)
392-
require.NotEmpty(t.t, resp.Alias)
393-
require.Contains(t.t, resp.Alias, "0")
394-
395-
// Open a channel between Alice and Bob so that we have something to
396-
// query later.
397-
channelOp := openChannelAndAssert(
398-
t, net, net.Alice, net.Bob, lntest.OpenChannelParams{
399-
Amt: 100000,
400-
},
401-
)
402-
defer closeChannelAndAssert(t, net, net.Alice, channelOp, true)
403-
404-
t.t.Run("history limit rule", func(_ *testing.T) {
405-
testHistoryLimitRule(net, t)
406-
})
407-
408-
t.t.Run("channel policy bounds rule", func(_ *testing.T) {
409-
testChanPolicyBoundsRule(net, t)
410-
})
411-
412-
t.t.Run("peer and channel restrict rules", func(_ *testing.T) {
413-
testPeerAndChannelRestrictRules(net, t)
414-
})
415-
}
416-
417407
// testHistoryLimitRule tests that the autopilot server is forced to adhere to
418408
// the history-limit rule.
419409
func testHistoryLimitRule(net *NetworkHarness, t *harnessTest) {

0 commit comments

Comments
 (0)