graph/tests: make randEdgePolicy assert internally
What changed, and why it matters
This commit only changes a test helper function in LND's graph test code. It makes the helper report its own errors instead of returning them to callers. There is no change to production code, user-facing behavior, or security-sensitive logic.
No security action needed. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors randEdgePolicy in graph/notifications_test.go to accept a testing.TB parameter, call t.Helper(), and use require.NoError internally for extraOpaqueData.PackRecords. Call sites are simplified by removing the returned error and the immediate require.NoError checks. This is a pure test-code ergonomics improvement with no functional or security implications.
Changed components
graph/notifications_test.goInspect captured patch +8 / −10
diff --git a/graph/notifications_test.go b/graph/notifications_test.go
index 340cdaf..bef6ebd 100644
--- a/graph/notifications_test.go
+++ b/graph/notifications_test.go
@@ -98,8 +98,10 @@ func createTestNode(t *testing.T) *models.Node {
return n
}
-func randEdgePolicy(chanID *lnwire.ShortChannelID,
- node *models.Node) (*models.ChannelEdgePolicy, error) {
+func randEdgePolicy(t testing.TB, chanID *lnwire.ShortChannelID,
+ node *models.Node) *models.ChannelEdgePolicy {
+
+ t.Helper()
InboundFee := models.InboundFee{
Base: prand.Int31() * -1,
@@ -108,9 +110,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID,
inboundFee := InboundFee.ToWire()
var extraOpaqueData lnwire.ExtraOpaqueData
- if err := extraOpaqueData.PackRecords(&inboundFee); err != nil {
- return nil, err
- }
+ require.NoError(t, extraOpaqueData.PackRecords(&inboundFee))
return &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
@@ -125,7 +125,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID,
ToNode: node.PubKeyBytes,
InboundFee: fn.Some(inboundFee),
ExtraOpaqueData: extraOpaqueData,
- }, nil
+ }
}
func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte,
@@ -480,12 +480,10 @@ func TestEdgeUpdateNotification(t *testing.T) {
// Create random policy edges that are stemmed to the channel id
// created above.
- edge1, err := randEdgePolicy(chanID, node1)
- require.NoError(t, err, "unable to create a random chan policy")
+ edge1 := randEdgePolicy(t, chanID, node1)
edge1.ChannelFlags = 0
- edge2, err := randEdgePolicy(chanID, node2)
- require.NoError(t, err, "unable to create a random chan policy")
+ edge2 := randEdgePolicy(t, chanID, node2)
edge2.ChannelFlags = 1
require.NoError(t, ctx.builder.UpdateEdge(ctxb, edge1))
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.