@@ -5,14 +5,14 @@ import (
55 "encoding/hex"
66 "fmt"
77 "io/ioutil"
8+ "os"
89 "strconv"
910 "strings"
1011 "testing"
1112 "time"
1213
1314 "github.com/btcsuite/btcd/btcec/v2"
1415 "github.com/btcsuite/btcd/btcutil"
15- "github.com/btcsuite/btcd/chaincfg/chainhash"
1616 "github.com/lightninglabs/lightning-node-connect/mailbox"
1717 "github.com/lightninglabs/lightning-terminal/autopilotserver/mock"
1818 "github.com/lightninglabs/lightning-terminal/firewall"
@@ -132,11 +132,16 @@ var (
132132 }
133133)
134134
135- // testFWRateLimitAndPrivacyMapper tests that an Autopilot session is forced to
136- // adhere to the rate limits applied to the features of a session. Along the
137- // way, the privacy mapper is also tested.
138- func testFWRateLimitAndPrivacyMapper (net * NetworkHarness , t * harnessTest ) {
139- ctx := context .Background ()
135+ // assertStatusErr asserts that the given error contains the given status code.
136+ func assertStatusErr (t * testing.T , err error , code codes.Code ) {
137+ require .Error (t , err )
138+ require .Contains (t , err .Error (), code .String ())
139+ }
140+
141+ // testFirewallRules tests that the various firewall rules are enforced
142+ // correctly.
143+ func testFirewallRules (ctx context.Context , net * NetworkHarness ,
144+ t * harnessTest ) {
140145
141146 // Some very basic functionality tests to make sure lnd is working fine
142147 // in integrated mode.
@@ -157,22 +162,48 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
157162 )
158163 defer closeChannelAndAssert (t , net , net .Alice , channelOp , true )
159164
165+ t .t .Run ("history limit rule" , func (_ * testing.T ) {
166+ testHistoryLimitRule (net , t )
167+ })
168+
169+ t .t .Run ("channel policy bounds rule" , func (_ * testing.T ) {
170+ testChanPolicyBoundsRule (net , t )
171+ })
172+
173+ t .t .Run ("peer and channel restrict rules" , func (_ * testing.T ) {
174+ testPeerAndChannelRestrictRules (net , t )
175+ })
176+
177+ t .t .Run ("rate limit and privacy mapper" , func (_ * testing.T ) {
178+ testRateLimitAndPrivacyMapper (net , t )
179+ })
180+ }
181+
182+ // testRateLimitAndPrivacyMapper tests that an Autopilot session is forced to
183+ // adhere to the rate limits applied to the features of a session. Along the
184+ // way, the privacy mapper is also tested.
185+ func testRateLimitAndPrivacyMapper (net * NetworkHarness , t * harnessTest ) {
186+ ctx := context .Background ()
187+
188+ // Fetch the channel that Alice has so that we can get the channel
189+ // point.
190+ resp , err := net .Alice .ListChannels (ctx , & lnrpc.ListChannelsRequest {})
191+ require .NoError (t .t , err )
192+ require .Len (t .t , resp .Channels , 1 )
193+
160194 // We extract the txid of the channel so that we can use it later to
161195 // check that the autopilot's actions successfully completed and to
162196 // check that the txid that the autopilot server sees is not the same
163197 // as this one.
164- realTxidBytes , err := getChanPointFundingTxid (channelOp )
165- require .NoError (t .t , err )
166- realTxid , err := chainhash .NewHash (realTxidBytes )
167- require .NoError (t .t , err )
198+ realTxid := strings .Split (resp .Channels [0 ].ChannelPoint , ":" )[0 ]
168199
169200 // We create a connection to the Alice node's RPC server.
170201 cfg := net .Alice .Cfg
171202 rawConn , err := connectRPC (ctx , cfg .LitAddr (), cfg .LitTLSCertPath )
172203 require .NoError (t .t , err )
173204 defer rawConn .Close ()
174205
175- macBytes , err := ioutil .ReadFile (cfg .LitMacPath )
206+ macBytes , err := os .ReadFile (cfg .LitMacPath )
176207 require .NoError (t .t , err )
177208 ctxm := macaroonContext (ctx , macBytes )
178209
@@ -185,6 +216,8 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
185216 require .NoError (t .t , err )
186217 require .NotEmpty (t .t , featResp )
187218
219+ net .autopilotServer .ResetDefaultFeatures ()
220+
188221 // Add a new Autopilot session that subscribes to both a "HealthCheck",
189222 // and an "AutoFees" feature. Apply rate limits to the two features.
190223 // This call is expected to also result in Litd registering this session
@@ -304,7 +337,7 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
304337
305338 // Make sure that the txid returned by the call for Alice's channel is
306339 // not the same as the real txid of the channel.
307- require .NotEqual (t .t , txid , realTxid . String () )
340+ require .NotEqual (t .t , txid , realTxid )
308341
309342 chanPoint := & lnrpc.ChannelPoint {
310343 FundingTxid : & lnrpc.ChannelPoint_FundingTxidStr {
@@ -335,7 +368,7 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
335368
336369 txid2 , _ , err := decodeChannelPoint (feeResp .ChannelFees [0 ].ChannelPoint )
337370 require .NoError (t .t , err )
338- require .Equal (t .t , realTxid . String () , txid2 )
371+ require .Equal (t .t , realTxid , txid2 )
339372 require .Equal (t .t , float64 (8 ), feeResp .ChannelFees [0 ].FeeRate )
340373
341374 // Now we will check the same thing but from the PoV of the autopilot
@@ -370,49 +403,6 @@ func testFWRateLimitAndPrivacyMapper(net *NetworkHarness, t *harnessTest) {
370403 assertStatusErr (t .t , err , codes .ResourceExhausted )
371404}
372405
373- // assertStatusErr asserts that the given error contains the given status code.
374- func assertStatusErr (t * testing.T , err error , code codes.Code ) {
375- require .Error (t , err )
376- require .True (t , strings .Contains (err .Error (), code .String ()))
377- }
378-
379- // testFirewallRules tests that the various firewall rules are enforced
380- // correctly.
381- func testFirewallRules (ctx context.Context , net * NetworkHarness ,
382- t * harnessTest ) {
383-
384- // Some very basic functionality tests to make sure lnd is working fine
385- // in integrated mode.
386- net .SendCoins (t .t , btcutil .SatoshiPerBitcoin , net .Alice )
387-
388- // We expect a non-empty alias (truncated node ID) to be returned.
389- resp , err := net .Alice .GetInfo (ctx , & lnrpc.GetInfoRequest {})
390- require .NoError (t .t , err )
391- require .NotEmpty (t .t , resp .Alias )
392- require .Contains (t .t , resp .Alias , "0" )
393-
394- // Open a channel between Alice and Bob so that we have something to
395- // query later.
396- channelOp := openChannelAndAssert (
397- t , net , net .Alice , net .Bob , lntest.OpenChannelParams {
398- Amt : 100000 ,
399- },
400- )
401- defer closeChannelAndAssert (t , net , net .Alice , channelOp , true )
402-
403- t .t .Run ("history limit rule" , func (_ * testing.T ) {
404- testHistoryLimitRule (net , t )
405- })
406-
407- t .t .Run ("channel policy bounds rule" , func (_ * testing.T ) {
408- testChanPolicyBoundsRule (net , t )
409- })
410-
411- t .t .Run ("peer and channel restrict rules" , func (_ * testing.T ) {
412- testPeerAndChannelRestrictRules (net , t )
413- })
414- }
415-
416406// testHistoryLimitRule tests that the autopilot server is forced to adhere to
417407// the history-limit rule.
418408func testHistoryLimitRule (net * NetworkHarness , t * harnessTest ) {
0 commit comments