Example #1
0
 def clean_db_all(self):
     """
     Close all nodes and delete the database
     """
     log.info("clean db all node")
     self.clean_db_nodes(self.get_all_nodes())
Example #2
0
    def test_PR_IN_001_002(self, no_vp_proposal):
        pip = no_vp_proposal
        pip_id = str(time.time())
        result = pip.submitVersion(pip.node.node_id,
                                   pip_id,
                                   pip.cfg.version8,
                                   3,
                                   pip.node.staking_address,
                                   transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit version proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_version = pip.get_effect_proposal_info_of_vote(
            pip.cfg.version_proposal)
        log.info('Get version proposal information : {}'.format(
            proposalinfo_version))
        pip_id_cancel = str(time.time())
        result = pip.submitCancel(pip.node.node_id,
                                  pip_id_cancel,
                                  1,
                                  proposalinfo_version.get('ProposalID'),
                                  pip.node.staking_address,
                                  transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit cancel proposal result : {}'.format(result))
        assert_code(result, 0)

        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(
            pip.cfg.cancel_proposal)
        log.info(
            'Get cancel proposal information : {}'.format(proposalinfo_cancel))

        result_version = pip.pip.getProposal(
            proposalinfo_version.get('ProposalID'))
        log.info(
            'Interface getProposal-version result : {}'.format(result_version))

        result_cancel = pip.pip.getProposal(
            proposalinfo_cancel.get('ProposalID'))
        log.info(
            'Interface getProposal-cancel result : {}'.format(result_cancel))

        assert result_version.get('Ret').get('Proposer') == pip.node.node_id
        assert result_version.get('Ret').get(
            'ProposalType') == pip.cfg.version_proposal
        assert result_version.get('Ret').get('PIPID') == pip_id
        assert result_version.get('Ret').get(
            'SubmitBlock') == proposalinfo_version.get('SubmitBlock')
        caculated_endvotingblock = math.ceil(
            proposalinfo_version.get('SubmitBlock') /
            pip.economic.consensus_size + 3) * pip.economic.consensus_size - 20
        assert result_version.get('Ret').get(
            'EndVotingBlock') == caculated_endvotingblock

        assert result_cancel.get('Ret').get('Proposer') == pip.node.node_id
        assert result_cancel.get('Ret').get(
            'ProposalType') == pip.cfg.cancel_proposal
        assert result_cancel.get('Ret').get('PIPID') == pip_id_cancel
        assert result_cancel.get('Ret').get(
            'SubmitBlock') == proposalinfo_cancel.get('SubmitBlock')
        caculated_endvotingblock = math.ceil(proposalinfo_cancel.get('SubmitBlock') / pip.economic.consensus_size) * \
            pip.economic.consensus_size + 20
        assert result_cancel.get('Ret').get(
            'EndVotingBlock') == caculated_endvotingblock
Example #3
0
    def test_IN_GG_001(self, client_noconsensus):
        client_noconsensus.economic.env.deploy_all()
        genesis = from_dict(
            data_class=Genesis,
            data=client_noconsensus.economic.env.genesis_config)
        pip = client_noconsensus.pip.pip
        result = pip.getGovernParamValue('slashing', 'slashBlocksReward')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.slashing.slashBlocksReward == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('slashing', 'maxEvidenceAge')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.slashing.maxEvidenceAge == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('slashing',
                                         'slashFractionDuplicateSign')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.slashing.slashFractionDuplicateSign == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('slashing',
                                         'duplicateSignReportReward')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.slashing.duplicateSignReportReward == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('slashing',
                                         'zeroProduceFreezeDuration')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.slashing.zeroProduceFreezeDuration == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('staking', 'stakeThreshold')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.staking.stakeThreshold == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('staking', 'operatingThreshold')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.staking.operatingThreshold == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('staking', 'unStakeFreezeDuration')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.staking.unStakeFreezeDuration == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('staking', 'maxValidators')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert genesis.economicModel.staking.maxValidators == int(
            result.get('Ret'))

        result = pip.getGovernParamValue('block', 'maxBlockGasLimit')
        log.info('Interface getGovernParamValue result : {}'.format(result))
        assert_code(result, 0)
Example #4
0
    def test_2(self, new_genesis_env, clients_consensus):
        new_genesis_env.deploy_all()
        pip = clients_consensus[0].pip
        submitvpandvote(clients_consensus[0:2])
        # replace_version_declare(pip, pip.cfg.PLATON_NEW_BIN, pip.cfg.version5)
        proposalinfo = pip.get_effect_proposal_info_of_vote()
        wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
        assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 3)
        submitvpandvote(clients_consensus[1:4])
        proposalinfo = pip.get_effect_proposal_info_of_vote()
        wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
        assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 4)
        pip.economic.wait_consensus_blocknum(pip.node)
        validator = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info(validator)
        assert pip.node.node_id not in validator
        programversion = clients_consensus[0].staking.get_version()
        log.info(programversion)

        programversion = clients_consensus[1].staking.get_version()
        log.info(programversion)

        programversion = clients_consensus[2].staking.get_version()
        log.info(programversion)

        programversion = clients_consensus[3].staking.get_version()
        log.info(programversion)

        verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList)
        log.info(verifier_list)
Example #5
0
    def test_AC_IN_001_002_004_to_006_012_to_014(self, new_genesis_env,
                                                 clients_consensus):
        # genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config)
        # genesis.economicModel.slashing.maxEvidenceAge = 1
        # new_genesis_env.set_genesis(genesis.to_dict())
        new_genesis_env.deploy_all()
        pip = clients_consensus[-1].pip
        result = pip.submitVersion(pip.node.node_id,
                                   str(time.time()),
                                   pip.cfg.version5,
                                   12,
                                   pip.node.staking_address,
                                   transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit version proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_version = pip.get_effect_proposal_info_of_vote()
        log.info('Get version proposal information : {}'.format(
            proposalinfo_version))

        result = pip.submitCancel(pip.node.node_id,
                                  str(time.time()),
                                  10,
                                  proposalinfo_version.get('ProposalID'),
                                  pip.node.staking_address,
                                  transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit cancel proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(
            pip.cfg.cancel_proposal)
        log.info('Get cancel proposal information : {}'.format(
            proposalinfo_version))

        for index in range(3):
            log.info(f'index == {index}')
            client = clients_consensus[index]
            result = version_proposal_vote(client.pip)
            assert_code(result, 0)
            result = client.pip.vote(client.node.node_id,
                                     proposalinfo_cancel.get('ProposalID'),
                                     index + 1,
                                     client.node.staking_address,
                                     transaction_cfg=pip.cfg.transaction_cfg)
            log.info('Node {} vote cancel proposal result : {}'.format(
                client.node.node_id, result))
            assert_code(result, 0)
        log.info(f'blocknumber0000 == {pip.node.block_number}')
        log.info(f'getCandidateList == {pip.node.ppos.getCandidateList()}')
        assert pip.get_accuverifiers_count(
            proposalinfo_version.get('ProposalID')) == [4, 3, 0, 0]
        assert pip.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 1, 1]
        log.info('Stop the node {}'.format(clients_consensus[0].node.node_id))
        clients_consensus[0].node.stop()
        pip.economic.wait_consensus(pip.node, 2)
        log.info(pip.node.debug.getWaitSlashingNodeList())
        log.info(pip.pip.listGovernParam())
        log.info(clients_consensus[1].ppos.getCandidateInfo(
            pip.node.node_id, pip.node.staking_address))
        assert pip.get_accuverifiers_count(
            proposalinfo_version.get('ProposalID')) == [4, 3, 0, 0]
        assert pip.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 1, 1]

        log.info(f'blocknumber1111 == {pip.node.block_number}')
        report_information = mock_duplicate_sign(
            1, clients_consensus[1].node.nodekey,
            clients_consensus[1].node.blsprikey, 41)
        log.info("Report information: {}".format(report_information))
        address, _ = pip.economic.account.generate_account(
            pip.node.web3, 10**18 * 1000)
        result = clients_consensus[-1].duplicatesign.reportDuplicateSign(
            1, report_information, address)
        log.info('Node duplicate block result : {}'.format(result))
        assert_code(result, 0)
        log.info(f'blocknumber2222 == {pip.node.block_number}')
        assert pip.get_accuverifiers_count(
            proposalinfo_version.get('ProposalID')) == [4, 2, 0, 0]
        assert pip.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 0, 1]

        report_information = mock_duplicate_sign(
            2, clients_consensus[2].node.nodekey,
            clients_consensus[2].node.blsprikey, 41)
        log.info("Report information: {}".format(report_information))
        address, _ = pip.economic.account.generate_account(
            pip.node.web3, 10**18 * 1000)
        result = clients_consensus[-1].duplicatesign.reportDuplicateSign(
            2, report_information, address)
        log.info('Node duplicate block result : {}'.format(result))
        assert_code(result, 0)
        assert pip.get_accuverifiers_count(
            proposalinfo_version.get('ProposalID')) == [4, 1, 0, 0]
        assert pip.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 0, 0]
Example #6
0
 def test_V_STA_2_to_5(self, no_vp_proposal, clients_verifier):
     pip = no_vp_proposal
     value = len(clients_verifier) - 2
     submitvpandvote(clients_verifier[:value], votingrounds=4)
     proposalinfo = pip.get_effect_proposal_info_of_vote()
     log.info('Get version proposal information : {}'.format(proposalinfo))
     result = version_proposal_vote(clients_verifier[-2].pip)
     log.info('Node {} vote proposal result : {}'.format(
         clients_verifier[-1].node.node_id, result))
     assert_code(result, 0)
     wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
     pip = clients_verifier[-1].pip
     upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN)
     pip.node.restart()
     log.info('Replace the platon bin and restart the node {}'.format(
         pip.node.node_id))
     result = pip.vote(pip.node.node_id,
                       proposalinfo.get('ProposalID'),
                       pip.cfg.vote_option_yeas,
                       pip.node.staking_address,
                       transaction_cfg=pip.cfg.transaction_cfg)
     log.info('Node {} vote proposal result : {}'.format(
         clients_verifier[-1].node.node_id, result))
     assert_code(result, 302026)
     log.info('{}'.format(
         pip.pip.getTallyResult(proposalinfo.get('ProposalID'))))
     assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')),
                 4)
     result = pip.vote(pip.node.node_id,
                       proposalinfo.get('ProposalID'),
                       pip.cfg.vote_option_yeas,
                       pip.node.staking_address,
                       transaction_cfg=pip.cfg.transaction_cfg)
     log.info('Node {} vote proposal result : {}'.format(
         clients_verifier[-1].node.node_id, result))
     assert_code(result, 302026)
     wait_block_number(pip.node, proposalinfo.get('ActiveBlock'))
     assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')),
                 5)
Example #7
0
    def test_UV_UPG_1_UV_UPG_2(self, new_genesis_env, clients_consensus, client_noconsensus):
        new_genesis_env.deploy_all()
        pip = clients_consensus[0].pip
        pip_test = client_noconsensus.pip
        address, _ = pip_test.economic.account.generate_account(pip_test.node.web3, 10**18 * 10000000)
        result = client_noconsensus.staking.create_staking(0, address, address, amount=10 ** 18 * 2000000,
                                                           transaction_cfg=pip_test.cfg.transaction_cfg)
        log.info('Node {} staking result : {}'.format(pip_test.node.node_id, result))
        programversion = client_noconsensus.staking.get_version()
        assert_code(programversion, pip.cfg.version0)
        pip_test.economic.wait_settlement_blocknum(pip_test.node)
        log.info(f'blocknem ====== {pip_test.node.eth.blockNumber}')
        verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList)
        log.info('Get verifier list : {}'.format(verifier_list))
        assert pip_test.node.node_id in verifier_list

        submitvpandvote(clients_consensus)
        programversion = clients_consensus[0].staking.get_version()
        assert_code(programversion, pip.cfg.version0)
        proposalinfo = pip.get_effect_proposal_info_of_vote()
        log.info('Get version proposal information : {}'.format(proposalinfo))
        wait_block_number(pip.node, proposalinfo.get('EndVotingBlock') - 1)
        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list =====: {}'.format(validator_list))

        wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
        assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 4)
        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list : {}'.format(validator_list))
        wait_block_number(pip.node, proposalinfo.get('ActiveBlock'))
        log.info(f'blocknem ====== {pip_test.node.eth.blockNumber}')

        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list : {}'.format(validator_list))
        assert pip_test.node.node_id not in validator_list

        assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 5)
        pip.economic.wait_settlement_blocknum(pip.node)
        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list : {}'.format(validator_list))
        assert pip_test.node.node_id not in validator_list
        verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList)
        log.info('Get verifier list : {}'.format(verifier_list))
        assert pip_test.node.node_id not in verifier_list
        balance_before = pip.node.eth.getBalance(address, 2 * pip.economic.settlement_size - 1)
        log.info('Block number {} address balace {}'.format(2 * pip.economic.settlement_size - 1, balance_before))
        balance_after = pip.node.eth.getBalance(address, 2 * pip.economic.settlement_size)
        log.info('Block number {} address balace {}'.format(2 * pip.economic.settlement_size, balance_after))
        _, staking_reward = pip_test.economic.get_current_year_reward(pip_test.node, verifier_num=5)
        log.info('Staking reward : {}'.format(staking_reward))
        assert balance_after - balance_before == staking_reward
Example #8
0
 def upload_file(self, local_file, remote_file):
     if local_file and os.path.exists(local_file):
         self.sftp.put(local_file, remote_file)
     else:
         log.info("file: {} not found".format(local_file))
