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
Esempio n. 2
0
def test_PIP_PVF_010(new_genesis_env, client_con_list_obj):
    """
    治理修改区块双签-证据有效期(超出有效期)
    :param new_genesis_env:
    :param client_con_list_obj:
    :return:
    """
    # Change configuration parameters
    adjust_initial_parameters(new_genesis_env)
    # view Parameter value before treatment
    slash_blocks1 = get_governable_parameter_value(client_con_list_obj[0], 'maxEvidenceAge')
    assert slash_blocks1 == '2', "ErrMsg:Parameter value before treatment {}".format(slash_blocks1)
    # create Parametric proposal
    param_governance_verify(client_con_list_obj[0], 'slashing', 'maxEvidenceAge', '1')
    # view Parameter value before treatment again
    slash_blocks2 = get_governable_parameter_value(client_con_list_obj[0], 'maxEvidenceAge')
    assert slash_blocks2 == '1', "ErrMsg:Parameter value after treatment {}".format(slash_blocks2)
    report_address, _ = client_con_list_obj[0].economic.account.generate_account(client_con_list_obj[0].node.web3,
                                                                                 client_con_list_obj[0].node.web3.toWei(
                                                                                     1000, 'ether'))
    # wait consensus block
    client_con_list_obj[0].economic.wait_consensus_blocknum(client_con_list_obj[0].node)
    # Verify changed parameters
    effective_block1 = client_con_list_obj[0].economic.get_front_settlement_switchpoint(client_con_list_obj[0].node,
                                                                                        int(slash_blocks1))
    log.info("Effective1 block height: {}".format(effective_block1))
    # Report1 prepareblock signature
    report_information = mock_duplicate_sign(1, client_con_list_obj[0].node.nodekey,
                                             client_con_list_obj[0].node.blsprikey,
                                             effective_block1)
    log.info("Report information: {}".format(report_information))
    result = client_con_list_obj[0].duplicatesign.reportDuplicateSign(1, report_information, report_address)
    assert_code(result, 303003)
Esempio n. 3
0
def test_UP_FV_003(client_new_node):
    """
    多个锁仓期,依次部分释放期返回解锁金额
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create account
    address1, _ = economic.account.generate_account(
        node.web3, von_amount(economic.create_staking_limit, 2))
    # create Restricting Plan
    amount = von_amount(economic.delegate_limit, 10)
    plan = [{'Epoch': 1, 'Amount': amount}, {'Epoch': 2, 'Amount': amount}]
    result = client.restricting.createRestrictingPlan(address1, plan, address1)
    assert_code(result, 0)
    # view Restricting Plan again
    restricting_info = client.ppos.getRestrictingInfo(address1)
    log.info("restricting plan information: {}".format(restricting_info))
    assert len(restricting_info['Ret']
               ['plans']) == 2, "ErrMsg:Planned releases: {}".format(
                   len(restricting_info['Ret']['plans']))
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # view Restricting Plan
    restricting_info = client.ppos.getRestrictingInfo(address1)
    log.info("restricting plan information: {}".format(restricting_info))
    assert len(restricting_info['Ret']
               ['plans']) == 1, "ErrMsg:Planned releases: {}".format(
                   len(restricting_info['Ret']['plans']))
Esempio n. 4
0
def test_PIP_PVF_004(client_con_list_obj, client_new_node_obj_list, reset_environment):
    """
    治理修改低0出块率扣除验证人自有质押金块数成功扣除区块奖励块数60100-自由金额质押
    :param client_con_list_obj:
    :param reset_environment:
    :return:
    """
    # get pledge amount1 and block reward
    pledge_amount1, block_reward, slash_blocks1 = information_before_slash_blocks(client_con_list_obj[0])
    # create Parametric proposal
    param_governance_verify(client_con_list_obj[0], 'slashing', 'slashBlocksReward', '60100')
    log.info("Current block height: {}".format(client_con_list_obj[0].node.eth.blockNumber))
    # Get governable parameters again
    slash_blocks2 = get_governable_parameter_value(client_con_list_obj[0], 'slashBlocksReward')
    assert slash_blocks2 == '60100', "ErrMsg:Change parameters {}".format(slash_blocks2)
    # create account
    address, _ = client_con_list_obj[0].economic.account.generate_account(client_con_list_obj[0].node.web3,
                                                                          client_con_list_obj[
                                                                              0].economic.create_staking_limit * 2)
    # create staking
    result = client_new_node_obj_list[0].staking.create_staking(0, address, address)
    assert_code(result, 0)
    # wait settlement block
    client_new_node_obj_list[0].economic.wait_settlement_blocknum(client_new_node_obj_list[0].node)
    for i in range(4):
        result = check_node_in_list(client_con_list_obj[0].node.node_id, client_con_list_obj[0].ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # Verify changed parameters
            Verify_changed_parameters(client_con_list_obj, pledge_amount1, block_reward, slash_blocks2)
            break
        else:
            # wait consensus block
            client_con_list_obj[0].economic.wait_consensus_blocknum(client_con_list_obj[0].node)
Esempio n. 5
0
def test_UP_FV_004(client_new_node):
    """
    锁仓账户申请质押到释放期后释放锁定金额不足
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create restricting plan
    address1 = restricting_plan_validation_release(client, economic, node)
    # create staking
    staking_amount = economic.create_staking_limit
    result = client.staking.create_staking(1,
                                           address1,
                                           address1,
                                           amount=staking_amount)
    assert_code(result, 0)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # view restricting plan
    restricting_info = client.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'])
