funding: refactor manager test

This commit is contained in:
Oliver Gugger committed 2023-04-18 09:40:17 +02:00
1 parent 37911e2413
commit 68881f5c20
1 file changed
+41 -79
+41 -79
View File
@@ -1085,6 +1085,22 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
t.Helper() t.Helper()
// The following checks are to make sure the parameters are used
// correctly, as we currently only support 2 values, one for each node.
aliceCfg := alice.fundingMgr.cfg
if len(customMinHtlc) > 0 {
require.Len(t, customMinHtlc, 2, "incorrect usage")
}
if len(customMaxHtlc) > 0 {
require.Len(t, customMaxHtlc, 2, "incorrect usage")
}
if len(baseFees) > 0 {
require.Len(t, baseFees, 2, "incorrect usage")
}
if len(feeRates) > 0 {
require.Len(t, feeRates, 2, "incorrect usage")
}
// After the ChannelReady message is sent, Alice and Bob will each send // After the ChannelReady message is sent, Alice and Bob will each send
// the following messages to their gossiper: // the following messages to their gossiper:
// 1) ChannelAnnouncement // 1) ChannelAnnouncement
@@ -1115,102 +1131,50 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
// advertise the MinHTLC value required by the // advertise the MinHTLC value required by the
// _other_ node. // _other_ node.
other := (j + 1) % 2 other := (j + 1) % 2
minHtlc := nodes[other].fundingMgr.cfg. otherCfg := nodes[other].fundingMgr.cfg
DefaultMinHtlcIn
minHtlc := otherCfg.DefaultMinHtlcIn
maxHtlc := aliceCfg.RequiredRemoteMaxValue(
capacity,
)
baseFee := aliceCfg.DefaultRoutingPolicy.BaseFee
feeRate := aliceCfg.DefaultRoutingPolicy.FeeRate
require.EqualValues(t, 1, m.MessageFlags)
// We might expect a custom MinHTLC value. // We might expect a custom MinHTLC value.
if len(customMinHtlc) > 0 { if len(customMinHtlc) > 0 {
if len(customMinHtlc) != 2 {
t.Fatalf("only 0 or 2 custom " +
"min htlc values " +
"currently supported")
}
minHtlc = customMinHtlc[j] minHtlc = customMinHtlc[j]
} }
require.Equal(t, minHtlc, m.HtlcMinimumMsat)
if m.HtlcMinimumMsat != minHtlc {
t.Fatalf("expected ChannelUpdate to "+
"advertise min HTLC %v, had %v",
minHtlc, m.HtlcMinimumMsat)
}
maxHtlc := alice.fundingMgr.cfg.RequiredRemoteMaxValue(
capacity,
)
// We might expect a custom MaxHltc value. // We might expect a custom MaxHltc value.
if len(customMaxHtlc) > 0 { if len(customMaxHtlc) > 0 {
if len(customMaxHtlc) != 2 {
t.Fatalf("only 0 or 2 custom " +
"min htlc values " +
"currently supported")
}
maxHtlc = customMaxHtlc[j] maxHtlc = customMaxHtlc[j]
} }
if m.MessageFlags != 1 { require.Equal(t, maxHtlc, m.HtlcMaximumMsat)
t.Fatalf("expected message flags to "+
"be 1, was %v", m.MessageFlags)
}
if maxHtlc != m.HtlcMaximumMsat {
t.Fatalf("expected ChannelUpdate to "+
"advertise max HTLC %v, had %v",
maxHtlc,
m.HtlcMaximumMsat)
}
baseFee := alice.fundingMgr.cfg.DefaultRoutingPolicy.BaseFee
// We might expect a custom baseFee value. // We might expect a custom baseFee value.
if len(baseFees) > 0 { if len(baseFees) > 0 {
if len(baseFees) != 2 {
t.Fatalf("only 0 or 2 custom " +
"base fee values " +
"currently supported")
}
baseFee = baseFees[j] baseFee = baseFees[j]
} }
require.EqualValues(t, baseFee, m.BaseFee)
if uint32(baseFee) != m.BaseFee {
t.Fatalf("expected ChannelUpdate to "+
"advertise base fee %v, had %v",
baseFee,
m.BaseFee)
}
feeRate := alice.fundingMgr.cfg.DefaultRoutingPolicy.FeeRate
// We might expect a custom feeRate value. // We might expect a custom feeRate value.
if len(feeRates) > 0 { if len(feeRates) > 0 {
if len(feeRates) != 2 {
t.Fatalf("only 0 or 2 custom " +
"fee rate values " +
"currently supported")
}
feeRate = feeRates[j] feeRate = feeRates[j]
} }
require.EqualValues(t, feeRate, m.FeeRate)
if uint32(feeRate) != m.FeeRate {
t.Fatalf("expected ChannelUpdate to "+
"advertise base fee %v, had %v",
feeRate,
m.FeeRate)
}
gotChannelUpdate = true gotChannelUpdate = true
} }
} }
if !gotChannelAnnouncement { require.Truef(
t.Fatalf("did not get ChannelAnnouncement from node %d", t, gotChannelAnnouncement,
j) "ChannelAnnouncement from %d", j,
} )
if !gotChannelUpdate { require.Truef(t, gotChannelUpdate, "ChannelUpdate from %d", j)
t.Fatalf("did not get ChannelUpdate from node %d", j)
}
// Make sure no other message is sent. // Make sure no other message is sent.
select { select {
@@ -1335,14 +1299,12 @@ func assertInitialFwdingPolicyNotFound(t *testing.T, node *testNode,
time.Sleep(testPollSleepMs * time.Millisecond) time.Sleep(testPollSleepMs * time.Millisecond)
} }
fwdingPolicy, err = node.fundingMgr.getInitialFwdingPolicy( fwdingPolicy, err = node.fundingMgr.getInitialFwdingPolicy(
*chanID) *chanID,
if err == channeldb.ErrChannelNotFound { )
// Got expected result, return with success. require.ErrorIs(t, err, channeldb.ErrChannelNotFound)
return
} else if err != nil { // Got expected result, return with success.
t.Fatalf("unable to get forwarding policy from db: %v", return
err)
}
} }
// 10 tries without success. // 10 tries without success.