Example #9
0
def test_POP_010_011(client_consensus, client_new_node):
    """
    (hesitation period, lockup period) free amount initiate revocation entrustment
    :param client_consensus:
    :param client_new_node:
    :param new_genesis_env:
    :return:
    """
    client_consensus.economic.env.deploy_all()
    address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
                                                                    10 ** 18 * 10000000)
    address_delegate_1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
                                                                              10 ** 18 * 10000000)
    result = client_new_node.staking.create_staking(0, address1, address1)
    assert_code(result, 0)
    delegate_amount = client_consensus.economic.delegate_limit + client_consensus.node.web3.toWei(40, "ether")
    log.info("Entrust the sum{}".format(delegate_amount))
    result = client_new_node.delegate.delegate(0, address_delegate_1, amount=delegate_amount)
    assert_code(result, 0)
    amount1_before = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount1_before))
    parameters_amount = client_consensus.economic.delegate_limit + client_consensus.node.web3.toWei(10, "ether")

    block = param_governance_verify_before_endblock(client_consensus, "staking", "operatingThreshold",
                                                    str(parameters_amount))
    log.info("The value of the proposal parameters{}".format(parameters_amount))
    wait_block_number(client_new_node.node, block)
    log.info("The delegate is initiated after the parameter takes effect")
    address_delegate_2, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
                                                                              10 ** 18 * 10000000)
    result = client_new_node.delegate.delegate(0, address_delegate_2, amount=delegate_amount)
    assert_code(result, 0)
    amount2_before = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount2_before))

    msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id)
    staking_blocknum = msg["Ret"]["StakingBlockNum"]
    withdrew_delegate_amount = delegate_amount - parameters_amount + client_consensus.node.web3.toWei(1, "ether")

    result = client_new_node.delegate.withdrew_delegate(staking_blocknum, address_delegate_1,
                                                        amount=withdrew_delegate_amount)
    assert_code(result, 0)
    amount1_after = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount1_after))
    assert amount1_before - amount1_after < client_new_node.node.web3.toWei(1, "ether")

    result = client_new_node.delegate.withdrew_delegate(staking_blocknum, address_delegate_2,
                                                        amount=withdrew_delegate_amount)
    assert_code(result, 0)
    amount2_after = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount2_after))
    assert amount1_before - amount1_after < client_new_node.node.web3.toWei(1, "ether")
Example #10
0
def param_governance_verify(client_obj, module, name, newvalue, effectiveflag=True):
    """
    effectiveflag indicates whether it takes effect
    """
    if isinstance(client_obj, Client):
        pip_obj = client_obj.pip
    else:
        raise Exception("client must Client class")
    if pip_obj.is_exist_effective_proposal_for_vote(pip_obj.cfg.param_proposal) or \
            pip_obj.is_exist_effective_proposal_for_vote(pip_obj.cfg.version_proposal):
        raise Exception('There is effective param proposal or version proposal')
    result = pip_obj.submitParam(pip_obj.node.node_id, str(time.time()), module, name, newvalue, pip_obj.node.staking_address,
                                 transaction_cfg=pip_obj.cfg.transaction_cfg)
    log.info('submit param proposal result : {}'.format(result))
    assert_code(result, 0)
    proposalinfo = pip_obj.get_effect_proposal_info_of_vote(pip_obj.cfg.param_proposal)
    log.info('param proposalinfo : {}'.format(proposalinfo))
    client_obj_list = []
    for node_obj in pip_obj.economic.env.get_all_nodes():
        client_obj_list.append(Client(pip_obj.economic.env, node_obj,
                                      StakingConfig("externalId", "nodeName", "website", "details")))
    client_obj = get_client_obj(pip_obj.node.node_id, client_obj_list)
    verifier_list = get_pledge_list(client_obj.ppos.getVerifierList)
    log.info('verifierlist : {}'.format(verifier_list))
    client_verifier_obj_list = get_client_obj_list(verifier_list, client_obj_list)
    if effectiveflag:
        for client_obj in client_verifier_obj_list:
            result = client_obj.pip.vote(client_obj.node.node_id, proposalinfo.get('ProposalID'),
                                         client_obj.pip.cfg.vote_option_yeas,
                                         client_obj.node.staking_address, transaction_cfg=client_obj.pip.cfg.transaction_cfg)
            log.info('Node {} vote proposal result : {}'.format(client_obj.node.node_id, result))
    wait_block_number(pip_obj.node, proposalinfo.get('EndVotingBlock'))
    if effectiveflag:
        assert pip_obj.get_status_of_proposal(proposalinfo.get('ProposalID')) == 2
        log.info("blockNumber {}, the {} has become {}".format(proposalinfo.get('EndVotingBlock'), name, newvalue))
    else:
        assert pip_obj.get_status_of_proposal(proposalinfo.get('ProposalID')) == 3
        log.info("{} retains the original value".format(name))
Example #11
0
def test_CH_IN_015(global_test_env):
    """
    View economic model parameters, governance parameters, penalty parameters, and whether the reward parameters are correctly configured parameters
    """
    log.info(
        "View economic model parameters, governance parameters, penalty parameters, and whether the reward parameters are correctly configured parameters"
    )
    # economic_info = global_test_env.genesis_config['EconomicModel']
    if not global_test_env.running:
        global_test_env.deploy_all()
    genesis = to_genesis(global_test_env.genesis_config)
    w3_list = [
        one_node.web3 for one_node in global_test_env.consensus_node_list
    ]
    for w3 in w3_list:
        info = w3.debug.economicConfig()
        assert info['common'][
            'maxEpochMinutes'] == genesis.economicModel.common.maxEpochMinutes
        assert info['common'][
            'maxConsensusVals'] == genesis.economicModel.common.maxConsensusVals
        assert info["common"][
            "additionalCycleTime"] == genesis.economicModel.common.additionalCycleTime

        assert info['staking'][
            'stakeThreshold'] == genesis.economicModel.staking.stakeThreshold
        assert info['staking'][
            'operatingThreshold'] == genesis.economicModel.staking.operatingThreshold
        assert info['staking'][
            'maxValidators'] == genesis.economicModel.staking.maxValidators
        # assert info['staking']['hesitateRatio'] == genesis.economicModel.staking.hesitateRatio
        assert info['staking'][
            'unStakeFreezeDuration'] == genesis.economicModel.staking.unStakeFreezeDuration

        assert info['slashing'][
            'slashFractionDuplicateSign'] == genesis.economicModel.slashing.slashFractionDuplicateSign
        assert info['slashing'][
            'duplicateSignReportReward'] == genesis.economicModel.slashing.duplicateSignReportReward
        assert info['slashing'][
            'slashBlocksReward'] == genesis.economicModel.slashing.slashBlocksReward
        assert info['slashing'][
            'maxEvidenceAge'] == genesis.economicModel.slashing.maxEvidenceAge

        assert info['gov'][
            'versionProposalVoteDurationSeconds'] == genesis.economicModel.gov.versionProposalVoteDurationSeconds
        assert info['gov'][
            'versionProposalSupportRate'] == genesis.economicModel.gov.versionProposalSupportRate
        assert info['gov'][
            'textProposalVoteDurationSeconds'] == genesis.economicModel.gov.textProposalVoteDurationSeconds
        assert info['gov'][
            'textProposalVoteRate'] == genesis.economicModel.gov.textProposalVoteRate
        assert info['gov'][
            'textProposalSupportRate'] == genesis.economicModel.gov.textProposalSupportRate
        assert info['gov'][
            'cancelProposalVoteRate'] == genesis.economicModel.gov.cancelProposalVoteRate
        assert info['gov'][
            'cancelProposalSupportRate'] == genesis.economicModel.gov.cancelProposalSupportRate
        assert info['gov'][
            'paramProposalVoteDurationSeconds'] == genesis.economicModel.gov.paramProposalVoteDurationSeconds
        assert info['gov'][
            'paramProposalVoteRate'] == genesis.economicModel.gov.paramProposalVoteRate
        assert info['gov'][
            'paramProposalSupportRate'] == genesis.economicModel.gov.paramProposalSupportRate

        assert info['reward'][
            'newBlockRate'] == genesis.economicModel.reward.newBlockRate
        assert info['reward'][
            'platonFoundationYear'] == genesis.economicModel.reward.platONFoundationYear

        assert w3.toChecksumAddress(
            info['innerAcc']['platonFundAccount']) == w3.toChecksumAddress(
                genesis.economicModel.innerAcc.platonFundAccount)
        assert info['innerAcc'][
            'platonFundBalance'] == genesis.economicModel.innerAcc.platonFundBalance
        assert w3.toChecksumAddress(
            info['innerAcc']['cdfAccount']) == w3.toChecksumAddress(
                genesis.economicModel.innerAcc.cdfAccount)
        assert info['innerAcc'][
            'cdfBalance'] == genesis.economicModel.innerAcc.cdfBalance
