mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
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:
parent
143111e368
commit
e68ae33c9a
1 changed files with 40 additions and 32 deletions
|
@ -668,38 +668,7 @@ var populateHopHintsTestCases = []struct {
|
||||||
name: "populate hop hints stops after having considered all the open " +
|
name: "populate hop hints stops after having considered all the open " +
|
||||||
"channels",
|
"channels",
|
||||||
setupMock: func(h *hopHintsConfigMock) {
|
setupMock: func(h *hopHintsConfigMock) {
|
||||||
fundingOutpoint1 := wire.OutPoint{Index: 9}
|
chanID1, chanID2 := setupMockTwoChannels(h)
|
||||||
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)
|
|
||||||
|
|
||||||
// Prepare the mock for the first channel.
|
// Prepare the mock for the first channel.
|
||||||
h.Mock.On(
|
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) {
|
func TestPopulateHopHints(t *testing.T) {
|
||||||
for _, tc := range populateHopHintsTestCases {
|
for _, tc := range populateHopHintsTestCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
|
|
Loading…
Add table
Reference in a new issue