Exemplo n.º 1
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'])
Exemplo n.º 2
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)
Exemplo 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']))
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def test_UP_FV_013(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
    delegate_amount = von_amount(economic.create_staking_limit, 2)
    plan = [{'Epoch': 3, 'Amount': delegate_amount}]
    result = client1.restricting.createRestrictingPlan(address1, plan,
                                                       address1)
    assert_code(result, 0)
    # view restricting plan again
    restricting_info = client1.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    # create staking
    result = client1.staking.create_staking(1, address1, address1)
    assert_code(result, 0)
    # view restricting plan again
    restricting_info = client1.ppos.getRestrictingInfo(address1)
    log.info("restricting plan informtion: {}".format(restricting_info))
    # 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)
            # withdrew staking
            result = client1.staking.withdrew_staking(address1)
            assert_code(result, 301103)
            break
        else:
            # wait consensus block
            client1.economic.wait_consensus_blocknum(node)
Exemplo n.º 7
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)
Exemplo n.º 8
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'])
Exemplo n.º 9
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
Exemplo n.º 10
0
def test_UP_FV_018(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.delegate_limit, 10)
    plan = [{'Epoch': 1, 'Amount': delegate_amount}]
    result = client.restricting.createRestrictingPlan(address2, plan, address2)
    assert_code(result, 0)
    # create staking
    result = client.staking.create_staking(0, address1, address1)
    assert_code(result, 0)
    # Lock in amount Application for delegate
    result = client.delegate.delegate(1, address2, amount=delegate_amount)
    assert_code(result, 0)
    # Free amount Application for delegate
    result = client.delegate.delegate(0, address2, amount=delegate_amount)
    assert_code(result, 0)
    # Waiting for the end of the settlement period
    economic.wait_settlement_blocknum(node)
    # Access to pledge information
    candidate_info = client.ppos.getCandidateInfo(node.node_id)
    info = candidate_info['Ret']
    staking_blocknum = info['StakingBlockNum']
    # withdrew delegate
    withdrew_amount = von_amount(economic.delegate_limit, 15)
    result = client.delegate.withdrew_delegate(staking_blocknum,
                                               address2,
                                               amount=withdrew_amount)
    assert_code(result, 0)
    # view restricting plan
    restricting_info = client.ppos.getRestrictingInfo(address2)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    assert info['debt'] == von_amount(
        economic.delegate_limit,
        5), 'ErrMsg: restricting debt amount {}'.format(info['debt'])
Exemplo n.º 11
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
def test_AL_BI_004(client_consensus_obj):
    """
    初始验证人退出后重新质押进来
    :param client_consensus_obj:
    :return:
    """
    client = client_consensus_obj
    economic = client.economic
    node = client.node
    # Reset environment
    economic.env.deploy_all()
    # Query Developer Fund Amount
    log.info("nodeid: {}".format(node.node_id))
    developer_foundation_balance = node.eth.getBalance(EconomicConfig.DEVELOPER_FOUNDATAION_ADDRESS)
    log.info("incentive_pool_balance: {}".format(developer_foundation_balance))
    staking_balance = client_consensus_obj.node.eth.getBalance(EconomicConfig.STAKING_ADDRESS)
    log.info("staking_balance: {}".format(staking_balance))
    # Built in node return pledge
    result = client.staking.withdrew_staking(EconomicConfig.DEVELOPER_FOUNDATAION_ADDRESS)
    assert_code(result, 0)
    # Waiting for the end of the 2 settlement
    economic.wait_settlement_blocknum(node, 2)
    # create account
    address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2))
    address1, _ = economic.account.generate_account(node.web3, 0)
    # Check account balance
    balance = node.eth.getBalance(address1)
    log.info("Account Balance: {}".format(balance))
    # Node pledge again
    result = client.staking.create_staking(0, address1, address)
    assert_code(result, 0)
    # Waiting for the end of the settlement
    economic.wait_settlement_blocknum(node)
    # view block_reward
    block_reward, staking_reward = economic.get_current_year_reward(node)
    log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward))
    # withdrew of pledge
    result = client.staking.withdrew_staking(address)
    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 balance1 == balance + total_reward, "ErrMsg:benifit_balance: {}".format(balance1)
Exemplo n.º 15
0
def test_UP_FV_007(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.delegate_limit, 10)
    plan = [{'Epoch': 1, 'Amount': delegate_amount}]
    result = client.restricting.createRestrictingPlan(address2, plan, address2)
    assert_code(result, 0)
    # view restricting plan
    restricting_info = client.ppos.getRestrictingInfo(address2)
    log.info("restricting plan informtion: {}".format(restricting_info))
    # create staking
    result = client.staking.create_staking(0, address1, address1)
    assert_code(result, 0)
    # Application for Commission
    result = client.delegate.delegate(1, address2, amount=delegate_amount)
    assert_code(result, 0)
    # view restricting plan
    restricting_info = client.ppos.getRestrictingInfo(address2)
    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(address2)
    log.info("restricting plan informtion: {}".format(restricting_info))
    info = restricting_info['Ret']
    assert info[
        'debt'] == delegate_amount, 'ErrMsg: restricting debt amount {}'.format(
            info['debt'])
