From c80d3926194fb7dab7d280f2281a04925049db2c Mon Sep 17 00:00:00 2001 From: Vanshdeep Singh Date: Mon, 27 Aug 2018 16:24:41 +0200 Subject: [PATCH] Problem: Exceptions are not informational when executing upsert-validator Solution: generate error logs or print statement indicating success --- bigchaindb/commands/bigchaindb.py | 18 ++++++++++-------- tests/commands/test_commands.py | 4 +--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bigchaindb/commands/bigchaindb.py b/bigchaindb/commands/bigchaindb.py index bf6bde52..b17f82f5 100644 --- a/bigchaindb/commands/bigchaindb.py +++ b/bigchaindb/commands/bigchaindb.py @@ -16,9 +16,7 @@ import sys from bigchaindb.utils import load_node_key from bigchaindb.common.exceptions import (DatabaseAlreadyExists, DatabaseDoesNotExist, - ValidationError, - OperationError, - KeypairMismatchException) + ValidationError) import bigchaindb from bigchaindb import (backend, ValidatorElection, BigchainDB, ValidatorElectionVote) @@ -152,7 +150,8 @@ def run_upsert_validator_new(args, bigchain): print('[SUCCESS] Submitted proposal with id:', election.id) return election.id else: - raise OperationError('Failed to commit election') + logger.error('Failed to commit election proposal') + return False def run_upsert_validator_approve(args, bigchain): @@ -174,10 +173,12 @@ def run_upsert_validator_approve(args, bigchain): if len(voting_powers) > 0: voting_power = voting_powers[0] else: - raise KeypairMismatchException( - 'The key you provided does not match any of the eligible voters in this election.' - ) + logger.error('The key you provided does not match any of the eligible voters in this election.') + return False + # NOTE: The code below assumes no vote delegation has taken place. Vote delegation + # is a by-product of the transaction state model which hasn't been offered as + # feature in current version of upsert-validator inputs = [i for i in tx.to_inputs() if key.public_key in i.owners_before] election_pub_key = ValidatorElection.to_public_key(tx.id) approval = ValidatorElectionVote.generate(inputs, @@ -191,7 +192,8 @@ def run_upsert_validator_approve(args, bigchain): print('Your vote has been submitted.') return approval.id else: - raise OperationError('Failed to vote for election') + logger.error('Failed to commit election proposal') + return False def _run_init(): diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 6ed28488..f6add7b0 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -10,7 +10,6 @@ from argparse import Namespace import pytest from bigchaindb import ValidatorElection -from bigchaindb.common.exceptions import KeypairMismatchException from tests.conftest import node_keys @@ -481,8 +480,7 @@ def test_upsert_validator_approve_called_with_bad_key(b, bad_validator_path, new sk=bad_validator_path, config={}) - with pytest.raises(KeypairMismatchException): - run_upsert_validator_approve(args, b) + assert not run_upsert_validator_approve(args, b) def mock_get(height):