@@ -14,6 +14,7 @@ import (
14
14
"time"
15
15
16
16
"github.com/davecgh/go-spew/spew"
17
+ "github.com/lightningnetwork/lnd/lnwire"
17
18
"github.com/roasbeef/btcd/btcec"
18
19
"github.com/roasbeef/btcd/chaincfg/chainhash"
19
20
"github.com/roasbeef/btcd/wire"
35
36
}
36
37
_ , _ = testSig .R .SetString ("63724406601629180062774974542967536251589935445068131219452686511677818569431" , 10 )
37
38
_ , _ = testSig .S .SetString ("18801056069249825825291287104931333862866033135609736119018462340006816851118" , 10 )
39
+
40
+ testFeatures = lnwire .NewFeatureVector ([]lnwire.Feature {})
38
41
)
39
42
40
43
func createTestVertex (db * DB ) (* LightningNode , error ) {
@@ -48,10 +51,11 @@ func createTestVertex(db *DB) (*LightningNode, error) {
48
51
pub := priv .PubKey ().SerializeCompressed ()
49
52
return & LightningNode {
50
53
LastUpdate : time .Unix (updateTime , 0 ),
51
- Addresses : testAddrs ,
52
54
PubKey : priv .PubKey (),
53
55
Color : color.RGBA {1 , 2 , 3 , 0 },
54
56
Alias : "kek" + string (pub [:]),
57
+ Features : testFeatures ,
58
+ Addresses : testAddrs ,
55
59
db : db ,
56
60
}, nil
57
61
}
@@ -70,10 +74,11 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
70
74
_ , testPub := btcec .PrivKeyFromBytes (btcec .S256 (), key [:])
71
75
node := & LightningNode {
72
76
LastUpdate : time .Unix (1232342 , 0 ),
73
- Addresses : testAddrs ,
74
77
PubKey : testPub ,
75
78
Color : color.RGBA {1 , 2 , 3 , 0 },
76
79
Alias : "kek" ,
80
+ Features : testFeatures ,
81
+ Addresses : testAddrs ,
77
82
db : db ,
78
83
}
79
84
@@ -97,9 +102,8 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
97
102
}
98
103
99
104
// The two nodes should match exactly!
100
- if ! reflect .DeepEqual (node , dbNode ) {
101
- t .Fatalf ("retrieved node doesn't match: expected %#v\n , got %#v\n " ,
102
- node , dbNode )
105
+ if err := compareNodes (node , dbNode ); err != nil {
106
+ t .Fatalf ("nodes don't match: %v" , err )
103
107
}
104
108
105
109
// Next, delete the node from the graph, this should purge all data
@@ -194,9 +198,8 @@ func TestSourceNode(t *testing.T) {
194
198
if err != nil {
195
199
t .Fatalf ("unable to fetch source node: %v" , err )
196
200
}
197
- if ! reflect .DeepEqual (testNode , sourceNode ) {
198
- t .Fatalf ("nodes don't match, expected %#v \n got %#v" ,
199
- testNode , sourceNode )
201
+ if err := compareNodes (testNode , sourceNode ); err != nil {
202
+ t .Fatalf ("nodes don't match: %v" , err )
200
203
}
201
204
}
202
205
@@ -454,13 +457,11 @@ func TestEdgeInfoUpdates(t *testing.T) {
454
457
if err != nil {
455
458
t .Fatalf ("unable to fetch channel by ID: %v" , err )
456
459
}
457
- if ! reflect .DeepEqual (dbEdge1 , edge1 ) {
458
- t .Fatalf ("edge doesn't match: expected %#v, \n got %#v" , edge1 ,
459
- dbEdge1 )
460
+ if err := compareEdgePolicies (dbEdge1 , edge1 ); err != nil {
461
+ t .Fatalf ("edge doesn't match: %v" , err )
460
462
}
461
- if ! reflect .DeepEqual (dbEdge2 , edge2 ) {
462
- t .Fatalf ("edge doesn't match: expected %#v, \n got %#v" , edge2 ,
463
- dbEdge2 )
463
+ if err := compareEdgePolicies (dbEdge2 , edge2 ); err != nil {
464
+ t .Fatalf ("edge doesn't match: %v" , err )
464
465
}
465
466
assertEdgeInfoEqual (t , dbEdgeInfo , edgeInfo )
466
467
@@ -470,13 +471,11 @@ func TestEdgeInfoUpdates(t *testing.T) {
470
471
if err != nil {
471
472
t .Fatalf ("unable to fetch channel by ID: %v" , err )
472
473
}
473
- if ! reflect .DeepEqual (dbEdge1 , edge1 ) {
474
- t .Fatalf ("edge doesn't match: expected %#v, \n got %#v" , edge1 ,
475
- dbEdge1 )
474
+ if err := compareEdgePolicies (dbEdge1 , edge1 ); err != nil {
475
+ t .Fatalf ("edge doesn't match: %v" , err )
476
476
}
477
- if ! reflect .DeepEqual (dbEdge2 , edge2 ) {
478
- t .Fatalf ("edge doesn't match: expected %#v, \n got %#v" , edge2 ,
479
- dbEdge2 )
477
+ if err := compareEdgePolicies (dbEdge2 , edge2 ); err != nil {
478
+ t .Fatalf ("edge doesn't match: %v" , err )
480
479
}
481
480
assertEdgeInfoEqual (t , dbEdgeInfo , edgeInfo )
482
481
}
@@ -830,3 +829,77 @@ func TestGraphPruning(t *testing.T) {
830
829
assertPruneTip (t , graph , & blockHash , blockHeight )
831
830
asserNumChans (t , graph , 0 )
832
831
}
832
+
833
+ // compareNodes is used to compare two LightningNodes while excluding the
834
+ // Features struct, which cannot be compared as the semantics for reserializing
835
+ // the featuresMap have not been defined.
836
+ func compareNodes (a , b * LightningNode ) error {
837
+ if ! reflect .DeepEqual (a .LastUpdate , b .LastUpdate ) {
838
+ return fmt .Errorf ("LastUpdate doesn't match: expected %#v, \n " +
839
+ "got %#v" , a .LastUpdate , b .LastUpdate )
840
+ }
841
+ if ! reflect .DeepEqual (a .Addresses , b .Addresses ) {
842
+ return fmt .Errorf ("Addresses doesn't match: expected %#v, \n " +
843
+ "got %#v" , a .Addresses , b .Addresses )
844
+ }
845
+ if ! reflect .DeepEqual (a .PubKey , b .PubKey ) {
846
+ return fmt .Errorf ("PubKey doesn't match: expected %#v, \n " +
847
+ "got %#v" , a .PubKey , b .PubKey )
848
+ }
849
+ if ! reflect .DeepEqual (a .Color , b .Color ) {
850
+ return fmt .Errorf ("Color doesn't match: expected %#v, \n " +
851
+ "got %#v" , a .Color , b .Color )
852
+ }
853
+ if ! reflect .DeepEqual (a .Alias , b .Alias ) {
854
+ return fmt .Errorf ("Alias doesn't match: expected %#v, \n " +
855
+ "got %#v" , a .Alias , b .Alias )
856
+ }
857
+ if ! reflect .DeepEqual (a .db , b .db ) {
858
+ return fmt .Errorf ("db doesn't match: expected %#v, \n " +
859
+ "got %#v" , a .db , b .db )
860
+ }
861
+
862
+ return nil
863
+ }
864
+
865
+ // compareEdgePolicies is used to compare two ChannelEdgePolices using
866
+ // compareNodes, so as to exclude comparisons of the Nodes' Features struct.
867
+ func compareEdgePolicies (a , b * ChannelEdgePolicy ) error {
868
+ if a .ChannelID != b .ChannelID {
869
+ return fmt .Errorf ("ChannelID doesn't match: expected %v, " +
870
+ "got %v" , a .ChannelID , b .ChannelID )
871
+ }
872
+ if ! reflect .DeepEqual (a .LastUpdate , b .LastUpdate ) {
873
+ return fmt .Errorf ("LastUpdate doesn't match: expected %#v, \n " +
874
+ "got %#v" , a .LastUpdate , b .LastUpdate )
875
+ }
876
+ if a .Flags != b .Flags {
877
+ return fmt .Errorf ("Flags doesn't match: expected %v, " +
878
+ "got %v" , a .Flags , b .Flags )
879
+ }
880
+ if a .TimeLockDelta != b .TimeLockDelta {
881
+ return fmt .Errorf ("TimeLockDelta doesn't match: expected %v, " +
882
+ "got %v" , a .TimeLockDelta , b .TimeLockDelta )
883
+ }
884
+ if a .MinHTLC != b .MinHTLC {
885
+ return fmt .Errorf ("MinHTLC doesn't match: expected %v, " +
886
+ "got %v" , a .MinHTLC , b .MinHTLC )
887
+ }
888
+ if a .FeeBaseMSat != b .FeeBaseMSat {
889
+ return fmt .Errorf ("FeeBaseMSat doesn't match: expected %v, " +
890
+ "got %v" , a .FeeBaseMSat , b .FeeBaseMSat )
891
+ }
892
+ if a .FeeProportionalMillionths != b .FeeProportionalMillionths {
893
+ return fmt .Errorf ("FeeProportionalMillionths doesn't match: " +
894
+ "expected %v, got %v" , a .FeeProportionalMillionths ,
895
+ b .FeeProportionalMillionths )
896
+ }
897
+ if err := compareNodes (a .Node , b .Node ); err != nil {
898
+ return err
899
+ }
900
+ if ! reflect .DeepEqual (a .db , b .db ) {
901
+ return fmt .Errorf ("db doesn't match: expected %#v, \n " +
902
+ "got %#v" , a .db , b .db )
903
+ }
904
+ return nil
905
+ }
0 commit comments