Exemplo n.º 16
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)
Exemplo n.º 17
0
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 = von_amount(economic.delegate_limit, 10)
    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_blocknum(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_blocknum(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_blocknum(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
def test_AL_FI_004_005(new_genesis_env, staking_cfg):
    """
    AL_FI_004:查看每年区块奖励变化
    AL_FI_005:查看每年质押奖励变化
    :param new_genesis_env:
    :param staking_cfg:
    :return:
    """
    # Initialization genesis file Initial amount
    node_count = len(new_genesis_env.consensus_node_list)
    default_pledge_amount = Web3.toWei(node_count * 1500000, 'ether')
    community_amount = default_pledge_amount + 259096239000000000000000000 + 62215742000000000000000000
    genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config)
    genesis.economicModel.innerAcc.cdfBalance = community_amount
    surplus_amount = str(EconomicConfig.TOKEN_TOTAL - community_amount - 200000000000000000000000000)
    genesis.alloc = {
        "lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqrzpqayr": {
            "balance": "200000000000000000000000000"
        },
        "lax196278ns22j23awdfj9f2d4vz0pedld8au6xelj": {
            "balance": surplus_amount
        }
    }
    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)
    normal_node = new_genesis_env.get_a_normal_node()
    client = Client(new_genesis_env, normal_node, staking_cfg)
    economic = client.economic
    node = client.node
    log.info("Current connection node:{}".format(node.node_mark))
    log.info("Current connection nodeid:{}".format(node.node_id))
    address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2))
    log.info("address: {}".format(address))
    address1, _ = economic.account.generate_account(node.web3, 0)
    log.info("address1: {}".format(address1))
    end_cycle_timestamp = None
    for i in range(10):
        result = client.staking.create_staking(0, address1, address)
        assert_code(result, 0)
        # view account amount
        benifit_balance = node.eth.getBalance(address1)
        log.info("benifit_balance: {}".format(benifit_balance))
        # 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))
        # withdrew of pledge
        result = client.staking.withdrew_staking(address)
        assert_code(result, 0)
        # wait settlement block
        economic.wait_settlement_blocknum(node)
        # wait consensus block
        economic.wait_consensus_blocknum(node)
        # count the number of blocks
        blocknumber = economic.get_block_count_number(node, 10)
        log.info("blocknumber: {}".format(blocknumber))
        # 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 == benifit_balance + staking_reward + reward, "ErrMsg:benifit_balance: {}".format(
            benifit_balance1)
        if i == 0:
            block_info = node.eth.getBlock(1)
            log.info("block_info:{}".format(block_info))
            first_timestamp = block_info['timestamp']
            log.info("First block timestamp: {}".format(first_timestamp))
            end_cycle_timestamp = first_timestamp + (economic.additional_cycle_time * 60000)
            log.info("End time stamp of current issue cycle: {}".format(end_cycle_timestamp))
        else:
            # Waiting for the end of the annual issuance cycle
            end_cycle_timestamp = end_cycle_timestamp + (economic.additional_cycle_time * 60000)
            log.info("End time stamp of current issue cycle: {}".format(end_cycle_timestamp))
        annual_last_block = (math.ceil(node.eth.blockNumber / economic.settlement_size) - 1) * economic.settlement_size
        log.info("The last block height in the last issue cycle: {}".format(annual_last_block))
        settlement_block_info = node.eth.getBlock(annual_last_block)
        settlement_timestamp = settlement_block_info['timestamp']
        log.info("High block timestamp at the end of settlement cycle: {}".format(settlement_timestamp))
        remaining_additional_time = end_cycle_timestamp - settlement_timestamp
        log.info("Remaining time of current issuance cycle: {}".format(remaining_additional_time))
        result = client.ppos.getAvgPackTime()
        average_interval = result['Ret']
        log.info("Block interval on the chain:{}".format(average_interval))
        log.info("Block interval on the chain:{}".format(average_interval))
        number_of_remaining_blocks = math.ceil(remaining_additional_time / average_interval)
        log.info("Remaining block height of current issuance cycle: {}".format(number_of_remaining_blocks))
        remaining_settlement_cycle = math.ceil(number_of_remaining_blocks / economic.settlement_size)
        log.info("remaining settlement cycles issuance cycle: {}".format(remaining_settlement_cycle))
        while remaining_settlement_cycle != 1:
            tmp_current_block = node.eth.blockNumber
            if tmp_current_block % economic.settlement_size == 0:
                time.sleep(economic.interval)
            tmp_current_block = node.eth.blockNumber
            last_settlement_block = (math.ceil(
                tmp_current_block / economic.settlement_size) - 1) * economic.settlement_size
            log.info("The last block height of the previous settlement period: {}".format(last_settlement_block))
            settlement_block_info = node.eth.getBlock(last_settlement_block)
            settlement_timestamp = settlement_block_info['timestamp']
            log.info("High block timestamp at the end of settlement cycle: {}".format(settlement_timestamp))
            remaining_additional_time = end_cycle_timestamp - settlement_timestamp
            log.info("Remaining time of current issuance cycle: {}".format(remaining_additional_time))
            result = client.ppos.getAvgPackTime()
            average_interval = result['Ret']
            log.info("Block interval on the chain:{}".format(average_interval))
            number_of_remaining_blocks = math.ceil(remaining_additional_time / average_interval)
            log.info("Remaining block height of current issuance cycle: {}".format(number_of_remaining_blocks))
            remaining_settlement_cycle = math.ceil(number_of_remaining_blocks / economic.settlement_size)
            log.info("remaining settlement cycles issuance cycle: {}".format(remaining_settlement_cycle))
            economic.wait_settlement_blocknum(node)
