def staking_client(client_new_node):
    print(client_new_node.node.node_mark)
    amount = calculate(client_new_node.economic.create_staking_limit, 5)
    staking_amount = calculate(client_new_node.economic.create_staking_limit,
                               2)
    staking_address, _ = client_new_node.economic.account.generate_account(
        client_new_node.node.web3, amount)
    log.info("staking_address {} amount {}".format(
        staking_address, client_new_node.node.eth.getBalance(staking_address)))
    delegate_address, _ = client_new_node.economic.account.generate_account(
        client_new_node.node.web3,
        client_new_node.economic.add_staking_limit * 2)
    result = client_new_node.staking.create_staking(0,
                                                    staking_address,
                                                    staking_address,
                                                    amount=staking_amount)
    assert_code(result, 0)
    print(
        client_new_node.node.ppos.getCandidateInfo(
            client_new_node.node.node_id))
    setattr(client_new_node, "staking_address", staking_address)
    setattr(client_new_node, "delegate_address", delegate_address)
    setattr(client_new_node, "amount", amount)
    setattr(client_new_node, "staking_amount", staking_amount)
    yield client_new_node
예제 #2
0
def test_ZB_NP_29(update_zero_produce_env, clients_noconsensus):
    client_a = clients_noconsensus[0]
    client_b = clients_noconsensus[1]
    amount = calculate(client_a.economic.create_staking_limit, 5)
    staking_amount_a = calculate(client_a.economic.create_staking_limit, 1)
    staking_amount_b = calculate(client_a.economic.create_staking_limit, 2)
    staking_address, _ = client_a.economic.account.generate_account(
        client_a.node.web3, amount)
    result = client_a.staking.create_staking(0,
                                             staking_address,
                                             staking_address,
                                             amount=staking_amount_a,
                                             reward_per=10)
    assert_code(result, 0)
    economic = client_b.economic
    economic.wait_settlement(client_b.node)
    client_a.node.stop()

    economic = client_b.economic
    node = economic.env.get_consensus_node_by_index(0)

    initial_validator, slashing_node_list = gen_validator_list(
        economic.env.consensus_node_id_list(), client_a.node.node_id)

    assert_set_validator_list(node, initial_validator)
    current_validator = get_pledge_list(node.ppos.getValidatorList)
    log.info("current validator: {}".format(current_validator))
    economic.wait_consensus(node, 1)
    result = client_b.staking.create_staking(0,
                                             staking_address,
                                             staking_address,
                                             amount=staking_amount_b,
                                             reward_per=10)
    assert_code(result, 0)
    assert_set_validator_list(node, slashing_node_list)
    economic.wait_consensus(node)
    assert_set_validator_list(node, initial_validator)
    economic.wait_consensus(node)
    economic.wait_consensus(node, 3)
    wait_slashing_list = node.debug.getWaitSlashingNodeList()
    assert get_slash_count(wait_slashing_list,
                           client_a.node.node_id) == to_int(1)

    economic.wait_consensus(node)
    wait_slashing_list = node.debug.getWaitSlashingNodeList()
    assert len(wait_slashing_list) == 0
    assert_not_slashing(node.ppos.getCandidateInfo(client_a.node.node_id),
                        staking_amount_a)
def test_RV_014_015(staking_client):
    """
    After becoming a verifier, there are pledge rewards and block rewards.
    """
    client = staking_client
    staking_address = client.staking_address
    node = client.node
    economic = client.economic
    economic.wait_settlement(node)
    log.info("Enter the next cycle")
    block_reward, staking_reward = economic.get_current_year_reward(node)
    msg = client.staking.withdrew_staking(staking_address)
    log.info(msg)
    balance_1 = node.eth.getBalance(staking_address)
    log.info(balance_1)
    log.info("Enter the next cycle")
    economic.wait_settlement(node, 2)
    economic.wait_consensus(node)
    balance_2 = node.eth.getBalance(staking_address)
    log.info(balance_2)
    verifier_list = get_pledge_list(node.ppos.getVerifierList)
    log.info("Current certifier list:{}".format(verifier_list))
    validator_list = get_pledge_list(node.ppos.getValidatorList)
    log.info("Current consensus certifier list:{}".format(validator_list))
    block_number = get_block_count_number(node, economic.settlement_size * 3)
    sum_block_reward = calculate(block_reward, block_number)
    reward_sum = sum_block_reward + staking_reward
    log.info("Total amount of reward {}".format(reward_sum))
    assert balance_1 + reward_sum + client.staking_amount == balance_2, "The bonus amount is abnormal"
