diff --git a/silkaj/money.py b/silkaj/money.py index 1236805f09b426adc96064082b86f2a6e68f9226..3462d13c737ec04f48b16c8a48614d616a21000f 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -79,7 +79,7 @@ def show_amount_from_pubkey(label, inputs_balance): totalAmountInput = inputs_balance[0] balance = inputs_balance[1] currency_symbol = get_currency_symbol() - ud_value = UDValue().ud_value + ud_value = get_ud_value() average, monetary_mass = get_average() member = False @@ -184,23 +184,12 @@ def get_sources(pubkey): return listinput, amount -class UDValue: - __instance = None - - def __new__(cls): - if UDValue.__instance is None: - UDValue.__instance = object.__new__(cls) - return UDValue.__instance - - def __init__(self): - self.ud_value = self.get_ud_value() - - def get_ud_value(self): - client = ClientInstance().client - blockswithud = client(blockchain.ud) - NBlastUDblock = blockswithud["result"]["blocks"][-1] - lastUDblock = client(blockchain.block, NBlastUDblock) - return lastUDblock["dividend"] * 10 ** lastUDblock["unitbase"] +def get_ud_value(): + client = ClientInstance().client + blockswithud = client(blockchain.ud) + NBlastUDblock = blockswithud["result"]["blocks"][-1] + lastUDblock = client(blockchain.block, NBlastUDblock) + return lastUDblock["dividend"] * 10 ** lastUDblock["unitbase"] def amount_in_current_base(source): diff --git a/silkaj/tx.py b/silkaj/tx.py index 9cdc8d9e5fa33518e1c5a9c05a0cbd222891ea89..a5bc63a340dbb043701ceb88b3cbd900a676ef92 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -224,7 +224,7 @@ def parse_file_containing_amounts_recipients(file_path: str) -> List: if reference == "ABSOLUTE": reference_mult = CENT_MULT_TO_UNIT else: - reference_mult = money.UDValue().ud_value + reference_mult = money.get_ud_value() tx_amounts = compute_amounts(amounts, reference_mult) return tx_amounts, recipients @@ -239,7 +239,7 @@ def transaction_amount(amounts, UDs_amounts, outputAddresses): if amounts: amounts_list = compute_amounts(amounts, CENT_MULT_TO_UNIT) elif UDs_amounts: - UD_value = money.UDValue().ud_value + UD_value = money.get_ud_value() amounts_list = compute_amounts(UDs_amounts, UD_value) if len(amounts_list) != len(outputAddresses) and len(amounts_list) != 1: tools.message_exit( @@ -313,7 +313,7 @@ def gen_confirmation_table( """ currency_symbol = tools.get_currency_symbol() - ud_value = money.UDValue().ud_value + ud_value = money.get_ud_value() total_tx_amount = sum(tx_amounts) tx = list() # display account situation diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index a8bdcd587c4e59d6be9a7e9a8d7c6e75ad712d2f..274e47964f6c05b04e7546b6dee11062a8b227ee 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -26,7 +26,7 @@ from silkaj import wot from silkaj import wot_tools as wt from silkaj.constants import ALL, ALL_DIGITAL from silkaj.crypto_tools import check_pubkey_format, validate_checksum -from silkaj.money import UDValue, amount_in_current_base, get_amount_from_pubkey +from silkaj.money import amount_in_current_base, get_amount_from_pubkey, get_ud_value from silkaj.network_tools import ClientInstance from silkaj.tools import get_currency_symbol from silkaj.tui import display_pubkey_and_checksum @@ -41,7 +41,7 @@ def transaction_history(pubkey, uids, full_pubkey): pubkey = validate_checksum(pubkey) client = ClientInstance().client - ud_value = UDValue().ud_value + ud_value = get_ud_value() currency_symbol = get_urrency_symbol() header = generate_header(pubkey, currency_symbol, ud_value) diff --git a/tests/patched/money.py b/tests/patched/money.py index ba41853867111c36781500d6c6d2b924b1cadcfa..32d0f815c1e8cfd9511137d20d2561066c015709 100644 --- a/tests/patched/money.py +++ b/tests/patched/money.py @@ -40,7 +40,7 @@ from silkaj.money import amount_in_current_base from silkaj.tx import MAX_INPUTS_PER_TX -def patched_ud_value(self): +def patched_get_ud_value(): return mock_ud_value diff --git a/tests/test_tx.py b/tests/test_tx.py index 94464efc6cae3664eae2690e891a1af839ba68f7..0bc7ac82635349dddd9b239dbfffdb6b6e82a7a1 100644 --- a/tests/test_tx.py +++ b/tests/test_tx.py @@ -21,7 +21,7 @@ from click import pass_context from click.testing import CliRunner from patched.auth import patched_auth_method -from patched.money import patched_get_sources, patched_ud_value +from patched.money import patched_get_sources, patched_get_ud_value from patched.test_constants import mock_ud_value from patched.tx import patched_gen_confirmation_table from silkaj import auth, money, tx @@ -50,7 +50,7 @@ def test_transaction_amount(monkeypatch): """test passed amounts passed tx command float ≠100 does not give the exact value""" - monkeypatch.setattr(money.UDValue, "get_ud_value", patched_ud_value) + monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value) trials = ( # tests for --amount (unit) ([141.89], None, ["A"], [14189]), @@ -111,7 +111,7 @@ def test_transaction_amount_errors( amounts, UDs_amounts, outputAddresses, expected, capsys, monkeypatch ): # patched functions - monkeypatch.setattr(money.UDValue, "get_ud_value", patched_ud_value) + monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value) def too_little_amount(amounts, multiplicator): for amount in amounts: diff --git a/tests/test_tx_file.py b/tests/test_tx_file.py index 628a7d1e49f09dcd40d1e2aedea1a70de6a7d7bb..48b00a35f554809ad8cfc54f59ceb76a0329ca5d 100644 --- a/tests/test_tx_file.py +++ b/tests/test_tx_file.py @@ -17,12 +17,12 @@ import pytest from click.testing import CliRunner from silkaj.constants import CENT_MULT_TO_UNIT -from silkaj.money import UDValue +from silkaj.money import get_ud_value from silkaj.tx import parse_file_containing_amounts_recipients FILE_PATH = "recipients.txt" -ud_value = UDValue().ud_value +ud_value = get_ud_value() @pytest.mark.parametrize( diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index 4189e44af85282aff06e87c0ab60da349b5e11c3..2d3620e2fc202e2090d0693f6ab5e79e031df745 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -28,7 +28,7 @@ from duniterpy.documents.transaction import ( from patched.auth import patched_auth_method from patched.blockchain_tools import fake_block_id, patched_get_head_block -from patched.money import patched_get_sources, patched_ud_value +from patched.money import patched_get_sources, patched_get_ud_value from patched.test_constants import mock_ud_value from patched.tools import patched_get_currency_symbol from patched.tx import ( @@ -123,7 +123,7 @@ def test_gen_confirmation_table( ): # patched functions monkeypatch.setattr(wot_tools, "is_member", patched_is_member) - monkeypatch.setattr(money.UDValue, "get_ud_value", patched_ud_value) + monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value) monkeypatch.setattr(tools, "get_currency_symbol", patched_get_currency_symbol) # creating expected list @@ -1032,7 +1032,7 @@ def test_send_transaction( patched_handle_intermediaries_transactions, ) monkeypatch.setattr(money, "get_sources", patched_get_sources) - monkeypatch.setattr(money.UDValue, "get_ud_value", patched_ud_value) + monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value) # reset patched_get_sources patched_get_sources.counter = 0