From 1d40ec34a2410483a3553f9702568d58ed3bf256 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 30 Aug 2018 17:12:57 -0400 Subject: [PATCH] account_balance returns Decimal intead of rounded float --- lbrynet/daemon/Daemon.py | 34 +++++++++++------------ tests/integration/wallet/test_commands.py | 9 +++--- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 4d6081e97..b46b606e1 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -1140,23 +1140,21 @@ class Daemon(AuthJSONRPCServer): (map) balance of account(s) """ if account_id: - for account in self.wallet_manager.accounts: - if account.id == account_id: - if include_claims and not isinstance(account, LBCAccount): - raise Exception( - "'--include-claims' requires specifying an LBC ledger account. " - "Found '{}', but it's an {} ledger account." - .format(account_id, account.ledger.symbol) - ) - args = { - 'confirmations': confirmations, - 'include_reserved': include_reserved, - 'include_seed': show_seed - } - if include_claims: - args['include_claims'] = True - return account.get_details(**args) - raise Exception("Couldn't find an account: '{}'.".format(account_id)) + account = self.get_account_or_error('account', account_id) + args = { + 'confirmations': confirmations, + 'include_reserved': include_reserved, + 'include_seed': show_seed + } + if include_claims: + args['include_claims'] = True + if not isinstance(account, LBCAccount): + raise Exception( + "'--include-claims' requires specifying an LBC ledger account. " + "Found '{}', but it's an {} ledger account." + .format(account_id, account.ledger.symbol) + ) + return account.get_details(**args) else: if include_claims: raise Exception("'--include-claims' requires specifying an LBC account by id.") @@ -1185,7 +1183,7 @@ class Daemon(AuthJSONRPCServer): dewies = yield self.default_account.get_balance( 0 if include_unconfirmed else 6 ) - return round(dewies / COIN, 3) + return Decimal(dewies) / COIN @requires("wallet") @defer.inlineCallbacks diff --git a/tests/integration/wallet/test_commands.py b/tests/integration/wallet/test_commands.py index 2d5710d62..286595d8c 100644 --- a/tests/integration/wallet/test_commands.py +++ b/tests/integration/wallet/test_commands.py @@ -2,6 +2,7 @@ import json import tempfile import logging import asyncio +from decimal import Decimal from types import SimpleNamespace from twisted.internet import defer @@ -206,7 +207,7 @@ class EpicAdventuresOfChris45(CommandTestCase): # To get the unconfirmed balance he has to pass the '--include-unconfirmed' # flag to lbrynet: result = yield self.daemon.jsonrpc_account_balance(include_unconfirmed=True) - self.assertEqual(result, 8.99) + self.assertEqual(result, Decimal('8.989893')) # "Well, that's a relief." he thinks to himself as he exhales a sigh of relief. # He waits for a block @@ -227,7 +228,7 @@ class EpicAdventuresOfChris45(CommandTestCase): yield self.d_generate(1) # and it should be 6 total, enough to get the correct balance! result = yield self.daemon.jsonrpc_account_balance() - self.assertEqual(result, 8.99) + self.assertEqual(result, Decimal('8.989893')) # Like a Swiss watch (right niko?) the blockchain never disappoints! We're # at 6 confirmations and the total is correct. @@ -258,7 +259,7 @@ class EpicAdventuresOfChris45(CommandTestCase): # He quickly checks the unconfirmed balance to make sure everything looks # correct. result = yield self.daemon.jsonrpc_account_balance(include_unconfirmed=True) - self.assertEqual(round(result, 2), 7.97) + self.assertEqual(result, Decimal('7.969786')) # Also checks that his new story can be found on the blockchain before # giving the link to all his friends. @@ -270,7 +271,7 @@ class EpicAdventuresOfChris45(CommandTestCase): yield self.d_generate(5) # When he comes back he verifies the confirmed balance. result = yield self.daemon.jsonrpc_account_balance() - self.assertEqual(round(result, 2), 7.97) + self.assertEqual(result, Decimal('7.969786')) # As people start reading his story they discover some typos and notify # Chris who explains in despair "Oh! Noooooos!" but then remembers