@@ -76,26 +76,26 @@ func TestPrivacyMapper(t *testing.T) {
7676 expectedReplacement : & lnrpc.ForwardingHistoryResponse {
7777 ForwardingEvents : []* lnrpc.ForwardingEvent {
7878 {
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 ,
8787 ChanIdIn : 5178778334600911958 ,
8888 ChanIdOut : 3446430762436373227 ,
8989 },
9090 {
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 ,
9999 ChanIdIn : 8672172843977902018 ,
100100 ChanIdOut : 1378354177616075123 ,
101101 },
@@ -167,11 +167,11 @@ func TestPrivacyMapper(t *testing.T) {
167167 Channels : []* lnrpc.Channel {
168168 {
169169 Capacity : 1_000_000 ,
170- RemoteBalance : 513_375 ,
171- LocalBalance : 485_625 ,
170+ RemoteBalance : 525_850 ,
171+ LocalBalance : 474_150 ,
172172 CommitFee : 1_000 ,
173- TotalSatoshisSent : 487_600 ,
174- TotalSatoshisReceived : 438_850 ,
173+ TotalSatoshisSent : 475_100 ,
174+ TotalSatoshisReceived : 427_600 ,
175175 RemotePubkey : "c8134495" ,
176176 Initiator : true ,
177177 ChanId : 5178778334600911958 ,
@@ -362,16 +362,16 @@ func TestPrivacyMapper(t *testing.T) {
362362 // would also be dependend on the fee variation).
363363 amtOutMsat := msg .ForwardingEvents [0 ].AmtOutMsat
364364 amtInterval := uint64 (amountVariation * float64 (amtOutMsat ))
365- minAmt := amtOutMsat - amtInterval / 2
366- maxAmt := amtOutMsat + amtInterval / 2
365+ minAmt := amtOutMsat - amtInterval
366+ maxAmt := amtOutMsat + amtInterval
367367
368368 // We keep track of the timestamp. We test only the timestamp in
369369 // seconds as there can be numerical inaccuracies with the
370370 // nanosecond one.
371371 timestamp := msg .ForwardingEvents [0 ].Timestamp
372372 timestampInterval := uint64 (timeVariation ) / 1e9
373- minTime := timestamp - timestampInterval / 2
374- maxTime := timestamp + timestampInterval / 2
373+ minTime := timestamp - timestampInterval
374+ maxTime := timestamp + timestampInterval
375375
376376 // We need a certain number of samples to have statistical
377377 // accuracy.
@@ -537,7 +537,9 @@ func TestRandBetween(t *testing.T) {
537537func TestHideAmount (t * testing.T ) {
538538 testAmount := uint64 (10_000 )
539539 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 )
541543
542544 tests := []struct {
543545 name string
@@ -559,21 +561,21 @@ func TestHideAmount(t *testing.T) {
559561 name : "min value" ,
560562 randIntFn : func (int ) (int , error ) { return 0 , nil },
561563 amount : testAmount ,
562- expected : 9750 ,
564+ expected : lowerBound ,
563565 },
564566 {
565567 name : "max value" ,
566568 randIntFn : func (int ) (int , error ) {
567- return fuzzInterval , nil
569+ return int ( upperBound - lowerBound ) , nil
568570 },
569571 amount : testAmount ,
570- expected : 10250 ,
572+ expected : upperBound ,
571573 },
572574 {
573575 name : "some fuzz" ,
574576 randIntFn : func (int ) (int , error ) { return 123 , nil },
575577 amount : testAmount ,
576- expected : 9750 + 123 ,
578+ expected : lowerBound + 123 ,
577579 },
578580 }
579581
@@ -608,6 +610,8 @@ func TestHideAmount(t *testing.T) {
608610func TestHideTimestamp (t * testing.T ) {
609611 timestamp := time .Unix (1_000_000 , 0 )
610612 absoluteVariation := time .Duration (10 ) * time .Minute
613+ lowerBound := timestamp .Add (- absoluteVariation )
614+ upperBound := timestamp .Add (absoluteVariation )
611615
612616 tests := []struct {
613617 name string
@@ -623,21 +627,21 @@ func TestHideTimestamp(t *testing.T) {
623627 name : "min value" ,
624628 randIntFn : func (int ) (int , error ) { return 0 , nil },
625629 timestamp : timestamp ,
626- expected : time . Unix ( 999_700 , 0 ) ,
630+ expected : lowerBound ,
627631 },
628632 {
629633 name : "max value" ,
630634 randIntFn : func (int ) (int , error ) {
631- return int (absoluteVariation ), nil
635+ return int (upperBound . Sub ( lowerBound ) ), nil
632636 },
633637 timestamp : timestamp ,
634- expected : time . Unix ( 1_000_300 , 0 ) ,
638+ expected : upperBound ,
635639 },
636640 {
637641 name : "some fuzz" ,
638642 randIntFn : func (int ) (int , error ) { return 123 , nil },
639643 timestamp : timestamp ,
640- expected : time .Unix ( 999_700 , 123 ),
644+ expected : lowerBound . Add ( time .Duration ( 123 ) ),
641645 },
642646 }
643647
0 commit comments