Esempio n. 6
0
def test_AL_NBI_015(client_new_node_obj):
    """
    退回质押金并处于锁定期
    :param client_new_node_obj:
    :return:
    """
    # create pledge node
    address, benifit_address = create_pledge_node(client_new_node_obj, 1.5)
    # wait settlement block
    client_new_node_obj.economic.wait_settlement_blocknum(client_new_node_obj.node)
    # view account amount
    benifit_balance = query_ccount_amount(client_new_node_obj, benifit_address)
    for i in range(4):
        result = check_node_in_list(client_new_node_obj.node.node_id, client_new_node_obj.ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # withdrew of pledge
            result = client_new_node_obj.staking.withdrew_staking(address)
            assert_code(result, 0)
            log.info("Current settlement cycle verifier list:{}".format(client_new_node_obj.ppos.getVerifierList()))
            for i in range(40):
                client_new_node_obj.economic.account.sendTransaction(client_new_node_obj.node.web3, '',
                                                                     client_new_node_obj.economic.account.account_with_money[
                                                                         'address'], address,
                                                                     client_new_node_obj.node.web3.platon.gasPrice,
                                                                     21000, 100)
                time.sleep(1)
            # view account amount again
            benifit_balance1 = query_ccount_amount(client_new_node_obj, benifit_address)
            assert benifit_balance1 > benifit_balance, "ErrMsg: {} > {}".format(benifit_balance1, benifit_balance)
            break
        else:
            # wait consensus block
            client_new_node_obj.economic.wait_consensus_blocknum(client_new_node_obj.node)
Esempio n. 7
0
def test_UP_FV_005(client_new_node):
    """
    到达释放期释放锁仓金额之后再申请退回质押金
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create restricting plan and staking
    address1 = restricting_plan_validation_staking(client, economic, node)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # Application for return of pledge
    result = client.staking.withdrew_staking(address1)
    assert_code(result, 0)
    # view restricting plan
    restricting_info = client.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'])
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node, 2)
    # view restricting plan again
    restricting_info = client.ppos.getRestrictingInfo(address1)
    assert_code(restricting_info, 304005)
Esempio n. 8
0
def create_pledge_node(client_new_node_obj, base, multiple=2):
    """
    create pledge node return benifit balance
    :param client_new_node_obj:
    :param base:
    :param multiple:
    :return:
    """
    log.info("Transfer accounts: {}".format(client_new_node_obj.economic.create_staking_limit * multiple))
    account_balance = client_new_node_obj.node.eth.getBalance(
        client_new_node_obj.economic.account.account_with_money['address'])
    log.info("address: {} accounts: {}".format(client_new_node_obj.economic.account.account_with_money['address'],
                                               account_balance))
    # create account
    address, _ = client_new_node_obj.economic.account.generate_account(client_new_node_obj.node.web3,
                                                                       client_new_node_obj.economic.create_staking_limit * multiple)

    log.info("address: {} ,amount: {}".format(address, client_new_node_obj.node.eth.getBalance(address)))
    benifit_address, _ = client_new_node_obj.economic.account.generate_account(client_new_node_obj.node.web3, 0)
    log.info("address: {} ,amount: {}".format(benifit_address, client_new_node_obj.node.eth.getBalance(benifit_address)))
    # create staking
    staking_amount = von_amount(client_new_node_obj.economic.create_staking_limit, base)
    result = client_new_node_obj.staking.create_staking(0, benifit_address, address, amount=staking_amount)
    assert_code(result, 0)
    log.info("Pledge node information: {}".format(client_new_node_obj.ppos.getCandidateInfo(client_new_node_obj.node.node_id)))
    return address, benifit_address
Esempio n. 9
0
def consensus_node_pledge_award_assertion(client_new_node_obj, address):
    """
    内置节点质押奖励断言
    :param client_new_node_obj:
    :param address:
    :return:
    """
    blockNumber = client_new_node_obj.node.eth.blockNumber
    log.info("Current block height:{}".format(blockNumber))
    incentive_pool_balance = client_new_node_obj.node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS)
    log.info("Balance of incentive pool:{}".format(incentive_pool_balance))
    CandidateInfo = client_new_node_obj.ppos.getCandidateInfo(client_new_node_obj.node.node_id)
    log.info("Pledgor node information:{}".format(CandidateInfo))

    # wait settlement block
    client_new_node_obj.economic.wait_settlement_blocknum(client_new_node_obj.node)
    time.sleep(5)
    VerifierList = client_new_node_obj.ppos.getVerifierList()
    log.info("Current settlement cycle verifier list:{}".format(VerifierList))
    ValidatorList = client_new_node_obj.ppos.getValidatorList()
    log.info("Current consensus cycle verifier list:{}".format(ValidatorList))
    # Application for withdrew staking
    result = client_new_node_obj.staking.withdrew_staking(address)
    assert_code(result, 0)
    # wait settlement block
    client_new_node_obj.economic.wait_settlement_blocknum(client_new_node_obj.node)
    # view incentive pool amonut
    incentive_pool_balance2 = client_new_node_obj.node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS)
    log.info(
        "incentive pool address:{} amount:{}".format(EconomicConfig.INCENTIVEPOOL_ADDRESS, incentive_pool_balance2))
    assert incentive_pool_balance2 - incentive_pool_balance < client_new_node_obj.node.web3.toWei(1,
                                                                                                  'ether'), "ErrMsg:Balance of incentive pool:{}".format(
        incentive_pool_balance2)
Esempio n. 10
0
def test_UP_FV_015(client_new_node):
    """
    锁仓账户申请之后到达释放期,账户锁仓不足再新增新的锁仓计划
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create restricting plan and staking
    address1 = restricting_plan_validation_staking(client, economic, node)
    # create account2
    address2, _ = economic.account.generate_account(
        node.web3, von_amount(economic.create_staking_limit, 2))
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # view restricting plan
    restricting_info = client.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'])
    # create Restricting Plan
    delegate_amount = von_amount(economic.create_staking_limit, 1)
    plan = [{'Epoch': 1, 'Amount': delegate_amount}]
    result = client.restricting.createRestrictingPlan(address1, plan, address2)
    assert_code(result, 0)
    # view restricting plan
    restricting_info = client.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    assert info['debt'] == 0, 'ErrMsg: restricting debt amount {}'.format(
        info['debt'])
def test_PIP_PVF_009(new_genesis_env):
    """
    治理修改区块双签-证据有效期(节点质押退回锁定周期-1)
    :param new_genesis_env:
    :return:
    """
    # Change configuration parameters
    genesis = from_dict(data_class=Genesis,
                        data=new_genesis_env.genesis_config)
    genesis.economicModel.staking.unStakeFreezeDuration = 3
    genesis.economicModel.slashing.maxEvidenceAge = 1
    new_file = new_genesis_env.cfg.env_tmp + "/genesis_0.13.0.json"
    genesis.to_file(new_file)
    new_genesis_env.deploy_all(new_file)

    first_client = get_client_consensus(new_genesis_env, staking_cfg)
    log.info("Current connection non-consensus node:{}".format(
        first_client.node.node_mark))
    economic = first_client.economic
    node = first_client.node
    change_parameter_value = '2'
    # view Parameter value before treatment
    first_slash_blocks = get_governable_parameter_value(
        first_client, 'maxEvidenceAge')
    # create Parametric proposal
    param_governance_verify(first_client, 'slashing', 'maxEvidenceAge',
                            change_parameter_value)
    # view Parameter value before treatment again
    second_slash_blocks = get_governable_parameter_value(
        first_client, 'maxEvidenceAge')
    assert second_slash_blocks != first_slash_blocks, "ErrMsg:Parameter value after treatment {}".format(
        second_slash_blocks)
    assert second_slash_blocks == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format(
        second_slash_blocks)
    report_address, _ = economic.account.generate_account(
        node.web3, node.web3.toWei(1000, 'ether'))
    # wait consensus block
    economic.wait_consensus_blocknum(node)
    # Verify changed parameters
    first_effective_block = economic.get_front_settlement_switchpoint(
        node, int(first_slash_blocks))
    log.info("first effective block height: {}".format(first_effective_block))
    second_effective_block = economic.get_front_settlement_switchpoint(
        node, int(second_slash_blocks))
    log.info(
        "second effective block height: {}".format(second_effective_block))
    # first Report prepareblock signature
    report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey,
                                             first_effective_block)
    log.info("Report information: {}".format(report_information))
    result = first_client.duplicatesign.reportDuplicateSign(
        1, report_information, report_address)
    assert_code(result, 0)
    # second Report prepareblock signature
    report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey,
                                             second_effective_block)
    log.info("Report information: {}".format(report_information))
    result = first_client.duplicatesign.reportDuplicateSign(
        1, report_information, report_address)
    assert_code(result, 303000)
