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_UV_UPG_1_UV_UPG_2(self, new_genesis_env, clients_consensus, client_noconsensus): new_genesis_env.deploy_all() pip = clients_consensus[0].pip pip_test = client_noconsensus.pip address, _ = pip_test.economic.account.generate_account(pip_test.node.web3, 10**18 * 10000000) result = client_noconsensus.staking.create_staking(0, address, address, amount=10 ** 18 * 2000000, transaction_cfg=pip_test.cfg.transaction_cfg) log.info('Node {} staking result : {}'.format(pip_test.node.node_mark, result)) programversion = client_noconsensus.staking.get_version() assert_code(programversion, pip.cfg.version0) pip_test.economic.wait_settlement(pip_test.node) verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList) log.info('Get verifier list : {}'.format(verifier_list)) assert pip_test.node.node_id in verifier_list submitvpandvote(clients_consensus, 5) upload_platon(pip_test.node, pip_test.cfg.PLATON_NEW_BIN) programversion = clients_consensus[0].staking.get_version() assert_code(programversion, pip.cfg.version0) proposalinfo = pip.get_effect_proposal_info_of_vote() log.info('Get version proposal information : {}'.format(proposalinfo)) wait_block_number(pip.node, proposalinfo.get('EndVotingBlock') - 1) validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList) wait_block_number(pip.node, proposalinfo.get('EndVotingBlock')) assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 4) validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList) log.info('Validator list : {}'.format(validator_list)) wait_block_number(pip.node, proposalinfo.get('ActiveBlock')) validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList) log.info('Validator list : {}'.format(validator_list)) assert pip_test.node.node_id not in validator_list assert_code(pip.get_status_of_proposal(proposalinfo.get('ProposalID')), 5) block_reward, staking_reward = pip_test.economic.get_current_year_reward(pip_test.node, verifier_num=5) pip.economic.wait_settlement(client_noconsensus.node) count = get_block_count_number(client_noconsensus.node, 320) validator_list = get_pledge_list(clients_consensus[0].ppos.getValidatorList) log.info('Validator list : {}'.format(validator_list)) assert pip_test.node.node_id not in validator_list verifier_list = get_pledge_list(clients_consensus[0].ppos.getVerifierList) log.info('Get verifier list : {}'.format(verifier_list)) assert pip_test.node.node_id not in verifier_list block_reward, staking_reward = pip.economic.get_current_year_reward(pip.node, 5) log.info(f'block_reward == {block_reward}, staking_reward == {staking_reward}') balance_before = pip.node.eth.getBalance(address, 2 * pip.economic.settlement_size - 1) log.info('Block number {} address balace {}'.format(2 * pip.economic.settlement_size - 1, balance_before)) pip.economic.wait_consensus(pip.node) balance_after = pip.node.eth.getBalance(address, 2 * pip.economic.settlement_size) log.info('Block number {} address balace {}'.format(2 * pip.economic.settlement_size, balance_after)) log.info('Staking reward : {}'.format(staking_reward)) assert balance_after - balance_before == staking_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 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"