def AL_FI_004_005(new_genesis_env, staking_cfg):
    """
    AL_FI_004:查看每年区块奖励变化
    AL_FI_005:查看每年质押奖励变化
    :param new_genesis_env:
    :param staking_cfg:
    :return:
    """
    # Initialization genesis file Initial amount
    node_count = len(new_genesis_env.consensus_node_list)
    default_pledge_amount = Web3.toWei(node_count * 1500000, 'ether')
    community_amount = default_pledge_amount + 259096239000000000000000000 + 62215742000000000000000000
    genesis = from_dict(data_class=Genesis,
                        data=new_genesis_env.genesis_config)
    genesis.economicModel.innerAcc.cdfBalance = community_amount
    surplus_amount = str(EconomicConfig.TOKEN_TOTAL - community_amount -
                         200000000000000000000000000)
    genesis.alloc = {
        "1000000000000000000000000000000000000003": {
            "balance": "200000000000000000000000000"
        },
        "0x2e95E3ce0a54951eB9A99152A6d5827872dFB4FD": {
            "balance": surplus_amount
        }
    }
    new_file = new_genesis_env.cfg.env_tmp + "/genesis.json"
    genesis.to_file(new_file)
    new_genesis_env.deploy_all(new_file)
    normal_node = new_genesis_env.get_a_normal_node()
    client1 = Client(new_genesis_env, normal_node, staking_cfg)
    economic = client1.economic
    node = client1.node
    log.info("Current connection node:{}".format(node.node_mark))
    log.info("Current connection nodeid:{}".format(node.node_id))
    address, _ = client1.economic.account.generate_account(
        node.web3, von_amount(economic.create_staking_limit, 2))
    log.info("address: {}".format(address))
    address1, _ = client1.economic.account.generate_account(node.web3, 0)
    log.info("address1: {}".format(address1))
    for i in range(10):
        current_block = node.eth.blockNumber
        log.info("Current query block height: {}".format(node.eth.blockNumber))
        annualcycle = (economic.additional_cycle_time *
                       60) // economic.settlement_size
        annual_size = annualcycle * economic.settlement_size
        starting_block_height = math.floor(
            current_block / annual_size) * annual_size
        amount = node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS,
                                     starting_block_height)
        log.info("Current annual incentive pool amount: {}".format(amount))
        # if i == 0:
        #     current_annual_incentive_pool_amount = 262215742000000000000000000
        # else:
        #     current_annual_incentive_pool_amount = node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS)
        #     log.info("Current annual incentive pool amount: {}".format(current_annual_incentive_pool_amount))
        # Free amount application pledge node
        result = client1.staking.create_staking(0, address1, address)
        assert_code(result, 0)
        # view account amount
        benifit_balance = node.eth.getBalance(address1)
        log.info("benifit_balance: {}".format(benifit_balance))
        # 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, amount=amount)
        log.info("block_reward: {} staking_reward: {}".format(
            block_reward, staking_reward))
        # withdrew of pledge
        result = client1.staking.withdrew_staking(address)
        assert_code(result, 0)
        # wait settlement block
        client1.economic.wait_settlement_blocknum(node)
        # wait consensus block
        client1.economic.wait_consensus_blocknum(node)
        # count the number of blocks
        blocknumber = client1.economic.get_block_count_number(client1.node, 10)
        log.info("blocknumber: {}".format(blocknumber))
        # 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 == benifit_balance + staking_reward + reward, "ErrMsg:benifit_balance: {}".format(
            benifit_balance1)
        # Waiting for the end of the annual increase
        economic.wait_annual_blocknum(node)