graph/db: convert testEdgePolicyCRUD to versioned test
Convert testEdgePolicyCRUD to a versioned test that runs against both v1 and v2 gossip versions. Update the test to use version-specific edge creation helpers and to test version-specific fields and flag behavior (ChannelFlags/MessageFlags for v1, DisableFlags/ ExtraSignedFields for v2).
This commit is contained in:
1 file changed
+48
-15
+48
-15
@@ -146,6 +146,10 @@ var versionedTests = []versionedTest{
|
|||||||
name: "edge insertion deletion",
|
name: "edge insertion deletion",
|
||||||
test: testEdgeInsertionDeletion,
|
test: testEdgeInsertionDeletion,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "edge policy crud",
|
||||||
|
test: testEdgePolicyCRUD,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "partial node",
|
name: "partial node",
|
||||||
test: testPartialNode,
|
test: testPartialNode,
|
||||||
@@ -1182,18 +1186,28 @@ func TestEdgeInfoUpdates(t *testing.T) {
|
|||||||
assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo)
|
assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestEdgePolicyCRUD tests basic CRUD operations for edge policies.
|
// testEdgePolicyCRUD tests basic CRUD operations for edge policies.
|
||||||
func TestEdgePolicyCRUD(t *testing.T) {
|
func testEdgePolicyCRUD(t *testing.T, v lnwire.GossipVersion) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
graph := MakeTestGraph(t)
|
graph := NewVersionedGraph(MakeTestGraph(t), v)
|
||||||
|
|
||||||
node1 := createTestVertex(t, lnwire.GossipVersion1)
|
node1 := createTestVertex(t, v)
|
||||||
node2 := createTestVertex(t, lnwire.GossipVersion1)
|
node2 := createTestVertex(t, v)
|
||||||
|
|
||||||
// Create an edge. Don't add it to the DB yet.
|
// Create an edge. Don't add it to the DB yet.
|
||||||
edgeInfo, edge1, edge2 := createChannelEdge(node1, node2)
|
edgeInfo, shortChanID := createEdge(
|
||||||
|
v, 100, 1, 0, 0, node1, node2,
|
||||||
|
)
|
||||||
|
chanID := shortChanID.ToUint64()
|
||||||
|
|
||||||
|
edge1 := newEdgePolicy(v, chanID, nextUpdateTime().Unix(), true)
|
||||||
|
edge2 := newEdgePolicy(v, chanID, nextUpdateTime().Unix(), false)
|
||||||
|
edge1.ToNode = edgeInfo.NodeKey2Bytes
|
||||||
|
edge2.ToNode = edgeInfo.NodeKey1Bytes
|
||||||
|
edge1.SigBytes = testSig.Serialize()
|
||||||
|
edge2.SigBytes = testSig.Serialize()
|
||||||
|
|
||||||
updateAndAssertPolicies := func() {
|
updateAndAssertPolicies := func() {
|
||||||
// Make copies of the policies before calling UpdateEdgePolicy
|
// Make copies of the policies before calling UpdateEdgePolicy
|
||||||
@@ -1202,8 +1216,14 @@ func TestEdgePolicyCRUD(t *testing.T) {
|
|||||||
edge1 := copyEdgePolicy(edge1)
|
edge1 := copyEdgePolicy(edge1)
|
||||||
edge2 := copyEdgePolicy(edge2)
|
edge2 := copyEdgePolicy(edge2)
|
||||||
|
|
||||||
edge1.LastUpdate = nextUpdateTime()
|
switch v {
|
||||||
edge2.LastUpdate = nextUpdateTime()
|
case lnwire.GossipVersion1:
|
||||||
|
edge1.LastUpdate = nextUpdateTime()
|
||||||
|
edge2.LastUpdate = nextUpdateTime()
|
||||||
|
case lnwire.GossipVersion2:
|
||||||
|
edge1.LastBlockHeight = nextBlockHeight()
|
||||||
|
edge2.LastBlockHeight = nextBlockHeight()
|
||||||
|
}
|
||||||
|
|
||||||
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
|
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
|
||||||
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2))
|
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2))
|
||||||
@@ -1219,7 +1239,7 @@ func TestEdgePolicyCRUD(t *testing.T) {
|
|||||||
// assert that the deserialized policies match the original
|
// assert that the deserialized policies match the original
|
||||||
// ones.
|
// ones.
|
||||||
err := graph.ForEachChannel(
|
err := graph.ForEachChannel(
|
||||||
ctx, lnwire.GossipVersion1,
|
ctx,
|
||||||
func(info *models.ChannelEdgeInfo,
|
func(info *models.ChannelEdgeInfo,
|
||||||
policy1 *models.ChannelEdgePolicy,
|
policy1 *models.ChannelEdgePolicy,
|
||||||
policy2 *models.ChannelEdgePolicy) error {
|
policy2 *models.ChannelEdgePolicy) error {
|
||||||
@@ -1251,13 +1271,26 @@ func TestEdgePolicyCRUD(t *testing.T) {
|
|||||||
|
|
||||||
updateAndAssertPolicies()
|
updateAndAssertPolicies()
|
||||||
|
|
||||||
// Update one of the edges to have ChannelFlags include a bit unknown
|
switch v {
|
||||||
// to us.
|
case lnwire.GossipVersion1:
|
||||||
edge1.ChannelFlags |= 1 << 6
|
// Update one of the edges to have ChannelFlags include a bit
|
||||||
|
// unknown to us.
|
||||||
|
edge1.ChannelFlags |= 1 << 6
|
||||||
|
|
||||||
// Update the other edge to have MessageFlags include a bit unknown to
|
// Update the other edge to have MessageFlags include a bit
|
||||||
// us.
|
// unknown to us.
|
||||||
edge2.MessageFlags |= 1 << 4
|
edge2.MessageFlags |= 1 << 4
|
||||||
|
|
||||||
|
case lnwire.GossipVersion2:
|
||||||
|
// Update one of the edges to have DisableFlags include a bit
|
||||||
|
// unknown to us.
|
||||||
|
edge1.DisableFlags |= 1 << 6
|
||||||
|
|
||||||
|
// Update the other edge to have a modified extra signed field.
|
||||||
|
edge2.ExtraSignedFields = map[uint64][]byte{
|
||||||
|
200: {0x4, 0x5},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateAndAssertPolicies()
|
updateAndAssertPolicies()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user