1
0
mirror of https://github.com/bigchaindb/bigchaindb.git synced 2024-06-23 17:56:41 +02:00

cleanup has_previous_vote

This commit is contained in:
Scott Sadler 2017-02-27 16:25:29 +01:00
parent 9bdc8ca341
commit ebeb94f35a
3 changed files with 2 additions and 39 deletions

View File

@ -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"""

View File

@ -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.

View File

@ -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