liquidity: add clock for mocking time in tests

pull/289/head
carla 4 years ago
parent 7e9034b2ff
commit ad8b5d0552
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -14,6 +14,7 @@ require (
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d
github.com/lightningnetwork/lnd v0.11.1-beta.rc3 github.com/lightningnetwork/lnd v0.11.1-beta.rc3
github.com/lightningnetwork/lnd/cert v1.0.3 github.com/lightningnetwork/lnd/cert v1.0.3
github.com/lightningnetwork/lnd/clock v1.0.1
github.com/lightningnetwork/lnd/queue v1.0.4 github.com/lightningnetwork/lnd/queue v1.0.4
github.com/stretchr/testify v1.5.1 github.com/stretchr/testify v1.5.1
github.com/urfave/cli v1.20.0 github.com/urfave/cli v1.20.0

@ -13,6 +13,7 @@ import (
"github.com/lightninglabs/lndclient" "github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -57,6 +58,9 @@ type Config struct {
// Lnd provides us with access to lnd's rpc servers. // Lnd provides us with access to lnd's rpc servers.
Lnd *lndclient.LndServices Lnd *lndclient.LndServices
// Clock allows easy mocking of time in unit tests.
Clock clock.Clock
} }
// Parameters is a set of parameters provided by the user which guide // Parameters is a set of parameters provided by the user which guide

@ -3,16 +3,20 @@ package liquidity
import ( import (
"context" "context"
"testing" "testing"
"time"
"github.com/lightninglabs/lndclient" "github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/test" "github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var ( var (
testTime = time.Date(2020, 02, 13, 0, 0, 0, 0, time.UTC)
chanID1 = lnwire.NewShortChanIDFromInt(1) chanID1 = lnwire.NewShortChanIDFromInt(1)
chanID2 = lnwire.NewShortChanIDFromInt(2) chanID2 = lnwire.NewShortChanIDFromInt(2)
@ -55,7 +59,8 @@ func newTestConfig() (*Config, *test.LndMockServices) {
return NewRestrictions(1, 10000), nil return NewRestrictions(1, 10000), nil
}, },
Lnd: &lnd.LndServices, Lnd: &lnd.LndServices,
Clock: clock.NewTestClock(testTime),
}, lnd }, lnd
} }

@ -7,6 +7,7 @@ import (
"github.com/lightninglabs/lndclient" "github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/liquidity" "github.com/lightninglabs/loop/liquidity"
"github.com/lightningnetwork/lnd/clock"
) )
// getClient returns an instance of the swap client. // getClient returns an instance of the swap client.
@ -46,7 +47,8 @@ func getLiquidityManager(client *loop.Client) *liquidity.Manager {
outTerms.MinSwapAmount, outTerms.MaxSwapAmount, outTerms.MinSwapAmount, outTerms.MaxSwapAmount,
), nil ), nil
}, },
Lnd: client.LndServices, Lnd: client.LndServices,
Clock: clock.NewDefaultClock(),
} }
return liquidity.NewManager(mngrCfg) return liquidity.NewManager(mngrCfg)

Loading…
Cancel
Save