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

     1  # -*- coding: utf-8 -*-
     2  from tests.lib.utils import *
     3  import pytest
     4  from tests.lib.config import EconomicConfig
     5  import allure
     6  
     7  
     8  @allure.title("Verify the validity of human parameters")
     9  @pytest.mark.P1
    10  def test_IV_001_002_010(global_test_env, client_consensus):
    11      """
    12      001:Verify the validity of human parameters
    13      002:The built-in account is found with the verifier list query
    14      010:The initial number of nodes is consistent with the number of verifier consensus nodes set
    15      """
    16      global_test_env.deploy_all()
    17      node_info = client_consensus.ppos.getValidatorList()
    18      log.info(node_info)
    19      nodeid_list = []
    20      for node in node_info.get("Ret"):
    21          nodeid_list.append(node.get("NodeId"))
    22          StakingAddress = node.get("StakingAddress")
    23          log.info(StakingAddress)
    24          assert client_consensus.node.web3.toChecksumAddress(StakingAddress) == \
    25              client_consensus.economic.cfg.DEVELOPER_FOUNDATAION_ADDRESS
    26      log.info(nodeid_list)
    27      consensus_node_list = global_test_env.consensus_node_list
    28      nodeid_list_ = [node.node_id for node in consensus_node_list]
    29      log.info(nodeid_list_)
    30      assert len(nodeid_list_) == len(consensus_node_list)
    31      for nodeid in nodeid_list_:
    32          assert nodeid in nodeid_list
    33  
    34  
    35  @allure.title("Verify the validity of human parameters")
    36  @pytest.mark.P1
    37  def test_IV_003(client_consensus):
    38      StakingAddress = EconomicConfig.DEVELOPER_FOUNDATAION_ADDRESS
    39      result = client_consensus.staking.create_staking(0, StakingAddress, StakingAddress)
    40      log.info("Staking result:{}".format(result))
    41      assert_code(result, 301101)
    42  
    43  
    44  @allure.title("The initial verifier accepts the delegate")
    45  @pytest.mark.P1
    46  def test_IV_004(client_consensus):
    47      address, _ = client_consensus.economic.account.generate_account(client_consensus.node.web3,
    48                                                                      10 ** 18 * 10000000)
    49      result = client_consensus.delegate.delegate(0, address)
    50      log.info(result)
    51      assert_code(result, 301107)
    52  
    53  
    54  @allure.title("The initial verifier holds an additional pledge")
    55  @pytest.mark.P1
    56  def test_IV_005(client_consensus):
    57      StakingAddress = EconomicConfig.DEVELOPER_FOUNDATAION_ADDRESS
    58      result = client_consensus.staking.increase_staking(0, StakingAddress)
    59      assert_code(result, 0)
    60  
    61  
    62  @allure.title("Initial verifier exits")
    63  @pytest.mark.P1
    64  def test_IV_006_007_008(client_consensus):
    65      """
    66      006:Initial verifier exits
    67      007:The original verifier exits and re-pledges the pledge
    68      008:After the initial verifier quits, re-pledge and accept the entrustment
    69      """
    70      StakingAddress = client_consensus.economic.cfg.DEVELOPER_FOUNDATAION_ADDRESS
    71      result = client_consensus.staking.withdrew_staking(StakingAddress)
    72      log.info(result)
    73      result = client_consensus.ppos.getCandidateInfo(client_consensus.node.node_id)
    74      log.info(result)
    75      log.info("Let's go to the next three cycles")
    76      client_consensus.economic.wait_settlement_blocknum(client_consensus.node, number=2)
    77      msg = client_consensus.ppos.getCandidateInfo(client_consensus.node.node_id)
    78      log.info(msg)
    79      assert msg["Code"] == 301204, "预期验证人已退出"
    80      result = client_consensus.staking.create_staking(0, StakingAddress, StakingAddress)
    81      assert_code(result, 0)
    82      address, _ = client_consensus.economic.account.generate_account(client_consensus.node.web3,
    83                                                                      10 ** 18 * 10000000)
    84      result = client_consensus.delegate.delegate(0, address)
    85      log.info(result)
    86      assert_code(result, 0)
    87  
    88  
    89  @allure.title("Modify the initial verifier information")
    90  @pytest.mark.P3
    91  def test_IV_009(client_consensus):
    92      address1, _ = client_consensus.economic.account.generate_account(client_consensus.node.web3,
    93                                                                       10 ** 18 * 10000000)
    94      StakingAddress = client_consensus.economic.cfg.DEVELOPER_FOUNDATAION_ADDRESS
    95      result = client_consensus.staking.edit_candidate(StakingAddress, address1)
    96      log.info(result)
    97      assert_code(result, 0)
    98  
    99  
   100  @allure.title("Normal pledge、Repeat pledge")
   101  @pytest.mark.P1
   102  @pytest.mark.compatibility
   103  def test_IV_014_015_019_024(client_new_node):
   104      """
   105      014:Normal pledge
   106      015:Repeat pledg
   107      019:The amount pledged by free account reaches the threshold of pledge
   108      024:Use the correct version signature
   109      """
   110      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   111                                                                     10 ** 18 * 10000000)
   112      log.info("Generate address:{}".format(address))
   113      result = client_new_node.staking.create_staking(0, address, address)
   114      log.info(result)
   115      assert_code(result, 0)
   116      result = client_new_node.staking.create_staking(0, address, address)
   117      log.info(result)
   118      assert_code(result, 301101)
   119  
   120  
   121  @allure.title("Node ID pledge not added to the chain")
   122  @pytest.mark.P3
   123  def test_IV_016(client_new_node):
   124      """
   125      :param client_new_node_obj:
   126      :return:
   127      """
   128      illegal_nodeID = "7ee3276fd6b9c7864eb896310b5393324b6db785a2528c00cc28ca8c" \
   129                       "3f86fc229a86f138b1f1c8e3a942204c03faeb40e3b22ab11b8983c35dc025de42865990"
   130      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   131                                                                     10 ** 18 * 10000000)
   132      result = client_new_node.staking.create_staking(0, address, address, node_id=illegal_nodeID)
   133      log.info(result)
   134      assert_code(result, 301003)
   135  
   136  
   137  @allure.title("The beneficiary address is the excitation pool address")
   138  @pytest.mark.P3
   139  def test_IV_017(client_new_node):
   140      """
   141      :param client_new_node_obj:
   142      :return:
   143      """
   144      INCENTPEPOOL_ADDRESS = EconomicConfig.INCENTIVEPOOL_ADDRESS
   145      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   146                                                                     10 ** 18 * 10000000)
   147      result = client_new_node.staking.create_staking(0, INCENTPEPOOL_ADDRESS, address)
   148      assert_code(result, 0)
   149  
   150  
   151  @allure.title("Beneficiary address is the foundation address")
   152  @pytest.mark.P3
   153  def test_IV_018(client_new_node):
   154      """
   155      :param client_new_node_obj:
   156      :param get_generate_account:
   157      :return:
   158      """
   159      FOUNDATION_ADDRESS = client_new_node.economic.cfg.FOUNDATION_ADDRESS
   160      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   161                                                                     10 ** 18 * 10000000)
   162      result = client_new_node.staking.create_staking(0, FOUNDATION_ADDRESS, address)
   163      assert_code(result, 0)
   164  
   165  
   166  @allure.title("The amount pledged by free account is less than the threshold of pledge, and gas is insufficient")
   167  @pytest.mark.P2
   168  def test_IV_020_21(client_new_node):
   169      """
   170      020:The amount pledged by free account is less than the threshold of pledge
   171      021:gas is insufficient
   172      """
   173      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   174                                                                     10 ** 18 * 10000000)
   175      amount = client_new_node.economic.create_staking_limit
   176      result = client_new_node.staking.create_staking(0, address, address, amount=amount - 1)
   177      log.info(result)
   178      assert_code(result, 301100)
   179      cfg = {"gas": 1}
   180      status = 0
   181      try:
   182          result = client_new_node.staking.create_staking(0, address, address, transaction_cfg=cfg)
   183          log.info(result)
   184      except BaseException:
   185          status = 1
   186      assert status == 1
   187  
   188  
   189  @allure.title("Incorrect version signature used")
   190  @pytest.mark.P3
   191  def test_IV_025(client_new_node, client_consensus):
   192      """
   193      :param client_new_node_obj:
   194      :param client_consensus_obj:
   195      :return:
   196      """
   197      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   198                                                                     10 ** 18 * 10000000)
   199      program_version_sign = client_consensus.node.program_version_sign
   200      result = client_new_node.staking.create_staking(0, address, address, program_version_sign=program_version_sign)
   201      log.info(result)
   202      assert_code(result, 301003)
   203  
   204  
   205  @allure.title("BlsPublicKey is too long")
   206  @pytest.mark.P2
   207  def test_IV_026_01(client_new_node):
   208      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   209                                                                     10 ** 18 * 10000000)
   210      blspubkey = client_new_node.node.blspubkey + "00000000"
   211      log.info(blspubkey)
   212      status = 0
   213      try:
   214          result = client_new_node.staking.create_staking(0, address, address, bls_pubkey=blspubkey)
   215          log.info(result)
   216      except BaseException:
   217          status = 1
   218      assert status == 1
   219  
   220  
   221  @allure.title("BlsPublicKey is too short")
   222  @pytest.mark.P2
   223  def test_IV_026_02(client_new_node):
   224      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   225                                                                     10 ** 18 * 10000000)
   226      blspubkey = client_new_node.node.blspubkey[0:10]
   227      log.info(blspubkey)
   228      status = 0
   229      try:
   230          result = client_new_node.staking.create_staking(0, address, address, bls_pubkey=blspubkey)
   231          log.info(result)
   232      except BaseException:
   233          status = 1
   234      assert status == 1
   235  
   236  
   237  @allure.title("Incorrect version signature used")
   238  @pytest.mark.P2
   239  def test_IV_026_03(client_new_node):
   240      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   241                                                                     10 ** 18 * 10000000)
   242      program_version = 0000
   243      result = client_new_node.staking.create_staking(0, address, address, program_version=program_version)
   244      assert_code(result, 301003)
   245  
   246  
   247  @allure.title("Field length overflow")
   248  @pytest.mark.P2
   249  def test_IV_027(client_new_node):
   250      external_id = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111"
   251      node_name = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
   252      website = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 "
   253      details = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 "
   254      program_version = client_new_node.node.program_version
   255      program_version_sign = client_new_node.node.program_version_sign
   256      bls_pubkey = client_new_node.node.blspubkey
   257      bls_proof = client_new_node.node.schnorr_NIZK_prove
   258      amount = client_new_node.economic.create_staking_limit
   259      address, pri_key = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   260                                                                           10 ** 18 * 10000000)
   261  
   262      result = client_new_node.ppos.createStaking(0, address, client_new_node.node.node_id,
   263                                                  external_id, node_name, website, details, amount,
   264                                                  program_version, program_version_sign, bls_pubkey, bls_proof,
   265                                                  pri_key)
   266      assert_code(result, 301002)
   267  
   268  
   269  @allure.title("Pledge has been made before and the candidate has been invalidated (penalized)")
   270  @pytest.mark.P2
   271  def test_IV_028(clients_new_node, client_consensus):
   272      client = clients_new_node[0]
   273      node = client.node
   274      other_node = client_consensus.node
   275      economic = client.economic
   276      address, pri_key = economic.account.generate_account(node.web3, 10 ** 18 * 10000000)
   277  
   278      value = economic.create_staking_limit * 2
   279      result = client.staking.create_staking(0, address, address, amount=value)
   280      assert_code(result, 0)
   281      economic.wait_consensus_blocknum(other_node, number=4)
   282      validator_list = get_pledge_list(other_node.ppos.getValidatorList)
   283      assert node.node_id in validator_list
   284      log.info("Close one node")
   285      node.stop()
   286      for i in range(4):
   287          economic.wait_consensus_blocknum(other_node, number=i)
   288          candidate_info = other_node.ppos.getCandidateInfo(node.node_id)
   289          log.info(candidate_info)
   290          if candidate_info["Ret"]["Released"] < value:
   291              break
   292      log.info("Restart the node")
   293      node.start()
   294      result = client.staking.edit_candidate(address, address)
   295      log.info(result)
   296      assert_code(result, 301103)
   297      log.info("Next settlement period")
   298      economic.wait_settlement_blocknum(node, number=2)
   299      result = client.staking.create_staking(0, address, address)
   300      assert_code(result, 0)
   301  
   302  
   303  @allure.title("Pledge has been made before, and the candidate is invalid (voluntarily withdraw)")
   304  @pytest.mark.P1
   305  def test_IV_029(client_new_node):
   306      """
   307      :param client_new_node_obj:
   308      :param get_generate_account:
   309      :return:
   310      """
   311      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   312                                                                     10 ** 18 * 10000000)
   313      result = client_new_node.staking.create_staking(0, address, address)
   314      assert_code(result, 0)
   315      result = client_new_node.staking.withdrew_staking(address)
   316      log.info(result)
   317      assert_code(result, 0)
   318      result = client_new_node.staking.create_staking(0, address, address)
   319      assert_code(result, 0)
   320  
   321  
   322  @allure.title("Lockup pledge")
   323  @pytest.mark.P1
   324  def test_IV_030(client_new_node):
   325      """
   326      :param client_new_node_obj:
   327      :param get_generate_account:
   328      :return:
   329      """
   330      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   331                                                                     10 ** 18 * 10000000)
   332      result = client_new_node.staking.create_staking(0, address, address)
   333      assert_code(result, 0)
   334      log.info("Into the next grandchild")
   335      client_new_node.economic.wait_settlement_blocknum(client_new_node.node)
   336      result = client_new_node.staking.withdrew_staking(address)
   337      assert_code(result, 0)
   338      result = client_new_node.staking.create_staking(0, address, address)
   339      log.info(result)
   340      assert_code(result, 301101)
   341  
   342  
   343  @allure.title("Use a new wallet as pledge")
   344  @pytest.mark.P2
   345  def test_IV_031(client_new_node):
   346      """
   347      :param client_new_node_obj:
   348      :param get_generate_account:
   349      :return:
   350      """
   351      address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   352                                                                     10 ** 18 * 10000000)
   353      result = client_new_node.staking.create_staking(0, address, address)
   354      assert_code(result, 0)
   355  
   356      address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3,
   357                                                                      10 ** 18 * 10000000)
   358      result = client_new_node.staking.create_staking(0, address1, address1)
   359      log.info(result)
   360      assert_code(result, 301101)