Example #12
0
def new_genesis_env(global_test_env):
    cfg = copy(global_test_env.cfg)
    yield global_test_env
    log.info("reset deploy.................")
    global_test_env.set_cfg(cfg)
    global_test_env.deploy_all()
Example #13
0
def reset_environment(global_test_env):
    log.info("case execution completed")
    yield
    global_test_env.deploy_all()
Example #14
0
def reset_env(global_test_env):
    cfg = copy(global_test_env.cfg)
    yield
    log.info("reset deploy.................")
    global_test_env.cfg = cfg
    global_test_env.deploy_all()
Example #15
0
    def test_VO_VE_001_002_VO_CA_001_002_VO_TER_002_VO_TER_004(
            self, new_genesis_env, clients_consensus, client_noconsensus):
        pip = clients_consensus[0].pip
        genesis = from_dict(data_class=Genesis,
                            data=new_genesis_env.genesis_config)
        genesis.economicModel.gov.versionProposalVoteDurationSeconds = 3200
        genesis.economicModel.staking.unStakeFreezeDuration = 2
        new_genesis_env.set_genesis(genesis.to_dict())
        new_genesis_env.deploy_all()
        result = pip.submitVersion(pip.node.node_id,
                                   str(time.time()),
                                   pip.cfg.version5,
                                   20,
                                   pip.node.staking_address,
                                   transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit version proposal information : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_version = pip.get_effect_proposal_info_of_vote(
            pip.cfg.version_proposal)
        log.info(
            'Get param proposal information : {}'.format(proposalinfo_version))

        result = pip.submitCancel(pip.node.node_id,
                                  str(time.time()),
                                  10,
                                  proposalinfo_version.get('ProposalID'),
                                  pip.node.staking_address,
                                  transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit cancel proposal information : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(
            pip.cfg.cancel_proposal)
        log.info(
            'Get cancel proposal information : {}'.format(proposalinfo_cancel))

        result = clients_consensus[0].staking.withdrew_staking(
            clients_consensus[0].node.staking_address)
        log.info('Node {} withdrew staking result {}'.format(
            clients_consensus[0].node.node_id, result))
        assert_code(result, 0)
        address = clients_consensus[0].node.staking_address

        result = version_proposal_vote(pip)
        log.info('node vote version proposal result {}'.format(result))
        assert_code(result, 302020)

        result = proposal_vote(pip, proposaltype=pip.cfg.cancel_proposal)
        log.info('node vote cancel proposal result {}'.format(result))
        assert_code(result, 302020)

        address_test, _ = pip.economic.account.generate_account(
            pip.node.web3, 10**18 * 100000)
        result = client_noconsensus.pip.vote(
            client_noconsensus.node.node_id,
            proposalinfo_version.get('ProposalID'),
            pip.cfg.vote_option_yeas,
            address_test,
            transaction_cfg=pip.cfg.transaction_cfg)
        log.info('node {} vote param proposal result {}'.format(
            client_noconsensus.node.node_id, result))
        assert_code(result, 302022)

        result = client_noconsensus.pip.vote(
            client_noconsensus.node.node_id,
            proposalinfo_cancel.get('ProposalID'),
            pip.cfg.vote_option_yeas,
            address_test,
            transaction_cfg=pip.cfg.transaction_cfg)
        log.info('node {} vote cancel proposal result {}'.format(
            client_noconsensus.node.node_id, result))
        assert_code(result, 302022)

        pip.economic.wait_settlement_blocknum(
            pip.node, pip.economic.unstaking_freeze_ratio)
        result = pip.vote(pip.node.node_id,
                          proposalinfo_version.get('ProposalID'),
                          pip.cfg.vote_option_yeas,
                          address,
                          transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Exited node vote version proposal result {}'.format(result))
        assert_code(result, 302022)

        result = pip.vote(pip.node.node_id,
                          proposalinfo_cancel.get('ProposalID'),
                          pip.cfg.vote_option_nays,
                          address,
                          transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Exited node vote cancel proposal result {}'.format(result))
        assert_code(result, 302022)
Example #16
0
def test_POP_014(client_consensus, client_new_node):
    """
    Parameter not in effect - initiate redemption
    :param client_consensus:
    :param client_new_node:
    :param new_genesis_env:
    :return:
    """
    client_consensus.economic.env.deploy_all()
    address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
                                                                    10 ** 18 * 10000000)
    address_delegate_1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
                                                                              10 ** 18 * 10000000)
    result = client_new_node.staking.create_staking(0, address1, address1)
    assert_code(result, 0)
    delegate_amount = client_consensus.economic.delegate_limit + client_consensus.node.web3.toWei(20, "ether")
    log.info("Amount entrusted{}".format(delegate_amount))

    result = client_new_node.delegate.delegate(0, address_delegate_1, amount=delegate_amount)
    assert_code(result, 0)
    amount1_before = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount1_before))
    param_amount = client_consensus.economic.delegate_limit + client_consensus.node.web3.toWei(10, "ether")

    block = param_governance_verify_before_endblock(client_consensus, "staking", "operatingThreshold",
                                                    str(param_amount), effectiveflag=False)
    wait_block_number(client_new_node.node, block)
    log.info("The delegate is initiated after the parameter takes effect")
    address_delegate_2, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
                                                                              10 ** 18 * 10000000)
    result = client_new_node.delegate.delegate(0, address_delegate_2, amount=delegate_amount)
    assert_code(result, 0)
    amount2_before = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount2_before))

    msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id)
    staking_blocknum = msg["Ret"]["StakingBlockNum"]
    withdrew_delegate = delegate_amount - param_amount + client_consensus.node.web3.toWei(1, "ether")
    result = client_new_node.delegate.withdrew_delegate(staking_blocknum, address_delegate_1,
                                                        amount=withdrew_delegate)
    assert_code(result, 0)
    amount1_after = client_new_node.node.eth.getBalance(address_delegate_1)
    log.info("The wallet balance:{}".format(amount1_after))
    amount1_dill = amount1_after - amount1_before
    assert withdrew_delegate - amount1_dill < client_new_node.node.web3.toWei(1, "ether")

    result = client_new_node.delegate.withdrew_delegate(staking_blocknum, address_delegate_2,
                                                        amount=withdrew_delegate)
    assert_code(result, 0)
    amount2_after = client_new_node.node.eth.getBalance(address_delegate_2)
    log.info("The wallet balance:{}".format(amount2_after))
    amount1_dill = amount2_after - amount2_before
    assert withdrew_delegate - amount1_dill < client_new_node.node.web3.toWei(1, "ether")
