What changed, and why it matters
This commit only adds and reorganizes test code. It introduces a new test helper that runs existing node database tests against both v1 and v2 gossip data formats, and refactors one existing test to use that helper. There is no change to production code, runtime behavior, or security-sensitive logic.
No security action needed. This is a routine test-only refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies graph/db/graph_test.go. It replaces TestNodeInsertionAndDeletion with a versionedTest struct, a versionedTests registry, a new TestVersionedDBs entry point, and a renamed testNodeInsertionAndDeletion helper that accepts a GossipVersion parameter. The helper creates v1 or v2 node models depending on the version and runs the same CRUD assertions. No non-test source files are changed.
Changed components
graph/db/graph_test.goInspect captured patch +59 / −9
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 894d308..d7ceb06 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -120,22 +120,47 @@ func createTestVertex(t testing.TB, v lnwire.GossipVersion) *models.Node {
return createNode(t, v, priv)
}
-// TestNodeInsertionAndDeletion tests the CRUD operations for a Node.
-func TestNodeInsertionAndDeletion(t *testing.T) {
+type versionedTest struct {
+ name string
+ test func(t *testing.T, v lnwire.GossipVersion)
+}
+
+var versionedTests = []versionedTest{
+ {
+ name: "node crud",
+ test: testNodeInsertionAndDeletion,
+ },
+}
+
+// TestVersionedDBs runs various tests against both v1 and v2 versioned
+// backends.
+func TestVersionedDBs(t *testing.T) {
t.Parallel()
- ctx := t.Context()
- graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1)
+ for _, vt := range versionedTests {
+ vt := vt
+
+ t.Run(vt.name+"/v1", func(t *testing.T) {
+ vt.test(t, lnwire.GossipVersion1)
+ })
+
+ if !isSQLDB {
+ continue
+ }
+
+ t.Run(vt.name+"/v2", func(t *testing.T) {
+ vt.test(t, lnwire.GossipVersion2)
+ })
+ }
+}
- // We'd like to test basic insertion/deletion for vertexes from the
- // graph, so we'll create a test vertex to start with.
- timeStamp := int64(1232342)
+// testNodeInsertionAndDeletion tests the CRUD operations for a Node.
+func testNodeInsertionAndDeletion(t *testing.T, v lnwire.GossipVersion) {
nodeWithAddrs := func(addrs []net.Addr) *models.Node {
- timeStamp++
return models.NewV1Node(
testPub, &models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
- LastUpdate: time.Unix(timeStamp, 0),
+ LastUpdate: nextUpdateTime(),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek",
Features: testFeatures.RawFeatureVector,
@@ -145,6 +170,31 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
)
}
+ if v == lnwire.GossipVersion2 {
+ nodeWithAddrs = func(addrs []net.Addr) *models.Node {
+ return models.NewV2Node(
+ testPub, &models.NodeV2Fields{
+ Signature: testSig.Serialize(),
+ LastBlockHeight: nextBlockHeight(),
+ Color: fn.Some(
+ color.RGBA{1, 2, 3, 0},
+ ),
+ Alias: fn.Some("kek"),
+ Features: testFeatures.
+ RawFeatureVector,
+ Addresses: addrs,
+ ExtraSignedFields: map[uint64][]byte{
+ 20: {0x1, 0x2, 0x3},
+ 21: {0x4, 0x5, 0x6, 0x7},
+ },
+ },
+ )
+ }
+ }
+
+ ctx := t.Context()
+ graph := NewVersionedGraph(MakeTestGraph(t), v)
+
// First, insert the node into the graph DB. This should succeed
// without any errors.
node := nodeWithAddrs(testAddrs)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.