Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in how reserved balance is calculated #3264

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lbry/wallet/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,10 @@ async def get_detailed_balance(self, accounts, read_only=False, **constraints):
constraints['accounts'] = accounts
result = (await self.select_txos(
f"COALESCE(SUM(amount), 0) AS total,"
f"COALESCE(SUM(CASE WHEN txo_type != {TXO_TYPES['other']} THEN amount ELSE 0 END), 0) AS reserved,"
f"COALESCE(SUM("
f" CASE WHEN"
f" txo_type NOT IN ({TXO_TYPES['other']}, {TXO_TYPES['purchase']})"
f" THEN amount ELSE 0 END), 0) AS reserved,"
f"COALESCE(SUM("
f" CASE WHEN"
f" txo_type IN ({','.join(map(str, CLAIM_TYPES))})"
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/blockchain/test_purchase_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ async def test_seller_can_spend_received_purchase_funds(self):
await self.generate(1)
await self.ledger.wait(purchase)

await self.assertBalance(self.account, '10.987893')
# confirm that available and reserved take into account purchase received
self.assertEqual(await self.account.get_detailed_balance(), {
'total': 1099789300,
'available': 1098789300,
'reserved': 1000000,
'reserved_subtotals': {'claims': 1000000, 'supports': 0, 'tips': 0}
})
self.assertItemCount(await self.daemon.jsonrpc_utxo_list(), 2)

spend = await self.daemon.jsonrpc_wallet_send('10.5', address2)
Expand Down