Example #17
0
    def test_VO_TER_001_003_005(self, candidate_has_proposal, client_verifier):
        pip = candidate_has_proposal
        pip_test = client_verifier.pip
        proposalinfo_version = pip_test.get_effect_proposal_info_of_vote()
        log.info('Get proposal information :{}'.format(proposalinfo_version))
        result = pip_test.submitCancel(
            pip_test.node.node_id,
            str(time.time()),
            1,
            proposalinfo_version.get('ProposalID'),
            pip_test.node.staking_address,
            transaction_cfg=pip_test.cfg.transaction_cfg)
        log.info('Submit cancel proposal result : {}'.format(result))
        assert_code(result, 0)
        result = pip_test.submitText(
            pip_test.node.node_id,
            str(time.time()),
            pip_test.node.staking_address,
            transaction_cfg=pip_test.cfg.transaction_cfg)
        log.info('Submit text proposal result : {}'.format(result))
        assert_code(result, 0)
        result = version_proposal_vote(pip)
        log.info('Candidate node {} vote version proposal result : {}'.format(
            pip.node.node_id, result))
        assert_code(result, 302022)

        result = proposal_vote(pip, proposaltype=pip.cfg.cancel_proposal)
        log.info('Candidate node {} vote cancel proposal result : {}'.format(
            pip.node.node_id, result))
        assert_code(result, 302022)

        result = proposal_vote(pip, proposaltype=pip.cfg.text_proposal)
        log.info('Candidate node {} vote text proposal result : {}'.format(
            pip.node.node_id, result))
        assert_code(result, 302022)
Example #18
0
def version_proposal_vote(pip, vote_option=None):
    proposalinfo = pip.get_effect_proposal_info_of_vote()
    log.info('Version proposalinfo: {}'.format(proposalinfo))
    if not proposalinfo:
        raise Exception('there is no voting version proposal')
    if proposalinfo.get('NewVersion') == pip.cfg.version5:
        upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN)
        log.info('Replace the node {} version to {}'.format(pip.node.node_id, pip.cfg.version5))
    elif proposalinfo.get('NewVersion') == pip.cfg.version8:
        upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN8)
        log.info('Replace the node {} version to {}'.format(pip.node.node_id, pip.cfg.version8))
    elif proposalinfo.get('NewVersion') == pip.cfg.version9:
        upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN9)
        log.info('Replace the node {} version to {}'.format(pip.node.node_id, pip.cfg.version9))
    else:
        raise Exception('The new version of the proposal is{}'.format(proposalinfo.get('NewVersion')))
    pip.node.restart()
    log.info('Restart the node {}'.format(pip.node.node_id))
    if not vote_option:
        vote_option = pip.cfg.vote_option_yeas
    result = pip.vote(pip.node.node_id, proposalinfo.get('ProposalID'), vote_option,
                      pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg)
    log.info('The node {} vote result {}'.format(pip.node.node_id, result))
    return result
Example #19
0
    def test_UV_TR_002_003_009_010(self, new_genesis_env, clients_consensus):
        new_genesis_env.deploy_all()
        pip = clients_consensus[0].pip
        submitvpandvote(clients_consensus[:3])
        proposalinfo_version = pip.get_effect_proposal_info_of_vote()
        log.info('Get version proposal information {}'.format(proposalinfo_version))
        wait_block_number(pip.node, proposalinfo_version.get('ActiveBlock'))
        assert pip.get_status_of_proposal(proposalinfo_version.get('ProposalID')) == 5
        assert pip.chain_version == pip.cfg.version5
        assert pip.get_accuverifiers_count(proposalinfo_version.get('ProposalID'))

        result = pip.submitVersion(pip.node.node_id, str(time.time()), pip.cfg.version8, 3,
                                   pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit version proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_version = pip.get_effect_proposal_info_of_vote()
        log.info('Get version proposal information : {}'.format(proposalinfo_version))
        result = pip.submitCancel(pip.node.node_id, str(time.time()), 1, proposalinfo_version.get('ProposalID'),
                                  pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit cancel proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(pip.cfg.cancel_proposal)
        log.info('Get version proposal information : {}'.format(proposalinfo_cancel))

        upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN8)
        pip.node.restart()

        result = pip.vote(pip.node.node_id, proposalinfo_version.get('ProposalID'), pip.cfg.vote_option_yeas,
                          pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Vote result : {}'.format(result))
        assert_code(result, 0)
        result = pip.vote(pip.node.node_id, proposalinfo_cancel.get('ProposalID'), pip.cfg.vote_option_yeas,
                          pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg)
        assert_code(result, 0)
        log.info('Node {} vote result : {}'.format(pip.node.node_id, result))
def test_UP_FV_009(clients_new_node):
    """
    锁仓账号申请质押,验证人违规被扣除节点自有质押金k
    :param clients_new_node:
    :return:
    """
    client1 = clients_new_node[0]
    client2 = clients_new_node[1]
    economic = client1.economic
    node = client1.node
    print(node.node_mark)
    # create restricting plan and staking
    restricting_balance = node.eth.getBalance(node.ppos.restrictingAddress)
    staking_balance = node.eth.getBalance(node.ppos.stakingAddress)
    address1 = restricting_plan_validation_staking(client1, economic, node)
    # Waiting for the end of the settlement period
    time.sleep(2)
    restricting_balance1 = node.eth.getBalance(node.ppos.restrictingAddress)
    staking_balance1 = node.eth.getBalance(node.ppos.stakingAddress)

    assert restricting_balance == restricting_balance1
    assert staking_balance + economic.create_staking_limit == staking_balance1
    economic.wait_settlement(node)
    # Obtain block bonus and pledge bonus
    balance = client2.node.eth.getBalance(address1)
    print(balance)
    block_reward, staking_reward = client1.economic.get_current_year_reward(
        node)
    # Get penalty blocks
    slash_blocks = get_governable_parameter_value(client1, 'slashBlocksReward')
    # view restricting plan
    restricting_info = client1.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    assert info[
        'debt'] == economic.create_staking_limit, 'ErrMsg: restricting debt amount {}'.format(
            info['debt'])
    log.info("Current block height: {}".format(client2.node.eth.blockNumber))
    # stop node
    client1.node.stop()
    # Waiting for a 3 consensus round
    client2.economic.wait_consensus(client2.node, 3)
    log.info("Current block height: {}".format(client2.node.eth.blockNumber))
    # view verifier list
    verifier_list = client2.ppos.getVerifierList()
    log.info("verifier_list: {}".format(verifier_list))
    punishment_amonut = int(
        Decimal(str(block_reward)) * Decimal(str(slash_blocks)))
    log.info("punishment_amonut: {}".format(punishment_amonut))
    # view restricting plan again
    restricting_info = client2.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    if punishment_amonut < economic.create_staking_limit:
        assert info[
            'Pledge'] == economic.create_staking_limit - punishment_amonut
    else:
        assert_code(restricting_info, 304005)
    client2.economic.wait_settlement(client2.node, 3)
    balance1 = client2.node.eth.getBalance(address1)
    print(balance1)
    assert balance == balance1
Example #21
0
    def test_UV_UPG_2(self, new_genesis_env, clients_consensus, client_noconsensus):
        new_genesis_env.deploy_all()
        pip = clients_consensus[0].pip
        pip_test = client_noconsensus.pip
        address, _ = pip_test.economic.account.generate_account(pip_test.node.web3, 10 ** 18 * 10000000)
        result = client_noconsensus.staking.create_staking(0, address, address, amount=10 ** 18 * 2000000,
                                                           transaction_cfg=pip_test.cfg.transaction_cfg)
        log.info('Node {} staking result : {}'.format(pip_test.node.node_id, result))
        programversion = client_noconsensus.staking.get_version()
        assert_code(programversion, pip.cfg.version0)
        pip_test.economic.wait_settlement_blocknum(pip_test.node)
        verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList)
        log.info('Get verifier list : {}'.format(verifier_list))
        assert pip_test.node.node_id in verifier_list

        submitvpandvote(clients_consensus)
        programversion = clients_consensus[0].staking.get_version()
        assert_code(programversion, pip.cfg.version0)
        proposalinfo = pip.get_effect_proposal_info_of_vote()
        log.info('Get version proposal information : {}'.format(proposalinfo))
        replace_version_declare(pip_test, pip_test.cfg.PLATON_NEW_BIN, pip_test.cfg.version5)
        assert_code(result, 0)
        programversion = client_noconsensus.staking.get_version()
        assert_code(programversion, pip.cfg.version0)
        wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
        verifier_node_version(pip, proposalinfo.get('NewVersion'))
        assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 4)
        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list : {}'.format(validator_list))
        wait_block_number(pip.node, proposalinfo.get('ActiveBlock'))

        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list : {}'.format(validator_list))
        assert pip_test.node.node_id in validator_list

        assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 5)
        pip.economic.wait_settlement_blocknum(pip.node)
        validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList)
        log.info('Validator list : {}'.format(validator_list))
        assert pip_test.node.node_id in validator_list
        verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList)
        log.info('Get verifier list : {}'.format(verifier_list))
        assert pip_test.node.node_id in verifier_list
        programversion = clients_consensus[0].staking.get_version()
        assert_code(programversion, pip.cfg.version5)
        programversion = client_noconsensus.staking.get_version()
        assert_code(programversion, pip_test.cfg.version5)
