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',
            'data': node_pub
        },
        'voting_power': 10
    }]

    latest_block = b.get_latest_block()
    # reset the validator set
    b.store_validator_set(latest_block['height'], validators,
                          'previous_election_id')

    power = 1
    public_key = '9B3119650DF82B9A5D8A12E38953EA47475C09F0C48A4E6A0ECE182944B24403'
    public_key64 = public_key_to_base64(public_key)
    new_validator = {
        'public_key': public_key,
        'node_id': 'some_node_id',
        'power': power
    }

    voters = ValidatorElection.recipients(b)
    election = ValidatorElection.generate([node_key.public_key], voters,
                                          new_validator,
                                          None).sign([node_key.private_key])
    code, message = b.write_transaction(election, 'broadcast_tx_commit')
    assert code == 202
    time.sleep(3)

    assert b.get_transaction(election.id)

    tx_vote = gen_vote(election, 0, ed25519_node_keys)
    assert tx_vote.validate(b)
    code, message = b.write_transaction(tx_vote, 'broadcast_tx_commit')
    assert code == 202
    time.sleep(3)

    resp = requests.get(b.endpoint + 'validators')
    validator_pub_keys = []
    for v in resp.json()['result']['validators']:
        validator_pub_keys.append(v['pub_key']['value'])

    assert (public_key64 in validator_pub_keys)
    new_validator_set = b.get_validators()
    validator_pub_keys = []
    for v in new_validator_set:
        validator_pub_keys.append(v['pub_key']['data'])

    assert (public_key64 in validator_pub_keys)
示例#2
0
def test_upsert_validator(b, node_key, node_keys, ed25519_node_keys):

    if b.get_latest_block()['height'] == 0:
        generate_block(b)

    (node_pub, _) = list(node_keys.items())[0]

    validators = [{
        'public_key': {
            'type': 'ed25519-base64',
            'value': node_pub
        },
        'voting_power': 10
    }]

    latest_block = b.get_latest_block()
    # reset the validator set
    b.store_validator_set(latest_block['height'], validators)
    generate_block(b)

    power = 1
    public_key = '9B3119650DF82B9A5D8A12E38953EA47475C09F0C48A4E6A0ECE182944B24403'
    public_key64 = public_key_to_base64(public_key)
    new_validator = {
        'public_key': {
            'value': public_key,
            'type': 'ed25519-base16'
        },
        'node_id': 'some_node_id',
        'power': power
    }

    voters = ValidatorElection.recipients(b)
    election = ValidatorElection.generate([node_key.public_key], voters,
                                          new_validator,
                                          None).sign([node_key.private_key])
    code, message = b.write_transaction(election, BROADCAST_TX_COMMIT)
    assert code == 202
    assert b.get_transaction(election.id)

    tx_vote = gen_vote(election, 0, ed25519_node_keys)
    assert tx_vote.validate(b)
    code, message = b.write_transaction(tx_vote, BROADCAST_TX_COMMIT)
    assert code == 202

    resp = b.get_validators()
    validator_pub_keys = []
    for v in resp:
        validator_pub_keys.append(v['public_key']['value'])

    assert (public_key64 in validator_pub_keys)
    new_validator_set = b.get_validators()
    validator_pub_keys = []
    for v in new_validator_set:
        validator_pub_keys.append(v['public_key']['value'])

    assert (public_key64 in validator_pub_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 = [{'public_key': {'type': 'ed25519-base64', 'value': node_pub},
                   'voting_power': 10}]

    latest_block = b.get_latest_block()
    # reset the validator set
    b.store_validator_set(latest_block['height'], validators)

    power = 1
    public_key = '9B3119650DF82B9A5D8A12E38953EA47475C09F0C48A4E6A0ECE182944B24403'
    public_key64 = public_key_to_base64(public_key)
    new_validator = {'public_key': {'value': public_key, 'type': 'ed25519-base16'},
                     'node_id': 'some_node_id',
                     'power': power}

    voters = ValidatorElection.recipients(b)
    election = ValidatorElection.generate([node_key.public_key],
                                          voters,
                                          new_validator, None).sign([node_key.private_key])
    code, message = b.write_transaction(election, 'broadcast_tx_commit')
    assert code == 202
    time.sleep(3)

    assert b.get_transaction(election.id)

    tx_vote = gen_vote(election, 0, ed25519_node_keys)
    assert tx_vote.validate(b)
    code, message = b.write_transaction(tx_vote, 'broadcast_tx_commit')
    assert code == 202
    time.sleep(3)

    resp = requests.get(b.endpoint + 'validators')
    validator_pub_keys = []
    for v in resp.json()['result']['validators']:
        validator_pub_keys.append(v['pub_key']['value'])

    assert (public_key64 in validator_pub_keys)
    new_validator_set = b.get_validators()
    validator_pub_keys = []
    for v in new_validator_set:
        validator_pub_keys.append(v['public_key']['value'])

    assert (public_key64 in validator_pub_keys)