Beispiel #1
0
def proposal_pips(all_clients):
    '''
    get verifier Client object list
    :param global_test_env:
    :return:
    '''
    verifier_list = get_pledge_list(all_clients[0].ppos.getVerifierList)
    pip = get_client_by_nodeid(verifier_list[0], all_clients).pip
    if pip.chain_version != pip.cfg.version0:
        pip.economic.env.deploy_all()
    if pip.is_exist_effective_proposal():
        proposalinfo = pip.get_effect_proposal_info_of_vote()
        log.info('proprosalinfo : {}'.format(proposalinfo))
        if proposalinfo.get('EndVotingBlock') - pip.node.block_number > 2 * pip.economic.consensus_size \
                and proposalinfo.get('NewVersion') == pip.cfg.version5:
            verifier_list = get_pledge_list(all_clients[0].ppos.getVerifierList)
            log.info('verifierlist{}'.format(verifier_list))
            clients_verifier = get_clients_by_nodeid(verifier_list, all_clients)
            return [client.pip for client in clients_verifier]
        else:
            pip.economic.env.deploy_all()
    result = pip.submitVersion(pip.node.node_id, str(time.time()), pip.cfg.version5, 10,
                               pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg)
    log.info('version proposal result :{}'.format(result))
    verifier_list = get_pledge_list(all_clients[0].ppos.getVerifierList)
    log.info('verifierlist{}'.format(verifier_list))
    clients_verifier = get_clients_by_nodeid(verifier_list, all_clients)
    return [client.pip for client in clients_verifier]
Beispiel #2
0
def noproposal_candidate_pips(all_clients) -> List[Pip]:
    '''
    Get verifier Client object list
    :param global_test_env:
    :return:
    '''
    if all_clients[0].pip.is_exist_effective_proposal() or all_clients[0].pip.chain_version != \
            all_clients[0].pip.cfg.version0:
        log.info('There is effective proposal, Restart the chain')
        all_clients[0].economic.env.deploy_all()
    nodeid_list = all_clients[0].pip.get_candidate_list_not_verifier()
    log.info('candidate not verifier list {}'.format(nodeid_list))
    if not nodeid_list:
        candidate_list = get_pledge_list(all_clients[0].ppos.getCandidateList)
        log.info('candidate_list{}'.format(candidate_list))
        for client in all_clients:
            if client.node.node_id not in candidate_list:
                address, _ = client.economic.account.generate_account(client.node.web3, 10**18 * 10000000)
                result = client.staking.create_staking(0, address, address)
                log.info('node {} staking result {}'.format(client.node.node_id, result))
        client.economic.wait_settlement_blocknum(client.node)
        nodeid_list = all_clients[0].pip.get_candidate_list_not_verifier()
        if not nodeid_list:
            raise Exception('get candidate not verifier failed')
    clients_candidate = get_clients_by_nodeid(nodeid_list, all_clients)
    return [client_candidate.pip for client_candidate in clients_candidate]
Beispiel #3
0
def preactive_proposal_pips(all_clients):
    if all_clients[0].pip.is_exist_effective_proposal() or all_clients[0].pip.chain_version != \
            all_clients[0].pip.cfg.version0 or all_clients[0].pip.is_exist_effective_proposal_for_vote(
        all_clients[0].pip.cfg.param_proposal
    ):
        log.info('There is effective version proposal, restart the chain')
        all_clients[0].economic.env.deploy_all()
    verifier_list = get_pledge_list(all_clients[0].ppos.getVerifierList)
    log.info('verifierlist :{}'.format(verifier_list))
    client_verifiers = get_clients_by_nodeid(verifier_list, all_clients)
    pips = [client_verifier.pip for client_verifier in client_verifiers]
    log.info('pips :{}'.format(pips))
    result = pips[0].submitVersion(pips[0].node.node_id,
                                   str(time.time()),
                                   pips[0].cfg.version5,
                                   8,
                                   pips[0].node.staking_address,
                                   transaction_cfg=pips[0].cfg.transaction_cfg)
    log.info('submit version proposal, result : {}'.format(result))
    proposalinfo = pips[0].get_effect_proposal_info_of_vote()
    log.info('Version proposalinfo: {}'.format(proposalinfo))
    for pip in pips:
        result = version_proposal_vote(pip)
        assert_code(result, 0)
    wait_block_number(pips[0].node, proposalinfo.get('EndVotingBlock'))
    assert pips[0].get_status_of_proposal(proposalinfo.get('ProposalID')) == 4
    return pips