def test_UP_FV_019(client_new_node):
    """
    账户自由金额和锁仓金额申请委托同一个验证人,再申请赎回
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create account
    amount = economic.create_staking_limit
    first_address, second_address = create_account_amount(
        client, amount, amount)
    delegate_amount = economic.delegate_limit * 100
    plan = [{'Epoch': 2, 'Amount': delegate_amount}]

    # create Restricting Plan1
    result = client.restricting.createRestrictingPlan(first_address, plan,
                                                      first_address)
    assert_code(result, 0)
    economic.wait_settlement(node)
    log.info("Current block height:{}".format(node.eth.blockNumber))

    # create Restricting Plan2
    first_balance1 = node.eth.getBalance(first_address)
    log.info("first_balance1: {}".format(first_balance1))
    result = client.restricting.createRestrictingPlan(second_address, plan,
                                                      second_address)
    assert_code(result, 0)

    economic.wait_settlement(node)
    log.info("Current block height:{}".format(node.eth.blockNumber))
    second_balance1 = node.eth.getBalance(second_address)
    log.info("second_balance1: {}".format(second_balance1))
    restricting_info = client.ppos.getRestrictingInfo(first_address)
    log.info("restricting plan1 informtion: {}".format(restricting_info))
    first_balance2 = node.eth.getBalance(first_address)
    log.info("first_balance2: {}".format(first_balance2))
    assert first_balance2 == first_balance1 + delegate_amount

    economic.wait_settlement(node)
    log.info("Current block height:{}".format(node.eth.blockNumber))
    restricting_info = client.ppos.getRestrictingInfo(second_address)
    log.info("restricting plan2 informtion: {}".format(restricting_info))
    second_balance2 = node.eth.getBalance(second_address)
    log.info("second_balance2: {}".format(second_balance2))
    assert second_balance2 == second_balance1 + delegate_amount
Example #23
0
    def test_AC_IN_018_to_025(self, new_genesis_env, clients_consensus):
        genesis = from_dict(data_class=Genesis,
                            data=new_genesis_env.genesis_config)
        genesis.economicModel.gov.paramProposalVoteDurationSeconds = 0
        new_genesis_env.set_genesis(genesis.to_dict())
        new_genesis_env.deploy_all()
        pip = clients_consensus[0].pip
        pip_test = clients_consensus[-1].pip
        result = pip.submitParam(pip.node.node_id,
                                 str(time.time()),
                                 'slashing',
                                 'slashBlocksReward',
                                 '999',
                                 pip.node.staking_address,
                                 transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Node submit param proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_param = pip.get_effect_proposal_info_of_vote(
            pip.cfg.param_proposal)
        log.info(
            'Get param proposal information : {}'.format(proposalinfo_param))
        result = pip.submitCancel(pip.node.node_id,
                                  str(time.time()),
                                  3,
                                  proposalinfo_param.get('ProposalID'),
                                  pip.node.staking_address,
                                  transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Node submit cancel proposal result : {}'.format(result))
        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(
            pip.cfg.cancel_proposal)
        log.info(
            'Get cancel proposal information : {}'.format(proposalinfo_cancel))
        for index in range(3):
            client = clients_consensus[index]
            result = client.pip.vote(client.node.node_id,
                                     proposalinfo_param.get('ProposalID'),
                                     index + 1,
                                     client.node.staking_address,
                                     transaction_cfg=pip.cfg.transaction_cfg)
            log.info('Node {} vote param proposal result : {}'.format(
                client.node.node_id, result))
            assert_code(result, 0)
            result = client.pip.vote(client.node.node_id,
                                     proposalinfo_cancel.get('ProposalID'),
                                     index + 1,
                                     client.node.staking_address,
                                     transaction_cfg=pip.cfg.transaction_cfg)
            log.info('Node {} vote cancel proposal result : {}'.format(
                client.node.node_id, result))
            assert_code(result, 0)
        assert pip.get_accuverifiers_count(
            proposalinfo_param.get('ProposalID')) == [4, 1, 1, 1]
        assert pip.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 1, 1]
        log.info('Stop the node {}'.format(pip.node.node_id))
        pip.node.stop()
        pip_test.economic.wait_consensus(pip_test.node, 2)
        assert pip_test.get_accuverifiers_count(
            proposalinfo_param.get('ProposalID')) == [4, 1, 1, 1]
        assert pip_test.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 1, 1]

        report_information = mock_duplicate_sign(
            1, clients_consensus[1].node.nodekey,
            clients_consensus[1].node.blsprikey, 41)
        log.info("Report information: {}".format(report_information))
        address, _ = pip_test.economic.account.generate_account(
            pip_test.node.web3, 10**18 * 1000)
        result = clients_consensus[-1].duplicatesign.reportDuplicateSign(
            1, report_information, address)
        log.info('Node duplicate block result : {}'.format(result))
        assert_code(result, 0)
        time.sleep(2)
        assert pip_test.get_accuverifiers_count(
            proposalinfo_param.get('ProposalID')) == [4, 1, 0, 1]
        assert pip_test.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 0, 1]

        report_information = mock_duplicate_sign(
            2, clients_consensus[2].node.nodekey,
            clients_consensus[2].node.blsprikey, 41)
        log.info("Report information: {}".format(report_information))
        address, _ = pip_test.economic.account.generate_account(
            pip_test.node.web3, 10**18 * 1000)
        result = clients_consensus[-1].duplicatesign.reportDuplicateSign(
            2, report_information, address)
        log.info('Node duplicate block result : {}'.format(result))
        assert_code(result, 0)
        assert pip_test.get_accuverifiers_count(
            proposalinfo_param.get('ProposalID')) == [4, 1, 0, 0]
        assert pip_test.get_accuverifiers_count(
            proposalinfo_cancel.get('ProposalID')) == [4, 1, 0, 0]
Example #24
0
def test_CMD_005(account_env):
    node, env = account_env
    returnList = run_ssh_cmd(node.ssh, "{} account update {} --datadir {}".format(node.remote_bin_file, env.remote_account_address, node.remote_data_dir), "88888888", "88888888", "88888888")
    log.info(f'returnList is {returnList}')
    assert len(returnList) == 6
    assert returnList[5].strip() == "Repeat passphrase:"
Example #25
0
    def test_AC_IN_003_008_010(self, new_genesis_env, clients_consensus):
        genesis = from_dict(data_class=Genesis,
                            data=new_genesis_env.genesis_config)
        genesis.economicModel.gov.textProposalVoteDurationSeconds = 120
        new_genesis_env.set_genesis(genesis.to_dict())
        new_genesis_env.deploy_all()
        pip = clients_consensus[-1].pip
        submittpandvote(clients_consensus, 1, 2, 3, 1)
        proposalinfo = pip.get_effect_proposal_info_of_vote(
            pip.cfg.text_proposal)
        log.info('Get text proposal information : {}'.format(proposalinfo))
        assert pip.get_accuverifiers_count(
            proposalinfo.get('ProposalID')) == [4, 2, 1, 1]
        log.info('Stop the node {}'.format(clients_consensus[0].node.node_id))
        clients_consensus[0].node.stop()
        pip.economic.wait_consensus(pip.node, 2)
        assert pip.get_accuverifiers_count(
            proposalinfo.get('ProposalID')) == [4, 2, 1, 1]

        report_information = mock_duplicate_sign(
            1, clients_consensus[1].node.nodekey,
            clients_consensus[1].node.blsprikey, 41)
        log.info("Report information: {}".format(report_information))
        address, _ = pip.economic.account.generate_account(
            pip.node.web3, 10**18 * 1000)
        result = clients_consensus[-1].duplicatesign.reportDuplicateSign(
            1, report_information, address)
        log.info('Node duplicate block result : {}'.format(result))
        assert_code(result, 0)
        assert pip.get_accuverifiers_count(
            proposalinfo.get('ProposalID')) == [4, 2, 0, 1]

        report_information = mock_duplicate_sign(
            2, clients_consensus[2].node.nodekey,
            clients_consensus[2].node.blsprikey, 41)
        log.info("Report information: {}".format(report_information))
        address, _ = pip.economic.account.generate_account(
            pip.node.web3, 10**18 * 1000)
        result = clients_consensus[-1].duplicatesign.reportDuplicateSign(
            2, report_information, address)
        log.info('Node duplicate block result : {}'.format(result))
        assert_code(result, 0)
        assert pip.get_accuverifiers_count(
            proposalinfo.get('ProposalID')) == [4, 2, 0, 0]
Example #26
0
def test_VO_VO_001_V0_RE_001_V0_WA_001_V_STA_1_VO_OP_001_VO_OP_002(
        no_vp_proposal):
    pip = no_vp_proposal
    result = pip.submitVersion(pip.node.node_id,
                               str(time.time()),
                               pip.cfg.version8,
                               2,
                               pip.node.staking_address,
                               transaction_cfg=pip.cfg.transaction_cfg)
    log.info('Submit version proposal result : {}'.format(result))
    assert_code(result, 0)
    proposalinfo = pip.get_effect_proposal_info_of_vote()
    log.info('Get version proposalinfo {}'.format(proposalinfo))

    upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN)
    log.info('Replace the node platon package to {}'.format(pip.cfg.version5))
    pip.node.restart()
    log.info('Restart the node {}'.format(pip.node.node_id))
    address, _ = pip.economic.account.generate_account(pip.node.web3,
                                                       10**18 * 10000)
    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      pip.cfg.vote_option_yeas,
                      address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('Not staking address vote result : {}'.format(result))
    assert_code(result, 302021)

    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      pip.cfg.vote_option_nays,
                      pip.node.staking_address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('vote option {} result {}'.format(pip.cfg.vote_option_nays,
                                               result))
    assert_code(result, 302002)

    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      pip.cfg.vote_option_Abstentions,
                      pip.node.staking_address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('vote option {} result {}'.format(pip.cfg.vote_option_Abstentions,
                                               result))
    assert_code(result, 302002)

    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      0,
                      pip.node.staking_address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('vote option {} result {}'.format(0, result))
    assert_code(result, 302002)

    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      'a',
                      pip.node.staking_address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('vote option {} result {}'.format(pip.cfg.vote_option_nays,
                                               result))
    assert_code(result, 302002)

    address, _ = pip.economic.account.generate_account(pip.node.web3,
                                                       10**18 * 10000)
    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      pip.cfg.vote_option_yeas,
                      address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    assert_code(result, 302021)

    node_version = verifier_node_version(pip)
    result = version_proposal_vote(pip)
    assert_code(result, 0)
    verifier_node_version(pip, node_version)

    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      pip.cfg.vote_option_yeas,
                      pip.node.staking_address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('vote duplicated result: {}'.format(result))
    assert_code(result, 302027)

    wait_block_number(pip.node, proposalinfo.get('EndVotingBlock'))
    result = pip.vote(pip.node.node_id,
                      proposalinfo.get('ProposalID'),
                      pip.cfg.vote_option_yeas,
                      pip.node.staking_address,
                      transaction_cfg=pip.cfg.transaction_cfg)
    log.info('endblock vote result: {}'.format(result))
    assert_code(result, 302026)
Example #27
0
 def test_IN_LG_005(self, client_noconsensus):
     result = client_noconsensus.pip.pip.listGovernParam('txpool')
     log.info('Interface listGovernParam result {}'.format(result))
     assert_code(result, 2)
     assert result.get('Ret') == "Object not found"
Example #28
0
    def test_VO_TE_001_002_PP_VO_009_010_PP_VO_011_012_PP_VO_014_VO_TER_008_VO_TER_006(
            self, new_genesis_env, clients_consensus, client_noconsensus):
        genesis = from_dict(data_class=Genesis,
                            data=new_genesis_env.genesis_config)
        genesis.economicModel.gov.paramProposalVoteDurationSeconds = 640
        genesis.economicModel.staking.unStakeFreezeDuration = 2
        new_genesis_env.set_genesis(genesis.to_dict())
        new_genesis_env.deploy_all()
        pip = clients_consensus[0].pip
        result = pip.submitText(pip.node.node_id,
                                str(time.time()),
                                pip.node.staking_address,
                                transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit text proposal information : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_text = pip.get_effect_proposal_info_of_vote(
            pip.cfg.text_proposal)
        log.info(
            'Get text proposal information : {}'.format(proposalinfo_text))

        result = pip.submitParam(pip.node.node_id,
                                 str(time.time()),
                                 'slashing',
                                 'slashBlocksReward',
                                 '123',
                                 pip.node.staking_address,
                                 transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit param proposal information : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_param = pip.get_effect_proposal_info_of_vote(
            pip.cfg.param_proposal)
        log.info(
            'Get param proposal information : {}'.format(proposalinfo_param))

        result = pip.submitCancel(pip.node.node_id,
                                  str(time.time()),
                                  10,
                                  proposalinfo_param.get('ProposalID'),
                                  pip.node.staking_address,
                                  transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit cancel proposal information : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(
            pip.cfg.cancel_proposal)
        log.info(
            'Get cancel proposal information : {}'.format(proposalinfo_cancel))

        result = clients_consensus[0].staking.withdrew_staking(
            clients_consensus[0].node.staking_address)
        log.info('Node {} withdrew staking result {}'.format(
            clients_consensus[0].node.node_id, result))
        assert_code(result, 0)
        address = clients_consensus[0].node.staking_address

        result = proposal_vote(pip, proposaltype=pip.cfg.text_proposal)
        log.info('node vote text proposal result {}'.format(result))
        assert_code(result, 302020)

        result = proposal_vote(pip)
        log.info('node vote param proposal result {}'.format(result))
        assert_code(result, 302020)

        result = proposal_vote(pip, proposaltype=pip.cfg.cancel_proposal)
        log.info('node vote cancel proposal result {}'.format(result))
        assert_code(result, 302020)

        address_test, _ = pip.economic.account.generate_account(
            pip.node.web3, 10**18 * 10000)
        result = client_noconsensus.pip.vote(
            client_noconsensus.node.node_id,
            proposalinfo_text.get('ProposalID'),
            pip.cfg.vote_option_yeas,
            address_test,
            transaction_cfg=pip.cfg.transaction_cfg)
        log.info('node {} vote text proposal result {}'.format(
            client_noconsensus.node.node_id, result))
        assert_code(result, 302022)

        result = client_noconsensus.pip.vote(
            client_noconsensus.node.node_id,
            proposalinfo_param.get('ProposalID'),
            pip.cfg.vote_option_yeas,
            address_test,
            transaction_cfg=pip.cfg.transaction_cfg)
        log.info('node {} vote param proposal result {}'.format(
            client_noconsensus.node.node_id, result))
        assert_code(result, 302022)

        result = client_noconsensus.pip.vote(
            client_noconsensus.node.node_id,
            proposalinfo_cancel.get('ProposalID'),
            pip.cfg.vote_option_yeas,
            address_test,
            transaction_cfg=pip.cfg.transaction_cfg)
        log.info('node {} vote cancel proposal result {}'.format(
            client_noconsensus.node.node_id, result))
        assert_code(result, 302022)

        pip.economic.wait_settlement_blocknum(
            pip.node, pip.economic.unstaking_freeze_ratio)
        result = pip.vote(pip.node.node_id,
                          proposalinfo_text.get('ProposalID'),
                          pip.cfg.vote_option_nays,
                          address,
                          transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Exited node vote text proposal result {}'.format(result))
        assert_code(result, 302022)

        result = pip.vote(pip.node.node_id,
                          proposalinfo_param.get('ProposalID'),
                          pip.cfg.vote_option_nays,
                          address,
                          transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Exited node vote param proposal result {}'.format(result))
        assert_code(result, 302022)

        result = pip.vote(pip.node.node_id,
                          proposalinfo_cancel.get('ProposalID'),
                          pip.cfg.vote_option_nays,
                          address,
                          transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Exited node vote cancel proposal result {}'.format(result))
        assert_code(result, 302022)
Example #29
0
    def test_LP_IN_001_002(self, no_vp_proposal):
        pip = no_vp_proposal
        pip_id = str(time.time())
        result = pip.submitParam(pip.node.node_id,
                                 pip_id,
                                 'slashing',
                                 'slashBlocksReward',
                                 '456',
                                 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('Get param proposal information : {}'.format(proposalinfo))
        assert proposalinfo.get('Proposer') == pip.node.node_id
        assert proposalinfo.get('ProposalType') == pip.cfg.param_proposal
        log.info('{}'.format(pip.economic.pp_vote_settlement_wheel))
        calculated_endvotingblock = math.ceil(
            proposalinfo.get('SubmitBlock') / pip.economic.settlement_size +
            pip.economic.pp_vote_settlement_wheel
        ) * pip.economic.settlement_size
        assert proposalinfo.get('EndVotingBlock') == calculated_endvotingblock

        pip_id = str(time.time())
        result = pip.submitCancel(pip.node.node_id,
                                  pip_id,
                                  1,
                                  proposalinfo.get('ProposalID'),
                                  pip.node.staking_address,
                                  transaction_cfg=pip.cfg.transaction_cfg)
        log.info('Submit cancel proposal result : {}'.format(result))
        assert_code(result, 0)
        proposalinfo_cancel = pip.get_effect_proposal_info_of_vote(
            pip.cfg.cancel_proposal)
        log.info(
            'Get cancel proposal information : {}'.format(proposalinfo_cancel))

        assert proposalinfo_cancel.get('Proposer') == pip.node.node_id
        assert proposalinfo_cancel.get(
            'ProposalType') == pip.cfg.cancel_proposal
        log.info('{}'.format(pip.economic.pp_vote_settlement_wheel))
        calculated_endvotingblock = math.ceil(
            proposalinfo_cancel.get('SubmitBlock') /
            pip.economic.consensus_size + 1) * pip.economic.consensus_size - 20
        assert proposalinfo_cancel.get(
            'EndVotingBlock') == calculated_endvotingblock
Example #30
0
 def clean_all(self):
     """
     Close all nodes and delete the directory of the deployment node
     """
     log.info("clean all node")
     self.clean_nodes(self.get_all_nodes())