6
6
"testing"
7
7
"time"
8
8
9
+ "github.com/lightninglabs/lightning-terminal/accounts"
9
10
"github.com/lightninglabs/lightning-terminal/session"
10
11
"github.com/lightningnetwork/lnd/clock"
11
12
"github.com/lightningnetwork/lnd/fn"
@@ -24,8 +25,9 @@ func TestActionStorage(t *testing.T) {
24
25
ctx := context .Background ()
25
26
clock := clock .NewTestClock (testTime1 )
26
27
sessDB := session .NewTestDB (t , clock )
28
+ accountsDB := accounts .NewTestDB (t , clock )
27
29
28
- db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , clock )
30
+ db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , accountsDB , clock )
29
31
require .NoError (t , err )
30
32
t .Cleanup (func () {
31
33
_ = db .Close ()
@@ -38,6 +40,13 @@ func TestActionStorage(t *testing.T) {
38
40
})
39
41
require .ErrorIs (t , err , session .ErrSessionNotFound )
40
42
43
+ // Assert that attempting to add an action that links to an account
44
+ // that does not exist returns an error.
45
+ _ , err = db .AddAction (ctx , & AddActionReq {
46
+ AccountID : fn .Some (accounts.AccountID {1 , 2 , 3 , 4 }),
47
+ })
48
+ require .ErrorIs (t , err , accounts .ErrAccNotFound )
49
+
41
50
// Add two sessions to the session DB so that we can reference them.
42
51
sess1 , err := sessDB .NewSession (
43
52
ctx , "sess 1" , session .TypeAutopilot , time .Unix (1000 , 0 ),
@@ -51,8 +60,13 @@ func TestActionStorage(t *testing.T) {
51
60
)
52
61
require .NoError (t , err )
53
62
63
+ // Add an account that we can link to as well.
64
+ acct1 , err := accountsDB .NewAccount (ctx , 0 , time.Time {}, "foo" )
65
+ require .NoError (t , err )
66
+
54
67
action1Req := & AddActionReq {
55
68
SessionID : fn .Some (sess1 .ID ),
69
+ AccountID : fn .Some (acct1 .ID ),
56
70
MacaroonIdentifier : sess1 .ID ,
57
71
ActorName : "Autopilot" ,
58
72
FeatureName : "auto-fees" ,
@@ -185,7 +199,7 @@ func TestListActions(t *testing.T) {
185
199
clock := clock .NewDefaultClock ()
186
200
sessDB := session .NewTestDB (t , clock )
187
201
188
- db , err := NewBoltDB (tmpDir , "test.db" , sessDB , clock )
202
+ db , err := NewBoltDB (tmpDir , "test.db" , sessDB , nil , clock )
189
203
require .NoError (t , err )
190
204
t .Cleanup (func () {
191
205
_ = db .Close ()
@@ -452,7 +466,7 @@ func TestListGroupActions(t *testing.T) {
452
466
State : ActionStateInit ,
453
467
}
454
468
455
- db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , clock )
469
+ db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , nil , clock )
456
470
require .NoError (t , err )
457
471
t .Cleanup (func () {
458
472
_ = db .Close ()
@@ -490,6 +504,9 @@ func TestListGroupActions(t *testing.T) {
490
504
}
491
505
492
506
func assertEqualActions (t * testing.T , expected , got * Action ) {
507
+ // Accounts are not explicitly linked in our bbolt DB implementation.
508
+ got .AccountID = expected .AccountID
509
+
493
510
expectedAttemptedAt := expected .AttemptedAt
494
511
actualAttemptedAt := got .AttemptedAt
495
512
@@ -501,4 +518,6 @@ func assertEqualActions(t *testing.T, expected, got *Action) {
501
518
502
519
expected .AttemptedAt = expectedAttemptedAt
503
520
got .AttemptedAt = actualAttemptedAt
521
+
522
+ got .AccountID = fn .None [accounts.AccountID ]()
504
523
}
0 commit comments