@@ -119,23 +119,48 @@ func createTestVertex(t testing.TB, v lnwire.GossipVersion) *models.Node {
119119 return createNode (t , v , priv )
120120}
121121
122- // TestNodeInsertionAndDeletion tests the CRUD operations for a Node.
123- func TestNodeInsertionAndDeletion (t * testing.T ) {
122+ type versionedTest struct {
123+ name string
124+ test func (t * testing.T , v lnwire.GossipVersion )
125+ }
126+
127+ var versionedTests = []versionedTest {
128+ {
129+ name : "node crud" ,
130+ test : testNodeInsertionAndDeletion ,
131+ },
132+ }
133+
134+ // TestVersionedDBs runs various tests against both v1 and v2 versioned
135+ // backends.
136+ func TestVersionedDBs (t * testing.T ) {
124137 t .Parallel ()
125- ctx := t .Context ()
126138
127- graph := NewVersionedReader (MakeTestGraph (t ), lnwire .GossipVersion1 )
139+ for _ , vt := range versionedTests {
140+ vt := vt
128141
129- // We'd like to test basic insertion/deletion for vertexes from the
130- // graph, so we'll create a test vertex to start with.
131- timeStamp := int64 (1232342 )
132- nodeWithAddrs := func (addrs []net.Addr ) * models.Node {
133- timeStamp ++
142+ t .Run (vt .name + "/v1" , func (t * testing.T ) {
143+ vt .test (t , lnwire .GossipVersion1 )
144+ })
145+
146+ if ! isSQLDB {
147+ t .Logf ("The rest of the test is for SQL store only" )
148+ return
149+ }
134150
151+ t .Run (vt .name + "/v2" , func (t * testing.T ) {
152+ vt .test (t , lnwire .GossipVersion2 )
153+ })
154+ }
155+ }
156+
157+ // testNodeInsertionAndDeletion tests the CRUD operations for a Node.
158+ func testNodeInsertionAndDeletion (t * testing.T , v lnwire.GossipVersion ) {
159+ nodeWithAddrs := func (addrs []net.Addr ) * models.Node {
135160 return models .NewV1Node (
136161 testPub , & models.NodeV1Fields {
137162 AuthSigBytes : testSig .Serialize (),
138- LastUpdate : time . Unix ( timeStamp , 0 ),
163+ LastUpdate : nextUpdateTime ( ),
139164 Color : color.RGBA {1 , 2 , 3 , 0 },
140165 Alias : "kek" ,
141166 Features : testFeatures .RawFeatureVector ,
@@ -145,6 +170,31 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
145170 )
146171 }
147172
173+ if v == lnwire .GossipVersion2 {
174+ nodeWithAddrs = func (addrs []net.Addr ) * models.Node {
175+ return models .NewV2Node (
176+ testPub , & models.NodeV2Fields {
177+ Signature : testSig .Serialize (),
178+ LastBlockHeight : nextBlockHeight (),
179+ Color : fn .Some (
180+ color.RGBA {1 , 2 , 3 , 0 },
181+ ),
182+ Alias : fn .Some ("kek" ),
183+ Features : testFeatures .
184+ RawFeatureVector ,
185+ Addresses : addrs ,
186+ ExtraSignedFields : map [uint64 ][]byte {
187+ 20 : {0x1 , 0x2 , 0x3 },
188+ 21 : {0x4 , 0x5 , 0x6 , 0x7 },
189+ },
190+ },
191+ )
192+ }
193+ }
194+
195+ ctx := t .Context ()
196+ graph := NewVersionedReader (MakeTestGraph (t ), v )
197+
148198 // First, insert the node into the graph DB. This should succeed
149199 // without any errors.
150200 node := nodeWithAddrs (testAddrs )
@@ -180,7 +230,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
180230 // Check that the node's features are fetched correctly. This check
181231 // will check the database directly.
182232 features , err = graph .ChannelGraph .db .FetchNodeFeatures (
183- lnwire . GossipVersion1 , node .PubKeyBytes ,
233+ v , node .PubKeyBytes ,
184234 )
185235 require .NoError (t , err )
186236 require .Equal (t , testFeatures , features )
0 commit comments