diff --git a/silkaj/money/history.py b/silkaj/money/history.py index 748f2775653e96bcd0abca69c9c6c81d76a32e9d..5d8b18f0f6125512a37f13a947e73fe713b54d8a 100644 --- a/silkaj/money/history.py +++ b/silkaj/money/history.py @@ -27,11 +27,7 @@ from duniterpy.documents.transaction import OutputSource, Transaction from duniterpy.grammars.output import Condition from silkaj.constants import ALL, ALL_DIGITAL -from silkaj.money.tools import ( - amount_in_current_base, - get_amount_from_pubkey, - get_ud_value, -) +from silkaj.money import tools as mt from silkaj.network import client_instance from silkaj.public_key import ( check_pubkey_format, @@ -66,7 +62,7 @@ def transaction_history( pubkey = validate_checksum(pubkey) client = client_instance() - ud_value = get_ud_value() + ud_value = mt.get_ud_value() currency_symbol = get_currency_symbol() received_txs, sent_txs = [], [] # type: list[Transaction], list[Transaction] @@ -107,7 +103,7 @@ def generate_header(pubkey: str, currency_symbol: str, ud_value: int) -> str: idty = wt.identity_of(pubkey) except HTTPError: idty = {"uid": ""} - balance = get_amount_from_pubkey(pubkey) + balance = mt.get_amount_from_pubkey(pubkey) balance_ud = round(balance[1] / ud_value, 2) date = arrow.now().format(ALL) return f"Transactions history from: {idty['uid']} {gen_pubkey_checksum(pubkey)}\n\ @@ -212,7 +208,7 @@ def parse_received_tx( ) amounts = tx_amount(received_tx, pubkey, received_func)[0] tx_list.append(amounts / 100) - tx_list.append(amounts / ud_value) + tx_list.append(round(amounts / ud_value, 2)) tx_list.append(received_tx.comment) received_txs_table.append(tx_list) @@ -258,10 +254,10 @@ def parse_sent_tx( for i, output in enumerate(outputs): if output_available(output.condition, ne, pubkey): amounts += prefix(None, outputs, i) + str( - neg(amount_in_current_base(output)) / 100, + neg(mt.amount_in_current_base(output)) / 100, ) amounts_ud += prefix(None, outputs, i) + str( - round(neg(amount_in_current_base(output)) / ud_value, 2), + round(neg(mt.amount_in_current_base(output)) / ud_value, 2), ) tx_list[1] += prefix(tx_list[1], outputs, 0) + assign_idty_from_pubkey( output.condition.left.pubkey, @@ -293,13 +289,13 @@ def tx_amount( def received_func(output: OutputSource, pubkey: str) -> int: if output_available(output.condition, eq, pubkey): - return amount_in_current_base(output) + return mt.amount_in_current_base(output) return 0 def sent_func(output: OutputSource, pubkey: str) -> int: if output_available(output.condition, ne, pubkey): - return neg(amount_in_current_base(output)) + return neg(mt.amount_in_current_base(output)) return 0 diff --git a/tests/unit/money/test_history.py b/tests/unit/money/test_history.py index 07aed17b883e5029f86b964a938a5cf96386ad06..7770d8d8f0f2b3cc2d89ef30bce26a338532b0d5 100644 --- a/tests/unit/money/test_history.py +++ b/tests/unit/money/test_history.py @@ -24,6 +24,7 @@ from silkaj import tools from silkaj.cli import cli from silkaj.constants import ( ALL_DIGITAL, + CENT_MULT_TO_UNIT, PUBKEY_MAX_LENGTH, PUBKEY_MIN_LENGTH, SHORT_PUBKEY_SIZE, @@ -34,6 +35,7 @@ from silkaj.public_key import CHECKSUM_SIZE from silkaj.wot import tools as wt from tests.patched.blockchain_tools import currency from tests.patched.money import patched_get_ud_value +from tests.patched.test_constants import mock_ud_value from tests.patched.tools import patched_get_currency_symbol from tests.patched.tx_history import patched_get_transactions_history from tests.patched.wot import patched_identities_from_pubkeys @@ -177,34 +179,35 @@ def test_prefix(tx_addresses, outputs, occurence, return_value): assert history.prefix(tx_addresses, outputs, occurence) == return_value +relative_amount = str(round(CENT_MULT_TO_UNIT / mock_ud_value, 2)) csv_reference = ( ["Date", "Issuers/Recipients", "Amounts Äž1", "Amounts UDÄž1", "Comment"], [ arrow.get(111111114).to("local").format(ALL_DIGITAL), "CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB", "1.0", - "0.09041591320072333", + relative_amount, "initialisation", ], [ arrow.get(111111113).to("local").format(ALL_DIGITAL), "CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd:CQ5", "1.0", - "0.09041591320072333", + relative_amount, "", ], [ arrow.get(111111112).to("local").format(ALL_DIGITAL), "CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB", "-1.0", - "-0.09", + f"-{relative_amount}", "", ], [ arrow.get(111111111).to("local").format(ALL_DIGITAL), "CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd:CQ5", "-1.0", - "-0.09", + f"-{relative_amount}", "", ], )