From e54c31d2d500466758d8388d6fc16789399f09de Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Fri, 16 Apr 2021 10:42:51 -0400 Subject: [PATCH] fix bug in how reserved balance is calculated --- lbry/wallet/database.py | 5 ++++- tests/integration/blockchain/test_purchase_command.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lbry/wallet/database.py b/lbry/wallet/database.py index 95cf15b62..2c5777c23 100644 --- a/lbry/wallet/database.py +++ b/lbry/wallet/database.py @@ -1146,7 +1146,10 @@ class Database(SQLiteMixin): 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))})" diff --git a/tests/integration/blockchain/test_purchase_command.py b/tests/integration/blockchain/test_purchase_command.py index 78bc92838..9c110b91c 100644 --- a/tests/integration/blockchain/test_purchase_command.py +++ b/tests/integration/blockchain/test_purchase_command.py @@ -184,7 +184,13 @@ class PurchaseCommandTests(CommandTestCase): 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)