Esempio n. 12
0
 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)
Esempio n. 13
0
def test_UP_FV_014(client_new_node, reset_environment):
    """
    锁仓验证人违规被剔除验证人列表,申请赎回委托金
    :param client_new_node:
    :param reset_environment:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create account
    amount1 = von_amount(economic.create_staking_limit, 2)
    amount2 = von_amount(economic.create_staking_limit, 1)
    address1, report_address = create_account_amount(client, amount1, amount2)
    # create Restricting Plan
    delegate_amount = von_amount(economic.delegate_limit, 10)
    plan = [{'Epoch': 3, 'Amount': delegate_amount}]
    result = client.restricting.createRestrictingPlan(report_address, plan,
                                                      report_address)
    assert_code(result, 0)
    # create staking
    result = client.staking.create_staking(0, address1, address1)
    assert_code(result, 0)
    # Application for Commission
    result = client.delegate.delegate(1, report_address)
    assert_code(result, 0)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    #
    for i in range(4):
        result = check_node_in_list(node.node_id, client.ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # view current block
            current_block = node.eth.blockNumber
            log.info("Current block: {}".format(current_block))
            # Report prepareblock signature
            report_information = mock_duplicate_sign(1, node.nodekey,
                                                     node.blsprikey,
                                                     current_block)
            log.info("Report information: {}".format(report_information))
            result = client.duplicatesign.reportDuplicateSign(
                1, report_information, report_address)
            assert_code(result, 0)
            time.sleep(3)
            # Access to pledge information
            candidate_info = client.ppos.getCandidateInfo(node.node_id)
            info = candidate_info['Ret']
            staking_blocknum = info['StakingBlockNum']
            # withdrew delegate
            result = client.delegate.withdrew_delegate(staking_blocknum,
                                                       report_address)
            assert_code(result, 0)
            break
        else:
            # wait consensus block
            client.economic.wait_consensus_blocknum(node)
Esempio n. 14
0
def test_AL_IE_002(client_new_node_obj_list):
    """
    转账到激励池
    :param client_new_node_obj_list:
    :return:
    """
    client1 = client_new_node_obj_list[0]
    client2 = client_new_node_obj_list[1]
    economic = client1.economic
    node = client1.node
    log.info("Node ID:{}".format(node.node_id))
    log.info("Current connection node: {}".format(node.node_mark))
    address, _ = client1.economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 4))
    address1, _ = client1.economic.account.generate_account(node.web3, 0)
    address2, _ = client1.economic.account.generate_account(node.web3, 0)
    log.info("staking address: {}".format(address))
    # Free amount application pledge node
    result = client1.staking.create_staking(0, address1, address)
    assert_code(result, 0)
    # Wait for the settlement round to end
    economic.wait_settlement_blocknum(node)
    # 获取当前结算周期验证人
    verifier_list = node.ppos.getVerifierList()
    log.info("verifier_list: {}".format(verifier_list))
    # view block_reward
    block_reward, staking_reward = economic.get_current_year_reward(node)
    log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward))
    # view account amount
    benifit_balance = node.eth.getBalance(address1)
    log.info("benifit_balance: {}".format(benifit_balance))
    # view benifit reward
    blocknumber = view_benifit_reward(client1, address)
    # view account amount again
    benifit_balance1 = node.eth.getBalance(address1)
    log.info("benifit_balance: {}".format(benifit_balance1))
    reward = int(blocknumber * Decimal(str(block_reward)))
    assert benifit_balance1 == staking_reward + reward, "ErrMsg:benifit_balance: {}".format(benifit_balance1)
    # Transfer to the incentive pool
    result = client1.economic.account.sendTransaction(node.web3, '', address, EconomicConfig.INCENTIVEPOOL_ADDRESS, node.eth.gasPrice, 21000, node.web3.toWei(1000, 'ether'))
    assert result is not None, "ErrMsg:Transfer result {}".format(result)
    time.sleep(5)
    # Free amount application pledge node
    result = client2.staking.create_staking(0, address2, address, amount=von_amount(economic.create_staking_limit, 2))
    assert_code(result, 0)
    # Wait for the settlement round to end
    economic.wait_settlement_blocknum(client2.node)
    # view account amount
    benifit_balance2 = client2.node.eth.getBalance(address2)
    log.info("benifit_balance: {}".format(benifit_balance2))
    # view benifit reward
    blocknumber = view_benifit_reward(client2, address)
    # view account amount again
    benifit_balance3 = client2.node.eth.getBalance(address2)
    log.info("benifit_balance: {}".format(benifit_balance3))
    reward = int(blocknumber * Decimal(str(block_reward)))
    assert benifit_balance3 == staking_reward + reward, "ErrMsg:benifit_balance: {}".format(benifit_balance3)
Esempio n. 15
0
def duplicate_sign(client_obj, report_address, report_block):
    if report_block < 41:
        report_block = 41
    # Report1 prepareblock signature
    report_information = mock_duplicate_sign(1, client_obj.node.nodekey,
                                             client_obj.node.blsprikey,
                                             report_block)
    log.info("Report information: {}".format(report_information))
    result = client_obj.duplicatesign.reportDuplicateSign(1, report_information, report_address)
    assert_code(result, 0)
Esempio n. 16
0
def restricting_plan_validation_release(client, economic, node):
    # create account
    address1, _ = economic.account.generate_account(
        node.web3, von_amount(economic.create_staking_limit, 2))
    # create Restricting Plan
    amount = economic.create_staking_limit
    plan = [{'Epoch': 1, 'Amount': amount}]
    result = client.restricting.createRestrictingPlan(address1, plan, address1)
    assert_code(result, 0)
    return address1
def test_PIP_PVF_004(client_consensus, clients_noconsensus, reset_environment):
    """
    治理修改低0出块率扣除验证人自有质押金块数成功扣除区块奖励块数49999-自由金额质押
    :param client_consensus:
    :param clients_noconsensus:
    :param reset_environment:
    :return:
    """
    consensus_client = client_consensus
    log.info("Current connection consensus node".format(
        consensus_client.node.node_mark))
    first_index = 0
    first_client = clients_noconsensus[first_index]
    log.info("Current connection non-consensus node:{}".format(
        first_client.node.node_mark))
    economic = consensus_client.economic
    node = consensus_client.node
    change_parameter_value = '49999'
    # get pledge amount1 and block reward
    consensus_pledge_amount, block_reward, first_slash_blocks = information_before_slash_blocks(
        consensus_client)
    # create Parametric proposal
    param_governance_verify(consensus_client, 'slashing', 'slashBlocksReward',
                            change_parameter_value)
    log.info("Current block height: {}".format(node.eth.blockNumber))
    # Get governable parameters again
    second_slash_blocks = get_governable_parameter_value(
        consensus_client, 'slashBlocksReward')
    assert second_slash_blocks == change_parameter_value, "ErrMsg:Change parameters {}".format(
        second_slash_blocks)
    # create account
    address, _ = economic.account.generate_account(
        node.web3, von_amount(economic.create_staking_limit, 2))
    # create staking
    result = first_client.staking.create_staking(0, address, address)
    assert_code(result, 0)
    # wait settlement block
    economic.wait_settlement_blocknum(node)
    candidate_info = consensus_client.ppos.getCandidateInfo(
        first_client.node.node_id)
    first_pledge_amount = candidate_info['Ret']['Released']
    log.info("Current pledge node amount:{}".format(first_pledge_amount))
    for i in range(4):
        result = check_node_in_list(node.node_id,
                                    consensus_client.ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # Verify changed parameters
            verify_changed_parameters(clients_noconsensus, first_pledge_amount,
                                      block_reward, second_slash_blocks)
            break
        else:
            # wait consensus block
            economic.wait_consensus_blocknum(node)
Esempio n. 18
0
def restricting_plan_validation_staking(client, economic, node):
    # create restricting plan
    address1 = restricting_plan_validation_release(client, economic, node)
    # create staking
    staking_amount = economic.create_staking_limit
    result = client.staking.create_staking(1,
                                           address1,
                                           address1,
                                           amount=staking_amount)
    assert_code(result, 0)
    return address1
def duplicate_sign(client, report_address, report_block):
    if report_block <= client.economic.consensus_size:
        report_block = client.economic.consensus_size + 1
    # Report1 prepareblock signature
    report_information = mock_duplicate_sign(1, client.node.nodekey,
                                             client.node.blsprikey,
                                             report_block)
    log.info("Report information: {}".format(report_information))
    result = client.duplicatesign.reportDuplicateSign(1, report_information,
                                                      report_address)
    assert_code(result, 0)
Esempio n. 20
0
def test_AL_NBI_018(new_genesis_env, client_new_node_obj):
    """
    调整质押和出块奖励比例
    :param client_new_node_obj:
    :return:
    """
    # Change configuration parameters
    genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config)
    genesis.economicModel.reward.newBlockRate = 60
    new_file = new_genesis_env.cfg.env_tmp + "/genesis.json"
    genesis.to_file(new_file)
    new_genesis_env.deploy_all(new_file)
    client = client_new_node_obj
    economic = client.economic
    node = client.node
    # create account
    address1, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2))
    address2, _ = economic.account.generate_account(node.web3, 0)
    # create pledge
    result = client.staking.create_staking(0, address1, address1)
    assert_code(result, 0)
    # Waiting for the end of the settlement
    economic.wait_settlement_blocknum(node)
    # Check account balance
    balance = node.eth.getBalance(address1)
    log.info("Account Balance: {}".format(balance))
    # Get the number of certifiers in the billing cycle list
    verifier_list = get_pledge_list(node.ppos.getVerifierList)
    verifier_num = len(verifier_list)
    # Get block_reward And pledge rewards
    amount = node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS, 0)
    block_proportion = str(60 / 100)
    staking_proportion = str(1 - 60 / 100)
    block_reward = int(Decimal(str(amount)) * Decimal(str(block_proportion)) / Decimal(str(1600)))
    staking_reward = int(Decimal(str(amount)) * Decimal(str(staking_proportion)) / Decimal(str(10)) / Decimal(
        str(verifier_num)))
    log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward))
    # withdrew of pledge
    result = client.staking.withdrew_staking(address1)
    assert_code(result, 0)
    # wait settlement block
    client.economic.wait_settlement_blocknum(client.node)
    # wait consensus block
    client.economic.wait_consensus_blocknum(client.node)
    # count the number of blocks
    blocknumber = client.economic.get_block_count_number(client.node, 10)
    log.info("blocknumber: {}".format(blocknumber))
    # Check account balance again
    balance1 = node.eth.getBalance(address1)
    log.info("Account Balance: {}".format(balance1))
    # Pledged income account to get the bonus amount
    total_reward = int(Decimal(str(block_reward)) * blocknumber) + staking_reward
    assert balance + total_reward - balance1 < node.web3.toWei(1, 'ether'), "ErrMsg:benifit_balance: {}".format(balance1)
Esempio n. 21
0
def test_AL_NBI_016(client_new_node_obj, reset_environment):
    """
    被双签处罚槛剔除验证人列表
    :param client_new_node_obj:
    :return:
    """
    client = client_new_node_obj
    economic = client.economic
    node = client.node
    client.economic.env.deploy_all()
    # create account
    address1, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2))
    address2, _ = economic.account.generate_account(node.web3, 0)
    report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether'))
    # create staking
    staking_amount = von_amount(economic.create_staking_limit, 1.6)
    result = client_new_node_obj.staking.create_staking(0, address2, address1, amount=staking_amount)
    assert_code(result, 0)
    # wait settlement block
    economic.wait_settlement_blocknum(node)
    # Check account balance
    balance = node.eth.getBalance(address2)
    log.info("Account Balance:{}".format(balance))
    # view block_reward
    block_reward, staking_reward = economic.get_current_year_reward(node)
    log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward))
    for i in range(4):
        result = check_node_in_list(client_new_node_obj.node.node_id, client_new_node_obj.ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # view Current block
            current_block = client_new_node_obj.node.eth.blockNumber
            log.info("Current block: {}".format(current_block))
            # Report prepareblock signature
            report_information = mock_duplicate_sign(1, client_new_node_obj.node.nodekey, client_new_node_obj.node.blsprikey, current_block)
            log.info("Report information: {}".format(report_information))
            result = client_new_node_obj.duplicatesign.reportDuplicateSign(1, report_information, report_address)
            assert_code(result, 0)
            # wait settlement block
            economic.wait_settlement_blocknum(node)
            # Check account balance again
            balance1 = node.eth.getBalance(address2)
            log.info("Account Balance:{}".format(balance1))
            # count the number of blocks
            blocknumber = client_new_node_obj.economic.get_block_count_number(node, 10)
            log.info("blocknumber: {}".format(blocknumber))
            total_block_reward = int(Decimal(str(block_reward)) * Decimal(str(blocknumber)))
            log.info("total_block_reward: {}".format(total_block_reward))
            assert balance1 == balance + total_block_reward, "ErrMsg:benifit_balance1:{}".format(balance1)
            break
        else:
            # wait consensus block
            economic.wait_consensus_blocknum(node)
Esempio n. 22
0
def test_UP_FV_012(client_new_node, reset_environment):
    """
    锁仓验证人违规被剔除验证人列表,申请增持质押
    :param client_new_node:
    :return:
    """
    client1 = client_new_node
    economic = client1.economic
    node = client1.node
    # create account
    amount1 = von_amount(economic.create_staking_limit, 3)
    amount2 = von_amount(economic.create_staking_limit, 1)
    address1, report_address = create_account_amount(client1, amount1, amount2)
    # create Restricting Plan
    staking_amount = von_amount(economic.create_staking_limit, 2)
    plan = [{'Epoch': 3, 'Amount': staking_amount}]
    result = client1.restricting.createRestrictingPlan(address1, plan,
                                                       address1)
    assert_code(result, 0)
    # create staking
    result = client1.staking.create_staking(1, address1, address1)
    assert_code(result, 0)
    # Apply for additional pledge
    result = client1.staking.increase_staking(1, address1)
    assert_code(result, 0)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    #
    for i in range(4):
        result = check_node_in_list(node.node_id,
                                    client1.ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # view current block
            current_block = node.eth.blockNumber
            log.info("Current block: {}".format(current_block))
            # Report prepareblock signature
            report_information = mock_duplicate_sign(1, node.nodekey,
                                                     node.blsprikey,
                                                     current_block)
            log.info("Report information: {}".format(report_information))
            result = client1.duplicatesign.reportDuplicateSign(
                1, report_information, report_address)
            assert_code(result, 0)
            time.sleep(3)
            # Apply for additional pledge
            result = client1.staking.increase_staking(1, address1)
            assert_code(result, 301103)
            break
        else:
            # wait consensus block
            client1.economic.wait_consensus_blocknum(node)
Esempio n. 23
0
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
    # create restricting plan and staking
    address1 = restricting_plan_validation_staking(client1, economic, node)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # Obtain block bonus and pledge bonus
    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_blocknum(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['balance']
                == economic.create_staking_limit - punishment_amonut) or (
                    info['balance']
                    == economic.create_staking_limit - punishment_amonut *
                    2), 'ErrMsg: restricting balance amount {}'.format(
                        info['balance'])
    else:
        assert_code(restricting_info, 304005)
Esempio n. 24
0
def test_UP_FV_006(client_new_node):
    """
    多个锁仓期,质押一部分锁仓金额再依次释放
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create account1
    address1, _ = client.economic.account.generate_account(
        client.node.web3, von_amount(economic.create_staking_limit, 2))
    # create Restricting Plan
    amount1 = economic.create_staking_limit
    amount2 = von_amount(economic.add_staking_limit, 10)
    plan = [{'Epoch': 1, 'Amount': amount1}, {'Epoch': 2, 'Amount': amount2}]
    result = client.restricting.createRestrictingPlan(address1, plan, address1)
    assert_code(result, 0)
    # create staking
    staking_amount = economic.create_staking_limit
    result = client.staking.create_staking(1,
                                           address1,
                                           address1,
                                           amount=staking_amount)
    assert_code(result, 0)
    # view restricting plan
    restricting_info = client.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # view restricting plan
    restricting_info = client.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    assert info[
        'debt'] == amount1 - amount2, 'ErrMsg: restricting debt amount {}'.format(
            info['debt'])
    assert info['plans'][0][
        'amount'] == amount2, 'ErrMsg: restricting plans amount {}'.format(
            info['plans'][0]['amount'])
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # view restricting plan again
    restricting_info = client.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    assert info[
        'debt'] == amount1, 'ErrMsg: restricting debt amount {}'.format(
            info['debt'])
    assert info['plans'] is None, 'ErrMsg: restricting plans'.format(
        info['plans'])
