Skip to content
Snippets Groups Projects
Commit 9690a675 authored by matograine's avatar matograine
Browse files

[fix] #342 : balance command sums up many times the same pubkey

    -> return error in that case.

* write tests for errors on `balance` command
parent 30d63301
No related branches found
No related tags found
No related merge requests found
Pipeline #9808 passed
...@@ -49,6 +49,12 @@ async def cmd_amount(ctx, pubkeys): ...@@ -49,6 +49,12 @@ async def cmd_amount(ctx, pubkeys):
checked_pubkeys = list() checked_pubkeys = list()
for pubkey in pubkeys: for pubkey in pubkeys:
pubkey = check_public_key(pubkey, True) 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) checked_pubkeys.append(pubkey)
if not pubkey: if not pubkey:
return return
......
"""
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment