lnrpc: refactor populateHopHintsTestCases in addinvoice_test.go

Extract into a separate function the steps to set up the two-channel
mock, to be reused in other cases.
This commit is contained in:
alpeb-btc 2022-10-26 13:13:43 -05:00
parent 143111e368
commit e68ae33c9a
No known key found for this signature in database
GPG key ID: D5ED3433FAD75FDC

View file

@ -668,38 +668,7 @@ var populateHopHintsTestCases = []struct {
name: "populate hop hints stops after having considered all the open " +
"channels",
setupMock: func(h *hopHintsConfigMock) {
fundingOutpoint1 := wire.OutPoint{Index: 9}
chanID1 := lnwire.NewChanIDFromOutPoint(&fundingOutpoint1)
remoteBalance1 := lnwire.MilliSatoshi(10_000_000)
fundingOutpoint2 := wire.OutPoint{Index: 2}
chanID2 := lnwire.NewChanIDFromOutPoint(&fundingOutpoint2)
remoteBalance2 := lnwire.MilliSatoshi(1_000_000)
allChannels := []*channeldb.OpenChannel{
// After sorting we will first process chanID1 and then
// chanID2.
{
LocalCommitment: channeldb.ChannelCommitment{
RemoteBalance: remoteBalance2,
},
FundingOutpoint: fundingOutpoint2,
ShortChannelID: lnwire.NewShortChanIDFromInt(2),
IdentityPub: getTestPubKey(),
},
{
LocalCommitment: channeldb.ChannelCommitment{
RemoteBalance: remoteBalance1,
},
FundingOutpoint: fundingOutpoint1,
ShortChannelID: lnwire.NewShortChanIDFromInt(9),
IdentityPub: getTestPubKey(),
},
}
h.Mock.On(
"FetchAllChannels",
).Once().Return(allChannels, nil)
chanID1, chanID2 := setupMockTwoChannels(h)
// Prepare the mock for the first channel.
h.Mock.On(
@ -752,6 +721,45 @@ var populateHopHintsTestCases = []struct {
},
}}
func setupMockTwoChannels(h *hopHintsConfigMock) (lnwire.ChannelID,
lnwire.ChannelID) {
fundingOutpoint1 := wire.OutPoint{Index: 9}
chanID1 := lnwire.NewChanIDFromOutPoint(&fundingOutpoint1)
remoteBalance1 := lnwire.MilliSatoshi(10_000_000)
fundingOutpoint2 := wire.OutPoint{Index: 2}
chanID2 := lnwire.NewChanIDFromOutPoint(&fundingOutpoint2)
remoteBalance2 := lnwire.MilliSatoshi(1_000_000)
allChannels := []*channeldb.OpenChannel{
// After sorting we will first process chanID1 and then
// chanID2.
{
LocalCommitment: channeldb.ChannelCommitment{
RemoteBalance: remoteBalance2,
},
FundingOutpoint: fundingOutpoint2,
ShortChannelID: lnwire.NewShortChanIDFromInt(2),
IdentityPub: getTestPubKey(),
},
{
LocalCommitment: channeldb.ChannelCommitment{
RemoteBalance: remoteBalance1,
},
FundingOutpoint: fundingOutpoint1,
ShortChannelID: lnwire.NewShortChanIDFromInt(9),
IdentityPub: getTestPubKey(),
},
}
h.Mock.On(
"FetchAllChannels",
).Once().Return(allChannels, nil)
return chanID1, chanID2
}
func TestPopulateHopHints(t *testing.T) {
for _, tc := range populateHopHintsTestCases {
tc := tc