def test_RV_005(staking_client):
    client = staking_client
    node = client.node
    staking_address = client.staking_address
    economic = client.economic
    log.info("Create a lockout plan")
    lockup_amount = economic.add_staking_limit * 100
    plan = [{'Epoch': 1, 'Amount': lockup_amount}]
    msg = client.restricting.createRestrictingPlan(
        staking_address, plan, economic.account.account_with_money["address"])
    assert_code(msg, 0)
    locked_info = client.ppos.getRestrictingInfo(staking_address)
    log.info(locked_info)
    before_create_balance = client.amount
    log.info("Initiate the balance before the pledge {}".format(
        before_create_balance))

    msg = client.staking.increase_staking(1, staking_address)
    assert_code(msg, 0)
    economic.wait_settlement(node)

    msg = client.ppos.getCandidateInfo(node.node_id)
    log.info("Query pledge {}".format(msg))
    assert msg["Ret"][
        "Shares"] == client.staking_amount + economic.add_staking_limit
    assert msg["Ret"]["Released"] == client.staking_amount
    assert msg["Ret"]["RestrictingPlan"] == economic.add_staking_limit

    block_reward, staking_reward = economic.get_current_year_reward(node)
    msg = client.staking.withdrew_staking(staking_address)
    assert_code(msg, 0)
    balance_withdrew = node.eth.getBalance(staking_address)
    log.info(
        "The second cycle initiated the revocation of the balance{}".format(
            balance_withdrew))
    log.info("Enter the 3rd cycle")
    economic.wait_settlement(node)

    balance_settlement = node.eth.getBalance(staking_address)
    log.info("The balance after launching the revocation in the third cycle{}".
             format(balance_settlement))

    log.info("Enter the 4th cycle")
    economic.wait_settlement(node, 1)

    balance_settlement_2 = node.eth.getBalance(staking_address)
    log.info("The balance after the withdrawal of the fourth cycle {}".format(
        balance_settlement_2))
    """Calculate block reward + pledge reward"""
    log.info("The following is the number of blocks to get the node")
    block_number = get_block_count_number(node, economic.settlement_size * 3)
    sum_block_reward = calculate(block_reward, block_number)
    reward_sum = sum_block_reward + staking_reward
    log.info("Total amount of reward {}".format(reward_sum))
    assert before_create_balance + reward_sum + lockup_amount - balance_settlement_2 < Web3.toWei(
        1, "ether"
    ), "After the expected result unlock period, the money has been refunded + the block reward + pledge reward"
def test_RV_003(staking_client):
    """
    The certifier applies for a refund of the quality deposit (hesitation period + lock-up period)
    """
    client = staking_client
    staking_address = client.staking_address
    node = client.node
    economic = client.economic
    log.info("Enter the next cycle")
    economic.wait_settlement(node)
    msg = client.staking.increase_staking(0, staking_address)
    assert_code(msg, 0)
    msg = node.ppos.getCandidateInfo(node.node_id)
    log.info("Pledge information {}".format(msg))
    assert msg["Ret"][
        "Shares"] == client.staking_amount + economic.add_staking_limit, "Expected display of the amount of deposit + increase in holding amount"
    assert msg["Ret"][
        "Released"] == client.staking_amount, "Expected display of the amount of the deposit"
    assert msg["Ret"][
        "ReleasedHes"] == economic.add_staking_limit, "Expected increase in holdings is shown during the hesitation period"
    block_reward, staking_reward = economic.get_current_year_reward(node)

    balance = node.eth.getBalance(staking_address)
    log.info("Initiate a pre-retardment balance{}".format(balance))

    log.info("Initiation of the return pledge in the second cycle")
    msg = client.staking.withdrew_staking(staking_address)
    assert_code(msg, 0)
    msg = node.ppos.getCandidateInfo(node.node_id)
    log.info("Initiate a refund after pledge information{}".format(msg))
    assert msg["Ret"][
        "ReleasedHes"] == 0, "The amount of expected increase in shareholding has been returned, showing 0"
    balance1 = node.eth.getBalance(client.staking_address)
    log.info(balance1)
    log.info("Enter the 3rd cycle")
    economic.wait_settlement(node, 2)

    balance2 = node.eth.getBalance(staking_address)
    log.info(balance2)

    block_number = get_block_count_number(node, economic.settlement_size * 3)
    sum_block_reward = calculate(block_reward, block_number)
    reward_sum = sum_block_reward + staking_reward
    log.info("Total amount of reward {}".format(reward_sum))
    assert balance1 + reward_sum + client.staking_amount == balance2, "The bonus amount is abnormal"
def staking_client1(client_new_node):
    amount = calculate(client_new_node.economic.create_staking_limit, 5)
    staking_amount = client_new_node.economic.create_staking_limit
    staking_address, _ = client_new_node.economic.account.generate_account(
        client_new_node.node.web3, amount)
    delegate_address, _ = client_new_node.economic.account.generate_account(
        client_new_node.node.web3,
        client_new_node.economic.add_staking_limit * 2)
    client_new_node.staking.create_staking(0,
                                           staking_address,
                                           staking_address,
                                           amount=staking_amount)
    setattr(client_new_node, "staking_address", staking_address)
    setattr(client_new_node, "delegate_address", delegate_address)
    setattr(client_new_node, "amount", amount)
    setattr(client_new_node, "staking_amount", staking_amount)
    yield client_new_node
    client_new_node.economic.env.deploy_all()
