66 "testing"
77 "time"
88
9+ "github.com/lightninglabs/lightning-terminal/accounts"
910 "github.com/lightninglabs/lightning-terminal/session"
1011 "github.com/lightningnetwork/lnd/clock"
1112 "github.com/lightningnetwork/lnd/fn"
@@ -24,8 +25,9 @@ func TestActionStorage(t *testing.T) {
2425 ctx := context .Background ()
2526 clock := clock .NewTestClock (testTime1 )
2627 sessDB := session .NewTestDB (t , clock )
28+ accountsDB := accounts .NewTestDB (t , clock )
2729
28- db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , clock )
30+ db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , accountsDB , clock )
2931 require .NoError (t , err )
3032 t .Cleanup (func () {
3133 _ = db .Close ()
@@ -38,6 +40,13 @@ func TestActionStorage(t *testing.T) {
3840 })
3941 require .ErrorIs (t , err , session .ErrSessionNotFound )
4042
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+
4150 // Add two sessions to the session DB so that we can reference them.
4251 sess1 , err := sessDB .NewSession (
4352 ctx , "sess 1" , session .TypeAutopilot , time .Unix (1000 , 0 ),
@@ -51,8 +60,13 @@ func TestActionStorage(t *testing.T) {
5160 )
5261 require .NoError (t , err )
5362
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+
5467 action1Req := & AddActionReq {
5568 SessionID : fn .Some (sess1 .ID ),
69+ AccountID : fn .Some (acct1 .ID ),
5670 MacaroonIdentifier : sess1 .ID ,
5771 ActorName : "Autopilot" ,
5872 FeatureName : "auto-fees" ,
@@ -185,7 +199,7 @@ func TestListActions(t *testing.T) {
185199 clock := clock .NewDefaultClock ()
186200 sessDB := session .NewTestDB (t , clock )
187201
188- db , err := NewBoltDB (tmpDir , "test.db" , sessDB , clock )
202+ db , err := NewBoltDB (tmpDir , "test.db" , sessDB , nil , clock )
189203 require .NoError (t , err )
190204 t .Cleanup (func () {
191205 _ = db .Close ()
@@ -452,7 +466,7 @@ func TestListGroupActions(t *testing.T) {
452466 State : ActionStateInit ,
453467 }
454468
455- db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , clock )
469+ db , err := NewBoltDB (t .TempDir (), "test.db" , sessDB , nil , clock )
456470 require .NoError (t , err )
457471 t .Cleanup (func () {
458472 _ = db .Close ()
@@ -488,17 +502,3 @@ func TestListGroupActions(t *testing.T) {
488502 assertEqualActions (t , action1 , al [0 ])
489503 assertEqualActions (t , action2 , al [1 ])
490504}
491-
492- func assertEqualActions (t * testing.T , expected , got * Action ) {
493- expectedAttemptedAt := expected .AttemptedAt
494- actualAttemptedAt := got .AttemptedAt
495-
496- expected .AttemptedAt = time.Time {}
497- got .AttemptedAt = time.Time {}
498-
499- require .Equal (t , expected , got )
500- require .Equal (t , expectedAttemptedAt .Unix (), actualAttemptedAt .Unix ())
501-
502- expected .AttemptedAt = expectedAttemptedAt
503- got .AttemptedAt = actualAttemptedAt
504- }
0 commit comments