5
5
"testing"
6
6
"time"
7
7
8
+ "github.com/lightningnetwork/lnd/clock"
8
9
"github.com/lightningnetwork/lnd/fn"
9
10
"github.com/lightningnetwork/lnd/lnrpc"
10
11
"github.com/lightningnetwork/lnd/lntypes"
@@ -17,7 +18,8 @@ func TestAccountStore(t *testing.T) {
17
18
t .Parallel ()
18
19
ctx := context .Background ()
19
20
20
- store := NewTestDB (t )
21
+ clock := clock .NewTestClock (time .Now ())
22
+ store := NewTestDB (t , clock )
21
23
22
24
// Create an account that does not expire.
23
25
acct1 , err := store .NewAccount (ctx , 0 , time.Time {}, "foo" )
@@ -39,7 +41,7 @@ func TestAccountStore(t *testing.T) {
39
41
40
42
// Update all values of the account that we can modify.
41
43
acct1 .CurrentBalance = - 500
42
- acct1 .ExpirationDate = time .Now ()
44
+ acct1 .ExpirationDate = clock .Now ()
43
45
acct1 .Payments [lntypes.Hash {12 , 34 , 56 , 78 }] = & PaymentEntry {
44
46
Status : lnrpc .Payment_FAILED ,
45
47
FullAmount : 123456 ,
@@ -114,7 +116,8 @@ func TestAccountUpdateMethods(t *testing.T) {
114
116
ctx := context .Background ()
115
117
116
118
t .Run ("UpdateAccountBalanceAndExpiry" , func (t * testing.T ) {
117
- store := NewTestDB (t )
119
+ clock := clock .NewTestClock (time .Now ())
120
+ store := NewTestDB (t , clock )
118
121
119
122
// Ensure that the function errors out if we try update an
120
123
// account that does not exist.
@@ -151,7 +154,7 @@ func TestAccountUpdateMethods(t *testing.T) {
151
154
assertBalanceAndExpiry (newBalance , time.Time {})
152
155
153
156
// Now update just the expiry of the account.
154
- newExpiry := time .Now ().Add (time .Hour )
157
+ newExpiry := clock .Now ().Add (time .Hour )
155
158
err = store .UpdateAccountBalanceAndExpiry (
156
159
ctx , acct .ID , fn .None [lnwire.MilliSatoshi ](),
157
160
fn .Some (newExpiry ),
@@ -161,7 +164,7 @@ func TestAccountUpdateMethods(t *testing.T) {
161
164
162
165
// Update both the balance and expiry of the account.
163
166
newBalance = 456
164
- newExpiry = time .Now ().Add (2 * time .Hour )
167
+ newExpiry = clock .Now ().Add (2 * time .Hour )
165
168
err = store .UpdateAccountBalanceAndExpiry (
166
169
ctx , acct .ID , fn .Some (newBalance ), fn .Some (newExpiry ),
167
170
)
@@ -179,7 +182,7 @@ func TestAccountUpdateMethods(t *testing.T) {
179
182
})
180
183
181
184
t .Run ("AddAccountInvoice" , func (t * testing.T ) {
182
- store := NewTestDB (t )
185
+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
183
186
184
187
acct , err := store .NewAccount (ctx , 0 , time.Time {}, "foo" )
185
188
require .NoError (t , err )
@@ -231,7 +234,7 @@ func TestAccountUpdateMethods(t *testing.T) {
231
234
})
232
235
233
236
t .Run ("IncreaseAccountBalance" , func (t * testing.T ) {
234
- store := NewTestDB (t )
237
+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
235
238
236
239
// Increasing the balance of an account that doesn't exist
237
240
// should error out.
@@ -259,7 +262,7 @@ func TestAccountUpdateMethods(t *testing.T) {
259
262
})
260
263
261
264
t .Run ("Upsert and Delete AccountPayment" , func (t * testing.T ) {
262
- store := NewTestDB (t )
265
+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
263
266
264
267
acct , err := store .NewAccount (ctx , 1000 , time.Time {}, "foo" )
265
268
require .NoError (t , err )
@@ -507,7 +510,7 @@ func TestLastInvoiceIndexes(t *testing.T) {
507
510
t .Parallel ()
508
511
ctx := context .Background ()
509
512
510
- store := NewTestDB (t )
513
+ store := NewTestDB (t , clock . NewTestClock ( time . Now ()) )
511
514
512
515
_ , _ , err := store .LastIndexes (ctx )
513
516
require .ErrorIs (t , err , ErrNoInvoiceIndexKnown )
0 commit comments