def test_RV_019(staking_client):
    """
    Modify the wallet address, the change of address income normal
    """
    client = staking_client
    node = client.node
    staking_address = client.staking_address
    economic = client.economic
    ben_address, _ = economic.account.generate_account(node.web3)
    log.info("ben address balance:{}".format(node.eth.getBalance(ben_address)))
    log.info("Modify node information")
    msg = client.staking.edit_candidate(staking_address, ben_address)
    assert_code(msg, 0)

    log.info("Enter the second billing cycle")
    economic.wait_settlement(node)

    block_reward, staking_reward = economic.get_current_year_reward(node)
    msg = client.staking.withdrew_staking(staking_address)
    assert_code(msg, 0)
    balance_before = node.eth.getBalance(ben_address)
    log.info(
        "Exit the new wallet balance after pledge:{}".format(balance_before))
    log.info("Enter the third billing cycle")
    economic.wait_settlement(node, 2)

    balance_after = node.eth.getBalance(ben_address)
    log.info(
        "Balance after the new wallet unlock period {}".format(balance_after))
    """Compute Block Reward + Pledge Reward"""
    log.info("The following is the number of blocks to get the node")
    block_number = get_block_count_number(node, economic.settlement_size * 3)
    sum_block_reward = calculate(block_reward, block_number)
    reward_sum = sum_block_reward + staking_reward
    log.info("Total amount of reward {}".format(reward_sum))
    assert balance_after == reward_sum, "Expected new wallet balance == earnings reward"
def test_RV_006(staking_client):
    client = staking_client
    staking_address = client.staking_address
    node = client.node
    economic = client.economic
    log.info("Create a lockout plan")
    lockup_amount = economic.add_staking_limit * 100
    plan = [{'Epoch': 3, 'Amount': lockup_amount}]
    msg = client.restricting.createRestrictingPlan(
        staking_address, plan, economic.account.account_with_money["address"])
    assert_code(msg, 0), "Creating a lockout plan failed"
    locked_info = client.ppos.getRestrictingInfo(staking_address)
    log.info(locked_info)

    msg = client.staking.increase_staking(1, staking_address)
    assert_code(msg, 0)
    log.info("Enter the second cycle")
    economic.wait_settlement(node)

    msg = client.staking.increase_staking(1, staking_address)
    assert_code(msg, 0)
    msg = client.staking.increase_staking(0, staking_address)
    assert_code(msg, 0)
    msg = client.ppos.getCandidateInfo(node.node_id)
    log.info("Query the pledge of the node {}".format(msg))

    assert msg["Ret"][
        "Shares"] == client.staking_amount + economic.add_staking_limit * 3
    assert msg["Ret"]["Released"] == client.staking_amount
    assert msg["Ret"]["RestrictingPlan"] == economic.add_staking_limit
    assert msg["Ret"]["RestrictingPlanHes"] == economic.add_staking_limit
    block_reward, staking_reward = economic.get_current_year_reward(node)

    log.info("Node 2 initiates revocation pledge")
    msg = client.staking.withdrew_staking(staking_address)
    assert_code(msg, 0)
    balance2 = node.eth.getBalance(staking_address)
    log.info(
        "The second cycle initiated the revocation of the balance{}".format(
            balance2))
    """ The current increase in free funds has been withdrawn, and the following is reduced to a fee"""
    assert client.amount - balance2 - client.staking_amount < Web3.toWei(
        1, "ether")
    locked_info = client.ppos.getRestrictingInfo(staking_address)
    log.info(
        "Query the lockout plan after the second cycle initiated revocation {}"
        .format(locked_info))
    assert_code(locked_info, 0)
    assert locked_info["Ret"][
        "Pledge"] == economic.add_staking_limit, "The amount in the lockout plan is expected to be the lockout period amount."

    msg = client.ppos.getCandidateInfo(node.node_id)
    log.info("Query the pledge of node {}".format(msg))

    assert msg["Ret"][
        "ReleasedHes"] == 0, "Expected amount of hesitation has been refunded"
    assert msg["Ret"][
        "RestrictingPlanHes"] == 0, "Expected lockout amount has been refunded during the hesitation period"

    log.info("Enter the 3rd cycle")
    economic.wait_settlement(node)
    balance3 = node.eth.getBalance(staking_address)
    log.info("The balance after launching the revocation in the third cycle{}".
             format(balance3))

    log.info("Enter the 4th cycle")
    economic.wait_settlement(node, 1)
    balance4 = node.eth.getBalance(staking_address)
    log.info("The balance after the revocation of the second cycle {}".format(
        balance4))

    locked_info = client.ppos.getRestrictingInfo(staking_address)
    log.info(locked_info)

    msg = client.ppos.getCandidateInfo(node.node_id)
    log.info("Query the pledge of the node{}".format(msg))
    assert_code(msg, 301204)
    """Compute Block Reward + Pledge Reward"""
    log.info("The following is the number of blocks to get the node")
    block_number = get_block_count_number(node, economic.settlement_size * 3)
    sum_block_reward = calculate(block_reward, block_number)
    reward_sum = sum_block_reward + staking_reward
    log.info("Total amount of reward {}".format(reward_sum))

    assert client.amount + reward_sum - balance4 < Web3.toWei(
        1, "ether"
    ), "After the expected result unlock period, the money has been refunded + the block reward + pledge reward"