def test_PIP_PVF_008(new_genesis_env):
    """
    治理修改区块双签-证据有效期处于已生效期
    :param new_genesis_env:
    :return:
    """
    # Change configuration parameters
    adjust_initial_parameters(new_genesis_env)
    first_client = get_client_consensus(new_genesis_env, staking_cfg)
    log.info("Current connection non-consensus node:{}".format(
        first_client.node.node_mark))
    economic = first_client.economic
    node = first_client.node
    change_parameter_value = '1'
    # view Parameter value before treatment
    first_slash_blocks = get_governable_parameter_value(
        first_client, 'maxEvidenceAge')
    # create Parametric proposal
    param_governance_verify(first_client, 'slashing', 'maxEvidenceAge',
                            change_parameter_value)
    # view Parameter value before treatment again
    second_slash_blocks = get_governable_parameter_value(
        first_client, 'maxEvidenceAge')
    assert second_slash_blocks != first_slash_blocks, "ErrMsg:Parameter value after treatment {}".format(
        second_slash_blocks)
    assert second_slash_blocks == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format(
        second_slash_blocks)
    report_address, _ = economic.account.generate_account(
        node.web3, node.web3.toWei(1000, 'ether'))
    # wait consensus block
    economic.wait_consensus_blocknum(node)
    # Verify changed parameters
    effective_block = economic.get_front_settlement_switchpoint(
        node, int(second_slash_blocks))
    log.info("effective_block block height: {}".format(effective_block))
    # wait consensus block
    economic.wait_consensus_blocknum(node)
    # first Report prepareblock signature
    report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey,
                                             economic.consensus_size + 1)
    log.info("Report information: {}".format(report_information))
    result = first_client.duplicatesign.reportDuplicateSign(
        1, report_information, report_address)
    assert_code(result, 303003)
    # second Report prepareblock signature
    report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey,
                                             effective_block)
    log.info("Report information: {}".format(report_information))
    result = first_client.duplicatesign.reportDuplicateSign(
        1, report_information, report_address)
    assert_code(result, 0)
