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 ()
@@ -490,6 +504,9 @@ func TestListGroupActions(t *testing.T) {
490504}
491505
492506func assertEqualActions (t * testing.T , expected , got * Action ) {
507+ // Accounts are not explicitly linked in our bbolt DB implementation.
508+ got .AccountID = expected .AccountID
509+
493510 expectedAttemptedAt := expected .AttemptedAt
494511 actualAttemptedAt := got .AttemptedAt
495512
@@ -501,4 +518,6 @@ func assertEqualActions(t *testing.T, expected, got *Action) {
501518
502519 expected .AttemptedAt = expectedAttemptedAt
503520 got .AttemptedAt = actualAttemptedAt
521+
522+ got .AccountID = fn .None [accounts.AccountID ]()
504523}
0 commit comments