Exemple #1
0
def test_election_new_upsert_validator_invalid_election(caplog, b, priv_validator_path, user_sk):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator

    args = Namespace(action='new',
                     election_type='upsert_validator',
                     public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
                     power=10,
                     node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                     sk='/tmp/invalid/path/key.json',
                     config={})

    with caplog.at_level(logging.ERROR):
        assert not run_election_new_upsert_validator(args, b)
        assert caplog.records[0].msg.__class__ == FileNotFoundError
Exemple #2
0
def test_election_new_upsert_validator_with_tendermint(b, priv_validator_path, user_sk, validators):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator

    new_args = Namespace(action='new',
                         election_type='upsert_validator',
                         public_key='HHG0IQRybpT6nJMIWWFWhMczCLHt6xcm7eP52GnGuPY=',
                         power=1,
                         node_id='unique_node_id_for_test_upsert_validator_new_with_tendermint',
                         sk=priv_validator_path,
                         config={})

    election_id = run_election_new_upsert_validator(new_args, b)

    assert b.get_transaction(election_id)
Exemple #3
0
def test_election_new_upsert_validator_invalid_election(
        caplog, b, priv_validator_path, user_sk):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator

    args = Namespace(action='new',
                     election_type='upsert-validator',
                     public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
                     power=10,
                     node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                     sk='/tmp/invalid/path/key.json',
                     config={})

    with caplog.at_level(logging.ERROR):
        assert not run_election_new_upsert_validator(args, b)
        assert caplog.records[0].msg.__class__ == FileNotFoundError
Exemple #4
0
def test_election_new_upsert_validator_with_tendermint(b, priv_validator_path,
                                                       user_sk, validators):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator

    new_args = Namespace(
        action='new',
        election_type='upsert-validator',
        public_key='HHG0IQRybpT6nJMIWWFWhMczCLHt6xcm7eP52GnGuPY=',
        power=1,
        node_id='unique_node_id_for_test_upsert_validator_new_with_tendermint',
        sk=priv_validator_path,
        config={})

    election_id = run_election_new_upsert_validator(new_args, b)

    assert b.get_transaction(election_id)
Exemple #5
0
def test_election_new_upsert_validator_invalid_power(caplog, b, priv_validator_path, user_sk):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator
    from bigchaindb.common.exceptions import InvalidPowerChange

    def mock_write(tx, mode):
        b.store_bulk_transactions([tx])
        return (400, '')

    b.write_transaction = mock_write
    b.get_validators = mock_get_validators
    args = Namespace(action='new',
                     election_type='upsert_validator',
                     public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
                     power=10,
                     node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                     sk=priv_validator_path,
                     config={})

    with caplog.at_level(logging.ERROR):
        assert not run_election_new_upsert_validator(args, b)
        assert caplog.records[0].msg.__class__ == InvalidPowerChange
Exemple #6
0
def test_election_new_upsert_validator_without_tendermint(caplog, b, priv_validator_path, user_sk):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator

    def mock_write(tx, mode):
        b.store_bulk_transactions([tx])
        return (202, '')

    b.get_validators = mock_get_validators
    b.write_transaction = mock_write

    args = Namespace(action='new',
                     election_type='upsert_validator',
                     public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
                     power=1,
                     node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                     sk=priv_validator_path,
                     config={})

    with caplog.at_level(logging.INFO):
        election_id = run_election_new_upsert_validator(args, b)
        assert caplog.records[0].msg == '[SUCCESS] Submitted proposal with id: ' + election_id
        assert b.get_transaction(election_id)
Exemple #7
0
def test_election_approve_with_tendermint(b, priv_validator_path, user_sk, validators):
    from bigchaindb.commands.bigchaindb import (run_election_new_upsert_validator,
                                                run_election_approve)

    public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg='
    new_args = Namespace(action='new',
                         election_type='upsert_validator',
                         public_key=public_key,
                         power=1,
                         node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                         sk=priv_validator_path,
                         config={})

    election_id = run_election_new_upsert_validator(new_args, b)
    assert election_id

    args = Namespace(action='approve',
                     election_id=election_id,
                     sk=priv_validator_path,
                     config={})
    approve = run_election_approve(args, b)

    assert b.get_transaction(approve)
Exemple #8
0
def test_election_new_upsert_validator_invalid_power(caplog, b,
                                                     priv_validator_path,
                                                     user_sk):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator
    from bigchaindb.common.exceptions import InvalidPowerChange

    def mock_write(tx, mode):
        b.store_bulk_transactions([tx])
        return (400, '')

    b.write_transaction = mock_write
    b.get_validators = mock_get_validators
    args = Namespace(action='new',
                     election_type='upsert-validator',
                     public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
                     power=10,
                     node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                     sk=priv_validator_path,
                     config={})

    with caplog.at_level(logging.ERROR):
        assert not run_election_new_upsert_validator(args, b)
        assert caplog.records[0].msg.__class__ == InvalidPowerChange
Exemple #9
0
def test_election_approve_with_tendermint(b, priv_validator_path, user_sk,
                                          validators):
    from bigchaindb.commands.bigchaindb import (
        run_election_new_upsert_validator, run_election_approve)

    public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg='
    new_args = Namespace(action='new',
                         election_type='upsert-validator',
                         public_key=public_key,
                         power=1,
                         node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                         sk=priv_validator_path,
                         config={})

    election_id = run_election_new_upsert_validator(new_args, b)
    assert election_id

    args = Namespace(action='approve',
                     election_id=election_id,
                     sk=priv_validator_path,
                     config={})
    approve = run_election_approve(args, b)

    assert b.get_transaction(approve)
Exemple #10
0
def test_election_new_upsert_validator_without_tendermint(
        caplog, b, priv_validator_path, user_sk):
    from bigchaindb.commands.bigchaindb import run_election_new_upsert_validator

    def mock_write(tx, mode):
        b.store_bulk_transactions([tx])
        return (202, '')

    b.get_validators = mock_get_validators
    b.write_transaction = mock_write

    args = Namespace(action='new',
                     election_type='upsert-validator',
                     public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
                     power=1,
                     node_id='fb7140f03a4ffad899fabbbf655b97e0321add66',
                     sk=priv_validator_path,
                     config={})

    with caplog.at_level(logging.INFO):
        election_id = run_election_new_upsert_validator(args, b)
        assert caplog.records[
            0].msg == '[SUCCESS] Submitted proposal with id: ' + election_id
        assert b.get_transaction(election_id)