Esempio n. 26
0
def test_UP_FV_017(client_new_node):
    """
    锁仓账户质押,自由资金再增持
    :param client_new_node:
    :return:
    """
    client = client_new_node
    economic = client.economic
    node = client.node
    # create account
    amount1 = von_amount(economic.create_staking_limit, 2)
    amount2 = von_amount(economic.create_staking_limit, 1)
    address1, address2 = create_account_amount(client, amount1, amount2)
    # create Restricting Plan
    delegate_amount = von_amount(economic.create_staking_limit, 1)
    plan = [{'Epoch': 3, 'Amount': delegate_amount}]
    result = client.restricting.createRestrictingPlan(address1, plan, address1)
    assert_code(result, 0)
    # create staking
    result = client.staking.create_staking(1, address1, address1)
    assert_code(result, 0)
    # Apply for additional pledge
    result = client.staking.increase_staking(0, address1)
    assert_code(result, 0)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # Apply for additional pledge
    result = client.staking.increase_staking(0, address1)
    assert_code(result, 0)
Esempio n. 27
0
def no_consensus_node_pledge_award_assertion(client_new_node_obj, benifit_address, from_address):
    """
    非内置节点质押奖励断言
    :param client_new_node_obj:
    :param benifit_address:
    :param from_address:
    :return:
    """
    CandidateInfo = client_new_node_obj.ppos.getCandidateInfo(client_new_node_obj.node.node_id)
    log.info("Pledgor node information:{}".format(CandidateInfo))
    balance = client_new_node_obj.node.eth.getBalance(benifit_address)
    log.info("benifit address:{} amount: {}".format(benifit_address, balance))

    # wait settlement block
    client_new_node_obj.economic.wait_settlement_blocknum(client_new_node_obj.node)
    time.sleep(5)
    VerifierList = client_new_node_obj.ppos.getVerifierList()
    log.info("Current settlement cycle verifier list:{}".format(VerifierList))
    ValidatorList = client_new_node_obj.ppos.getValidatorList()
    log.info("Current consensus cycle verifier list:{}".format(ValidatorList))
    block_reward, staking_reward = client_new_node_obj.economic.get_current_year_reward(client_new_node_obj.node)
    for i in range(4):
        result = check_node_in_list(client_new_node_obj.node.node_id, client_new_node_obj.ppos.getValidatorList)
        log.info("Current node in consensus list status:{}".format(result))
        if result:
            # wait consensus block
            client_new_node_obj.economic.wait_consensus_blocknum(client_new_node_obj.node)
            # Application for withdrew staking
            result = client_new_node_obj.staking.withdrew_staking(from_address)
            assert_code(result, 0)
            incentive_pool_balance1 = client_new_node_obj.node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS)
            log.info("incentive pool amount:{}".format(incentive_pool_balance1))
            # wait settlement block
            client_new_node_obj.economic.wait_settlement_blocknum(client_new_node_obj.node)
            # Count the number of blocks out of pledge node
            blocknumber = client_new_node_obj.economic.get_block_count_number(client_new_node_obj.node, 5)
            log.info("blocknumber: {}".format(blocknumber))
            balance1 = client_new_node_obj.node.eth.getBalance(benifit_address)
            log.info("benifit address:{} amount:{}".format(benifit_address, balance1))

            # Verify block rewards
            log.info("Expected bonus:{}".format(Decimal(str(block_reward)) * blocknumber))
            assert balance + Decimal(str(block_reward)) * blocknumber - balance1 < client_new_node_obj.node.web3.toWei(
                1, 'ether'), "ErrMsg:benifit address:{} amount:{}".format(
                benifit_address, balance1)
            break
        else:
            # wait consensus block
            client_new_node_obj.economic.wait_consensus_blocknum(client_new_node_obj.node)
