diff --git a/tests/test_tui.py b/tests/test_tui.py index 9161786a81e7933e0d64af81109ad2e80f79fc33..3edd27b56fe2c67df6cea1ab0b3e19f08c970c03 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -27,8 +27,7 @@ from patched.money import mock_ud_value "message, amount, currency_symbol", [("Total", 1000, G1_SYMBOL)] ) def test_display_amount(message, amount, currency_symbol): - ud_value = mock_ud_value - amount_UD = round(amount / ud_value, 2) + amount_UD = round(amount / mock_ud_value, 2) expected = [ [ message + " (unit|relative)", @@ -42,7 +41,7 @@ def test_display_amount(message, amount, currency_symbol): ] ] tx = list() - display_amount(tx, message, amount, ud_value, currency_symbol) + display_amount(tx, message, amount, mock_ud_value, currency_symbol) assert tx == expected diff --git a/tests/test_tx.py b/tests/test_tx.py index 5f66299264164989cafa94cfc626edb8ffe2582f..469baf066d7c91360a7e38bcb243711a1f247210 100644 --- a/tests/test_tx.py +++ b/tests/test_tx.py @@ -32,7 +32,6 @@ async def test_transaction_amount(monkeypatch): float ≠100 does not give the exact value""" monkeypatch.setattr(UDValue, "get_ud_value", patched_ud_value) - udvalue = mock_ud_value trials = ( # tests for --amount (unit) ([141.89], None, ["A"], [14189]), @@ -41,7 +40,7 @@ async def test_transaction_amount(monkeypatch): ([141.89], None, ["A", "B"], [14189, 14189]), ([141.89, 141.99], None, ["A", "B"], [14189, 14199]), # tests for --amount_UD - (None, [1.1], ["A"], [round(1.1 * udvalue)]), + (None, [1.1], ["A"], [round(1.1 * mock_ud_value)]), ( None, [1.9], @@ -49,11 +48,16 @@ async def test_transaction_amount(monkeypatch): "A", "B", ], - [round(1.9 * udvalue), round(1.9 * udvalue)], + [round(1.9 * mock_ud_value), round(1.9 * mock_ud_value)], + ), + (None, [1.0001], ["A"], [round(1.0001 * mock_ud_value)]), + (None, [9.9999], ["A"], [round(9.9999 * mock_ud_value)]), + ( + None, + [1.9, 2.3], + ["A", "B"], + [round(1.9 * mock_ud_value), round(2.3 * mock_ud_value)], ), - (None, [1.0001], ["A"], [round(1.0001 * udvalue)]), - (None, [9.9999], ["A"], [round(9.9999 * udvalue)]), - (None, [1.9, 2.3], ["A", "B"], [round(1.9 * udvalue), round(2.3 * udvalue)]), ) for trial in trials: diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index f2c89eefed0bbab0c0dd2ed3f0ac7ca1f71a88aa..d848b2c3f2ad90211afdd0081477d6cd5cfbf29e 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -126,7 +126,6 @@ async def test_transaction_confirmation( ) # creating expected list - ud_value = mock_ud_value expected = list() total_tx_amount = sum(tx_amounts) # display account situation @@ -134,28 +133,28 @@ async def test_transaction_confirmation( expected, "Initial balance", pubkey_balance, - ud_value, + mock_ud_value, currency_symbol, ) display_amount( expected, "Total transaction amount", total_tx_amount, - ud_value, + mock_ud_value, currency_symbol, ) display_amount( expected, "Balance after transaction", (pubkey_balance - total_tx_amount), - ud_value, + mock_ud_value, currency_symbol, ) await display_pubkey(expected, "From", issuer_pubkey) # display recipients and amounts for outputAddress, tx_amount in zip(outputAddresses, tx_amounts): await display_pubkey(expected, "To", outputAddress) - display_amount(expected, "Amount", tx_amount, ud_value, currency_symbol) + display_amount(expected, "Amount", tx_amount, mock_ud_value, currency_symbol) # display backchange and comment if outputBackChange: await display_pubkey(expected, "Backchange", outputBackChange) @@ -190,7 +189,6 @@ def test_compute_amounts_errors(capsys): def test_compute_amounts(): - ud_value = 314 assert compute_amounts((10.0, 2.0, 0.01, 0.011, 0.019), 100) == [ 1000, 200, @@ -198,12 +196,12 @@ def test_compute_amounts(): 1, 2, ] - assert compute_amounts([0.0032], ud_value) == [1] - assert compute_amounts([1.00], ud_value) == [314] - assert compute_amounts([1.01], ud_value) == [317] - assert compute_amounts([1.99], ud_value) == [625] - assert compute_amounts([1.001], ud_value) == [314] - assert compute_amounts([1.009], ud_value) == [317] + assert compute_amounts([0.0032], mock_ud_value) == [1] + assert compute_amounts([1.00], mock_ud_value) == [314] + assert compute_amounts([1.01], mock_ud_value) == [317] + assert compute_amounts([1.99], mock_ud_value) == [625] + assert compute_amounts([1.001], mock_ud_value) == [314] + assert compute_amounts([1.009], mock_ud_value) == [317] # This case will not happen in real use, but this particular function will allow it. assert compute_amounts([0.0099], 100) == [1] @@ -279,7 +277,6 @@ async def test_transaction_amount( ): # patched functions monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched_ud_value) - udvalue = mock_ud_value def too_little_amount(amounts, multiplicator): for amount in amounts: @@ -295,7 +292,7 @@ async def test_transaction_amount( # test errors if ( (len(given_amounts) > 1 and len(outputAddresses) != len(given_amounts)) - or (UDs_amounts and too_little_amount(given_amounts, udvalue)) + or (UDs_amounts and too_little_amount(given_amounts, mock_ud_value)) or (amounts and too_little_amount(given_amounts, CENT_MULT_TO_UNIT)) ): # check program exit on error