@@ -430,6 +430,74 @@ func TestAccountUpdateMethods(t *testing.T) {
430430 // error.
431431 err = store .DeleteAccountPayment (ctx , acct .ID , hash1 )
432432 require .ErrorIs (t , err , ErrPaymentNotAssociated )
433+
434+ // Try once more to insert a payment that is currently unknown
435+ // but this time add the WithErrIfUnknown option. This should
436+ // return the ErrPaymentNotAssociated error.
437+ _ , err = store .UpsertAccountPayment (
438+ ctx , acct .ID , hash1 , 600 , lnrpc .Payment_SUCCEEDED ,
439+ WithErrIfUnknown (),
440+ )
441+ require .ErrorIs (t , err , ErrPaymentNotAssociated )
442+
443+ // Show that using the two options WithErrIfUnknown and
444+ // WithPendingAmount together will return the
445+ // ErrPaymentNotAssociated and will not successfully update
446+ // the status. We call this for hash1 since it is no longer
447+ // known. We do this to simulate the behaviour of
448+ // removePayment.
449+ _ , err = store .UpsertAccountPayment (
450+ ctx , acct .ID , hash1 , 0 , lnrpc .Payment_SUCCEEDED ,
451+ WithErrIfUnknown (),
452+ WithPendingAmount (),
453+ )
454+ require .ErrorIs (t , err , ErrPaymentNotAssociated )
455+
456+ assertBalanceAndPayments (400 , AccountPayments {
457+ hash2 : & PaymentEntry {
458+ Status : lnrpc .Payment_SUCCEEDED ,
459+ FullAmount : 100 ,
460+ },
461+ })
462+
463+ // Now insert hash 1 again.
464+ known , err = store .UpsertAccountPayment (
465+ ctx , acct .ID , hash1 , 600 , lnrpc .Payment_IN_FLIGHT ,
466+ )
467+ require .NoError (t , err )
468+
469+ assertBalanceAndPayments (400 , AccountPayments {
470+ hash1 : & PaymentEntry {
471+ Status : lnrpc .Payment_IN_FLIGHT ,
472+ FullAmount : 600 ,
473+ },
474+ hash2 : & PaymentEntry {
475+ Status : lnrpc .Payment_SUCCEEDED ,
476+ FullAmount : 100 ,
477+ },
478+ })
479+
480+ // Once again call UpsertAccountPayment with both the
481+ // WithErrIfUnknown and WithPendingAmount options. This time
482+ // it should succeed since the payment is now known and so the
483+ // status should be updated.
484+ _ , err = store .UpsertAccountPayment (
485+ ctx , acct .ID , hash1 , 0 , lnrpc .Payment_SUCCEEDED ,
486+ WithErrIfUnknown (),
487+ WithPendingAmount (),
488+ )
489+ require .NoError (t , err )
490+
491+ assertBalanceAndPayments (400 , AccountPayments {
492+ hash1 : & PaymentEntry {
493+ Status : lnrpc .Payment_SUCCEEDED ,
494+ FullAmount : 600 ,
495+ },
496+ hash2 : & PaymentEntry {
497+ Status : lnrpc .Payment_SUCCEEDED ,
498+ FullAmount : 100 ,
499+ },
500+ })
433501 })
434502}
435503
0 commit comments