Skip to content
Snippets Groups Projects
Commit 4b4d3e0b authored by Moul's avatar Moul
Browse files

Fix history CSV test (#258)

UD got reevaluated and the test no longer work
since get_ud_value() was not patched (#328)
In money.history: import tools module not the objects

sent relative amounts are rounded to two digits
Also round to two digits received relative amounts
for consistency
parent 82ca0273
No related branches found
No related tags found
1 merge request!276Fix history CSV test (#258)
Pipeline #40195 passed
...@@ -27,11 +27,7 @@ from duniterpy.documents.transaction import OutputSource, Transaction ...@@ -27,11 +27,7 @@ from duniterpy.documents.transaction import OutputSource, Transaction
from duniterpy.grammars.output import Condition from duniterpy.grammars.output import Condition
from silkaj.constants import ALL, ALL_DIGITAL from silkaj.constants import ALL, ALL_DIGITAL
from silkaj.money.tools import ( from silkaj.money import tools as mt
amount_in_current_base,
get_amount_from_pubkey,
get_ud_value,
)
from silkaj.network import client_instance from silkaj.network import client_instance
from silkaj.public_key import ( from silkaj.public_key import (
check_pubkey_format, check_pubkey_format,
...@@ -66,7 +62,7 @@ def transaction_history( ...@@ -66,7 +62,7 @@ def transaction_history(
pubkey = validate_checksum(pubkey) pubkey = validate_checksum(pubkey)
client = client_instance() client = client_instance()
ud_value = get_ud_value() ud_value = mt.get_ud_value()
currency_symbol = get_currency_symbol() currency_symbol = get_currency_symbol()
received_txs, sent_txs = [], [] # type: list[Transaction], list[Transaction] 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: ...@@ -107,7 +103,7 @@ def generate_header(pubkey: str, currency_symbol: str, ud_value: int) -> str:
idty = wt.identity_of(pubkey) idty = wt.identity_of(pubkey)
except HTTPError: except HTTPError:
idty = {"uid": ""} idty = {"uid": ""}
balance = get_amount_from_pubkey(pubkey) balance = mt.get_amount_from_pubkey(pubkey)
balance_ud = round(balance[1] / ud_value, 2) balance_ud = round(balance[1] / ud_value, 2)
date = arrow.now().format(ALL) date = arrow.now().format(ALL)
return f"Transactions history from: {idty['uid']} {gen_pubkey_checksum(pubkey)}\n\ return f"Transactions history from: {idty['uid']} {gen_pubkey_checksum(pubkey)}\n\
...@@ -212,7 +208,7 @@ def parse_received_tx( ...@@ -212,7 +208,7 @@ def parse_received_tx(
) )
amounts = tx_amount(received_tx, pubkey, received_func)[0] amounts = tx_amount(received_tx, pubkey, received_func)[0]
tx_list.append(amounts / 100) 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) tx_list.append(received_tx.comment)
received_txs_table.append(tx_list) received_txs_table.append(tx_list)
...@@ -258,10 +254,10 @@ def parse_sent_tx( ...@@ -258,10 +254,10 @@ def parse_sent_tx(
for i, output in enumerate(outputs): for i, output in enumerate(outputs):
if output_available(output.condition, ne, pubkey): if output_available(output.condition, ne, pubkey):
amounts += prefix(None, outputs, i) + str( 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( 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( tx_list[1] += prefix(tx_list[1], outputs, 0) + assign_idty_from_pubkey(
output.condition.left.pubkey, output.condition.left.pubkey,
...@@ -293,13 +289,13 @@ def tx_amount( ...@@ -293,13 +289,13 @@ def tx_amount(
def received_func(output: OutputSource, pubkey: str) -> int: def received_func(output: OutputSource, pubkey: str) -> int:
if output_available(output.condition, eq, pubkey): if output_available(output.condition, eq, pubkey):
return amount_in_current_base(output) return mt.amount_in_current_base(output)
return 0 return 0
def sent_func(output: OutputSource, pubkey: str) -> int: def sent_func(output: OutputSource, pubkey: str) -> int:
if output_available(output.condition, ne, pubkey): if output_available(output.condition, ne, pubkey):
return neg(amount_in_current_base(output)) return neg(mt.amount_in_current_base(output))
return 0 return 0
......
...@@ -24,6 +24,7 @@ from silkaj import tools ...@@ -24,6 +24,7 @@ from silkaj import tools
from silkaj.cli import cli from silkaj.cli import cli
from silkaj.constants import ( from silkaj.constants import (
ALL_DIGITAL, ALL_DIGITAL,
CENT_MULT_TO_UNIT,
PUBKEY_MAX_LENGTH, PUBKEY_MAX_LENGTH,
PUBKEY_MIN_LENGTH, PUBKEY_MIN_LENGTH,
SHORT_PUBKEY_SIZE, SHORT_PUBKEY_SIZE,
...@@ -34,6 +35,7 @@ from silkaj.public_key import CHECKSUM_SIZE ...@@ -34,6 +35,7 @@ from silkaj.public_key import CHECKSUM_SIZE
from silkaj.wot import tools as wt from silkaj.wot import tools as wt
from tests.patched.blockchain_tools import currency from tests.patched.blockchain_tools import currency
from tests.patched.money import patched_get_ud_value 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.tools import patched_get_currency_symbol
from tests.patched.tx_history import patched_get_transactions_history from tests.patched.tx_history import patched_get_transactions_history
from tests.patched.wot import patched_identities_from_pubkeys from tests.patched.wot import patched_identities_from_pubkeys
...@@ -177,34 +179,35 @@ def test_prefix(tx_addresses, outputs, occurence, return_value): ...@@ -177,34 +179,35 @@ def test_prefix(tx_addresses, outputs, occurence, return_value):
assert history.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 = ( csv_reference = (
["Date", "Issuers/Recipients", "Amounts Ğ1", "Amounts UDĞ1", "Comment"], ["Date", "Issuers/Recipients", "Amounts Ğ1", "Amounts UDĞ1", "Comment"],
[ [
arrow.get(111111114).to("local").format(ALL_DIGITAL), arrow.get(111111114).to("local").format(ALL_DIGITAL),
"CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB", "CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB",
"1.0", "1.0",
"0.09041591320072333", relative_amount,
"initialisation", "initialisation",
], ],
[ [
arrow.get(111111113).to("local").format(ALL_DIGITAL), arrow.get(111111113).to("local").format(ALL_DIGITAL),
"CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd:CQ5", "CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd:CQ5",
"1.0", "1.0",
"0.09041591320072333", relative_amount,
"", "",
], ],
[ [
arrow.get(111111112).to("local").format(ALL_DIGITAL), arrow.get(111111112).to("local").format(ALL_DIGITAL),
"CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB", "CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB",
"-1.0", "-1.0",
"-0.09", f"-{relative_amount}",
"", "",
], ],
[ [
arrow.get(111111111).to("local").format(ALL_DIGITAL), arrow.get(111111111).to("local").format(ALL_DIGITAL),
"CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd:CQ5", "CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd:CQ5",
"-1.0", "-1.0",
"-0.09", f"-{relative_amount}",
"", "",
], ],
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment