From ebeb94f35a0975e7733ad522ae2714910822423d Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 27 Feb 2017 16:25:29 +0100 Subject: [PATCH] cleanup has_previous_vote --- bigchaindb/common/exceptions.py | 8 -------- bigchaindb/core.py | 18 ++---------------- tests/db/test_bigchain_api.py | 15 --------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/bigchaindb/common/exceptions.py b/bigchaindb/common/exceptions.py index 60340492..1b869e5c 100644 --- a/bigchaindb/common/exceptions.py +++ b/bigchaindb/common/exceptions.py @@ -62,14 +62,6 @@ class StartupError(BigchainDBError): """Raised when there is an error starting up the system""" -class ImproperVoteError(BigchainDBError): - """Raised if a vote is not constructed correctly, or signed incorrectly""" - - -class MultipleVotesError(BigchainDBError): - """Raised if a voter has voted more than once""" - - class GenesisBlockAlreadyExistsError(BigchainDBError): """Raised when trying to create the already existing genesis block""" diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 1f82fd78..e4419bb4 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -496,24 +496,10 @@ class Bigchain(object): bool: :const:`True` if this block already has a valid vote from this node, :const:`False` otherwise. - Raises: - ImproperVoteError: If there is already a vote, - but the vote is invalid. - """ votes = list(backend.query.get_votes_by_block_id_and_voter(self.connection, block_id, self.me)) - - if len(votes) > 1: - raise exceptions.MultipleVotesError('Block {block_id} has {n_votes} votes from public key {me}' - .format(block_id=block_id, n_votes=str(len(votes)), me=self.me)) - if len(votes) < 1: - return False - - if self.consensus.voting.verify_vote_signature(votes[0]): - return True - else: - raise exceptions.ImproperVoteError('Block {block_id} already has an incorrectly signed vote ' - 'from public key {me}'.format(block_id=block_id, me=self.me)) + el, _ = self.consensus.voting.partition_eligible_votes(votes, [self.me]) + return bool(el) def write_block(self, block): """Write a block to bigchain. diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 2363f9e7..5f5aa5c5 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -428,21 +428,6 @@ class TestBigchainApi(object): assert retrieved_block_1 == retrieved_block_2 - @pytest.mark.genesis - def test_improper_vote_error(selfs, b): - from bigchaindb.common.exceptions import ImproperVoteError - - block_1 = dummy_block() - b.write_block(block_1) - vote_1 = b.vote(block_1.id, b.get_last_voted_block().id, True) - # mangle the signature - vote_1['signature'] = 'a' * 87 - b.write_vote(vote_1) - with pytest.raises(ImproperVoteError) as excinfo: - b.has_previous_vote(block_1.id) - assert excinfo.value.args[0] == 'Block {block_id} already has an incorrectly signed ' \ - 'vote from public key {me}'.format(block_id=block_1.id, me=b.me) - @pytest.mark.usefixtures('inputs') def test_assign_transaction_one_node(self, b, user_pk, user_sk): from bigchaindb.backend import query