liquidity: tweak autoloop tests for recurring budget

pull/551/head
George Tsagkarelis 1 year ago
parent b025b9ae37
commit 5d6be011f9
No known key found for this signature in database
GPG Key ID: 0807D1013F48208A

@ -95,12 +95,12 @@ func TestAutoLoopEnabled(t *testing.T) {
// autoloop budget is set to allow exactly 2 swaps at the prices // autoloop budget is set to allow exactly 2 swaps at the prices
// that we set in our test quotes. // that we set in our test quotes.
params = Parameters{ params = Parameters{
Autoloop: true, Autoloop: true,
AutoFeeBudget: 40066, AutoFeeBudget: 40066,
AutoFeeStartDate: testTime, AutoFeeRefreshPeriod: testBudgetRefresh,
MaxAutoInFlight: 2, MaxAutoInFlight: 2,
FailureBackOff: time.Hour, FailureBackOff: time.Hour,
SweepConfTarget: 10, SweepConfTarget: 10,
FeeLimit: NewFeeCategoryLimit( FeeLimit: NewFeeCategoryLimit(
swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner, swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner,
prepayAmount, 20000, prepayAmount, 20000,
@ -112,6 +112,7 @@ func TestAutoLoopEnabled(t *testing.T) {
HtlcConfTarget: defaultHtlcConfTarget, HtlcConfTarget: defaultHtlcConfTarget,
} }
) )
c := newAutoloopTestCtx(t, params, channels, testRestrictions) c := newAutoloopTestCtx(t, params, channels, testRestrictions)
c.start() c.start()
@ -335,13 +336,13 @@ func TestAutoloopAddress(t *testing.T) {
// Create some dummy parameters for autoloop and also specify an // Create some dummy parameters for autoloop and also specify an
// destination address. // destination address.
params = Parameters{ params = Parameters{
Autoloop: true, Autoloop: true,
AutoFeeBudget: 40066, AutoFeeBudget: 40066,
DestAddr: addr, DestAddr: addr,
AutoFeeStartDate: testTime, AutoFeeRefreshPeriod: testBudgetRefresh,
MaxAutoInFlight: 2, MaxAutoInFlight: 2,
FailureBackOff: time.Hour, FailureBackOff: time.Hour,
SweepConfTarget: 10, SweepConfTarget: 10,
FeeLimit: NewFeeCategoryLimit( FeeLimit: NewFeeCategoryLimit(
swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner, swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner,
prepayAmount, 20000, prepayAmount, 20000,
@ -491,12 +492,12 @@ func TestCompositeRules(t *testing.T) {
swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner, swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner,
prepayAmount, 20000, prepayAmount, 20000,
), ),
Autoloop: true, Autoloop: true,
AutoFeeBudget: 100000, AutoFeeBudget: 100000,
AutoFeeStartDate: testTime, AutoFeeRefreshPeriod: testBudgetRefresh,
MaxAutoInFlight: 2, MaxAutoInFlight: 2,
FailureBackOff: time.Hour, FailureBackOff: time.Hour,
SweepConfTarget: 10, SweepConfTarget: 10,
ChannelRules: map[lnwire.ShortChannelID]*SwapRule{ ChannelRules: map[lnwire.ShortChannelID]*SwapRule{
chanID1: chanRule, chanID1: chanRule,
}, },
@ -670,13 +671,13 @@ func TestAutoLoopInEnabled(t *testing.T) {
peer2MaxFee = ppmToSat(peer2ExpectedAmt, swapFeePPM) peer2MaxFee = ppmToSat(peer2ExpectedAmt, swapFeePPM)
params = Parameters{ params = Parameters{
Autoloop: true, Autoloop: true,
AutoFeeBudget: peer1MaxFee + peer2MaxFee + 1, AutoFeeBudget: peer1MaxFee + peer2MaxFee + 1,
AutoFeeStartDate: testTime, AutoFeeRefreshPeriod: testBudgetRefresh,
MaxAutoInFlight: 2, MaxAutoInFlight: 2,
FailureBackOff: time.Hour, FailureBackOff: time.Hour,
FeeLimit: NewFeePortion(swapFeePPM), FeeLimit: NewFeePortion(swapFeePPM),
ChannelRules: make(map[lnwire.ShortChannelID]*SwapRule), ChannelRules: make(map[lnwire.ShortChannelID]*SwapRule),
PeerRules: map[route.Vertex]*SwapRule{ PeerRules: map[route.Vertex]*SwapRule{
peer1: rule, peer1: rule,
peer2: rule, peer2: rule,
@ -853,12 +854,12 @@ func TestAutoloopBothTypes(t *testing.T) {
loopInMaxFee = ppmToSat(loopInAmount, swapFeePPM) loopInMaxFee = ppmToSat(loopInAmount, swapFeePPM)
params = Parameters{ params = Parameters{
Autoloop: true, Autoloop: true,
AutoFeeBudget: loopOutMaxFee + loopInMaxFee + 1, AutoFeeBudget: loopOutMaxFee + loopInMaxFee + 1,
AutoFeeStartDate: testTime, AutoFeeRefreshPeriod: testBudgetRefresh,
MaxAutoInFlight: 2, MaxAutoInFlight: 2,
FailureBackOff: time.Hour, FailureBackOff: time.Hour,
FeeLimit: NewFeePortion(swapFeePPM), FeeLimit: NewFeePortion(swapFeePPM),
ChannelRules: map[lnwire.ShortChannelID]*SwapRule{ ChannelRules: map[lnwire.ShortChannelID]*SwapRule{
chanID1: outRule, chanID1: outRule,
}, },

@ -117,7 +117,8 @@ func newAutoloopTestCtx(t *testing.T, parameters Parameters,
testCtx.lnd.Channels = channels testCtx.lnd.Channels = channels
cfg := &Config{ cfg := &Config{
AutoloopTicker: ticker.NewForce(DefaultAutoloopTicker), AutoloopTicker: ticker.NewForce(DefaultAutoloopTicker),
AutoloopBudgetLastRefresh: testBudgetStart,
Restrictions: func(_ context.Context, swapType swap.Type) (*Restrictions, Restrictions: func(_ context.Context, swapType swap.Type) (*Restrictions,
error) { error) {

@ -24,6 +24,11 @@ import (
var ( var (
testTime = time.Date(2020, 02, 13, 0, 0, 0, 0, time.UTC) testTime = time.Date(2020, 02, 13, 0, 0, 0, 0, time.UTC)
testBudgetStart = testTime.Add(time.Hour * -1) testBudgetStart = testTime.Add(time.Hour * -1)
// In order to not influence existing tests we set the budget refresh
// period to 10 years so that it will never be refreshed. This way the
// behavior of autoloop remains identical to before recurring budget was
// introduced.
testBudgetRefresh = time.Hour * 24 * 365 * 10
chanID1 = lnwire.NewShortChanIDFromInt(1) chanID1 = lnwire.NewShortChanIDFromInt(1)
chanID2 = lnwire.NewShortChanIDFromInt(2) chanID2 = lnwire.NewShortChanIDFromInt(2)
@ -143,8 +148,9 @@ func newTestConfig() (*Config, *test.LndMockServices) {
return testRestrictions, nil return testRestrictions, nil
}, },
Lnd: &lnd.LndServices, Lnd: &lnd.LndServices,
Clock: clock.NewTestClock(testTime), Clock: clock.NewTestClock(testTime),
AutoloopBudgetLastRefresh: testBudgetStart,
ListLoopOut: func() ([]*loopdb.LoopOut, error) { ListLoopOut: func() ([]*loopdb.LoopOut, error) {
return nil, nil return nil, nil
}, },
@ -1100,8 +1106,8 @@ func TestFeeBudget(t *testing.T) {
chanID1: chanRule, chanID1: chanRule,
chanID2: chanRule, chanID2: chanRule,
} }
params.AutoFeeStartDate = testBudgetStart
params.AutoFeeBudget = testCase.budget params.AutoFeeBudget = testCase.budget
params.AutoFeeRefreshPeriod = testBudgetRefresh
params.MaxAutoInFlight = 2 params.MaxAutoInFlight = 2
params.FeeLimit = NewFeeCategoryLimit( params.FeeLimit = NewFeeCategoryLimit(
defaultSwapFeePPM, defaultRoutingFeePPM, defaultSwapFeePPM, defaultRoutingFeePPM,
@ -1758,7 +1764,7 @@ func TestBudgetWithLoopin(t *testing.T) {
params := defaultParameters params := defaultParameters
params.AutoFeeBudget = budget params.AutoFeeBudget = budget
params.AutoFeeStartDate = testBudgetStart params.AutoFeeRefreshPeriod = testBudgetRefresh
params.FeeLimit = NewFeePortion(testPPM) params.FeeLimit = NewFeePortion(testPPM)
params.ChannelRules = map[lnwire.ShortChannelID]*SwapRule{ params.ChannelRules = map[lnwire.ShortChannelID]*SwapRule{

Loading…
Cancel
Save