Beispiel #4
0
def param_governance_verify(client,
                            module,
                            name,
                            newvalue,
                            effectiveflag=True):
    """
    effectiveflag indicates whether it takes effect
    """
    if isinstance(client, Client):
        pip = client.pip
    else:
        raise Exception("client must Client class")
    if pip.is_exist_effective_proposal_for_vote(pip.cfg.param_proposal) or \
            pip.is_exist_effective_proposal_for_vote(pip.cfg.version_proposal):
        raise Exception(
            'There is effective param proposal or version proposal')
    result = pip.submitParam(pip.node.node_id,
                             str(time.time()),
                             module,
                             name,
                             newvalue,
                             pip.node.staking_address,
                             transaction_cfg=pip.cfg.transaction_cfg)
    log.info('submit param proposal result : {}'.format(result))
    assert_code(result, 0)
    proposalinfo = pip.get_effect_proposal_info_of_vote(pip.cfg.param_proposal)
    log.info('param proposalinfo : {}'.format(proposalinfo))
    all_clients = []
    for node_obj in pip.economic.env.get_all_nodes():
        all_clients.append(
            Client(
                pip.economic.env, node_obj,
                StakingConfig("externalId", "nodeName", "website", "details")))
    client = get_client_by_nodeid(pip.node.node_id, all_clients)
    verifier_list = get_pledge_list(client.ppos.getVerifierList)
    log.info('verifierlist : {}'.format(verifier_list))
    clients_verifier = get_clients_by_nodeid(verifier_list, all_clients)
    if effectiveflag:
        blocknum = 0
        for client in clients_verifier:
            if client.node.block_number < blocknum and blocknum != 0:
                wait_block_number(client.node, blocknum)
            result = client.pip.vote(
                client.node.node_id,
                proposalinfo.get('ProposalID'),
                client.pip.cfg.vote_option_yeas,
                client.node.staking_address,
                transaction_cfg=client.pip.cfg.transaction_cfg)
            log.info('Node {} vote proposal result : {}'.format(
                client.node.node_id, result))
            blocknum = client.node.block_number
    wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
    if effectiveflag:
        assert pip.get_status_of_proposal(proposalinfo.get('ProposalID')) == 2
        log.info("blockNumber {}, the {} has become {}".format(
            proposalinfo.get('EndVotingBlock'), name, newvalue))
    else:
        assert pip.get_status_of_proposal(proposalinfo.get('ProposalID')) == 3
        log.info("{} retains the original value".format(name))
Beispiel #5
0
def clients_verifier(global_running_env, staking_cfg) -> List[Client]:
    """
    Get verifier node  Client object list
    """
    all_clients = get_clients(global_running_env, staking_cfg)
    verifier_list = get_pledge_list(all_clients[0].ppos.getVerifierList)
    log.info('verifierlist{}'.format(verifier_list))
    return get_clients_by_nodeid(verifier_list, all_clients)
Beispiel #6
0
def noproposal_pips(all_clients) -> List[Pip]:
    '''
    Get candidate Client object list
    :param global_test_env:
    :return:
    '''
    if all_clients[0].pip.is_exist_effective_proposal() or all_clients[0].pip.chain_version != \
            all_clients[0].pip.cfg.version0:
        log.info('There is effective proposal, Restart the chain')
        all_clients[0].economic.env.deploy_all()
    verifier_list = get_pledge_list(all_clients[0].ppos.getVerifierList)
    log.info('verifierlist{}'.format(verifier_list))
    clients = get_clients_by_nodeid(verifier_list, all_clients)
    return [client.pip for client in clients]