diff --git a/silkaj/money.py b/silkaj/money.py index 3734ce5ed9c00ae89a2ef0e789017604dfce7a11..2828411aaf5469e9610efa7ca5c56617340a0481 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -49,6 +49,12 @@ async def cmd_amount(ctx, pubkeys): checked_pubkeys = list() for pubkey in pubkeys: pubkey = check_public_key(pubkey, True) + if pubkey in checked_pubkeys: + message_exit( + "Error : pubkey {0} was specified many times".format( + pubkey_with_checksum(pubkey) + ) + ) checked_pubkeys.append(pubkey) if not pubkey: return diff --git a/tests/test_money.py b/tests/test_money.py new file mode 100644 index 0000000000000000000000000000000000000000..969a3a68735d9105570f8223559927da38dec2d7 --- /dev/null +++ b/tests/test_money.py @@ -0,0 +1,52 @@ +""" +Copyright 2016-2020 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/>. +""" + +import pytest +from click.testing import CliRunner + +# had to import from wot to prevent loop dependencies +from silkaj.wot import pubkey_with_checksum +from silkaj.cli import cli +from silkaj.constants import FAILURE_EXIT_STATUS + + +def test_balance_errors(): + """ + test balance command errors + """ + + # twice the samepubkey + result = CliRunner().invoke( + cli, + [ + "balance", + "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", + "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", + ], + ) + assert ( + "Error : pubkey {0} was specified many times".format( + pubkey_with_checksum("BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh") + ) + in result.output + ) + assert result.exit_code == FAILURE_EXIT_STATUS + + # no pubkey + result = CliRunner().invoke(cli, ["balance"]) + assert "You should specify one or many pubkeys" in result.output + assert result.exit_code == FAILURE_EXIT_STATUS