From aeddf42e6a880d5943f933594a0e664c3ae8a08d Mon Sep 17 00:00:00 2001 From: matograine <tom.ngr@zaclys.net> Date: Fri, 14 Feb 2020 13:53:09 +0100 Subject: [PATCH] [feat] #281 : modify check_transaction_values() to check the number of outputs. * add case inrelated tests --- silkaj/tx.py | 5 +++++ tests/test_unit_tx.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/silkaj/tx.py b/silkaj/tx.py index 8b0d75af..0b1c9267 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -222,6 +222,11 @@ def check_transaction_values( Check the balance is big enough for the transaction """ checkComment(comment) + # we check output numbers and leave one line for the backchange. + if len(outputAddresses) > (MAX_OUTPUTS - 1): + tools.message_exit( + "Error : there should be less than {0} outputs.".format(MAX_OUTPUTS - 1) + ) for i, outputAddress in enumerate(outputAddresses): if ct.check_pubkey_format(outputAddress): outputAddresses[i] = ct.validate_checksum(outputAddress) diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index 1240ab9f..2d9dfd4b 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -1257,6 +1257,17 @@ async def test_generate_and_send_transaction( "A", "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", ), + ( + "Test", + [ + "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", + ] + * 92, + "", + False, + "A", + "", + ), ], ) def test_check_transaction_values( @@ -1335,6 +1346,16 @@ def test_check_transaction_values( False, "A", ), + ( + "Test", + [ + "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", + ] + * 93, + "", + False, + "A", + ), ], ) def test_check_transaction_values_errors( @@ -1345,6 +1366,8 @@ def test_check_transaction_values_errors( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey ) display = capsys.readouterr() + if len(outputAddresses) > (tx.MAX_OUTPUTS - 1): + assert display == "Error : there should be less than 92 outputs." if comment.find("Wrong_Char_") != -1: assert display == "Error: the format of the comment is invalid" elif len(comment) > tx.MAX_COMMENT_LENGTH: -- GitLab