20
20
testTimeout = time .Millisecond * 500
21
21
testInterval = time .Millisecond * 20
22
22
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 }
24
27
)
25
28
26
29
type mockLnd struct {
@@ -623,8 +626,10 @@ func TestAccountService(t *testing.T) {
623
626
}, {
624
627
name : "in-flight payments" ,
625
628
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.
628
633
acct := & OffChainBalanceAccount {
629
634
ID : testID ,
630
635
Type : TypeInitialBalance ,
@@ -646,12 +651,34 @@ func TestAccountService(t *testing.T) {
646
651
647
652
err := s .store .UpdateAccount (acct )
648
653
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 )
649
674
},
650
675
validate : func (t * testing.T , lnd * mockLnd ,
651
676
s * InterceptorService ) {
652
677
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.
655
682
err := s .CheckBalance (testID , 2000 )
656
683
require .NoError (t , err )
657
684
@@ -670,6 +697,15 @@ func TestAccountService(t *testing.T) {
670
697
err = s .CheckBalance (testID , 4000 )
671
698
return err == nil
672
699
})
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 )
673
709
},
674
710
}}
675
711
0 commit comments