Merge remote-tracking branch 'origin/master' into feat/461/deploy-cluster-on-aws-using-ebs

This commit is contained in:
troymc 2016-07-20 11:43:51 +02:00
commit ddd3dfde93
4 changed files with 11 additions and 122 deletions

View File

@ -17,6 +17,6 @@ install:
before_script: rethinkdb --daemon
script: py.test -n auto -v --cov=bigchaindb
script: py.test -n auto -s -v --cov=bigchaindb
after_success: codecov

View File

@ -106,6 +106,11 @@ class Voter(object):
logger.info('new_block arrived to voter')
with self.monitor.timer('validate_block'):
# FIXME: the following check is done also in `is_valid_block`,
# but validity can be true even if the block has already
# a vote.
if b.has_previous_vote(new_block):
continue
validity = b.is_valid_block(new_block)
self.q_validated_block.put((new_block,
@ -151,7 +156,7 @@ class Voter(object):
return
block, vote = elem
logger.info('updating block %s and with vote %s', block['id'], vote)
logger.info('updating block %s and with vote %s', block, vote)
b.write_vote(block, vote)
def bootstrap(self):

View File

@ -609,119 +609,6 @@ class TestBlockValidation(object):
b.validate_block(block)
class TestBigchainVoter(object):
def test_valid_block_voting(self, b):
# create queue and voter
q_new_block = mp.Queue()
voter = Voter(q_new_block)
genesis = b.create_genesis_block()
# create valid block
block = dummy_block()
# assert block is valid
assert b.is_valid_block(block)
b.write_block(block, durability='hard')
# insert into queue
# FIXME: we disable this because the voter can currently vote more than one time for a block
# q_new_block.put(block)
# vote
voter.start()
# wait for vote to be written
time.sleep(1)
voter.kill()
# retrive block from bigchain
bigchain_block = r.table('bigchain').get(block['id']).run(b.conn)
# retrieve vote
vote = r.table('votes').get_all([block['id'], b.me], index='block_and_voter').run(b.conn)
vote = vote.next()
# validate vote
assert vote is not None
assert vote['vote']['voting_for_block'] == block['id']
assert vote['vote']['previous_block'] == genesis['id']
assert vote['vote']['is_block_valid'] is True
assert vote['vote']['invalid_reason'] is None
assert vote['node_pubkey'] == b.me
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote['vote']), vote['signature']) is True
def test_invalid_block_voting(self, b, user_vk):
# create queue and voter
q_new_block = mp.Queue()
voter = Voter(q_new_block)
# create transaction
transaction = b.create_transaction(b.me, user_vk, None, 'CREATE')
transaction_signed = b.sign_transaction(transaction, b.me_private)
genesis = b.create_genesis_block()
# create invalid block
block = b.create_block([transaction_signed])
# change transaction id to make it invalid
block['block']['transactions'][0]['id'] = 'abc'
assert b.is_valid_block(block) is False
b.write_block(block, durability='hard')
# insert into queue
# FIXME: we disable this because the voter can currently vote more than one time for a block
# q_new_block.put(block)
# vote
voter.start()
# wait for the vote to be written
time.sleep(1)
voter.kill()
# retrive block from bigchain
bigchain_block = r.table('bigchain').get(block['id']).run(b.conn)
# retrieve vote
vote = r.table('votes').get_all([block['id'], b.me], index='block_and_voter').run(b.conn)
vote = vote.next()
# validate vote
assert vote is not None
assert vote['vote']['voting_for_block'] == block['id']
assert vote['vote']['previous_block'] == genesis['id']
assert vote['vote']['is_block_valid'] is False
assert vote['vote']['invalid_reason'] is None
assert vote['node_pubkey'] == b.me
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote['vote']), vote['signature']) is True
def test_vote_creation_valid(self, b):
# create valid block
block = dummy_block()
# retrieve vote
vote = b.vote(block, 'abc', True)
# assert vote is correct
assert vote['vote']['voting_for_block'] == block['id']
assert vote['vote']['previous_block'] == 'abc'
assert vote['vote']['is_block_valid'] is True
assert vote['vote']['invalid_reason'] is None
assert vote['node_pubkey'] == b.me
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote['vote']), vote['signature']) is True
def test_vote_creation_invalid(self, b):
# create valid block
block = dummy_block()
# retrieve vote
vote = b.vote(block, 'abc', False)
# assert vote is correct
assert vote['vote']['voting_for_block'] == block['id']
assert vote['vote']['previous_block'] == 'abc'
assert vote['vote']['is_block_valid'] is False
assert vote['vote']['invalid_reason'] is None
assert vote['node_pubkey'] == b.me
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote['vote']), vote['signature']) is True
class TestBigchainBlock(object):
def test_by_assignee(self, b, user_vk):
# create transactions and randomly assigne them

View File

@ -276,15 +276,14 @@ class TestBigchainVoter(object):
q_new_block = mp.Queue()
voter = Voter(q_new_block)
# vote
voter.start()
time.sleep(1)
# create a new block that will appear in the changefeed
block_3 = dummy_block()
b.write_block(block_3, durability='hard')
# put the last block in the queue
q_new_block.put(block_3)
# vote
voter.start()
time.sleep(1)
voter.kill()
@ -340,8 +339,6 @@ class TestBigchainVoter(object):
voter = Voter(q_new_block)
voter.start()
# queue block for voting
q_new_block.put(block_1)
time.sleep(1)
retrieved_block = r.table('bigchain').get(block_1['id']).run(b.conn)