github.com/platonnetwork/platon-go@v0.7.6/cases/tests/ppos_2/test_withdrew_staking.py (about)

     1  from decimal import Decimal
     2  
     3  import allure
     4  import pytest
     5  import time
     6  from common.log import log
     7  from client_sdk_python import Web3
     8  from tests.lib.utils import get_pledge_list, get_block_count_number, assert_code
     9  from common.key import generate_key
    10  from tests.ppos_2.conftest import calculate
    11  
    12  
    13  @pytest.fixture()
    14  def staking_client(client_new_node):
    15      amount = calculate(client_new_node.economic.create_staking_limit, 5)
    16      staking_amount = calculate(client_new_node.economic.create_staking_limit, 2)
    17      staking_address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, amount)
    18      delegate_address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
    19                                                                              client_new_node.economic.add_staking_limit * 2)
    20      client_new_node.staking.create_staking(0, staking_address, staking_address, amount=staking_amount)
    21      setattr(client_new_node, "staking_address", staking_address)
    22      setattr(client_new_node, "delegate_address", delegate_address)
    23      setattr(client_new_node, "amount", amount)
    24      setattr(client_new_node, "staking_amount", staking_amount)
    25      yield client_new_node
    26      client_new_node.economic.env.deploy_all()
    27  
    28  
    29  @allure.title("The verifier applies for returning the pledge money (hesitation period)")
    30  @pytest.mark.P0
    31  @pytest.mark.compatibility
    32  def test_RV_001(staking_client):
    33      """
    34      The certifier applies for a refund of the quality deposit (hesitation period)
    35      """
    36      client = staking_client
    37      staking_address = client.staking_address
    38      node = client.node
    39      balance_before = node.eth.getBalance(staking_address)
    40      log.info("Corresponding wallet balance {}".format(balance_before))
    41      client.staking.withdrew_staking(staking_address)
    42      balance_after = node.eth.getBalance(staking_address)
    43      log.info("Node 4 exits the pledge wallet balance {}".format(balance_after))
    44      assert balance_after > balance_before, "After exiting the pledge, the wallet balance has not increased"
    45      log.info(
    46          "Because the value of gas consumed by the pledge is greater than the value of the gas that cancels the pledge")
    47      assert balance_after > client.amount - 10 ** 18
    48      node_list = get_pledge_list(node.ppos.getCandidateList)
    49      assert node.node_id not in node_list, "Verify that the node exits abnormally"
    50  
    51  
    52  @allure.title("The verifier returns the pledge money (lockup period)")
    53  @pytest.mark.P1
    54  def test_RV_002(staking_client):
    55      """
    56      The certifier refunds the quality deposit (unreachable unlockable period)
    57      Pledge becomes the next cycle verifier, after exiting, exit in the next settlement cycle
    58      """
    59      client = staking_client
    60      staking_address = client.staking_address
    61      node = client.node
    62      economic = client.economic
    63      staking_address_balance = node.eth.getBalance(staking_address)
    64      log.info(staking_address_balance)
    65      economic.wait_settlement_blocknum(node)
    66      log.info("Query the certifier for the second billing cycle")
    67      node_list = get_pledge_list(client.ppos.getVerifierList)
    68      log.info(node_list)
    69      assert node.node_id in node_list
    70      log.info("The node applies for a return during the lockout period in the second settlement cycle.")
    71      client.staking.withdrew_staking(staking_address)
    72      """Initiation of returning consumes a certain amount of gas"""
    73      staking_address_balance_1 = node.eth.getBalance(staking_address)
    74      log.info(staking_address_balance_1)
    75      log.info("Enter the third billing cycle")
    76      economic.wait_settlement_blocknum(node)
    77      staking_address_balance_2 = node.eth.getBalance(staking_address)
    78      log.info(staking_address_balance_2)
    79      node_list = get_pledge_list(client.ppos.getVerifierList)
    80      log.info(node_list)
    81      assert node.node_id not in node_list
    82      log.info("Enter the 4th billing cycle")
    83      economic.wait_settlement_blocknum(node)
    84      msg = client.ppos.getCandidateInfo(node.node_id)
    85      log.info(msg)
    86      staking_address_balance_3 = node.eth.getBalance(staking_address)
    87      log.info(staking_address_balance_3)
    88      log.info(staking_address_balance_3 - staking_address_balance_1)
    89      assert staking_address_balance_3 - staking_address_balance_1 > client.staking_amount, "The amount of the returned transaction should be greater than the amount of the returned deposit."
    90  
    91  
    92  @allure.title("The verifier applies for returning the pledge money (hesitation period + lockup period)")
    93  @pytest.mark.P1
    94  def test_RV_003(staking_client):
    95      """
    96      The certifier applies for a refund of the quality deposit (hesitation period + lock-up period)
    97      """
    98      client = staking_client
    99      staking_address = client.staking_address
   100      node = client.node
   101      economic = client.economic
   102      log.info("Enter the next cycle")
   103      economic.wait_settlement_blocknum(node)
   104      msg = client.staking.increase_staking(0, staking_address)
   105      assert_code(msg, 0)
   106      msg = node.ppos.getCandidateInfo(node.node_id)
   107      log.info("Pledge information {}".format(msg))
   108      assert msg["Ret"][
   109                 "Shares"] == client.staking_amount + economic.add_staking_limit, "Expected display of the amount of deposit + increase in holding amount"
   110      assert msg["Ret"]["Released"] == client.staking_amount, "Expected display of the amount of the deposit"
   111      assert msg["Ret"][
   112                 "ReleasedHes"] == economic.add_staking_limit, "Expected increase in holdings is shown during the hesitation period"
   113      block_reward, staking_reward = economic.get_current_year_reward(node)
   114  
   115      balance = node.eth.getBalance(staking_address)
   116      log.info("Initiate a pre-retardment balance{}".format(balance))
   117  
   118      log.info("Initiation of the return pledge in the second cycle")
   119      msg = client.staking.withdrew_staking(staking_address)
   120      assert_code(msg, 0)
   121      msg = node.ppos.getCandidateInfo(node.node_id)
   122      log.info("Initiate a refund after pledge information{}".format(msg))
   123      assert msg["Ret"][
   124                 "ReleasedHes"] == 0, "The amount of expected increase in shareholding has been returned, showing 0"
   125      balance1 = node.eth.getBalance(client.staking_address)
   126      log.info(balance1)
   127      log.info("Enter the 3rd cycle")
   128      economic.wait_settlement_blocknum(node, 2)
   129  
   130      balance2 = node.eth.getBalance(staking_address)
   131      log.info(balance2)
   132  
   133      block_number = get_block_count_number(node, economic.settlement_size * 3)
   134      sum_block_reward = calculate(block_reward, block_number)
   135      reward_sum = sum_block_reward + staking_reward
   136      log.info("Total amount of reward {}".format(reward_sum))
   137      assert balance1 + reward_sum + client.staking_amount == balance2, "The bonus amount is abnormal"
   138  
   139  
   140  @allure.title("Free account pledge + lockup account increase (withdraw pledge after hesitation)")
   141  @pytest.mark.P1
   142  def test_RV_004(staking_client):
   143      client = staking_client
   144      staking_address = client.staking_address
   145      node = client.node
   146      economic = client.economic
   147      log.info("Create a lockout plan")
   148      lockup_amount = economic.add_staking_limit * 2
   149      plan = [{'Epoch': 1, 'Amount': lockup_amount}]
   150      msg = client.restricting.createRestrictingPlan(staking_address, plan,
   151                                                     economic.account.account_with_money["address"])
   152      assert_code(msg, 0)
   153      locked_info = client.ppos.getRestrictingInfo(staking_address)
   154      log.info(locked_info)
   155      before_create_balance = client.amount
   156      log.info("Initiate the balance before the pledge {}".format(before_create_balance))
   157  
   158      msg = client.staking.increase_staking(1, staking_address)
   159      assert_code(msg, 0)
   160      msg = client.ppos.getCandidateInfo(node.node_id)
   161      log.info("Query pledge {}".format(msg))
   162      log.info("Initiating a pledge")
   163      msg = client.staking.withdrew_staking(staking_address)
   164      assert_code(msg, 0)
   165  
   166      after_balance_1 = node.eth.getBalance(staking_address)
   167      log.info("Hesitant period to initiate a refunded balance{}".format(after_balance_1))
   168      """The balance after return is definitely less than the balance before the pledge, the consumption is less than 1 eth"""
   169      assert before_create_balance - after_balance_1 < Web3.toWei(1, "ether"), "The returned amount is abnormal"
   170      locked_info = client.ppos.getRestrictingInfo(staking_address)
   171      log.info(locked_info)
   172  
   173      msg = client.ppos.getCandidateInfo(node.node_id)
   174      assert_code(msg, 301204)
   175      log.info("Enter the next cycle")
   176      economic.wait_settlement_blocknum(node)
   177      locked_info = client.ppos.getRestrictingInfo(staking_address)
   178      log.info(locked_info)
   179      after_account = node.eth.getBalance(staking_address)
   180      log.info("Account balance after the lockout is released{}".format(after_account))
   181      assert after_account - after_balance_1 == lockup_amount, "The amount of the lockout returned is abnormal."
   182  
   183  
   184  @allure.title("Free account pledge + lock account increase (lock period depledge)")
   185  @pytest.mark.P1
   186  def test_RV_005(staking_client):
   187      client = staking_client
   188      node = client.node
   189      staking_address = client.staking_address
   190      economic = client.economic
   191      log.info("Create a lockout plan")
   192      lockup_amount = economic.add_staking_limit * 2
   193      plan = [{'Epoch': 1, 'Amount': lockup_amount}]
   194      msg = client.restricting.createRestrictingPlan(staking_address, plan,
   195                                                     economic.account.account_with_money["address"])
   196      assert_code(msg, 0)
   197      locked_info = client.ppos.getRestrictingInfo(staking_address)
   198      log.info(locked_info)
   199      before_create_balance = client.amount
   200      log.info("Initiate the balance before the pledge {}".format(before_create_balance))
   201  
   202      msg = client.staking.increase_staking(1, staking_address)
   203      assert_code(msg, 0)
   204      economic.wait_settlement_blocknum(node)
   205  
   206      msg = client.ppos.getCandidateInfo(node.node_id)
   207      log.info("Query pledge {}".format(msg))
   208      assert msg["Ret"]["Shares"] == client.staking_amount + economic.add_staking_limit
   209      assert msg["Ret"]["Released"] == client.staking_amount
   210      assert msg["Ret"]["RestrictingPlan"] == economic.add_staking_limit
   211  
   212      block_reward, staking_reward = economic.get_current_year_reward(node)
   213      msg = client.staking.withdrew_staking(staking_address)
   214      assert_code(msg, 0)
   215      balance_withdrew = node.eth.getBalance(staking_address)
   216      log.info("The second cycle initiated the revocation of the balance{}".format(balance_withdrew))
   217      log.info("Enter the 3rd cycle")
   218      economic.wait_settlement_blocknum(node)
   219  
   220      balance_settlement = node.eth.getBalance(staking_address)
   221      log.info("The balance after launching the revocation in the third cycle{}".format(balance_settlement))
   222  
   223      log.info("Enter the 4th cycle")
   224      economic.wait_settlement_blocknum(node, 1)
   225  
   226      balance_settlement_2 = node.eth.getBalance(staking_address)
   227      log.info("The balance after the withdrawal of the fourth cycle {}".format(balance_settlement_2))
   228  
   229      """Calculate block reward + pledge reward"""
   230      log.info("The following is the number of blocks to get the node")
   231      block_number = get_block_count_number(node, economic.settlement_size * 3)
   232      sum_block_reward = calculate(block_reward, block_number)
   233      reward_sum = sum_block_reward + staking_reward
   234      log.info("Total amount of reward {}".format(reward_sum))
   235      assert before_create_balance + reward_sum + lockup_amount - balance_settlement_2 < Web3.toWei(1,
   236                                                                                                    "ether"), "After the expected result unlock period, the money has been refunded + the block reward + pledge reward"
   237  
   238  
   239  @allure.title("Free account pledge + lockup account increase (both have hesitation period + lockup period)")
   240  @pytest.mark.P1
   241  def test_RV_006(staking_client):
   242      client = staking_client
   243      staking_address = client.staking_address
   244      node = client.node
   245      economic = client.economic
   246      log.info("Create a lockout plan")
   247      lockup_amount = economic.add_staking_limit * 5
   248      plan = [{'Epoch': 3, 'Amount': lockup_amount}]
   249      msg = client.restricting.createRestrictingPlan(staking_address, plan,
   250                                                     economic.account.account_with_money["address"])
   251      assert_code(msg, 0), "Creating a lockout plan failed"
   252      locked_info = client.ppos.getRestrictingInfo(staking_address)
   253      log.info(locked_info)
   254  
   255      msg = client.staking.increase_staking(1, staking_address)
   256      assert_code(msg, 0)
   257      log.info("Enter the second cycle")
   258      economic.wait_settlement_blocknum(node)
   259  
   260      msg = client.staking.increase_staking(1, staking_address)
   261      assert_code(msg, 0)
   262      msg = client.staking.increase_staking(0, staking_address)
   263      assert_code(msg, 0)
   264      msg = client.ppos.getCandidateInfo(node.node_id)
   265      log.info("Query the pledge of the node {}".format(msg))
   266  
   267      assert msg["Ret"]["Shares"] == client.staking_amount + economic.add_staking_limit * 3
   268      assert msg["Ret"]["Released"] == client.staking_amount
   269      assert msg["Ret"]["RestrictingPlan"] == economic.add_staking_limit
   270      assert msg["Ret"]["RestrictingPlanHes"] == economic.add_staking_limit
   271      block_reward, staking_reward = economic.get_current_year_reward(node)
   272  
   273      log.info("Node 2 initiates revocation pledge")
   274      msg = client.staking.withdrew_staking(staking_address)
   275      assert_code(msg, 0)
   276      balance2 = node.eth.getBalance(staking_address)
   277      log.info("The second cycle initiated the revocation of the balance{}".format(balance2))
   278      """ The current increase in free funds has been withdrawn, and the following is reduced to a fee"""
   279      assert client.amount - balance2 - client.staking_amount < Web3.toWei(1, "ether")
   280      locked_info = client.ppos.getRestrictingInfo(staking_address)
   281      log.info("Query the lockout plan after the second cycle initiated revocation {}".format(locked_info))
   282      assert_code(locked_info, 0)
   283      assert locked_info["Ret"][
   284                 "Pledge"] == economic.add_staking_limit, "The amount in the lockout plan is expected to be the lockout period amount."
   285  
   286      msg = client.ppos.getCandidateInfo(node.node_id)
   287      log.info("Query the pledge of node {}".format(msg))
   288  
   289      assert msg["Ret"]["ReleasedHes"] == 0, "Expected amount of hesitation has been refunded"
   290      assert msg["Ret"][
   291                 "RestrictingPlanHes"] == 0, "Expected lockout amount has been refunded during the hesitation period"
   292  
   293      log.info("Enter the 3rd cycle")
   294      economic.wait_settlement_blocknum(node)
   295      balance3 = node.eth.getBalance(staking_address)
   296      log.info("The balance after launching the revocation in the third cycle{}".format(balance3))
   297  
   298      log.info("Enter the 4th cycle")
   299      economic.wait_settlement_blocknum(node, 1)
   300      balance4 = node.eth.getBalance(staking_address)
   301      log.info("The balance after the revocation of the second cycle {}".format(balance4))
   302  
   303      locked_info = client.ppos.getRestrictingInfo(staking_address)
   304      log.info(locked_info)
   305  
   306      msg = client.ppos.getCandidateInfo(node.node_id)
   307      log.info("Query the pledge of the node{}".format(msg))
   308      assert_code(msg, 301204)
   309  
   310      """Compute Block Reward + Pledge Reward"""
   311      log.info("The following is the number of blocks to get the node")
   312      block_number = get_block_count_number(node, economic.settlement_size * 3)
   313      sum_block_reward = calculate(block_reward, block_number)
   314      reward_sum = sum_block_reward + staking_reward
   315      log.info("Total amount of reward {}".format(reward_sum))
   316  
   317      assert client.amount + reward_sum - balance4 < Web3.toWei(1,
   318                                                                "ether"), "After the expected result unlock period, the money has been refunded + the block reward + pledge reward"
   319  
   320  
   321  @allure.title("Gas shortage")
   322  @pytest.mark.P1
   323  def test_RV_007(client_new_node):
   324      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   325                                                                     10 ** 18 * 10000000)
   326      result = client_new_node.staking.create_staking(0, address, address)
   327      assert_code(result, 0)
   328      cfg = {"gas": 1}
   329      status = 0
   330      try:
   331          result = client_new_node.staking.withdrew_staking(address, transaction_cfg=cfg)
   332          log.info(result)
   333      except BaseException:
   334          status = 1
   335      assert status == 1
   336  
   337  
   338  @allure.title("not sufficient funds")
   339  @pytest.mark.P1
   340  def test_RV_008(client_new_node):
   341      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   342                                                                     10 ** 18 * 10000000)
   343      result = client_new_node.staking.create_staking(0, address, address)
   344      assert_code(result, 0)
   345      value = 10 ** 18 * 10000000
   346      cfg = {"gasPrice": value}
   347      status = 0
   348      try:
   349          result = client_new_node.staking.withdrew_staking(address, transaction_cfg=cfg)
   350          log.info(result)
   351      except BaseException:
   352          status = 1
   353      assert status == 1
   354  
   355  
   356  @allure.title("Initiate cancellation of pledge (pledge money + additional amount)")
   357  @pytest.mark.P1
   358  def test_RV_009(staking_client):
   359      client = staking_client
   360      node = client.node
   361      staking_address = client.staking_address
   362      economic = client.economic
   363      value_before = client.amount
   364      log.info("Initiate the balance before the pledge {}".format(value_before))
   365  
   366      log.info("Enter the second billing cycle, increase the amount")
   367      economic.wait_settlement_blocknum(node)
   368      client.staking.increase_staking(0, staking_address)
   369      value2 = node.eth.getBalance(staking_address)
   370      log.info("Pledged + increased balance {}".format(value2))
   371      log.info("Enter the third billing cycle, the node initiates a return")
   372      economic.wait_settlement_blocknum(node)
   373      value3 = node.eth.getBalance(staking_address)
   374      log.info("Balance of the 3rd cycle {}".format(value3))
   375      client.staking.withdrew_staking(staking_address)
   376      log.info("Enter the 4th billing cycle")
   377      economic.wait_settlement_blocknum(node)
   378      value4 = node.eth.getBalance(staking_address)
   379      log.info("The balance of the 4th billing cycle (including the reward for the 3rd cycle){}".format(value4))
   380      log.info("Enter the 5th billing cycle")
   381      economic.wait_settlement_blocknum(node)
   382      value5 = node.eth.getBalance(staking_address)
   383      log.info("Return to the pledge + overweight balance after the unlock period:{}".format(value5))
   384      log.info(value5 - value_before)
   385      amount_sum = client.staking_amount + economic.add_staking_limit
   386      assert value5 > value_before, "Out of the block reward exception"
   387      assert value5 > amount_sum, "The balance of the unlocking period is greater than the balance of the lockout period + pledge + overweight, but an exception occurs."
   388  
   389  
   390  @allure.title("Become a consensus verifier and revoke the pledge")
   391  @pytest.mark.P2
   392  def test_RV_011(staking_client):
   393      """
   394      The consensus verifier revoks the pledge
   395      """
   396      client = staking_client
   397      node = client.node
   398      economic = client.economic
   399      staking_address = client.staking_address
   400      log.info("Enter the next cycle")
   401      economic.wait_settlement_blocknum(node)
   402      log.info("Enter the next consensus round")
   403      economic.wait_consensus_blocknum(node)
   404  
   405      validator_list = get_pledge_list(node.ppos.getValidatorList)
   406      log.info("Consensus certifier list:{}".format(validator_list))
   407      assert node.node_id in validator_list
   408      msg = client.staking.withdrew_staking(staking_address)
   409      assert_code(msg, 0)
   410  
   411  
   412  @allure.title("Become a candidate and withdraw from pledge")
   413  @pytest.mark.P2
   414  def test_RV_012(global_test_env, clients_noconsensus):
   415      """
   416      Candidate cancels pledge
   417      """
   418      global_test_env.deploy_all()
   419      address1, _ = clients_noconsensus[0].economic.account.generate_account(clients_noconsensus[0].node.web3,
   420                                                                             10 ** 18 * 10000000)
   421      address2, _ = clients_noconsensus[0].economic.account.generate_account(clients_noconsensus[0].node.web3,
   422                                                                             10 ** 18 * 10000000)
   423  
   424      result = clients_noconsensus[0].staking.create_staking(0, address1, address1,
   425                                                             amount=clients_noconsensus[
   426                                                                        0].economic.create_staking_limit * 2)
   427      assert_code(result, 0)
   428  
   429      result = clients_noconsensus[1].staking.create_staking(0, address2, address2,
   430                                                             amount=clients_noconsensus[1].economic.create_staking_limit)
   431      assert_code(result, 0)
   432  
   433      log.info("Next settlement period")
   434      clients_noconsensus[1].economic.wait_settlement_blocknum(clients_noconsensus[1].node)
   435      msg = clients_noconsensus[1].ppos.getVerifierList()
   436      log.info(msg)
   437      verifierlist = get_pledge_list(clients_noconsensus[1].ppos.getVerifierList)
   438      log.info("verifierlist:{}".format(verifierlist))
   439      assert clients_noconsensus[1].node.node_id not in verifierlist
   440      msg = clients_noconsensus[1].staking.withdrew_staking(address2)
   441      assert_code(msg, 0)
   442  
   443  
   444  @allure.title("Become the verifier and quit the pledge")
   445  @pytest.mark.P2
   446  def test_RV_013(staking_client):
   447      """
   448      The verifier revoks the pledge
   449      """
   450      client = staking_client
   451      staking_address = client.staking_address
   452      node = client.node
   453      economic = client.economic
   454      log.info("Enter the next cycle")
   455      economic.wait_settlement_blocknum(node, 1)
   456      verifier_list = get_pledge_list(node.ppos.getVerifierList)
   457      log.info(log.info("Current billing cycle certifier {}".format(verifier_list)))
   458      assert node.node_id in verifier_list
   459      msg = client.staking.withdrew_staking(staking_address)
   460      assert_code(msg, 0)
   461  
   462  
   463  @allure.title("After exiting the verifier, return the pledge money + block award + pledge award")
   464  @pytest.mark.P1
   465  @pytest.mark.compatibility
   466  def test_RV_014_015(staking_client):
   467      """
   468      After becoming a verifier, there are pledge rewards and block rewards.
   469      """
   470      client = staking_client
   471      staking_address = client.staking_address
   472      node = client.node
   473      economic = client.economic
   474      economic.wait_settlement_blocknum(node)
   475      log.info("Enter the next cycle")
   476      block_reward, staking_reward = economic.get_current_year_reward(node)
   477      msg = client.staking.withdrew_staking(staking_address)
   478      log.info(msg)
   479      balance_1 = node.eth.getBalance(staking_address)
   480      log.info(balance_1)
   481      log.info("Enter the next cycle")
   482      economic.wait_settlement_blocknum(node, 2)
   483      balance_2 = node.eth.getBalance(staking_address)
   484      log.info(balance_2)
   485      verifier_list = get_pledge_list(node.ppos.getVerifierList)
   486      log.info("Current certifier list:{}".format(verifier_list))
   487      validator_list = get_pledge_list(node.ppos.getValidatorList)
   488      log.info("Current consensus certifier list:{}".format(validator_list))
   489      block_number = get_block_count_number(node, economic.settlement_size * 3)
   490      sum_block_reward = calculate(block_reward, block_number)
   491      reward_sum = sum_block_reward + staking_reward
   492      log.info("Total amount of reward {}".format(reward_sum))
   493      assert balance_1 + reward_sum + client.staking_amount == balance_2, "The bonus amount is abnormal"
   494  
   495  
   496  @allure.title("Cancel nonexistent candidates")
   497  @pytest.mark.P2
   498  def test_RV_016(staking_client):
   499      _, node_id = generate_key()
   500      msg = staking_client.staking.withdrew_staking(staking_client.staking_address, node_id=node_id)
   501      log.info(msg)
   502      assert_code(msg, 301102)
   503  
   504  
   505  @allure.title("Undo a candidate whose status is invalid")
   506  @pytest.mark.P2
   507  def test_RV_017(staking_client):
   508      client = staking_client
   509      node = client.node
   510      staking_address = client.staking_address
   511      msg = client.staking.withdrew_staking(staking_address)
   512      assert_code(msg, 0)
   513      msg = node.ppos.getCandidateInfo(node.node_id)
   514      assert msg[
   515                 "Ret"] == "Query candidate info failed:Candidate info is not found", "Expected pledge to be successful; pledge information is deleted"
   516      msg = client.staking.withdrew_staking(staking_address)
   517      assert_code(msg, 301102)
   518  
   519  
   520  @allure.title("Invalid nodeId")
   521  @pytest.mark.P2
   522  def test_RV_018(client_new_node):
   523      illegal_nodeID = "7ee3276fd6b9c7864eb896310b5393324b6db785a2528c00cc28ca8c" \
   524                       "3f86fc229a86f138b1f1c8e3a942204c03faeb40e3b22ab11b8983c35dc025de42865990"
   525  
   526      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   527                                                                     10 ** 18 * 10000000)
   528      result = client_new_node.staking.create_staking(0, address, address)
   529      assert_code(result, 0)
   530      msg = client_new_node.staking.withdrew_staking(address, node_id=illegal_nodeID)
   531      assert_code(msg, 301102)
   532  
   533  
   534  @allure.title("Modify the node income address and return: verify the pledge reward + block reward")
   535  @pytest.mark.P0
   536  def test_RV_019(staking_client):
   537      """
   538      Modify the wallet address, the change of address income normal
   539      """
   540      client = staking_client
   541      node = client.node
   542      staking_address = client.staking_address
   543      economic = client.economic
   544      ben_address, _ = economic.account.generate_account(node.web3)
   545      log.info("ben address balance:{}".format(node.eth.getBalance(ben_address)))
   546      log.info("Modify node information")
   547      msg = client.staking.edit_candidate(staking_address, ben_address)
   548      assert_code(msg, 0)
   549  
   550      log.info("Enter the second billing cycle")
   551      economic.wait_settlement_blocknum(node)
   552  
   553      block_reward, staking_reward = economic.get_current_year_reward(node)
   554      msg = client.staking.withdrew_staking(staking_address)
   555      assert_code(msg, 0)
   556      balance_before = node.eth.getBalance(ben_address)
   557      log.info("Exit the new wallet balance after pledge:{}".format(balance_before))
   558      log.info("Enter the third billing cycle")
   559      economic.wait_settlement_blocknum(node, 2)
   560  
   561      balance_after = node.eth.getBalance(ben_address)
   562      log.info("Balance after the new wallet unlock period {}".format(balance_after))
   563  
   564      """Compute Block Reward + Pledge Reward"""
   565      log.info("The following is the number of blocks to get the node")
   566      block_number = get_block_count_number(node, economic.settlement_size * 3)
   567      sum_block_reward = calculate(block_reward, block_number)
   568      reward_sum = sum_block_reward + staking_reward
   569      log.info("Total amount of reward {}".format(reward_sum))
   570      assert balance_after == reward_sum, "Expected new wallet balance == earnings reward"
   571  
   572  
   573  @allure.title("Modify pledge information in exit")
   574  @pytest.mark.P2
   575  def test__RV_020(staking_client):
   576      """
   577      Modify the pledge information in the exit
   578      """
   579      node_name = "Node"
   580      client = staking_client
   581      staking_address = client.staking_address
   582      node = client.node
   583      economic = client.economic
   584      economic.wait_settlement_blocknum(node)
   585      msg = client.staking.withdrew_staking(staking_address)
   586      log.info(msg)
   587      msg = node.ppos.getCandidateInfo(node.node_id)
   588      log.info(msg)
   589      log.info("Modify node information")
   590      client.staking.cfg.node_name = node_name
   591      msg = client.staking.edit_candidate(staking_address, staking_address)
   592      assert_code(msg, 301103)
   593  
   594  
   595  @allure.title("The modified pledge information has been withdrawn")
   596  @pytest.mark.P2
   597  def test_RV_021(staking_client):
   598      """
   599      Revoked modify pledge information
   600      """
   601      node_name = "Node"
   602      client = staking_client
   603      staking_address = client.staking_address
   604      node = client.node
   605      economic = client.economic
   606      economic.wait_settlement_blocknum(node)
   607      msg = client.staking.withdrew_staking(staking_address)
   608      log.info(msg)
   609      msg = node.ppos.getCandidateInfo(node.node_id)
   610      log.info(msg)
   611      economic.wait_settlement_blocknum(node, 2)
   612      log.info("Modify node information")
   613      client.staking.cfg.node_name = node_name
   614      msg = client.staking.edit_candidate(staking_address, staking_address)
   615      assert_code(msg, 301102)
   616  
   617  
   618  @pytest.mark.P2
   619  def test_RV_022(client_new_node):
   620      """
   621      Non-pledged wallets are pledged back
   622      """
   623      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   624                                                                     10 ** 18 * 10000000)
   625      address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   626                                                                      10 ** 18 * 10000000)
   627      result = client_new_node.staking.create_staking(0, address, address)
   628      assert_code(result, 0)
   629      log.info("Node exit pledge")
   630      result = client_new_node.staking.withdrew_staking(address1)
   631      assert_code(result, 301006)
   632  
   633  
   634  @allure.title("After the maximum penalty, the amount returned & re-pledge, entrustment and redemption")
   635  @pytest.mark.P1
   636  def test_RV_023(staking_client, global_test_env):
   637      """
   638      Return amount after the highest penalty
   639      """
   640      other_node = global_test_env.get_rand_node()
   641      client = staking_client
   642      staking_address = client.staking_address
   643      node = client.node
   644      economic = client.economic
   645      balance = node.eth.getBalance(staking_address)
   646      log.info(balance)
   647      candidate_info = client.ppos.getCandidateInfo(node.node_id)
   648      log.info(candidate_info)
   649      log.info("Stop the new verifier node")
   650      node.stop()
   651      log.info("Go to the next billing cycle")
   652      economic.wait_consensus_blocknum(other_node, 3)
   653      msg = get_pledge_list(other_node.ppos.getCandidateList)
   654      log.info("Real-time certifier list {}".format(msg))
   655      verifier_list = get_pledge_list(other_node.ppos.getVerifierList)
   656      log.info("Current billing cycle certifier {}".format(verifier_list))
   657      assert node.node_id not in verifier_list, "Expected to opt out of certifier list"
   658      balance_before = other_node.eth.getBalance(staking_address)
   659      log.info("Query the account balance after being punished: {}".format(balance_before))
   660      log.info("Go to the next billing cycle")
   661      candidate_info = other_node.ppos.getCandidateInfo(node.node_id)
   662      log.info(candidate_info)
   663      economic.wait_settlement_blocknum(other_node,number=2)
   664      balance_after = other_node.eth.getBalance(staking_address)
   665      log.info("The balance after the penalty is refunded to the account:{}".format(balance_after))
   666      assert balance_before + candidate_info["Ret"][
   667          "Released"] == balance_after, "After being sent out and removed from the certifier, the amount is refunded abnormally"
   668      msg = other_node.ppos.getCandidateInfo(node.node_id)
   669      log.info(msg)
   670      node.start()
   671      time.sleep(10)
   672      staking_result = client.staking.create_staking(0, staking_address, staking_address)
   673      assert_code(staking_result, 0)
   674      candidate_info = node.ppos.getCandidateInfo(node.node_id)
   675      log.info(candidate_info)
   676      staking_blocknum = candidate_info["Ret"]["StakingBlockNum"]
   677      log.info("Delegation")
   678      msg = client.delegate.delegate(0, client.delegate_address, node.node_id)
   679      assert_code(msg, 0)
   680      msg = client.delegate.withdrew_delegate(staking_blocknum, client.delegate_address, node.node_id)
   681      assert_code(msg, 0)
   682  
   683  
   684  @allure.title("The lockup period after withdrawal of pledge cannot be added or entrusted")
   685  @pytest.mark.P1
   686  def test_RV_024(staking_client):
   687      """
   688      Can not increase and entrust after exiting pledge
   689      """
   690      client = staking_client
   691      node = client.node
   692      staking_address = client.staking_address
   693      economic = client.economic
   694      log.info("Entering the lockout period")
   695      economic.wait_settlement_blocknum(node)
   696      log.info("Node exit pledge")
   697      client.staking.withdrew_staking(staking_address)
   698      log.info("Node to increase holding")
   699      msg = client.staking.increase_staking(0, staking_address, amount=economic.add_staking_limit)
   700      assert_code(msg, 301103)
   701      log.info("Node to commission")
   702      msg = client.delegate.delegate(0, client.delegate_address)
   703      assert_code(msg, 301103)