@@ -284,22 +284,24 @@ func TestAccountUpdateMethods(t *testing.T) {
284284
285285 // Assert that calling the method for a non-existent account
286286 // errors out.
287- err = store .UpsertAccountPayment (
287+ _ , err = store .UpsertAccountPayment (
288288 ctx , AccountID {}, lntypes.Hash {}, 0 ,
289289 lnrpc .Payment_UNKNOWN ,
290290 )
291291 require .ErrorIs (t , err , ErrAccNotFound )
292292
293293 // Add a payment to the account but don't update the balance.
294- // We do add a WithErrIfAlreadyPending option here just to show
295- // that no error is returned since the payment does not exist
296- // yet.
294+ // We do add a WithErrIfAlreadyPending and
295+ // WithErrIfAlreadySucceeded option. here just to show that no
296+ // error is returned since the payment does not exist yet.
297297 hash1 := lntypes.Hash {1 , 2 , 3 , 4 }
298- err = store .UpsertAccountPayment (
298+ known , err : = store .UpsertAccountPayment (
299299 ctx , acct .ID , hash1 , 600 , lnrpc .Payment_UNKNOWN ,
300300 WithErrIfAlreadyPending (),
301+ WithErrIfAlreadySucceeded (),
301302 )
302303 require .NoError (t , err )
304+ require .False (t , known )
303305
304306 assertBalanceAndPayments (1000 , AccountPayments {
305307 hash1 : & PaymentEntry {
@@ -311,10 +313,11 @@ func TestAccountUpdateMethods(t *testing.T) {
311313 // Add a second payment to the account and again don't update
312314 // the balance.
313315 hash2 := lntypes.Hash {5 , 6 , 7 , 8 }
314- err = store .UpsertAccountPayment (
316+ known , err = store .UpsertAccountPayment (
315317 ctx , acct .ID , hash2 , 100 , lnrpc .Payment_UNKNOWN ,
316318 )
317319 require .NoError (t , err )
320+ require .False (t , known )
318321
319322 assertBalanceAndPayments (1000 , AccountPayments {
320323 hash1 : & PaymentEntry {
@@ -329,11 +332,12 @@ func TestAccountUpdateMethods(t *testing.T) {
329332
330333 // Now, update the first payment to have a new status and this
331334 // time, debit the account.
332- err = store .UpsertAccountPayment (
335+ known , err = store .UpsertAccountPayment (
333336 ctx , acct .ID , hash1 , 600 , lnrpc .Payment_SUCCEEDED ,
334337 WithDebitAccount (),
335338 )
336339 require .NoError (t , err )
340+ require .True (t , known )
337341
338342 // The account should now have a balance of 400 and the first
339343 // payment should have a status of succeeded.
@@ -350,10 +354,11 @@ func TestAccountUpdateMethods(t *testing.T) {
350354
351355 // Calling the same method again with the same payment hash
352356 // should have no effect by default.
353- err = store .UpsertAccountPayment (
357+ known , err = store .UpsertAccountPayment (
354358 ctx , acct .ID , hash1 , 600 , lnrpc .Payment_SUCCEEDED ,
355359 )
356360 require .NoError (t , err )
361+ require .True (t , known )
357362
358363 assertBalanceAndPayments (400 , AccountPayments {
359364 hash1 : & PaymentEntry {
@@ -368,11 +373,46 @@ func TestAccountUpdateMethods(t *testing.T) {
368373
369374 // But, if we use the WithErrIfAlreadyPending option, we should
370375 // get an error since the payment already exists.
371- err = store .UpsertAccountPayment (
376+ known , err = store .UpsertAccountPayment (
372377 ctx , acct .ID , hash1 , 600 , lnrpc .Payment_SUCCEEDED ,
373378 WithErrIfAlreadyPending (),
374379 )
375380 require .ErrorContains (t , err , "is already in flight" )
381+ require .True (t , known )
382+
383+ // Do the above call again but this time, use the
384+ // WithErrIfAlreadySucceeded option. This should return the
385+ // ErrAlreadySucceeded error since the payment has already
386+ // succeeded.
387+ known , err = store .UpsertAccountPayment (
388+ ctx , acct .ID , hash1 , 600 , lnrpc .Payment_SUCCEEDED ,
389+ WithErrIfAlreadySucceeded (),
390+ )
391+ require .ErrorIs (t , err , ErrAlreadySucceeded )
392+ require .True (t , known )
393+
394+ // We now call the method again for hash 2 and update its status
395+ // to SUCCEEDED. This time, we will use the WithPendingAmount
396+ // option which means that whatever `fullAmount` is passed in
397+ // should be ignored and the pending amount should be used
398+ // instead.
399+ known , err = store .UpsertAccountPayment (
400+ ctx , acct .ID , hash2 , 0 , lnrpc .Payment_SUCCEEDED ,
401+ WithPendingAmount (),
402+ )
403+ require .NoError (t , err )
404+ require .True (t , known )
405+
406+ assertBalanceAndPayments (400 , AccountPayments {
407+ hash1 : & PaymentEntry {
408+ Status : lnrpc .Payment_SUCCEEDED ,
409+ FullAmount : 600 ,
410+ },
411+ hash2 : & PaymentEntry {
412+ Status : lnrpc .Payment_SUCCEEDED ,
413+ FullAmount : 100 ,
414+ },
415+ })
376416 })
377417}
378418
0 commit comments