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

     1  # -*- coding: utf-8 -*-
     2  '''
     3  @Description: rpc用例
     4  '''
     5  import json
     6  
     7  import allure
     8  import pytest
     9  import rlp
    10  from client_sdk_python import Web3
    11  from client_sdk_python.eth import Eth
    12  
    13  
    14  @allure.title("Check if the version of the protocol is 63")
    15  @pytest.mark.P1
    16  def test_platon_protocolVersion(global_running_env):
    17      node = global_running_env.get_rand_node()
    18      assert node.eth.protocolVersion == '63'
    19  
    20  
    21  @allure.title("Get the amount of the account")
    22  @pytest.mark.P1
    23  def test_platon_GetBalance(global_running_env):
    24      node = global_running_env.get_rand_node()
    25      platon = Eth(node.web3)
    26      account = global_running_env.account
    27      addr = account.account_with_money["address"]
    28      from_addr = Web3.toChecksumAddress(addr)
    29      # balance = platon.getBalance(from_addr)
    30      balance = platon.getBalance("0x1111111111111111111111111111111111111111")
    31      assert balance == 0
    32  
    33  
    34  def platon_call(platon, from_addr, to_addr="0x1000000000000000000000000000000000000002", data=""):
    35      recive = platon.call({
    36          "from": from_addr,
    37          "to": to_addr,
    38          "data": data
    39      })
    40      recive = str(recive, encoding="utf8")
    41      recive = recive.replace('\\', '').replace('"[', '[').replace(']"', ']')
    42      recive = json.loads(recive)
    43      return recive
    44  
    45  
    46  @allure.title("Call the built-in contract interface with platon.call")
    47  @pytest.mark.P1
    48  def test_platon_call(global_running_env):
    49      node = global_running_env.get_rand_node()
    50      platon = Eth(node.web3)
    51      account = global_running_env.account
    52      addr = account.account_with_money["address"]
    53      from_addr = Web3.toChecksumAddress(addr)
    54  
    55      to_addr = Web3.toChecksumAddress("0x1000000000000000000000000000000000000002")
    56      data = rlp.encode([rlp.encode(int(1100))])
    57      recive = platon_call(platon, from_addr, to_addr, data)
    58      assert recive != "0x"
    59      # not exist interface on staking contract
    60      data = rlp.encode([rlp.encode(int(2222))])
    61  
    62      status = 0
    63      try:
    64          recive = platon_call(platon, from_addr, to_addr, data)
    65          assert recive == "0x"
    66          status = 1
    67      except Exception as e:
    68          print("\nQuery the built-in contract interface that does not exist and return an exception.:{}".format(e))
    69      assert status == 0
    70  
    71  
    72  @allure.title("Get node double-sign evidence")
    73  @pytest.mark.P1
    74  def test_platon_evidences(global_running_env):
    75      node = global_running_env.get_rand_node()
    76      platon = Eth(node.web3)
    77      ret = platon.evidences
    78      assert ret is not None
    79  
    80  
    81  @allure.title("Get the aggregate signature of any block")
    82  @pytest.mark.P1
    83  @pytest.mark.compatibility
    84  def test_platon_getPrepareQC(global_running_env):
    85      node = global_running_env.get_rand_node()
    86      platon = Eth(node.web3)
    87      blockNumber = platon.blockNumber
    88      qc = platon.getPrepareQC(blockNumber)
    89      assert qc is not None
    90  
    91  
    92  if __name__ == '__main__':
    93      pytest.main(['-v', 'test_rpc_platon.py'])