diff --git a/silkaj/money/history.py b/silkaj/money/history.py index 897fab14b3a6017205e6b235da7b73a1488baf59..223462570042a1a21810efdc00919ca041b0d25b 100644 --- a/silkaj/money/history.py +++ b/silkaj/money/history.py @@ -85,7 +85,7 @@ def transaction_history( "Issuers/Recipients", f"Amounts {currency_symbol}", f"Amounts UD{currency_symbol}", - "Comment", + "Reference", ] if csv_file: txs_list.insert(0, table_headers) @@ -135,7 +135,7 @@ def remove_duplicate_txs(received_txs: list, sent_txs: list) -> None: """ Remove duplicate transactions from history Remove received tx which contains output back return - that we don`t want to displayed + that we don't want to displayed A copy of received_txs is necessary to remove elements """ for received_tx in list(received_txs): @@ -191,7 +191,7 @@ def parse_received_tx( Convert time into human format Assign identities Get amounts and assign amounts and amounts_ud - Append comment + Append reference/comment """ issuers = [] for received_tx in received_txs: diff --git a/silkaj/money/transfer.py b/silkaj/money/transfer.py index f2a2bed115dc27f2190e1b600a5712cee40748e5..e2e013936c5d46891fa820bdf12f3520506e8e0c 100644 --- a/silkaj/money/transfer.py +++ b/silkaj/money/transfer.py @@ -43,7 +43,7 @@ from silkaj.constants import ( from silkaj.money import tools as m_tools from silkaj.public_key import gen_pubkey_checksum -MAX_COMMENT_LENGTH = 255 +MAX_REFERENCE_LENGTH = 255 # max size for tx doc is 100 lines. @@ -51,7 +51,7 @@ MAX_COMMENT_LENGTH = 255 # (2 * IU + 2 * IS + OUT) <= ( MAX_LINES_IN_TX_DOC - FIX_LINES) # with IU = inputs/unlocks ; IS = Issuers/Signatures ; OUT = Outpouts. MAX_LINES_IN_TX_DOC = 100 -# 2 lines are necessary, and we block 1 more for the comment +# 2 lines are necessary, and we block 1 more for the reference/comment FIX_LINES = 3 # assuming there is only 1 issuer and 2 outputs, max inputs is 46 MAX_INPUTS_PER_TX = 46 @@ -111,7 +111,7 @@ relative reference and recipients' pubkeys", cls=tools.MutuallyExclusiveOption, mutually_exclusive=["recipients", "amounts", "amountsUD", "allsources"], ) -@click.option("--comment", "-c", default="", help="Comment") +@click.option("--reference", "-ref", default="", help="Transfer reference") @click.option( "--outputBackChange", help="Pubkey recipient to send the rest of the transaction: `<pubkey[:checksum]>`", @@ -128,7 +128,7 @@ def transfer_money( allsources: bool, recipients: list[str], file_path: Path, - comment: str, + reference: str, outputbackchange: str, yes: bool, ) -> None: @@ -162,7 +162,7 @@ No transaction sent.", recipients = list(recipients) outputbackchange = check_transaction_values( - comment, + reference, recipients, outputbackchange, pubkey_amount[0] < sum(tx_amounts), @@ -178,7 +178,7 @@ No transaction sent.", tx_amounts, recipients, outputbackchange, - comment, + reference, ), ) confirmation_table = table.draw() @@ -191,7 +191,7 @@ No transaction sent.", issuer_pubkey, tx_amounts, recipients, - comment, + reference, outputbackchange, ) @@ -207,9 +207,9 @@ def parse_file_containing_amounts_recipients( [ABSOLUTE/RELATIVE] # comment1 - amount1 recipient1`s pubkey + amount1 recipient1's pubkey # comment2 - amount2 recipient2`s pubkey + amount2 recipient2's pubkey ``` """ reference = "" @@ -290,19 +290,19 @@ def compute_amounts(amounts: list[float], multiplicator: float) -> list[int]: def check_transaction_values( - comment: str, + reference: str, outputAddresses: list[str], outputBackChange: str, enough_source: bool, issuer_pubkey: str, ) -> str: """ - Check the comment format + Check reference format Check the pubkeys and the checksums of the recipients and the outputbackchange In case of a valid checksum, assign and return the pubkey without the checksum Check the balance is big enough for the transaction """ - checkComment(comment) + check_reference(reference) # we check output numbers and leave one line for the backchange. if len(outputAddresses) > (MAX_OUTPUTS - 1): tools.message_exit( @@ -316,7 +316,7 @@ def check_transaction_values( if enough_source: pubkey = gen_pubkey_checksum(issuer_pubkey) tools.message_exit( - f"{pubkey} pubkey doesn`t have enough money for this transaction.", + f"{pubkey} pubkey doesn't have enough money for this transaction.", ) return outputBackChange @@ -327,7 +327,7 @@ def gen_confirmation_table( tx_amounts: list[int], outputAddresses: list[str], outputBackChange: str, - comment: str, + reference: str, ) -> list[list]: """ Generate transaction confirmation @@ -368,7 +368,7 @@ def gen_confirmation_table( # display last informations if outputBackChange: m_tools.display_pubkey(tx, "Backchange", outputBackChange) - tx.append(["Comment", comment]) + tx.append(["Reference", reference]) return tx @@ -413,7 +413,7 @@ def handle_intermediaries_transactions( issuers: str, tx_amounts: list[int], outputAddresses: list[str], - Comment: str = "", + reference: str = "", OutputbackChange: Optional[str] = None, ) -> None: while True: @@ -442,7 +442,7 @@ def handle_intermediaries_transactions( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, ) break @@ -465,7 +465,7 @@ def generate_and_send_transaction( tx_amounts: list[int], listinput_and_amount: tuple[list[InputSource], int, bool], outputAddresses: list[str], - Comment: str, + reference: str, OutputbackChange: Optional[str] = None, ) -> None: """ @@ -487,7 +487,7 @@ def generate_and_send_transaction( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, ) transaction.sign(key) @@ -508,7 +508,7 @@ def generate_transaction_document( tx_amounts: list[int], listinput_and_amount: tuple[list[InputSource], int, bool], outputAddresses: list[str], - Comment: str = "", + reference: str = "", OutputbackChange: Optional[str] = None, ) -> Transaction: listinput = listinput_and_amount[0] @@ -550,7 +550,7 @@ def generate_transaction_document( inputs=listinput, unlocks=unlocks, outputs=listoutput, - comment=Comment, + comment=reference, currency=head_block["currency"], ) @@ -583,15 +583,15 @@ def generate_output( unitbase = unitbase - 1 -def checkComment(comment: str) -> None: - if len(comment) > MAX_COMMENT_LENGTH: - tools.message_exit("Error: Comment is too long") +def check_reference(reference: str) -> None: + if len(reference) > MAX_REFERENCE_LENGTH: + tools.message_exit("Error: Transfer reference is too long") regex = re.compile( "^[0-9a-zA-Z\\ \\-\\_\\:\\/\\;\\*\\[\\]\\(\\)\\?\ \\!\\^\\+\\=\\@\\&\\~\\#\\{\\}\\|\\\\<\\>\\%\\.]*$", ) - if not re.search(regex, comment): - tools.message_exit("Error: the format of the comment is invalid") + if not re.search(regex, reference): + tools.message_exit("Error: the reference format is invalid") def truncBase(amount: int, base: int) -> int: diff --git a/silkaj/wot/certify.py b/silkaj/wot/certify.py index acf187f31bc41f50dbb6d3758b282dc3561ee821..be07e9939bf50daaeb931aeddfb2e3f61b42d5ab 100644 --- a/silkaj/wot/certify.py +++ b/silkaj/wot/certify.py @@ -91,7 +91,7 @@ def pre_checks(client: Client, issuer_pubkey: str, pubkey_to_certify: str) -> di sys.exit("Current identity is not member.") if issuer_pubkey == pubkey_to_certify: - sys.exit("You can`t certify yourself!") + sys.exit("You can't certify yourself!") # Check if the certification can be renewed params = bc_tools.get_blockchain_parameters() diff --git a/tests/unit/money/test_history.py b/tests/unit/money/test_history.py index 7770d8d8f0f2b3cc2d89ef30bce26a338532b0d5..36fabd75c4a896aca990400d0f2d25d7c5c7afa2 100644 --- a/tests/unit/money/test_history.py +++ b/tests/unit/money/test_history.py @@ -181,7 +181,7 @@ def test_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"], + ["Date", "Issuers/Recipients", "Amounts Ğ1", "Amounts UDĞ1", "Reference"], [ arrow.get(111111114).to("local").format(ALL_DIGITAL), "CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW:DNB", diff --git a/tests/unit/money/test_transfer.py b/tests/unit/money/test_transfer.py index 639f2a6db59e13cd382c02e981149f14336d36df..1cba1558976d0b59e69399da7a173e39d4bd0c88 100644 --- a/tests/unit/money/test_transfer.py +++ b/tests/unit/money/test_transfer.py @@ -62,7 +62,7 @@ def test_truncBase(amount, base, expected): "tx_amounts", "outputAddresses", "outputBackChange", - "comment", + "reference", ), [ # only one receiver @@ -81,7 +81,7 @@ def test_truncBase(amount, base, expected): [1000], ["BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh"], "", - "This is a comment", + "This is a reference", ), # many receivers and backchange ( @@ -93,7 +93,7 @@ def test_truncBase(amount, base, expected): "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", ], "C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", - "This is a comment", + "This is a reference", ), # many receivers and outputs ( @@ -105,7 +105,7 @@ def test_truncBase(amount, base, expected): "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", ], "", - "This is a comment", + "This is a reference", ), ], ) @@ -115,7 +115,7 @@ def test_gen_confirmation_table( tx_amounts, outputAddresses, outputBackChange, - comment, + reference, monkeypatch, ): # patched functions @@ -153,10 +153,10 @@ def test_gen_confirmation_table( for outputAddress, tx_amount in zip(outputAddresses, tx_amounts): m_tools.display_pubkey(expected, "To", outputAddress) m_tools.display_amount(expected, "Amount", tx_amount, mock_ud_value, G1_SYMBOL) - # display backchange and comment + # display backchange and reference if outputBackChange: m_tools.display_pubkey(expected, "Backchange", outputBackChange) - expected.append(["Comment", comment]) + expected.append(["Reference", reference]) # asserting table_list = transfer.gen_confirmation_table( @@ -165,7 +165,7 @@ def test_gen_confirmation_table( tx_amounts, outputAddresses, outputBackChange, - comment, + reference, ) assert table_list == expected @@ -252,7 +252,7 @@ result1 = Transaction( condition="SIG(BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh)", ), ], - comment="Test comment", + comment="Test reference", ) @@ -262,7 +262,7 @@ result1 = Transaction( "tx_amounts", "listinput_and_amount", "outputAddresses", - "Comment", + "reference", "OutputbackChange", "result", ), @@ -295,7 +295,7 @@ result1 = Transaction( "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", ), - "Test comment", + "Test reference", "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", result1, ), @@ -306,7 +306,7 @@ def test_generate_transaction_document( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, result, monkeypatch, @@ -319,7 +319,7 @@ def test_generate_transaction_document( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, ) @@ -473,7 +473,7 @@ def test_get_list_input_for_transaction( "issuers", "tx_amounts", "outputAddresses", - "Comment", + "reference", "OutputbackChange", "expected_listinput_amount", ), @@ -488,7 +488,7 @@ def test_get_list_input_for_transaction( "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", ], - "Test comment", + "Test reference", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", ( [ @@ -518,7 +518,7 @@ def test_get_list_input_for_transaction( "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", [350] * 14, # total 4900, pubkey has 5300 ["4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw"] * 14, - "Test comment", + "Test reference", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", ( [ @@ -856,7 +856,7 @@ def test_handle_intermediaries_transactions( issuers, tx_amounts, outputAddresses, - Comment, + reference, OutputbackChange, expected_listinput_amount, monkeypatch, @@ -878,7 +878,7 @@ def test_handle_intermediaries_transactions( issuers, tx_amounts, outputAddresses, - Comment, + reference, OutputbackChange, ) @@ -900,7 +900,7 @@ def test_handle_intermediaries_transactions( tx_amounts, expected_listinput_amount, outputAddresses, - Comment, + reference, issuers, ) @@ -912,7 +912,7 @@ def test_handle_intermediaries_transactions( "amountsud", "allsources", "recipients", - "comment", + "reference", "outputbackchange", "yes", "confirmation_answer", @@ -951,7 +951,7 @@ def test_handle_intermediaries_transactions( [ "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", ], - "Test Comment", + "Test reference", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", False, "no", @@ -964,7 +964,7 @@ def test_handle_intermediaries_transactions( "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", ], - "Test Comment", + "Test reference", None, False, "yes", @@ -977,7 +977,7 @@ def test_handle_intermediaries_transactions( "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", ], - "Test Comment", + "Test reference", None, False, "yes", @@ -990,7 +990,7 @@ def test_handle_intermediaries_transactions( "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", ], - "Test Comment", + "Test reference", None, False, "yes", @@ -1002,7 +1002,7 @@ def test_handle_intermediaries_transactions( [ "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", ], - "Test Comment", + "Test reference", None, False, "yes", @@ -1014,7 +1014,7 @@ def test_send_transaction( amountsud, allsources, recipients, - comment, + reference, outputbackchange, yes, confirmation_answer, @@ -1069,7 +1069,7 @@ def test_send_transaction( amountsud, allsources, recipients, - comment, + reference, outputbackchange, yes, ) @@ -1082,7 +1082,7 @@ def test_send_transaction( tx_amounts, recipients, outputbackchange, - comment, + reference, ) if yes or confirmation_answer == "yes": patched_handle_intermediaries_transactions.assert_called_once_with( @@ -1090,7 +1090,7 @@ def test_send_transaction( key_fifi.pubkey, tx_amounts, recipients, - comment, + reference, outputbackchange, ) elif confirmation_answer == "no": @@ -1115,7 +1115,7 @@ def construct_args( amountsud, allsources, recipients, - comment, + reference, outputbackchange, yes, ): @@ -1135,9 +1135,9 @@ def construct_args( for recipient in recipients: args_list.append("-r") args_list.append(recipient) - if comment: - args_list.append("--comment") - args_list.append(comment) + if reference: + args_list.append("--reference") + args_list.append(reference) if outputbackchange is not None: args_list.append("--outputBackChange") args_list.append(outputbackchange) @@ -1152,7 +1152,7 @@ def construct_args( "tx_amounts", "listinput_and_amount", "outputAddresses", - "Comment", + "reference", "OutputbackChange", ), [ @@ -1233,7 +1233,7 @@ def construct_args( "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", ), - "Test comment", + "Test reference", None, ), # Wrong tx : 3 amounts for 1 receiver @@ -1289,7 +1289,7 @@ def test_generate_and_send_transaction( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, monkeypatch, capsys, @@ -1308,7 +1308,7 @@ def test_generate_and_send_transaction( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, ) @@ -1328,7 +1328,7 @@ def test_generate_and_send_transaction( tx_amounts, listinput_and_amount, outputAddresses, - Comment, + reference, OutputbackChange, ) network.send_document.assert_called_once() @@ -1338,7 +1338,7 @@ def test_generate_and_send_transaction( @pytest.mark.parametrize( # issuer_pubkey can be invalid. It is only used for display. ( - "comment", + "reference", "outputAddresses", "outputBackChange", "enough_source", @@ -1391,7 +1391,7 @@ def test_generate_and_send_transaction( ], ) def test_check_transaction_values( - comment, + reference, outputAddresses, outputBackChange, enough_source, @@ -1400,7 +1400,7 @@ def test_check_transaction_values( capsys, ): result = transfer.check_transaction_values( - comment, + reference, outputAddresses, outputBackChange, enough_source, @@ -1414,7 +1414,7 @@ def test_check_transaction_values( @pytest.mark.parametrize( # issuer_pubkey can be invalid. It is only used for display. ( - "comment", + "reference", "outputAddresses", "outputBackChange", "enough_source", @@ -1489,7 +1489,7 @@ def test_check_transaction_values( ], ) def test_check_transaction_values_errors( - comment, + reference, outputAddresses, outputBackChange, enough_source, @@ -1498,7 +1498,7 @@ def test_check_transaction_values_errors( ): with pytest.raises(SystemExit) as pytest_exit: transfer.check_transaction_values( - comment, + reference, outputAddresses, outputBackChange, enough_source, @@ -1506,10 +1506,10 @@ def test_check_transaction_values_errors( ) 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) > transfer.MAX_COMMENT_LENGTH: - assert display.out == "Error: Comment is too long\n" + if reference.find("Wrong_Char_") != -1: + assert display.out == "Error: the reference format is invalid\n" + elif len(reference) > transfer.MAX_REFERENCE_LENGTH: + assert display.out == "Error: Transfer reference is too long\n" elif "Wrong_Pubkey" in outputAddresses: assert display.out.find("Error: bad format for following public key:") != -1 elif outputBackChange: @@ -1517,7 +1517,7 @@ def test_check_transaction_values_errors( assert display.out.find("Error: bad format for following public key:") != -1 elif enough_source is True: assert ( - display.out.find("pubkey doesn`t have enough money for this transaction.") + display.out.find("pubkey doesn't have enough money for this transaction.") != -1 )