@@ -76,26 +76,26 @@ func TestPrivacyMapper(t *testing.T) {
76
76
expectedReplacement : & lnrpc.ForwardingHistoryResponse {
77
77
ForwardingEvents : []* lnrpc.ForwardingEvent {
78
78
{
79
- AmtIn : 1_950 ,
80
- AmtInMsat : 1_950_200 ,
81
- AmtOut : 975 ,
82
- AmtOutMsat : 975_100 ,
83
- Fee : 975 ,
84
- FeeMsat : 975_100 ,
85
- Timestamp : 700 ,
86
- TimestampNs : 700_000_000_100 ,
79
+ AmtIn : 1_900 ,
80
+ AmtInMsat : 1_900_200 ,
81
+ AmtOut : 950 ,
82
+ AmtOutMsat : 950_100 ,
83
+ Fee : 950 ,
84
+ FeeMsat : 950_100 ,
85
+ Timestamp : 400 ,
86
+ TimestampNs : 400_000_000_100 ,
87
87
ChanIdIn : 5178778334600911958 ,
88
88
ChanIdOut : 3446430762436373227 ,
89
89
},
90
90
{
91
- AmtIn : 2_925 ,
92
- AmtInMsat : 2_925_200 ,
93
- AmtOut : 1_950 ,
94
- AmtOutMsat : 1_950_100 ,
95
- Fee : 975 ,
96
- FeeMsat : 975_100 ,
97
- Timestamp : 700 ,
98
- TimestampNs : 700_000_000_100 ,
91
+ AmtIn : 2_850 ,
92
+ AmtInMsat : 2_850_200 ,
93
+ AmtOut : 1_900 ,
94
+ AmtOutMsat : 1_900_100 ,
95
+ Fee : 950 ,
96
+ FeeMsat : 950_100 ,
97
+ Timestamp : 400 ,
98
+ TimestampNs : 400_000_000_100 ,
99
99
ChanIdIn : 8672172843977902018 ,
100
100
ChanIdOut : 1378354177616075123 ,
101
101
},
@@ -167,11 +167,11 @@ func TestPrivacyMapper(t *testing.T) {
167
167
Channels : []* lnrpc.Channel {
168
168
{
169
169
Capacity : 1_000_000 ,
170
- RemoteBalance : 513_375 ,
171
- LocalBalance : 485_625 ,
170
+ RemoteBalance : 525_850 ,
171
+ LocalBalance : 474_150 ,
172
172
CommitFee : 1_000 ,
173
- TotalSatoshisSent : 487_600 ,
174
- TotalSatoshisReceived : 438_850 ,
173
+ TotalSatoshisSent : 475_100 ,
174
+ TotalSatoshisReceived : 427_600 ,
175
175
RemotePubkey : "c8134495" ,
176
176
Initiator : true ,
177
177
ChanId : 5178778334600911958 ,
@@ -362,16 +362,16 @@ func TestPrivacyMapper(t *testing.T) {
362
362
// would also be dependend on the fee variation).
363
363
amtOutMsat := msg .ForwardingEvents [0 ].AmtOutMsat
364
364
amtInterval := uint64 (amountVariation * float64 (amtOutMsat ))
365
- minAmt := amtOutMsat - amtInterval / 2
366
- maxAmt := amtOutMsat + amtInterval / 2
365
+ minAmt := amtOutMsat - amtInterval
366
+ maxAmt := amtOutMsat + amtInterval
367
367
368
368
// We keep track of the timestamp. We test only the timestamp in
369
369
// seconds as there can be numerical inaccuracies with the
370
370
// nanosecond one.
371
371
timestamp := msg .ForwardingEvents [0 ].Timestamp
372
372
timestampInterval := uint64 (timeVariation ) / 1e9
373
- minTime := timestamp - timestampInterval / 2
374
- maxTime := timestamp + timestampInterval / 2
373
+ minTime := timestamp - timestampInterval
374
+ maxTime := timestamp + timestampInterval
375
375
376
376
// We need a certain number of samples to have statistical
377
377
// accuracy.
@@ -537,7 +537,9 @@ func TestRandBetween(t *testing.T) {
537
537
func TestHideAmount (t * testing.T ) {
538
538
testAmount := uint64 (10_000 )
539
539
relativeVariation := 0.05
540
- fuzzInterval := int (float64 (testAmount ) * relativeVariation )
540
+ absoluteVariation := int (float64 (testAmount ) * relativeVariation )
541
+ lowerBound := testAmount - uint64 (absoluteVariation )
542
+ upperBound := testAmount + uint64 (absoluteVariation )
541
543
542
544
tests := []struct {
543
545
name string
@@ -559,21 +561,21 @@ func TestHideAmount(t *testing.T) {
559
561
name : "min value" ,
560
562
randIntFn : func (int ) (int , error ) { return 0 , nil },
561
563
amount : testAmount ,
562
- expected : 9750 ,
564
+ expected : lowerBound ,
563
565
},
564
566
{
565
567
name : "max value" ,
566
568
randIntFn : func (int ) (int , error ) {
567
- return fuzzInterval , nil
569
+ return int ( upperBound - lowerBound ) , nil
568
570
},
569
571
amount : testAmount ,
570
- expected : 10250 ,
572
+ expected : upperBound ,
571
573
},
572
574
{
573
575
name : "some fuzz" ,
574
576
randIntFn : func (int ) (int , error ) { return 123 , nil },
575
577
amount : testAmount ,
576
- expected : 9750 + 123 ,
578
+ expected : lowerBound + 123 ,
577
579
},
578
580
}
579
581
@@ -608,6 +610,8 @@ func TestHideAmount(t *testing.T) {
608
610
func TestHideTimestamp (t * testing.T ) {
609
611
timestamp := time .Unix (1_000_000 , 0 )
610
612
absoluteVariation := time .Duration (10 ) * time .Minute
613
+ lowerBound := timestamp .Add (- absoluteVariation )
614
+ upperBound := timestamp .Add (absoluteVariation )
611
615
612
616
tests := []struct {
613
617
name string
@@ -623,21 +627,21 @@ func TestHideTimestamp(t *testing.T) {
623
627
name : "min value" ,
624
628
randIntFn : func (int ) (int , error ) { return 0 , nil },
625
629
timestamp : timestamp ,
626
- expected : time . Unix ( 999_700 , 0 ) ,
630
+ expected : lowerBound ,
627
631
},
628
632
{
629
633
name : "max value" ,
630
634
randIntFn : func (int ) (int , error ) {
631
- return int (absoluteVariation ), nil
635
+ return int (upperBound . Sub ( lowerBound ) ), nil
632
636
},
633
637
timestamp : timestamp ,
634
- expected : time . Unix ( 1_000_300 , 0 ) ,
638
+ expected : upperBound ,
635
639
},
636
640
{
637
641
name : "some fuzz" ,
638
642
randIntFn : func (int ) (int , error ) { return 123 , nil },
639
643
timestamp : timestamp ,
640
- expected : time .Unix ( 999_700 , 123 ),
644
+ expected : lowerBound . Add ( time .Duration ( 123 ) ),
641
645
},
642
646
}
643
647
0 commit comments