@@ -3,9 +3,11 @@ package firewall
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "fmt"
6
7
"testing"
7
8
"time"
8
9
10
+ "github.com/btcsuite/btcd/chaincfg/chainhash"
9
11
"github.com/lightninglabs/lightning-terminal/firewalldb"
10
12
"github.com/lightninglabs/lightning-terminal/session"
11
13
"github.com/lightningnetwork/lnd/lnrpc"
@@ -19,6 +21,33 @@ import (
19
21
// TestPrivacyMapper tests that the PrivacyMapper correctly intercepts specific
20
22
// RPC calls.
21
23
func TestPrivacyMapper (t * testing.T ) {
24
+ outPoint := func (txid string , index uint32 ) string {
25
+ return fmt .Sprintf ("%s:%d" , txid , index )
26
+ }
27
+
28
+ // Define some transaction outpoints used for mapping.
29
+ clearTxID := "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd"
30
+
31
+ obfusTxID0 := "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384"
32
+ obfusOut0 := uint32 (2161781494 )
33
+ obfusTxID0Reversed , err := chainhash .NewHashFromStr (obfusTxID0 )
34
+ require .NoError (t , err )
35
+
36
+ obfusTxID1 := "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c"
37
+ obfusOut1 := uint32 (1642614131 )
38
+
39
+ // Define some preexisting mappings for the privacy mapper.
40
+ mapPreloadRealToPseudo := map [string ]string {
41
+ "Tinker Bell's pub key" : "a44ef01c3bff970ef495c" ,
42
+ "000000000000007b" : "47deb774fc605c56" ,
43
+ "0000000000000141" : "2fd42e84b9ffaaeb" ,
44
+ "00000000000002a6" : "7859bf41241787c2" ,
45
+ "000000000000036c" : "1320e5d25b7b5973" ,
46
+ outPoint (clearTxID , 0 ): outPoint (obfusTxID0 , obfusOut0 ),
47
+ outPoint (clearTxID , 1 ): outPoint (obfusTxID1 , obfusOut1 ),
48
+ "01020304" : "c8134495" ,
49
+ }
50
+
22
51
var (
23
52
clearForwarding = & lnrpc.ForwardingHistoryResponse {
24
53
ForwardingEvents : []* lnrpc.ForwardingEvent {
@@ -61,8 +90,13 @@ func TestPrivacyMapper(t *testing.T) {
61
90
RemotePubkey : "01020304" ,
62
91
Initiator : false ,
63
92
ChanId : 123 ,
64
- ChannelPoint : "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:0" ,
65
- PendingHtlcs : []* lnrpc.HTLC {{HashLock : []byte ("aaaa" )}, {HashLock : []byte ("bbbb" )}},
93
+ ChannelPoint : outPoint (
94
+ clearTxID , 0 ,
95
+ ),
96
+ PendingHtlcs : []* lnrpc.HTLC {
97
+ {HashLock : []byte ("aaaa" )},
98
+ {HashLock : []byte ("bbbb" )},
99
+ },
66
100
},
67
101
},
68
102
}
@@ -164,24 +198,32 @@ func TestPrivacyMapper(t *testing.T) {
164
198
msg : & lnrpc.FeeReportResponse {
165
199
ChannelFees : []* lnrpc.ChannelFeeReport {
166
200
{
167
- ChanId : 123 ,
168
- ChannelPoint : "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:0" ,
201
+ ChanId : 123 ,
202
+ ChannelPoint : outPoint (
203
+ clearTxID , 0 ,
204
+ ),
169
205
},
170
206
{
171
- ChanId : 321 ,
172
- ChannelPoint : "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1" ,
207
+ ChanId : 321 ,
208
+ ChannelPoint : outPoint (
209
+ clearTxID , 1 ,
210
+ ),
173
211
},
174
212
},
175
213
},
176
214
expectedReplacement : & lnrpc.FeeReportResponse {
177
215
ChannelFees : []* lnrpc.ChannelFeeReport {
178
216
{
179
- ChanId : 5178778334600911958 ,
180
- ChannelPoint : "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384:2161781494" ,
217
+ ChanId : 5178778334600911958 ,
218
+ ChannelPoint : outPoint (
219
+ obfusTxID0 , obfusOut0 ,
220
+ ),
181
221
},
182
222
{
183
- ChanId : 3446430762436373227 ,
184
- ChannelPoint : "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131" ,
223
+ ChanId : 3446430762436373227 ,
224
+ ChannelPoint : outPoint (
225
+ obfusTxID1 , obfusOut1 ,
226
+ ),
185
227
},
186
228
},
187
229
},
@@ -214,8 +256,10 @@ func TestPrivacyMapper(t *testing.T) {
214
256
RemotePubkey : "c8134495" ,
215
257
Initiator : true ,
216
258
ChanId : 5178778334600911958 ,
217
- ChannelPoint : "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384:2161781494" ,
218
- PendingHtlcs : []* lnrpc.HTLC {{}, {}},
259
+ ChannelPoint : outPoint (
260
+ obfusTxID0 , obfusOut0 ,
261
+ ),
262
+ PendingHtlcs : []* lnrpc.HTLC {{}, {}},
219
263
},
220
264
},
221
265
},
@@ -242,17 +286,17 @@ func TestPrivacyMapper(t *testing.T) {
242
286
Scope : & lnrpc.PolicyUpdateRequest_ChanPoint {
243
287
ChanPoint : & lnrpc.ChannelPoint {
244
288
FundingTxid : & lnrpc.ChannelPoint_FundingTxidStr {
245
- FundingTxidStr : "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384" ,
289
+ FundingTxidStr : obfusTxID0 ,
246
290
},
247
- OutputIndex : 2161781494 ,
291
+ OutputIndex : obfusOut0 ,
248
292
},
249
293
},
250
294
},
251
295
expectedReplacement : & lnrpc.PolicyUpdateRequest {
252
296
Scope : & lnrpc.PolicyUpdateRequest_ChanPoint {
253
297
ChanPoint : & lnrpc.ChannelPoint {
254
298
FundingTxid : & lnrpc.ChannelPoint_FundingTxidStr {
255
- FundingTxidStr : "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd" ,
299
+ FundingTxidStr : clearTxID ,
256
300
},
257
301
OutputIndex : 0 ,
258
302
},
@@ -267,17 +311,17 @@ func TestPrivacyMapper(t *testing.T) {
267
311
Scope : & lnrpc.PolicyUpdateRequest_ChanPoint {
268
312
ChanPoint : & lnrpc.ChannelPoint {
269
313
FundingTxid : & lnrpc.ChannelPoint_FundingTxidBytes {
270
- FundingTxidBytes : [] byte { 132 , 227 , 191 , 172 , 166 , 31 , 110 , 128 , 103 , 165 , 12 , 12 , 247 , 8 , 172 , 203 , 165 , 227 , 234 , 1 , 183 , 179 , 19 , 52 , 255 , 25 , 25 , 166 , 102 , 246 , 126 , 9 } ,
314
+ FundingTxidBytes : obfusTxID0Reversed [:] ,
271
315
},
272
- OutputIndex : 2161781494 ,
316
+ OutputIndex : obfusOut0 ,
273
317
},
274
318
},
275
319
},
276
320
expectedReplacement : & lnrpc.PolicyUpdateRequest {
277
321
Scope : & lnrpc.PolicyUpdateRequest_ChanPoint {
278
322
ChanPoint : & lnrpc.ChannelPoint {
279
323
FundingTxid : & lnrpc.ChannelPoint_FundingTxidStr {
280
- FundingTxidStr : "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd" ,
324
+ FundingTxidStr : clearTxID ,
281
325
},
282
326
OutputIndex : 0 ,
283
327
},
@@ -292,7 +336,7 @@ func TestPrivacyMapper(t *testing.T) {
292
336
FailedUpdates : []* lnrpc.FailedUpdate {
293
337
{
294
338
Outpoint : & lnrpc.OutPoint {
295
- TxidStr : "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd" ,
339
+ TxidStr : clearTxID ,
296
340
OutputIndex : 0 ,
297
341
},
298
342
},
@@ -302,8 +346,8 @@ func TestPrivacyMapper(t *testing.T) {
302
346
FailedUpdates : []* lnrpc.FailedUpdate {
303
347
{
304
348
Outpoint : & lnrpc.OutPoint {
305
- TxidStr : "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384" ,
306
- OutputIndex : 2161781494 ,
349
+ TxidStr : obfusTxID0 ,
350
+ OutputIndex : uint32 ( obfusOut0 ) ,
307
351
},
308
352
},
309
353
},
@@ -332,17 +376,6 @@ func TestPrivacyMapper(t *testing.T) {
332
376
sessionID , err := session .IDFromMacaroon (mac )
333
377
require .NoError (t , err )
334
378
335
- mapPreloadRealToPseudo := map [string ]string {
336
- "Tinker Bell's pub key" : "a44ef01c3bff970ef495c" ,
337
- "000000000000007b" : "47deb774fc605c56" ,
338
- "0000000000000141" : "2fd42e84b9ffaaeb" ,
339
- "00000000000002a6" : "7859bf41241787c2" ,
340
- "000000000000036c" : "1320e5d25b7b5973" ,
341
- "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:0" : "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384:2161781494" ,
342
- "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1" : "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131" ,
343
- "01020304" : "c8134495" ,
344
- }
345
-
346
379
for _ , test := range tests {
347
380
t .Run (test .name , func (t * testing.T ) {
348
381
// Initialize privacy mapping.
@@ -383,6 +416,15 @@ func TestPrivacyMapper(t *testing.T) {
383
416
return
384
417
}
385
418
419
+ // Snippet to print the replacement for debugging, works
420
+ // only for specific test.
421
+ // mes := &lnrpc.PendingChannelsResponse{}
422
+ // err = proto.Unmarshal(
423
+ // feedback.ReplacementSerialized, mes,
424
+ // )
425
+ // require.NoError(t, err)
426
+ // t.Log(mes)
427
+
386
428
expectedRaw , err := proto .Marshal (
387
429
test .expectedReplacement ,
388
430
)
0 commit comments