def test_PIP_MG_001_002(client_consensus, mark, reset_environment): """ PIP_MG_001:治理修改默认每个区块的最大Gas 投票失败 PIP_MG_002:治理修改默认每个区块的最大Gas 处于未生效期 :param client_consensus: :param reset_environment: :return: """ first_client = client_consensus log.info("Current connection non-consensus first node:{}".format( first_client.node.node_mark)) node = first_client.node # view Parameter value before treatment first_max_gas_limit = get_governable_parameter_value( first_client, 'maxBlockGasLimit') # create Parametric proposal block = param_governance_verify_before_endblock(first_client, 'block', 'maxBlockGasLimit', '4712389', mark) # view Parameter value after treatment second_max_gas_limit = get_governable_parameter_value( first_client, 'maxBlockGasLimit') # wait block wait_block_number(node, block) assert second_max_gas_limit == first_max_gas_limit, "ErrMsg:Parameter value after treatment {}".format( second_max_gas_limit)
def wait_proposal_active(pip, pip_id): res = pip.pip.getProposal(pip_id) end_block = res['Ret']['EndVotingBlock'] end_block = pip.economic.get_consensus_switchpoint(end_block) log.info(f'wait proposal active block : {end_block}') wait_block_number(pip.node, end_block) return
def test_PIP_MG_001(client_con_list_obj, reset_environment): """ 治理修改默认每个区块的最大Gas 投票失败 :param client_con_list_obj: :param reset_environment: :return: """ # # Change configuration parameters # genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) # genesis.config.cbft.period = 50000 # genesis.EconomicModel.Common.MaxEpochMinutes = 14 # genesis.EconomicModel.Common.AdditionalCycleTime = 55 # new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" # genesis.to_file(new_file) # new_genesis_env.deploy_all(new_file) # client_con_list_obj[0].economic.env.deploy_all() # view Parameter value before treatment max_gas_limit1 = get_governable_parameter_value(client_con_list_obj[0], 'maxBlockGasLimit') # create Parametric proposal block = param_governance_verify_before_endblock(client_con_list_obj[0], 'block', 'maxBlockGasLimit', '4712389', False) # view Parameter value after treatment max_gas_limit2 = get_governable_parameter_value(client_con_list_obj[0], 'maxBlockGasLimit') # wait block wait_block_number(client_con_list_obj[0].node, block) assert max_gas_limit2 == max_gas_limit1, "ErrMsg:Parameter value after treatment {}".format(max_gas_limit2)
def test_modify_param_of_0mb_freeze_duration(self, verifiers, new_genesis_env, value): """ @describe: 参数提案修改‘zeroProduceFreezeDuration’的值-正常 @step: - 1. 提交参数提案,修改‘zeroProduceFreezeDuration’的值为正常值 - 2. 检查参数生效值和效果 @expect: - 1. 提案生效后查询该参数,返回正确 - 2. 参数在链上生效,影响零出块冻结持续时长 """ # init: 修改依赖参数的值,并重新部署环境 genesis = to_genesis(new_genesis_env.genesis_config) genesis.economicModel.staking.unStakeFreezeDuration = 4 genesis.economicModel.slashing.zeroProduceFreezeDuration = 2 genesis.economicModel.slashing.slashBlocksReward = 0 new_genesis_env.set_genesis(genesis.to_dict()) new_genesis_env.deploy_all() # step1: 发起参数提案,投票使提案生效 pips = get_pips(verifiers) pip = pips[0] pip_id = param_proposal(pip, 'slashing', 'zeroProduceFreezeDuration', value) votes(pip_id, pips, [1, 1, 1, 1]) wait_proposal_active(pip, pip_id) # step2: 检查参数生效值和效果 res = pip.pip.getGovernParamValue('slashing', 'zeroProduceFreezeDuration') assert res['Ret'] == value start_block, end_block = make_0mb_slash(verifiers[0], verifiers[1]) wait_block_number(pip.node, end_block) assert check_node_in_list(pip.node.node_id, pip.node.ppos.getCandidateList) is True node_info = pip.node.ppos.getCandidateInfo(pip.node.node_id) assert node_info['Ret']['Status'] == 0
def test_proposal_multiple_voting(self, verifiers, new_genesis_env): """ @describe: 同一提案,节点处罚前已经投票,处罚完成后再次投票 @step: - 1. 提交版本提案并进行投票 - 2. 停止节点,等待节点被零出块处罚 - 3. 处罚完成后,再次进行投票 @expect: - 1. 节点重复投票失败,提案未统计重复投票信息 """ # init: 修改依赖参数的值,并重新部署环境 genesis = to_genesis(new_genesis_env.genesis_config) genesis.economicModel.slashing.slashBlocksReward = 0 new_genesis_env.set_genesis(genesis.to_dict()) new_genesis_env.deploy_all() # step1: pips = get_pips(verifiers) pip = pips[0] pip_id = version_proposal(pip, pip.cfg.version5, 20) upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN) vote(pip, pip_id) # step2:停止节点,等待节点被零出块处罚 start_block, end_block = make_0mb_slash(verifiers[0], verifiers[1]) wait_block_number(pip.node, end_block) # step3:检查提案和投票信息是否正确 assert_code(vote(pip, pip_id), 302027) vote_info = pip.get_accuverifiers_count(pip_id) assert vote_info[0] == 4 # all verifiers assert vote_info[1] == 1 # all yeas vote
def test_submit_declare_at_0mb_freezing(self, verifiers, new_genesis_env): """ @describe: 节点零出块冻结期内,进行版本声明 @step: - 1. 节点零出块被冻结处罚 - 2. 冻结期内进行版本声明 @expect: - 1. 节点被处罚冻结期内,可以进行版本声明 - 2. 冻结期内,已发送版本声明,也不会被选举 """ # init: 修改依赖参数的值,并重新部署环境 genesis = to_genesis(new_genesis_env.genesis_config) genesis.economicModel.slashing.slashBlocksReward = 0 new_genesis_env.set_genesis(genesis.to_dict()) new_genesis_env.deploy_all() # step1:提交版本升级提案 pips = get_pips(verifiers) pip = pips[0] # setp2:使用其他节点,对提案进行投票,使提案通过 upload_platon(pips[0].node, pips[0].cfg.PLATON_NEW_BIN) upload_platon(pips[1].node, pips[1].cfg.PLATON_NEW_BIN) upload_platon(pips[2].node, pips[2].cfg.PLATON_NEW_BIN) upload_platon(pips[3].node, pips[3].cfg.PLATON_NEW_BIN) pip_id = version_proposal(pip, pip.cfg.version5, 5) vote(pips[1], pip_id) vote(pips[2], pip_id) vote(pips[3], pip_id) # setp3: 在投票期内,构造节点零出块,并等待提案通过 start_block, end_block = make_0mb_slash(verifiers[0], verifiers[1]) wait_proposal_active(pip, pip_id) # step4:进行版本声明 assert_code(version_declare(pip), 302023) # step5: 等待零出块冻结结束,进行版本声明 wait_block_number(pip.node, end_block) assert_code(version_declare(pip), 0)
def test_all_process_of_pip_after_slashed(self, verifiers, new_genesis_env): """ @describe: 节点投票后被处罚,升级提案生效后,节点投票时声明的版本被回退 @issues: 1666 @step: - 1. 节点发起升级提案 - 2. 节点进行投票后,被零出块处罚,不解质押 - 3. 提案生效后,节点解冻结 @expect: - 1. 节点解冻结后,可被选入验证人 """ # init: 修改依赖参数的值,并重新部署环境 genesis = to_genesis(new_genesis_env.genesis_config) genesis.economicModel.slashing.slashBlocksReward = 0 new_genesis_env.set_genesis(genesis.to_dict()) new_genesis_env.deploy_all() pips = get_pips(verifiers) pip = pips[0] # step1: 发起升级提案,并进行投票 pip_id = version_proposal(pip, pip.cfg.version5, 10) for pip in pips[:3]: upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN) assert_code(vote(pip, pip_id, pip.cfg.vote_option_yeas), 0) # step2: 构造零出块处罚,等待提案生效,并且处罚冻结期结束 start_block, end_block = make_0mb_slash(verifiers[1], verifiers[0]) assert start_block < pip.pip.getProposal( pip_id)['Ret']['EndVotingBlock'] vote_info = pip.get_accuverifiers_count(pip_id) assert vote_info[0] == 4 # all verifiers assert vote_info[1] == 3 # all yeas vote wait_proposal_active(pip, pip_id) wait_block_number(pip.node, end_block) # step3: 检查提案生效后,检查节点是否被选举 pip.economic.wait_settlement(pip.node) assert check_node_in_list(pip.node.node_id, pip.node.ppos.getCandidateList) is True assert check_node_in_list(pip.node.node_id, pip.node.ppos.getValidatorList) is True assert check_node_in_list(pip.node.node_id, pip.node.ppos.getVerifierList) is True
def test_submit_proposal_at_0mb_freezing(self, verifiers): """ @describe: 节点零出块冻结期内,进行提案,提案失败 @step: - 1. 节点零出块被冻结处罚 - 2. 冻结期内发送各种提案,提案失败 @expect: - 1. 节点被处罚冻结期内,提案失败 - 2. 查询未新增提案信息 """ # step1:停止节点,等待节点被零出块处罚 pips = get_pips(verifiers) pip = pips[0] make_0mb_slash(verifiers[0], verifiers[1]) # step2:提交各类提案,提案失败 assert_code(version_proposal(pip, pip.cfg.version5, 5), 302022) assert_code(param_proposal(pip, 'slashing', 'slashBlocksReward', '10'), 302022) assert_code(text_proposal(pip), 302022) pip_id = version_proposal(pips[1], pips[1].cfg.version5, 5) bn = pip.node.eth.blockNumber wait_block_number(pip.node, bn + 5) assert_code(cancel_proposal(pip, pip_id, 2), 302022)
def test_all_process_of_pip_after_slashed(self, verifiers, new_genesis_env): """ @describe: 在处罚结束之后,执行pip所有流程 @step: - 1. 节点在零出块处罚结束后发起提案 - 2. 节点在零出块处罚结束后进行投票 - 3. 节点在零出块处罚结束后进行版本声明 @expect: - 1. pip流程未受到处罚影响 """ # init: 修改依赖参数的值,并重新部署环境 genesis = to_genesis(new_genesis_env.genesis_config) genesis.economicModel.slashing.slashBlocksReward = 0 new_genesis_env.set_genesis(genesis.to_dict()) new_genesis_env.deploy_all() # step1: 构造零出块处罚,并在处罚结束后发起提案 pips = get_pips(verifiers) pip = pips[0] # _, end_block = make_0mb_slash(verifiers[0], verifiers[1]) # wait_block_number(pip.node, end_block) # assert check_node_in_list(pip.node.node_id, pip.node.ppos.getCandidateList) is True # pip.economic.wait_settlement(pip.node) # assert check_node_in_list(pip.node.node_id, pip.node.ppos.getValidatorList) is True # assert check_node_in_list(pip.node.node_id, pip.node.ppos.getVerifierList) is True # step2: 构造零出块处罚,并在处罚结束后进行投票 pip_id = version_proposal(pip, pip.cfg.version5, 10) _, end_block = make_0mb_slash(verifiers[1], verifiers[0]) wait_block_number(pip.node, end_block) upload_platon(pips[1].node, pip.cfg.PLATON_NEW_BIN) upload_platon(pips[2].node, pip.cfg.PLATON_NEW_BIN) upload_platon(pips[3].node, pip.cfg.PLATON_NEW_BIN) assert_code(vote(pips[1], pip_id, pips[1].cfg.vote_option_yeas), 0) assert_code(vote(pips[2], pip_id, pips[2].cfg.vote_option_yeas), 0) assert_code(vote(pips[3], pip_id, pips[3].cfg.vote_option_yeas), 0) # step3: 在提案生效后进行版本声明 wait_proposal_active(pip, pip_id) upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN) assert_code(version_declare(pip), 0)
def test_resync_block_after_upgrade(self, verifiers, new_genesis_env): """ @describe: 链升级后,节点重新同步区块 @step: - 1. 节点发起升级提案,投票并等待提案生效 - 2. 节点清理数据库,重新初始化,并重新同步区块 @expect: - 1. 块高可正常同步到提升生效后的块高 """ pips = get_pips(verifiers) pip = pips[0] # step1: 节点发起升级提案,投票并等待提案生效 pip_id = version_proposal(pip, pip.cfg.version5, 5) for pip in pips: upload_platon(pip.node, pip.cfg.PLATON_NEW_BIN) assert_code(vote(pip, pip_id, pip.cfg.vote_option_yeas), 0) wait_proposal_active(pip, pip_id) # step2: 节点清理数据库,重新初始化,并重新同步区块 block_number = pip.node.block_number pip.node.clean_db() pip.node.init() pip.node.restart() wait_block_number(pip.node, block_number)