55 "testing"
66 "time"
77
8+ "github.com/lightningnetwork/lnd/clock"
89 "github.com/lightningnetwork/lnd/fn"
910 "github.com/lightningnetwork/lnd/lnrpc"
1011 "github.com/lightningnetwork/lnd/lntypes"
@@ -17,7 +18,8 @@ func TestAccountStore(t *testing.T) {
1718 t .Parallel ()
1819 ctx := context .Background ()
1920
20- store := NewTestDB (t )
21+ clock := clock .NewTestClock (time .Now ())
22+ store := NewTestDB (t , clock )
2123
2224 // Create an account that does not expire.
2325 acct1 , err := store .NewAccount (ctx , 0 , time.Time {}, "foo" )
@@ -39,7 +41,7 @@ func TestAccountStore(t *testing.T) {
3941
4042 // Update all values of the account that we can modify.
4143 acct1 .CurrentBalance = - 500
42- acct1 .ExpirationDate = time .Now ()
44+ acct1 .ExpirationDate = clock .Now ()
4345 acct1 .Payments [lntypes.Hash {12 , 34 , 56 , 78 }] = & PaymentEntry {
4446 Status : lnrpc .Payment_FAILED ,
4547 FullAmount : 123456 ,
@@ -114,7 +116,8 @@ func TestAccountUpdateMethods(t *testing.T) {
114116 ctx := context .Background ()
115117
116118 t .Run ("UpdateAccountBalanceAndExpiry" , func (t * testing.T ) {
117- store := NewTestDB (t )
119+ clock := clock .NewTestClock (time .Now ())
120+ store := NewTestDB (t , clock )
118121
119122 // Ensure that the function errors out if we try update an
120123 // account that does not exist.
@@ -151,7 +154,7 @@ func TestAccountUpdateMethods(t *testing.T) {
151154 assertBalanceAndExpiry (newBalance , time.Time {})
152155
153156 // Now update just the expiry of the account.
154- newExpiry := time .Now ().Add (time .Hour )
157+ newExpiry := clock .Now ().Add (time .Hour )
155158 err = store .UpdateAccountBalanceAndExpiry (
156159 ctx , acct .ID , fn .None [lnwire.MilliSatoshi ](),
157160 fn .Some (newExpiry ),
@@ -161,7 +164,7 @@ func TestAccountUpdateMethods(t *testing.T) {
161164
162165 // Update both the balance and expiry of the account.
163166 newBalance = 456
164- newExpiry = time .Now ().Add (2 * time .Hour )
167+ newExpiry = clock .Now ().Add (2 * time .Hour )
165168 err = store .UpdateAccountBalanceAndExpiry (
166169 ctx , acct .ID , fn .Some (newBalance ), fn .Some (newExpiry ),
167170 )
@@ -179,7 +182,7 @@ func TestAccountUpdateMethods(t *testing.T) {
179182 })
180183
181184 t .Run ("AddAccountInvoice" , func (t * testing.T ) {
182- store := NewTestDB (t )
185+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
183186
184187 acct , err := store .NewAccount (ctx , 0 , time.Time {}, "foo" )
185188 require .NoError (t , err )
@@ -231,7 +234,7 @@ func TestAccountUpdateMethods(t *testing.T) {
231234 })
232235
233236 t .Run ("IncreaseAccountBalance" , func (t * testing.T ) {
234- store := NewTestDB (t )
237+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
235238
236239 // Increasing the balance of an account that doesn't exist
237240 // should error out.
@@ -265,7 +268,7 @@ func TestLastInvoiceIndexes(t *testing.T) {
265268 t .Parallel ()
266269 ctx := context .Background ()
267270
268- store := NewTestDB (t )
271+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
269272
270273 _ , _ , err := store .LastIndexes (ctx )
271274 require .ErrorIs (t , err , ErrNoInvoiceIndexKnown )
0 commit comments