From 5d6be011f94aee96db14a31d6ae9196940c3a84e Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 14 Feb 2023 15:52:34 +0200 Subject: [PATCH] liquidity: tweak autoloop tests for recurring budget --- liquidity/autoloop_test.go | 65 +++++++++++++------------- liquidity/autoloop_testcontext_test.go | 3 +- liquidity/liquidity_test.go | 14 ++++-- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/liquidity/autoloop_test.go b/liquidity/autoloop_test.go index 8ec3a26..b70a7d9 100644 --- a/liquidity/autoloop_test.go +++ b/liquidity/autoloop_test.go @@ -95,12 +95,12 @@ func TestAutoLoopEnabled(t *testing.T) { // autoloop budget is set to allow exactly 2 swaps at the prices // that we set in our test quotes. params = Parameters{ - Autoloop: true, - AutoFeeBudget: 40066, - AutoFeeStartDate: testTime, - MaxAutoInFlight: 2, - FailureBackOff: time.Hour, - SweepConfTarget: 10, + Autoloop: true, + AutoFeeBudget: 40066, + AutoFeeRefreshPeriod: testBudgetRefresh, + MaxAutoInFlight: 2, + FailureBackOff: time.Hour, + SweepConfTarget: 10, FeeLimit: NewFeeCategoryLimit( swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner, prepayAmount, 20000, @@ -112,6 +112,7 @@ func TestAutoLoopEnabled(t *testing.T) { HtlcConfTarget: defaultHtlcConfTarget, } ) + c := newAutoloopTestCtx(t, params, channels, testRestrictions) c.start() @@ -335,13 +336,13 @@ func TestAutoloopAddress(t *testing.T) { // Create some dummy parameters for autoloop and also specify an // destination address. params = Parameters{ - Autoloop: true, - AutoFeeBudget: 40066, - DestAddr: addr, - AutoFeeStartDate: testTime, - MaxAutoInFlight: 2, - FailureBackOff: time.Hour, - SweepConfTarget: 10, + Autoloop: true, + AutoFeeBudget: 40066, + DestAddr: addr, + AutoFeeRefreshPeriod: testBudgetRefresh, + MaxAutoInFlight: 2, + FailureBackOff: time.Hour, + SweepConfTarget: 10, FeeLimit: NewFeeCategoryLimit( swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner, prepayAmount, 20000, @@ -491,12 +492,12 @@ func TestCompositeRules(t *testing.T) { swapFeePPM, routeFeePPM, prepayFeePPM, maxMiner, prepayAmount, 20000, ), - Autoloop: true, - AutoFeeBudget: 100000, - AutoFeeStartDate: testTime, - MaxAutoInFlight: 2, - FailureBackOff: time.Hour, - SweepConfTarget: 10, + Autoloop: true, + AutoFeeBudget: 100000, + AutoFeeRefreshPeriod: testBudgetRefresh, + MaxAutoInFlight: 2, + FailureBackOff: time.Hour, + SweepConfTarget: 10, ChannelRules: map[lnwire.ShortChannelID]*SwapRule{ chanID1: chanRule, }, @@ -670,13 +671,13 @@ func TestAutoLoopInEnabled(t *testing.T) { peer2MaxFee = ppmToSat(peer2ExpectedAmt, swapFeePPM) params = Parameters{ - Autoloop: true, - AutoFeeBudget: peer1MaxFee + peer2MaxFee + 1, - AutoFeeStartDate: testTime, - MaxAutoInFlight: 2, - FailureBackOff: time.Hour, - FeeLimit: NewFeePortion(swapFeePPM), - ChannelRules: make(map[lnwire.ShortChannelID]*SwapRule), + Autoloop: true, + AutoFeeBudget: peer1MaxFee + peer2MaxFee + 1, + AutoFeeRefreshPeriod: testBudgetRefresh, + MaxAutoInFlight: 2, + FailureBackOff: time.Hour, + FeeLimit: NewFeePortion(swapFeePPM), + ChannelRules: make(map[lnwire.ShortChannelID]*SwapRule), PeerRules: map[route.Vertex]*SwapRule{ peer1: rule, peer2: rule, @@ -853,12 +854,12 @@ func TestAutoloopBothTypes(t *testing.T) { loopInMaxFee = ppmToSat(loopInAmount, swapFeePPM) params = Parameters{ - Autoloop: true, - AutoFeeBudget: loopOutMaxFee + loopInMaxFee + 1, - AutoFeeStartDate: testTime, - MaxAutoInFlight: 2, - FailureBackOff: time.Hour, - FeeLimit: NewFeePortion(swapFeePPM), + Autoloop: true, + AutoFeeBudget: loopOutMaxFee + loopInMaxFee + 1, + AutoFeeRefreshPeriod: testBudgetRefresh, + MaxAutoInFlight: 2, + FailureBackOff: time.Hour, + FeeLimit: NewFeePortion(swapFeePPM), ChannelRules: map[lnwire.ShortChannelID]*SwapRule{ chanID1: outRule, }, diff --git a/liquidity/autoloop_testcontext_test.go b/liquidity/autoloop_testcontext_test.go index 9acfe64..bf25ab1 100644 --- a/liquidity/autoloop_testcontext_test.go +++ b/liquidity/autoloop_testcontext_test.go @@ -117,7 +117,8 @@ func newAutoloopTestCtx(t *testing.T, parameters Parameters, testCtx.lnd.Channels = channels cfg := &Config{ - AutoloopTicker: ticker.NewForce(DefaultAutoloopTicker), + AutoloopTicker: ticker.NewForce(DefaultAutoloopTicker), + AutoloopBudgetLastRefresh: testBudgetStart, Restrictions: func(_ context.Context, swapType swap.Type) (*Restrictions, error) { diff --git a/liquidity/liquidity_test.go b/liquidity/liquidity_test.go index 76343bf..d195d8b 100644 --- a/liquidity/liquidity_test.go +++ b/liquidity/liquidity_test.go @@ -24,6 +24,11 @@ import ( var ( testTime = time.Date(2020, 02, 13, 0, 0, 0, 0, time.UTC) 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) chanID2 = lnwire.NewShortChanIDFromInt(2) @@ -143,8 +148,9 @@ func newTestConfig() (*Config, *test.LndMockServices) { return testRestrictions, nil }, - Lnd: &lnd.LndServices, - Clock: clock.NewTestClock(testTime), + Lnd: &lnd.LndServices, + Clock: clock.NewTestClock(testTime), + AutoloopBudgetLastRefresh: testBudgetStart, ListLoopOut: func() ([]*loopdb.LoopOut, error) { return nil, nil }, @@ -1100,8 +1106,8 @@ func TestFeeBudget(t *testing.T) { chanID1: chanRule, chanID2: chanRule, } - params.AutoFeeStartDate = testBudgetStart params.AutoFeeBudget = testCase.budget + params.AutoFeeRefreshPeriod = testBudgetRefresh params.MaxAutoInFlight = 2 params.FeeLimit = NewFeeCategoryLimit( defaultSwapFeePPM, defaultRoutingFeePPM, @@ -1758,7 +1764,7 @@ func TestBudgetWithLoopin(t *testing.T) { params := defaultParameters params.AutoFeeBudget = budget - params.AutoFeeStartDate = testBudgetStart + params.AutoFeeRefreshPeriod = testBudgetRefresh params.FeeLimit = NewFeePortion(testPPM) params.ChannelRules = map[lnwire.ShortChannelID]*SwapRule{