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