Esempio n. 28
0
def test_AL_IE_003(client_new_node_obj_list):
    """
    自由账户创建质押节点且收益地址为激励池
    :param client_new_node_obj_list:
    :return:
    """
    log.info("Node ID:{}".format(client_new_node_obj_list[0].node.node_id))
    address, _ = client_new_node_obj_list[0].economic.account.generate_account(client_new_node_obj_list[0].node.web3,
                                                                               client_new_node_obj_list[
                                                                                   0].economic.create_staking_limit * 2)
    log.info("staking address: {}".format(address))
    # Free amount application pledge node
    result = client_new_node_obj_list[0].staking.create_staking(0, EconomicConfig.INCENTIVEPOOL_ADDRESS, address)
    assert_code(result, 0)
    consensus_node_pledge_award_assertion(client_new_node_obj_list[0], address)
Esempio n. 29
0
def test_AL_NBI_013(client_new_node_obj):
    """
    修改节点质押收益地址查看收益变更
    :param client_new_node_obj:
    :return:
    """
    # create pledge node
    address, benifit_address = create_pledge_node(client_new_node_obj, 1.3)
    # create account
    benifit_address1, _ = client_new_node_obj.economic.account.generate_account(client_new_node_obj.node.web3, 0)
    # change benifit address
    result = client_new_node_obj.staking.edit_candidate(address, benifit_address1)
    assert_code(result, 0)
    # assert benifit reward
    assert_benifit_reward(client_new_node_obj, benifit_address1, address)
Esempio n. 30
0
def test_AL_BI_002(new_genesis_env, staking_cfg):
    """
    节点出块率为0被处罚,激励池金额增加
    :param new_genesis_env:
    :param staking_cfg:
    :return:
    """
    # Change configuration parameters
    genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config)
    genesis.economicModel.slashing.slashBlocksReward = 5
    new_file = new_genesis_env.cfg.env_tmp + "/genesis.json"
    genesis.to_file(new_file)
    new_genesis_env.deploy_all(new_file)
    client_noc_list_obj = get_client_noconsensus_list(new_genesis_env, staking_cfg)
    client1 = client_noc_list_obj[0]
    client2 = client_noc_list_obj[1]
    economic = client1.economic
    node = client1.node
    log.info("nodeid: {}".format(node.node_id))
    # create account
    address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2))
    # create staking
    result = client1.staking.create_staking(0, address, address)
    assert_code(result, 0)
    # Waiting for a settlement round
    client2.economic.wait_settlement_blocknum(client2.node)
    # view incentive account
    incentive_pool_balance = node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS)
    log.info("incentive_pool_balance: {}".format(incentive_pool_balance))
    # view block_reward
    block_reward, staking_reward = economic.get_current_year_reward(node)
    log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward))
    # stop node
    node.stop()
    # Waiting for 2 consensus round
    client2.economic.wait_consensus_blocknum(client2.node, 2)
    # view verifier list
    verifier_list = client2.ppos.getVerifierList()
    log.info("verifier_list: {}".format(verifier_list))
    slash_blocks = get_governable_parameter_value(client2, 'slashBlocksReward')
    # Get the penalty amount
    penalty_amount = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks)))
    log.info("penalty_amount: {}".format(penalty_amount))
    # view incentive account again
    incentive_pool_balance1 = client2.node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS)
    log.info("incentive_pool_balance1: {}".format(incentive_pool_balance1))
    assert incentive_pool_balance1 == incentive_pool_balance + penalty_amount, "ErrMsg: incentive_pool_balance: {}".format(
        incentive_pool_balance1)