Skip to content

Commit e573743

Browse files
accounts + main: allow new accounts with 0 balance
1 parent c03b040 commit e573743

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

accounts/service_test.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ func TestAccountService(t *testing.T) {
571571
acct := &OffChainBalanceAccount{
572572
ID: testID,
573573
Type: TypeInitialBalance,
574-
CurrentBalance: 1234,
574+
CurrentBalance: 0,
575575
Invoices: AccountInvoices{
576-
testHash: {},
576+
testHash: {},
577+
testHash2: {},
577578
},
578579
Payments: make(AccountPayments),
579580
}
@@ -589,7 +590,7 @@ func TestAccountService(t *testing.T) {
589590
AddIndex: 12,
590591
SettleIndex: 12,
591592
Hash: testHash,
592-
AmountPaid: 777,
593+
AmountPaid: 1000,
593594
State: invpkg.ContractSettled,
594595
}
595596

@@ -598,7 +599,25 @@ func TestAccountService(t *testing.T) {
598599
acct, err := s.store.Account(testID)
599600
require.NoError(t, err)
600601

601-
return acct.CurrentBalance == (1234 + 777)
602+
return acct.CurrentBalance == 1000
603+
})
604+
605+
// Then settle a second invoice.
606+
lnd.invoiceChan <- &lndclient.Invoice{
607+
AddIndex: 13,
608+
SettleIndex: 13,
609+
Hash: testHash2,
610+
AmountPaid: 777,
611+
State: invpkg.ContractSettled,
612+
}
613+
614+
// Ensure that the balance now adds up to the sum of
615+
// both invoices.
616+
assertEventually(t, func() bool {
617+
acct, err := s.store.Account(testID)
618+
require.NoError(t, err)
619+
620+
return acct.CurrentBalance == (1000 + 777)
602621
})
603622
},
604623
}, {

accounts/store.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ func (s *BoltStore) NewAccount(balance lnwire.MilliSatoshi,
107107
expirationDate time.Time, label string) (*OffChainBalanceAccount,
108108
error) {
109109

110-
if balance == 0 {
111-
return nil, fmt.Errorf("a new account cannot have balance of 0")
112-
}
113-
114110
// If a label is set, it must be unique, as we use it to identify the
115111
// account in some of the RPCs. It also can't be mistaken for a hex
116112
// encoded account ID to avoid confusion and make it easier for the CLI

accounts/store_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ func TestAccountStore(t *testing.T) {
1616
store, err := NewBoltStore(t.TempDir(), DBFilename)
1717
require.NoError(t, err)
1818

19-
// An initial balance of 0 is not allowed, but later we can reach a
20-
// zero balance.
21-
_, err = store.NewAccount(0, time.Time{}, "")
22-
require.ErrorContains(t, err, "cannot have balance of 0")
23-
2419
// Create an account that does not expire.
25-
acct1, err := store.NewAccount(123, time.Time{}, "foo")
20+
acct1, err := store.NewAccount(0, time.Time{}, "foo")
2621
require.NoError(t, err)
2722
require.False(t, acct1.HasExpired())
2823

cmd/litcli/accounts.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ func createAccount(ctx *cli.Context) error {
114114
args = args.Tail()
115115
}
116116

117-
if initialBalance <= 0 {
118-
return fmt.Errorf("initial balance cannot be smaller than 1")
119-
}
120-
121117
req := &litrpc.CreateAccountRequest{
122118
AccountBalance: initialBalance,
123119
ExpirationDate: expirationDate,

0 commit comments

Comments
 (0)