diff --git a/bigchaindb/pipelines/election.py b/bigchaindb/pipelines/election.py index fe4fbc68..a5818b3e 100644 --- a/bigchaindb/pipelines/election.py +++ b/bigchaindb/pipelines/election.py @@ -36,7 +36,7 @@ class Election: try: block_id = next_vote['vote']['voting_for_block'] node = next_vote['node_pubkey'] - except IndexError: + except KeyError: return next_block = self.bigchain.get_block(block_id) diff --git a/tests/pipelines/test_election.py b/tests/pipelines/test_election.py index e7491656..3127dcaf 100644 --- a/tests/pipelines/test_election.py +++ b/tests/pipelines/test_election.py @@ -114,6 +114,13 @@ def test_check_for_quorum_valid(b, user_pk): assert e.check_for_quorum(votes[-1]) is None +@patch('bigchaindb.core.Bigchain.get_block') +def test_invalid_vote(get_block, b): + e = election.Election() + assert e.check_for_quorum({}) is None + get_block.assert_not_called() + + @pytest.mark.bdb def test_check_requeue_transaction(b, user_pk): from bigchaindb.models import Transaction