diff --git a/silkaj/cli.py b/silkaj/cli.py index f2e38eca1131861f5f3592691f90277d2a54f6c1..ca6aed1008a5ab18e07977187f941a3a78e32799 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -34,7 +34,7 @@ from silkaj.constants import ( from silkaj.g1_monetary_license import license_command from silkaj.membership import send_membership from silkaj.money.balance import cmd_amount -from silkaj.tx import send_transaction +from silkaj.money.transfer import send_transaction from silkaj.tx_history import transaction_history from silkaj.wot import id_pubkey_correspondence, received_sent_certifications diff --git a/silkaj/tx.py b/silkaj/money/transfer.py similarity index 100% rename from silkaj/tx.py rename to silkaj/money/transfer.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..58426bbc2bbfc951dc181bdd19b5b2569c074af0 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2016-2022 Maël Azimi <m.a@moul.re> +# +# Silkaj is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Silkaj is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. diff --git a/tests/test_unit_tx.py b/tests/money/test_transfer.py similarity index 96% rename from tests/test_unit_tx.py rename to tests/money/test_transfer.py index 6dc148609bc903a78753fd5d5a71d2c8f2958b49..d8e0e4eefe943315586bc11a4646e41791bb71c3 100644 --- a/tests/test_unit_tx.py +++ b/tests/money/test_transfer.py @@ -32,11 +32,12 @@ from patched.money import Counter, 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.wot import patched_is_member -from silkaj import auth, network_tools, tools, tx, wot_tools +from silkaj import auth, network_tools, tools, wot_tools from silkaj.blockchain import tools as bc_tools from silkaj.cli import cli from silkaj.constants import CENT_MULT_TO_UNIT, G1_SYMBOL from silkaj.money import tools as m_tools +from silkaj.money import transfer from silkaj.tui import display_amount, display_pubkey # Values @@ -50,7 +51,7 @@ key_fifi = patched_auth_method("fifi") [(0, 0, 0), (10, 2, 0), (100, 2, 100), (306, 2, 300), (3060, 3, 3000)], ) def test_truncBase(amount, base, expected): - assert tx.truncBase(amount, base) == expected + assert transfer.truncBase(amount, base) == expected # transaction_confirmation() @@ -151,7 +152,7 @@ def test_gen_confirmation_table( expected.append(["Comment", comment]) # asserting - table_list = tx.gen_confirmation_table( + table_list = transfer.gen_confirmation_table( issuer_pubkey, pubkey_balance, tx_amounts, @@ -169,7 +170,7 @@ def test_compute_amounts_errors(capsys): # check program exit on error with pytest.raises(SystemExit) as pytest_exit: # read output to check error. - tx.compute_amounts( + transfer.compute_amounts( trial[0], trial[1], ) @@ -179,21 +180,21 @@ def test_compute_amounts_errors(capsys): def test_compute_amounts(): - assert tx.compute_amounts((10.0, 2.0, 0.01, 0.011, 0.019), 100) == [ + assert transfer.compute_amounts((10.0, 2.0, 0.01, 0.011, 0.019), 100) == [ 1000, 200, 1, 1, 2, ] - assert tx.compute_amounts([0.0032], mock_ud_value) == [1] - assert tx.compute_amounts([1.00], mock_ud_value) == [314] - assert tx.compute_amounts([1.01], mock_ud_value) == [317] - assert tx.compute_amounts([1.99], mock_ud_value) == [625] - assert tx.compute_amounts([1.001], mock_ud_value) == [314] - assert tx.compute_amounts([1.009], mock_ud_value) == [317] + assert transfer.compute_amounts([0.0032], mock_ud_value) == [1] + assert transfer.compute_amounts([1.00], mock_ud_value) == [314] + assert transfer.compute_amounts([1.01], mock_ud_value) == [317] + assert transfer.compute_amounts([1.99], mock_ud_value) == [625] + assert transfer.compute_amounts([1.001], mock_ud_value) == [314] + assert transfer.compute_amounts([1.009], mock_ud_value) == [317] # This case will not happen in real use, but this particular function will allow it. - assert tx.compute_amounts( + assert transfer.compute_amounts( [0.0099], 100, ) == [1] @@ -298,7 +299,7 @@ def test_generate_transaction_document( # patch Head_block monkeypatch.setattr(bc_tools, "get_head_block", patched_get_head_block) - assert result == tx.generate_transaction_document( + assert result == transfer.generate_transaction_document( issuers, tx_amounts, listinput_and_amount, @@ -428,12 +429,16 @@ def test_get_list_input_for_transaction( # testing error exit if isinstance(expected, str): with pytest.raises(SystemExit) as pytest_exit: - result = tx.get_list_input_for_transaction(pubkey, TXamount, outputs_number) + result = transfer.get_list_input_for_transaction( + pubkey, TXamount, outputs_number + ) assert expected == capsys.readouterr().out assert pytest_exit.type == SystemExit # testing good values else: - result = tx.get_list_input_for_transaction(pubkey, TXamount, outputs_number) + result = transfer.get_list_input_for_transaction( + pubkey, TXamount, outputs_number + ) assert (len(result[0]), result[1], result[2]) == expected @@ -829,13 +834,13 @@ def test_handle_intermediaries_transactions( patched_generate_and_send_transaction = Mock(return_value=None) monkeypatch.setattr(m_tools, "get_sources", patched_get_sources) monkeypatch.setattr( - tx, "generate_and_send_transaction", patched_generate_and_send_transaction + transfer, "generate_and_send_transaction", patched_generate_and_send_transaction ) Counter.counter = 0 # testing - tx.handle_intermediaries_transactions( + transfer.handle_intermediaries_transactions( key, issuers, tx_amounts, outputAddresses, Comment, OutputbackChange ) @@ -972,7 +977,7 @@ def test_send_transaction( ): """ This function only tests coherent values. - Errors are tested in test_tx.py. + Errors are tested in test_transfer.py. """ # mocking functions @@ -981,9 +986,11 @@ def test_send_transaction( # patching functions monkeypatch.setattr(auth, "auth_method", patched_auth_method_tx) - monkeypatch.setattr(tx, "gen_confirmation_table", patched_gen_confirmation_table) monkeypatch.setattr( - tx, + transfer, "gen_confirmation_table", patched_gen_confirmation_table + ) + monkeypatch.setattr( + transfer, "handle_intermediaries_transactions", patched_handle_intermediaries_transactions, ) @@ -1216,14 +1223,14 @@ def test_generate_and_send_transaction( capsys, ): # mock functions - tx.generate_transaction_document = Mock() + transfer.generate_transaction_document = Mock() network_tools.send_document = Mock() # patched functions monkeypatch.setattr(bc_tools, "get_head_block", patched_get_head_block) # monkeypatch.setattr(network_tools, "client_instance", patched_client_instance) - tx.generate_and_send_transaction( + transfer.generate_and_send_transaction( key, issuers, tx_amounts, @@ -1244,7 +1251,7 @@ def test_generate_and_send_transaction( f" - To: {outputAddress}\n - Amount: {tx_amount / 100}" ) - tx.generate_transaction_document.assert_called_once_with( + transfer.generate_transaction_document.assert_called_once_with( issuers, tx_amounts, listinput_and_amount, @@ -1314,7 +1321,7 @@ def test_check_transaction_values( expected_outputBackchange, capsys, ): - result = tx.check_transaction_values( + result = transfer.check_transaction_values( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey ) assert capsys.readouterr().out == "" @@ -1397,14 +1404,14 @@ def test_check_transaction_values_errors( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey, capsys ): with pytest.raises(SystemExit) as pytest_exit: - tx.check_transaction_values( + transfer.check_transaction_values( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey ) assert pytest_exit.type == SystemExit display = capsys.readouterr() if comment.find("Wrong_Char_") != -1: assert display.out == "Error: the format of the comment is invalid\n" - elif len(comment) > tx.MAX_COMMENT_LENGTH: + elif len(comment) > transfer.MAX_COMMENT_LENGTH: assert display.out == "Error: Comment is too long\n" elif "Wrong_Pubkey" in outputAddresses: assert display.out.find("Error: bad format for following public key:") != -1 @@ -1447,7 +1454,7 @@ def test_check_transaction_values_errors( ], ) def test_generate_unlocks(listinput, expected): - assert expected == tx.generate_unlocks(listinput) + assert expected == transfer.generate_unlocks(listinput) # test generate_output @@ -1517,7 +1524,7 @@ def test_generate_unlocks(listinput, expected): ], ) def test_generate_output(listoutput, unitbase, rest, recipient_address, expected): - tx.generate_output(listoutput, unitbase, rest, recipient_address) + transfer.generate_output(listoutput, unitbase, rest, recipient_address) assert len(expected) == len(listoutput) for e, o in zip(expected, listoutput): assert e == o @@ -1541,4 +1548,4 @@ def test_max_inputs_number(outputs_number, issuers_number, expected): This function does not take care of backchange line. formula is IU <= (MAX_LINES_IN_TX_DOC - FIX_LINES - O - 2*IS)/2 """ - assert tx.max_inputs_number(outputs_number, issuers_number) == expected + assert transfer.max_inputs_number(outputs_number, issuers_number) == expected diff --git a/tests/test_tx.py b/tests/money/test_transfer_cli.py similarity index 95% rename from tests/test_tx.py rename to tests/money/test_transfer_cli.py index bc76805ff504cd68c5c0a63119d32b8dd4674e0e..789a1152aada282eb97f09cd804d0fb475676913 100644 --- a/tests/test_tx.py +++ b/tests/money/test_transfer_cli.py @@ -22,7 +22,7 @@ from click.testing import CliRunner from patched.auth import patched_auth_method from patched.money import patched_get_sources, patched_get_ud_value from patched.test_constants import mock_ud_value -from silkaj import auth, tx +from silkaj import auth from silkaj.cli import cli from silkaj.constants import ( FAILURE_EXIT_STATUS, @@ -31,6 +31,7 @@ from silkaj.constants import ( PUBKEY_MIN_LENGTH, ) from silkaj.money import tools as m_tools +from silkaj.money import transfer # create test auths @@ -78,7 +79,7 @@ def test_transaction_amount(monkeypatch): ) for trial in trials: - assert trial[3] == tx.transaction_amount(trial[0], trial[1], trial[2]) + assert trial[3] == transfer.transaction_amount(trial[0], trial[1], trial[2]) # transaction_amount errors() @@ -114,7 +115,7 @@ def test_transaction_amount_errors( # check program exit on error with pytest.raises(SystemExit) as pytest_exit: # read output to check error. - tx.transaction_amount(amounts, UDs_amounts, outputAddresses) + transfer.transaction_amount(amounts, UDs_amounts, outputAddresses) assert expected == capsys.readouterr() assert pytest_exit.type == SystemExit @@ -216,7 +217,9 @@ def test_tx_passed_all_sources_empty( monkeypatch.setattr(auth, "auth_method", auth_method) monkeypatch.setattr(m_tools, "get_sources", patched_get_sources) patched_gen_confirmation_table = Mock() - monkeypatch.setattr(tx, "gen_confirmation_table", patched_gen_confirmation_table) + monkeypatch.setattr( + transfer, "gen_confirmation_table", patched_gen_confirmation_table + ) result = CliRunner().invoke(cli, args=arguments) # test error diff --git a/tests/test_tx_file.py b/tests/money/test_transfer_file.py similarity index 97% rename from tests/test_tx_file.py rename to tests/money/test_transfer_file.py index 64ead71a350351f8426c258f5032b01caa63cfb6..10a1ffae05b705971ddf50901981bfb71eec8935 100644 --- a/tests/test_tx_file.py +++ b/tests/money/test_transfer_file.py @@ -18,7 +18,7 @@ from click.testing import CliRunner from silkaj.constants import CENT_MULT_TO_UNIT from silkaj.money.tools import get_ud_value -from silkaj.tx import parse_file_containing_amounts_recipients +from silkaj.money.transfer import parse_file_containing_amounts_recipients FILE_PATH = "recipients.txt" diff --git a/tests/patched/__init__.py b/tests/patched/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..58426bbc2bbfc951dc181bdd19b5b2569c074af0 --- /dev/null +++ b/tests/patched/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2016-2022 Maël Azimi <m.a@moul.re> +# +# Silkaj is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Silkaj is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. diff --git a/tests/patched/money.py b/tests/patched/money.py index 88b5bfc6db6f85d91d3640ba191424090c1689e7..17e279336bb073631e03ba8dceb626e481a84743 100644 --- a/tests/patched/money.py +++ b/tests/patched/money.py @@ -19,7 +19,7 @@ from duniterpy.documents.transaction import InputSource from patched.test_constants import mock_ud_value from silkaj.money.tools import amount_in_current_base -from silkaj.tx import MAX_INPUTS_PER_TX +from silkaj.money.transfer import MAX_INPUTS_PER_TX def patched_get_ud_value():