From 4a4cbc8de0195edb64b159f64efaba0aaed73d72 Mon Sep 17 00:00:00 2001 From: z-bowen Date: Tue, 21 Aug 2018 17:24:28 +0200 Subject: [PATCH] Problem: `test_upsert_validator` fails if run with the initial block height == 0 Solution: Added a little helper function to make sure there is at least one block in the chain when the test is executed --- .../test_validator_election_vote.py | 7 +++++-- tests/utils.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/upsert_validator/test_validator_election_vote.py b/tests/upsert_validator/test_validator_election_vote.py index c0798224..d555b0d7 100644 --- a/tests/upsert_validator/test_validator_election_vote.py +++ b/tests/upsert_validator/test_validator_election_vote.py @@ -10,7 +10,7 @@ from bigchaindb.upsert_validator import ValidatorElection, ValidatorElectionVote from bigchaindb.common.exceptions import AmountError from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.exceptions import ValidationError - +from tests.utils import generate_block pytestmark = [pytest.mark.execute] @@ -219,10 +219,13 @@ def test_valid_election_conclude(b_mock, valid_election, ed25519_node_keys): @pytest.mark.abci -def test_upsert_validator(b, node_key, node_keys, new_validator, ed25519_node_keys): +def test_upsert_validator(b, node_key, node_keys, ed25519_node_keys): import time import requests + if b.get_latest_block()['height'] == 0: + generate_block(b) + (node_pub, _) = list(node_keys.items())[0] validators = [{'pub_key': {'type': 'ed25519', diff --git a/tests/utils.py b/tests/utils.py index d9805f62..349f7e5a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -21,3 +21,19 @@ def flush_localmongo_db(connection, dbname): connection.conn[dbname].metadata.delete_many({}) connection.conn[dbname].utxos.delete_many({}) connection.conn[dbname].validators.delete_many({}) + + +def generate_block(bigchain): + from bigchaindb.common.crypto import generate_key_pair + from bigchaindb.models import Transaction + import time + + alice = generate_key_pair() + tx = Transaction.create([alice.public_key], + [([alice.public_key], 1)], + asset=None)\ + .sign([alice.private_key]) + + code, message = bigchain.write_transaction(tx, 'broadcast_tx_commit') + assert code == 202 + time.sleep(2)