graph/tests: make randEdgePolicy assert internally
Update randEdgePolicy to take a testing handle, mark itself as a helper, and assert internal packing errors directly with require. Call sites now receive only the policy value without plumbing an error through immediate require.NoError checks.
This commit is contained in:
1 file changed
+8
-10
@@ -98,8 +98,10 @@ func createTestNode(t *testing.T) *models.Node {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
func randEdgePolicy(t testing.TB, chanID *lnwire.ShortChannelID,
|
||||||
node *models.Node) (*models.ChannelEdgePolicy, error) {
|
node *models.Node) *models.ChannelEdgePolicy {
|
||||||
|
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
InboundFee := models.InboundFee{
|
InboundFee := models.InboundFee{
|
||||||
Base: prand.Int31() * -1,
|
Base: prand.Int31() * -1,
|
||||||
@@ -108,9 +110,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
|||||||
inboundFee := InboundFee.ToWire()
|
inboundFee := InboundFee.ToWire()
|
||||||
|
|
||||||
var extraOpaqueData lnwire.ExtraOpaqueData
|
var extraOpaqueData lnwire.ExtraOpaqueData
|
||||||
if err := extraOpaqueData.PackRecords(&inboundFee); err != nil {
|
require.NoError(t, extraOpaqueData.PackRecords(&inboundFee))
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &models.ChannelEdgePolicy{
|
return &models.ChannelEdgePolicy{
|
||||||
Version: lnwire.GossipVersion1,
|
Version: lnwire.GossipVersion1,
|
||||||
@@ -125,7 +125,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
|||||||
ToNode: node.PubKeyBytes,
|
ToNode: node.PubKeyBytes,
|
||||||
InboundFee: fn.Some(inboundFee),
|
InboundFee: fn.Some(inboundFee),
|
||||||
ExtraOpaqueData: extraOpaqueData,
|
ExtraOpaqueData: extraOpaqueData,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte,
|
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
|
// Create random policy edges that are stemmed to the channel id
|
||||||
// created above.
|
// created above.
|
||||||
edge1, err := randEdgePolicy(chanID, node1)
|
edge1 := randEdgePolicy(t, chanID, node1)
|
||||||
require.NoError(t, err, "unable to create a random chan policy")
|
|
||||||
edge1.ChannelFlags = 0
|
edge1.ChannelFlags = 0
|
||||||
|
|
||||||
edge2, err := randEdgePolicy(chanID, node2)
|
edge2 := randEdgePolicy(t, chanID, node2)
|
||||||
require.NoError(t, err, "unable to create a random chan policy")
|
|
||||||
edge2.ChannelFlags = 1
|
edge2.ChannelFlags = 1
|
||||||
|
|
||||||
require.NoError(t, ctx.builder.UpdateEdge(ctxb, edge1))
|
require.NoError(t, ctx.builder.UpdateEdge(ctxb, edge1))
|
||||||
|
|||||||
Reference in new issue
Block a user