@@ -158,6 +158,53 @@ func TestAccountUpdateMethods(t *testing.T) {
158158 require .NoError (t , err )
159159 assertBalanceAndExpiry (newBalance , newExpiry )
160160 })
161+
162+ t .Run ("AddAccountInvoice" , func (t * testing.T ) {
163+ store := NewTestDB (t )
164+
165+ acct , err := store .NewAccount (ctx , 0 , time.Time {}, "foo" )
166+ require .NoError (t , err )
167+
168+ assertInvoices := func (invoices ... lntypes.Hash ) {
169+ dbAcct , err := store .Account (ctx , acct .ID )
170+ require .NoError (t , err )
171+
172+ // First make sure the number of invoices match before
173+ // de-duping the hashes.
174+ require .Len (t , dbAcct .Invoices , len (invoices ))
175+
176+ dbInvs := make ([]lntypes.Hash , 0 , len (dbAcct .Invoices ))
177+ for hash := range dbAcct .Invoices {
178+ dbInvs = append (dbInvs , hash )
179+ }
180+
181+ require .ElementsMatch (t , invoices , dbInvs )
182+ }
183+
184+ // The account initially has no invoices.
185+ assertInvoices ()
186+
187+ // Add an invoice to the account.
188+ hash1 := lntypes.Hash {1 , 2 , 3 , 4 }
189+ err = store .AddAccountInvoice (ctx , acct .ID , hash1 )
190+ require .NoError (t , err )
191+
192+ assertInvoices (hash1 )
193+
194+ // Assert that adding the same invoice again does not change the
195+ // state.
196+ err = store .AddAccountInvoice (ctx , acct .ID , hash1 )
197+ require .NoError (t , err )
198+
199+ assertInvoices (hash1 )
200+
201+ // Now add a second invoice.
202+ hash2 := lntypes.Hash {5 , 6 , 7 , 8 }
203+ err = store .AddAccountInvoice (ctx , acct .ID , hash2 )
204+ require .NoError (t , err )
205+
206+ assertInvoices (hash1 , hash2 )
207+ })
161208}
162209
163210// TestLastInvoiceIndexes makes sure the last known invoice indexes can be
0 commit comments