2020 testTimeout = time .Millisecond * 500
2121 testInterval = time .Millisecond * 20
2222
23- testHash2 = lntypes.Hash {99 , 88 , 77 }
23+ testID2 = AccountID {22 , 22 , 22 }
24+
25+ testHash2 = lntypes.Hash {2 , 2 , 2 , 2 , 2 }
26+ testHash3 = lntypes.Hash {3 , 3 , 3 , 3 , 3 }
2427)
2528
2629type mockLnd struct {
@@ -623,8 +626,10 @@ func TestAccountService(t *testing.T) {
623626 }, {
624627 name : "in-flight payments" ,
625628 setup : func (t * testing.T , lnd * mockLnd , s * InterceptorService ) {
626- // We set up our account with a balance of 5k msats and
627- // two in-flight payments with a total or 3k msats.
629+ // We set up two accounts with a balance of 5k msats.
630+
631+ // The first account has two in-flight payments, one of
632+ // 2k msats and one of 1k msats, totaling 3k msats.
628633 acct := & OffChainBalanceAccount {
629634 ID : testID ,
630635 Type : TypeInitialBalance ,
@@ -646,12 +651,34 @@ func TestAccountService(t *testing.T) {
646651
647652 err := s .store .UpdateAccount (acct )
648653 require .NoError (t , err )
654+
655+ // The second account has one in-flight payment of 4k
656+ // msats.
657+ acct2 := & OffChainBalanceAccount {
658+ ID : testID2 ,
659+ Type : TypeInitialBalance ,
660+ CurrentBalance : 5000 ,
661+ Invoices : AccountInvoices {
662+ testHash : {},
663+ },
664+ Payments : AccountPayments {
665+ testHash3 : {
666+ Status : lnrpc .Payment_IN_FLIGHT ,
667+ FullAmount : 4000 ,
668+ },
669+ },
670+ }
671+
672+ err = s .store .UpdateAccount (acct2 )
673+ require .NoError (t , err )
649674 },
650675 validate : func (t * testing.T , lnd * mockLnd ,
651676 s * InterceptorService ) {
652677
653- // We should be able to initiate another payment with an
654- // amount smaller or equal to 2k msats.
678+ // The first should be able to initiate another payment
679+ // with an amount smaller or equal to 2k msats. This
680+ // also asserts that the second accounts in-flight
681+ // payment doesn't affect the first account.
655682 err := s .CheckBalance (testID , 2000 )
656683 require .NoError (t , err )
657684
@@ -670,6 +697,15 @@ func TestAccountService(t *testing.T) {
670697 err = s .CheckBalance (testID , 4000 )
671698 return err == nil
672699 })
700+
701+ // The second account should be able to initiate a
702+ // payment of 1k msats.
703+ err = s .CheckBalance (testID2 , 1000 )
704+ require .NoError (t , err )
705+
706+ // But exactly one sat over it should fail.
707+ err = s .CheckBalance (testID2 , 1001 )
708+ require .ErrorIs (t , err , ErrAccBalanceInsufficient )
673709 },
674710 }}
675711
0 commit comments