github.com/turingchain2020/turingchain@v1.1.21/build/system-test-rpc.sh (about)

     1  #!/usr/bin/env bash
     2  # shellcheck disable=SC2128
     3  
     4  MAIN_HTTP=""
     5  IS_PARA=false
     6  CASE_ERR=""
     7  
     8  #color
     9  RED='\033[1;31m'
    10  GRE='\033[1;32m'
    11  NOC='\033[0m'
    12  
    13  # $2=0 means true, other false
    14  echo_rst() {
    15      if [ "$2" -eq 0 ]; then
    16          echo -e "${GRE}$1 ok${NOC}"
    17      elif [ "$2" -eq 2 ]; then
    18          echo -e "${GRE}$1 not support${NOC}"
    19      else
    20          echo -e "${RED}$1 fail${NOC}"
    21          echo -e "${RED}$3 ${NOC}"
    22          CASE_ERR="err"
    23      fi
    24  }
    25  
    26  http_req() {
    27      #  echo "#$4 request: $1"
    28      body=$(curl -ksd "$1" "$2")
    29      #  echo "#response: $body"
    30      ok=$(echo "$body" | jq -r "$3")
    31      [ "$ok" == true ]
    32      rst=$?
    33      echo_rst "$4" "$rst" "$body"
    34  }
    35  
    36  turingchain_lock() {
    37      http_req '{"method":"Turingchain.Lock","params":[]}' ${MAIN_HTTP} ".result.isOK" "$FUNCNAME"
    38  }
    39  
    40  turingchain_unlock() {
    41      http_req '{"method":"Turingchain.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}' ${MAIN_HTTP} ".result.isOK" "$FUNCNAME"
    42  }
    43  
    44  turingchain_WalletTxList() {
    45      req='{"method":"Turingchain.WalletTxList", "params":[{"fromTx":"", "count":2, "direction":1}]}'
    46      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.txDetails|length == 2)' "$FUNCNAME"
    47  }
    48  
    49  turingchain_ImportPrivkey() {
    50      req='{"method":"Turingchain.ImportPrivkey", "params":[{"privkey":"0x88b2fb90411935872f0501dd13345aba19b5fac9b00eb0dddd7df977d4d5477e", "label":"testimportkey"}]}'
    51      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.label=="testimportkey") and (.result.acc.addr == "1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt")' "$FUNCNAME"
    52  }
    53  
    54  turingchain_DumpPrivkey() {
    55      req='{"method":"Turingchain.DumpPrivkey", "params":[{"data":"1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt"}]}'
    56      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.data=="0x88b2fb90411935872f0501dd13345aba19b5fac9b00eb0dddd7df977d4d5477e")' "$FUNCNAME"
    57  }
    58  
    59  turingchain_DumpPrivkeysFile() {
    60      req='{"method":"Turingchain.DumpPrivkeysFile", "params":[{"fileName":"PrivkeysFile","passwd":"123456"}]}'
    61      http_req "$req" ${MAIN_HTTP} '(.error|not) and .result.isOK' "$FUNCNAME"
    62  }
    63  
    64  turingchain_ImportPrivkeysFile() {
    65      req='{"method":"Turingchain.ImportPrivkeysFile", "params":[{"fileName":"PrivkeysFile","passwd":"123456"}]}'
    66      http_req "$req" ${MAIN_HTTP} '(.error|not) and .result.isOK' "$FUNCNAME"
    67      # rm -rf ./PrivkeysFile
    68  }
    69  
    70  turingchain_SendToAddress() {
    71      req='{"method":"Turingchain.SendToAddress", "params":[{"from":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv","to":"1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt", "amount":100000000, "note":"test\n"}]}'
    72      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.hash|length==66)' "$FUNCNAME"
    73  }
    74  
    75  turingchain_SetTxFee() {
    76      http_req '{"method":"Turingchain.SetTxFee", "params":[{"amount":100000}]}' ${MAIN_HTTP} '(.error|not) and .result.isOK' "$FUNCNAME"
    77  }
    78  
    79  turingchain_SetLabl() {
    80      req='{"method":"Turingchain.SetLabl", "params":[{"addr":"1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt", "label":"updatetestimport"}]}'
    81      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.label=="updatetestimport") and (.result.acc.addr == "1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt")' "$FUNCNAME"
    82  }
    83  
    84  turingchain_GetPeerInfo() {
    85      if [ "$IS_PARA" == true ]; then
    86          echo_rst "$FUNCNAME" 2
    87      else
    88          resok='(.error|not) and (.result.peers|length >= 1) and (.result.peers[0] | [has("addr", "port", "name", "mempoolSize", "self", "header"), true] | unique | length == 1)'
    89          http_req '{"method":"Turingchain.GetPeerInfo", "params":[{}]}' ${MAIN_HTTP} "$resok" "$FUNCNAME"
    90      fi
    91  }
    92  
    93  turingchain_GetHeaders() {
    94      resok='(.error|not) and (.result.items|length == 2) and (.result.items[0] | [has("version","parentHash", "txHash", "stateHash", "height", "blockTime", "txCount", "hash", "difficulty"),true] | unique | length == 1 )'
    95      http_req '{"method":"Turingchain.GetHeaders", "params":[{"start":1, "end":2, "isDetail":true}]}' ${MAIN_HTTP} "$resok" "$FUNCNAME"
    96  }
    97  
    98  turingchain_GetLastMemPool() {
    99      if [ "$IS_PARA" == true ]; then
   100          echo_rst "$FUNCNAME" 2
   101      else
   102          http_req '{"method":"Turingchain.GetLastMemPool", "params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result.txs|length >= 0)' "$FUNCNAME"
   103      fi
   104  }
   105  
   106  turingchain_GetProperFee() {
   107      http_req '{"method":"Turingchain.GetProperFee", "params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result.properFee > 10000)' "$FUNCNAME"
   108  }
   109  
   110  turingchain_GetBlockOverview() {
   111      hash=$(curl -ksd '{"method":"Turingchain.GetHeaders", "params":[{"start":1, "end":1, "isDetail":true}]}' ${MAIN_HTTP} | jq '.result.items[0].hash')
   112      req='{"method":"Turingchain.GetBlockOverview", "params":[{"hash":'"$hash"'}]}'
   113      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result| [has("head", "txCount", "txHashes"), true]|unique|length == 1) and (.result.txCount == (.result.txHashes|length))' "$FUNCNAME"
   114  }
   115  
   116  turingchain_GetAddrOverview() {
   117      req='{"method":"Turingchain.GetAddrOverview", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]}'
   118      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result|[has("reciver", "balance", "txCount"), true]|unique|length == 1)' "$FUNCNAME"
   119  }
   120  
   121  turingchain_SetPasswd() {
   122      http_req '{"method":"Turingchain.SetPasswd", "params":[{"oldPass":"1314fuzamei", "newPass":"1314fuzamei"}]}' ${MAIN_HTTP} '(.error|not) and .result.isOK' "$FUNCNAME"
   123  }
   124  
   125  turingchain_MergeBalance() {
   126      http_req '{"method":"Turingchain.MergeBalance", "params":[{"to":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]}' ${MAIN_HTTP} '(.error|not) and (.result.hashes|length > 0)' "$FUNCNAME"
   127  }
   128  
   129  turingchain_QueryTotalFee() {
   130      local height=1
   131      hash=$(curl -ksd '{"method":"Turingchain.GetBlockHash","params":[{"height":'$height'}]}' ${MAIN_HTTP} | jq -r ".result.hash")
   132      if [ -z "$hash" ]; then
   133          echo "hash is null"
   134          echo_rst "$FUNCNAME" 1
   135      fi
   136      prefixhash_base64=$(echo -n "TotalFeeKey:" | base64)
   137      blockhash_base64=$(echo -n "$hash" | cut -d " " -f 1 | xxd -r -p | base64)
   138      base64_hash="$prefixhash_base64$blockhash_base64"
   139  
   140      req='{"method":"Turingchain.QueryTotalFee","params":[{"keys":["'$base64_hash'"]}]}'
   141      http_req "$req" ${MAIN_HTTP} '(.result.txCount >= 0)' "$FUNCNAME"
   142  }
   143  
   144  turingchain_GetNetInfo() {
   145      if [ "$IS_PARA" == true ]; then
   146          echo_rst "$FUNCNAME" 2
   147      else
   148          http_req '{"method":"Turingchain.GetNetInfo", "params":[]}' ${MAIN_HTTP} '(.result.externalAddr| length > 0)' "$FUNCNAME"
   149      fi
   150  }
   151  
   152  turingchain_GetFatalFailure() {
   153      http_req '{"method":"Turingchain.GetFatalFailure", "params":[]}' ${MAIN_HTTP} '(.error|not) and (.result | 0)' "$FUNCNAME"
   154  }
   155  
   156  turingchain_DecodeRawTransaction() {
   157      tx="0a05636f696e73122c18010a281080c2d72f222131477444795771577233553637656a7663776d333867396e7a6e7a434b58434b7120a08d0630a696c0b3f78dd9ec083a2131477444795771577233553637656a7663776d333867396e7a6e7a434b58434b71"
   158      http_req '{"method":"Turingchain.DecodeRawTransaction", "params":[{"txHex":"'$tx'"}]}' ${MAIN_HTTP} '(.result.txs[0].execer == "coins")' "$FUNCNAME"
   159  }
   160  
   161  turingchain_GetTimeStatus() {
   162      r1=$(curl -ksd '{"method":"Turingchain.GetTimeStatus","params":[]}' ${MAIN_HTTP} | jq -r ".result.localTime")
   163      if [ -z "$r1" ]; then
   164          curl -ksd '{"method":"Turingchain.GetTimeStatus","params":[]}' ${MAIN_HTTP}
   165      fi
   166      [ -n "$r1" ]
   167      echo_rst "$FUNCNAME" "$?"
   168  }
   169  
   170  turingchain_GetLastBlockSequence() {
   171      if [ "$IS_PARA" == true ]; then
   172          echo_rst "$FUNCNAME" 2
   173      else
   174          http_req '{"method":"Turingchain.GetLastBlockSequence","params":[]}' ${MAIN_HTTP} ".result >= 0" "$FUNCNAME"
   175      fi
   176  }
   177  
   178  turingchain_GetBlockSequences() {
   179      if [ "$IS_PARA" == true ]; then
   180          echo_rst "$FUNCNAME" 2
   181      else
   182          http_req '{"method":"Turingchain.GetBlockSequences","params":[{"start":1,"end":3,"isDetail":true}]}' ${MAIN_HTTP} ".result.blkseqInfos|length==3" "$FUNCNAME"
   183      fi
   184  }
   185  
   186  turingchain_GetBlockByHashes() {
   187      if [ "$IS_PARA" == true ]; then
   188          geneis=$(curl -ksd '{"method":"Turingchain.GetBlockHash", "params":[{"height":0}]}' "${MAIN_HTTP}" | jq -r '(.result.hash)')
   189          req='{"method":"Turingchain.GetBlockByHashes","params":[{"hashes":["'"${geneis}"'"]}]}'
   190          http_req "$req" ${MAIN_HTTP} '(.result.items[0].block.parentHash == "0x0000000000000000000000000000000000000000000000000000000000000000")' "$FUNCNAME"
   191      else
   192          hash0=$(curl -ksd '{"method":"Turingchain.GetBlockSequences","params":[{"start":1,"end":3,"isDetail":true}]}' ${MAIN_HTTP} | jq -r ".result.blkseqInfos[0].hash")
   193          hash1=$(curl -ksd '{"method":"Turingchain.GetBlockSequences","params":[{"start":1,"end":3,"isDetail":true}]}' ${MAIN_HTTP} | jq -r ".result.blkseqInfos[1].hash")
   194          hash2=$(curl -ksd '{"method":"Turingchain.GetBlockSequences","params":[{"start":1,"end":3,"isDetail":true}]}' ${MAIN_HTTP} | jq -r ".result.blkseqInfos[2].hash")
   195  
   196          req='{"method":"Turingchain.GetBlockByHashes","params":[{"hashes":["'"$hash1"'","'"$hash2"'"]}]}'
   197          resok='(.result.items[0].block.parentHash == "'"$hash0"'") and (.result.items[1].block.parentHash =="'"$hash1"'")'
   198          http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   199      fi
   200  }
   201  
   202  turingchain_ConvertExectoAddr() {
   203      http_req '{"method":"Turingchain.ConvertExectoAddr","params":[{"execname":"coins"}]}' ${MAIN_HTTP} '(.result == "1GaHYpWmqAJsqRwrpoNcB8VvgKtSwjcHqt")' "$FUNCNAME"
   204  }
   205  
   206  turingchain_GetExecBalance() {
   207      local height=6802
   208      statehash=$(curl -ksd '{"method":"Turingchain.GetBlocks","params":[{"start":'$height',"end":'$height',"isDetail":false}]}' ${MAIN_HTTP} | jq -r ".result.items[0].block.stateHash")
   209      state_base64=$(echo -n "$statehash" | cut -d " " -f 1 | xxd -r -p | base64)
   210      addr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
   211      addr_base64=$(echo -n "$addr" | base64)
   212  
   213      req='{"method":"Turingchain.GetExecBalance","params":[{"symbol":"trc","stateHash":"'$state_base64'","addr":"'$addr_base64'","execer":"coins","count":100}]}'
   214      http_req "$req" ${MAIN_HTTP} "(.error|not)" "$FUNCNAME"
   215  }
   216  
   217  turingchain_AddPushSubscribe() {
   218      http_req '{"method":"Turingchain.AddPushSubscribe","params":[{"name":"test","url":"http://test","encode":"json"}]}' ${MAIN_HTTP} '(.result.isOk == true)' "$FUNCNAME"
   219  }
   220  
   221  turingchain_ListPushes() {
   222      http_req '{"method":"Turingchain.ListPushes","params":[]}' ${MAIN_HTTP} ' (.result.pushes[0].name == "test")' "$FUNCNAME"
   223  }
   224  
   225  turingchain_GetPushSeqLastNum() {
   226      http_req '{"method":"Turingchain.GetPushSeqLastNum","params":[{"data":"test-another"}]}' ${MAIN_HTTP} '(.result.data == -1)' "$FUNCNAME"
   227  }
   228  
   229  turingchain_GetCoinSymbol() {
   230      symbol="trc"
   231      if [ "$IS_PARA" == true ]; then
   232          symbol="para"
   233      fi
   234  
   235      resok='(.result.data == "'"$symbol"'")'
   236      http_req '{"method":"Turingchain.GetCoinSymbol","params":[]}' ${MAIN_HTTP} "$resok" "$FUNCNAME"
   237  }
   238  
   239  turingchain_GetHexTxByHash() {
   240      #先获取一笔交易
   241      reHash=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Turingchain.GetTxByAddr","params":[{"addr":"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt","flag":0,"count":1,"direction":0,"height":-1,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r '.result.txInfos[0].hash')
   242      #查询交易
   243      req='{"method":"Turingchain.GetHexTxByHash","params":[{"hash":"'"$reHash"'","upgrade":false}]}'
   244      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
   245  }
   246  
   247  turingchain_QueryTransaction() {
   248      #先获取一笔交易
   249      reHash=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Turingchain.GetTxByAddr","params":[{"addr":"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt","flag":0,"count":1,"direction":0,"height":-1,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r '.result.txInfos[0].hash')
   250      #查询交易
   251      req='{"method":"Turingchain.QueryTransaction","params":[{"hash":"'"$reHash"'","upgrade":false}]}'
   252      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.receipt.tyName == "ExecOk") and (.result.height >= 0) and (.result.index >= 0) and (.result.amount >= 0)' "$FUNCNAME"
   253  }
   254  
   255  turingchain_GetBlocks() {
   256      http_req '{"method":"Turingchain.GetBlocks","params":[{"start":1,"end":2}]}' ${MAIN_HTTP} '(.result.items[1].block.height == 2)' "$FUNCNAME"
   257  }
   258  
   259  turingchain_GetLastHeader() {
   260      resok='(.error|not) and (.result.height >= 0) and (.result | [has("version","parentHash", "txHash", "stateHash", "height", "blockTime", "txCount", "hash", "difficulty"),true] | unique | length == 1)'
   261      http_req '{"method":"Turingchain.GetLastHeader","params":[{}]}' ${MAIN_HTTP} "$resok" "$FUNCNAME"
   262  }
   263  
   264  turingchain_GetTxByAddr() {
   265      req='{"method":"Turingchain.GetTxByAddr","params":[{"addr":"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt","flag":0,"count":1,"direction":0,"height":-1,"index":0}]}'
   266      resok='(.error|not) and (.result.txInfos[0].index >= 0) and (.result.txInfos[0] | [has("hash", "height", "index", "assets"),true] | unique | length == 1)'
   267      http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   268  }
   269  
   270  turingchain_GetTxByHashes() {
   271      req='{"method":"Turingchain.GetTxByHashes","params":[{"hashes":["0x8040109d3859827d0f0c80ce91cc4ec80c496c45250f5e5755064b6da60842ab","0x501b910fd85d13d1ab7d776bce41a462f27c4bfeceb561dc47f0a11b10f452e4"]}]}'
   272      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.txs|length == 2)' "$FUNCNAME"
   273  }
   274  
   275  turingchain_GetMempool() {
   276      if [ "$IS_PARA" == true ]; then
   277          echo_rst "$FUNCNAME" 2
   278      else
   279          http_req '{"method":"Turingchain.GetMempool","params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result.txs|length >= 0)' "$FUNCNAME"
   280      fi
   281  }
   282  
   283  turingchain_GetAccountsV2() {
   284      http_req '{"method":"Turingchain.GetAccountsV2","params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result.wallets|length >= 0)' "$FUNCNAME"
   285  }
   286  
   287  turingchain_GetAccounts() {
   288      http_req '{"method":"Turingchain.GetAccounts","params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result.wallets|length >= 0)' "$FUNCNAME"
   289  }
   290  
   291  turingchain_NewAccount() {
   292      http_req '{"method":"Turingchain.NewAccount","params":[{"label":"test169"}]}' ${MAIN_HTTP} '(.error|not) and (.result.label == "test169") and (.result.acc | [has("addr"),true] | unique | length == 1)' "$FUNCNAME"
   293  }
   294  
   295  # hyb
   296  turingchain_CreateRawTransaction() {
   297      local to="1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t"
   298      local amount=10000000
   299      tx=$(curl -ksd '{"method":"Turingchain.CreateRawTransaction","params":[{"to":"'$to'","amount":'$amount'}]}' ${MAIN_HTTP} | jq -r ".result")
   300  
   301      req='{"method":"Turingchain.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
   302      resok='(.result.txs[0].payload.transfer.amount == "'$amount'") and (.result.txs[0].to == "'$to'")'
   303      http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   304  }
   305  
   306  turingchain_CreateTransaction() {
   307      local to="1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t"
   308      local amount=10000000
   309      local exec=""
   310  
   311      if [ "$IS_PARA" == true ]; then
   312          exec="user.p.para.coins"
   313      else
   314          exec="coins"
   315      fi
   316  
   317      tx=$(curl -ksd '{"method":"Turingchain.CreateTransaction","params":[{"execer":"'$exec'","actionName":"Transfer","payload":{"to":"'$to'", "amount":'$amount'}}]}' ${MAIN_HTTP} | jq -r ".result")
   318  
   319      req='{"method":"Turingchain.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
   320      resok='(.result.txs[0].payload.transfer.amount == "'$amount'") and (.result.txs[0].payload.transfer.to == "'$to'")'
   321      http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   322  }
   323  
   324  turingchain_ReWriteRawTx() {
   325      local fee=1000000
   326      local tx1="0a05636f696e73122d18010a291080ade20422223145444467684174674273616d724e45744e6d5964517a43315145684c6b7238377420a08d0630f6db93c0e0d3f1ff5e3a223145444467684174674273616d724e45744e6d5964517a43315145684c6b72383774"
   327      tx=$(curl -ksd '{"method":"Turingchain.ReWriteRawTx","params":[{"expire":"120s","fee":'$fee',"tx":"'$tx1'"}]}' ${MAIN_HTTP} | jq -r ".result")
   328  
   329      req='{"method":"Turingchain.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
   330      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.txs[0].execer == "coins") and (.result.txs[0].to == "1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t") and (.result.txs[0].fee == '$fee')' "$FUNCNAME"
   331  }
   332  
   333  turingchain_CreateRawTxGroup() {
   334      local to="1DNaSDRG9RD19s59meAoeN4a2F6RH97fSo"
   335      local exec="user.write"
   336      local groupCount=2
   337      tx1="0a0a757365722e7772697465121d236d642368616b6468676f7177656a6872676f716a676f6a71776c6a6720a08d0630a0b7b1b1dda2f4c5743a2231444e615344524739524431397335396d65416f654e34613246365248393766536f"
   338      tx2="0a0a757365722e7772697465121d236d642368616b6468676f7177656a6872676f716a676f6a71776c6a6720a08d0630c5838f94e2f49acb4b3a2231444e615344524739524431397335396d65416f654e34613246365248393766536f"
   339      tx=$(curl -ksd '{"method":"Turingchain.CreateRawTxGroup","params":[{"txs":["'$tx1'","'$tx2'"]}]}' ${MAIN_HTTP} | jq -r ".result")
   340  
   341      req='{"method":"Turingchain.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
   342      resok='(.error|not) and (.result.txs[0].execer == "'$exec'") and (.result.txs[0].to == "'$to'") and (.result.txs[0].groupCount == '$groupCount') and (.result.txs[1].execer == "'$exec'") and (.result.txs[1].to == "'$to'") and (.result.txs[1].groupCount == '$groupCount')'
   343      http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   344  }
   345  
   346  turingchain_SignRawTx() {
   347      local fee=1000000
   348      local privkey="CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
   349  
   350      tx1="0a05636f696e73122d18010a291080ade20422223145444467684174674273616d724e45744e6d5964517a43315145684c6b7238377420a08d0628e1ddcae60530f6db93c0e0d3f1ff5e3a223145444467684174674273616d724e45744e6d5964517a43315145684c6b72383774"
   351      tx=$(curl -ksd '{"method":"Turingchain.SignRawTx","params":[{"expire":"120s","fee":'$fee',"privkey":"'$privkey'","txHex":"'$tx1'"}]}' ${MAIN_HTTP} | jq -r ".result")
   352  
   353      req='{"method":"Turingchain.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
   354      resok='(.error|not) and (.result.txs[0].execer == "coins") and (.result.txs[0].to == "1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t") and (.result.txs[0].fee == '$fee') and (.result.txs[0].from == "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")'
   355      http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   356  }
   357  
   358  turingchain_SendTransaction() {
   359      local fee=1000000
   360      local exec="coins"
   361      local to="1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t"
   362      local privkey="CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
   363  
   364      tx1="0a05636f696e73122d18010a291080ade20422223145444467684174674273616d724e45744e6d5964517a43315145684c6b7238377420a08d0628e1ddcae60530f6db93c0e0d3f1ff5e3a223145444467684174674273616d724e45744e6d5964517a43315145684c6b72383774"
   365      tx=$(curl -ksd '{"method":"Turingchain.SignRawTx","params":[{"expire":"120s","fee":'$fee',"privkey":"'$privkey'","txHex":"'$tx1'"}]}' ${MAIN_HTTP} | jq -r ".result")
   366  
   367      req='{"method":"Turingchain.SendTransaction","params":[{"data":"'"$tx"'"}]}'
   368      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
   369  }
   370  
   371  turingchain_CreateNoBalanceTransaction() {
   372      local to="1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t"
   373      local txHex=""
   374      local exec=""
   375      local coinexec=""
   376  
   377      if [ "$IS_PARA" == true ]; then
   378          exec="user.p.para.none"
   379          coinexec="user.p.para.coins"
   380          txHex="0a11757365722e702e706172612e636f696e73122d18010a291080ade20422223145444467684174674273616d724e45744e6d5964517a43315145684c6b7238377420a08d0630e6cbfbf1a7bafcb8263a2231415662506538776f524a7a7072507a4575707735554262433259507331344a4354"
   381      else
   382          exec="none"
   383          coinexec="coins"
   384          txHex="0a05636f696e73122d18010a291080ade20422223145444467684174674273616d724e45744e6d5964517a43315145684c6b7238377420a08d0630a1938af2e88e97fb0d3a223145444467684174674273616d724e45744e6d5964517a43315145684c6b72383774"
   385      fi
   386  
   387      tx=$(curl -ksd '{"method":"Turingchain.CreateNoBalanceTransaction","params":[{"txHex":"'$txHex'"}]}' ${MAIN_HTTP} | jq -r ".result")
   388      req='{"method":"Turingchain.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
   389      resok='(.error|not) and (.result.txs[0].execer == "'$exec'") and (.result.txs[0].groupCount == 2) and (.result.txs[1].execer == "'$coinexec'") and (.result.txs[1].groupCount == 2) and (.result.txs[1].to == "'$to'")'
   390      http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
   391  }
   392  
   393  turingchain_GetBlockHash() {
   394      http_req '{"method":"Turingchain.GetBlockHash","params":[{"height":1}]}' ${MAIN_HTTP} '(.error|not) and (.result| has("hash"))' "$FUNCNAME"
   395  }
   396  
   397  turingchain_GenSeed() {
   398      http_req '{"method":"Turingchain.GenSeed", "params":[{"lang":0}]}' ${MAIN_HTTP} '(.error|not) and (.result| has("seed"))' "$FUNCNAME"
   399      seed=$(curl -ksd '{"method":"Turingchain.GenSeed", "params":[{"lang":0}]}' ${MAIN_HTTP} | jq -r ".result.seed")
   400  }
   401  
   402  turingchain_SaveSeed() {
   403      req='{"method":"Turingchain.SaveSeed", "params":[{"seed":"'"$seed"'", "passwd": "1314fuzamei"}]}'
   404      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result| has("isOK"))' "$FUNCNAME"
   405  }
   406  
   407  turingchain_GetSeed() {
   408      http_req '{"method":"Turingchain.GetSeed", "params":[{"passwd": "1314fuzamei"}]}' ${MAIN_HTTP} '(.error|not) and (.result| has("seed"))' "$FUNCNAME"
   409  }
   410  
   411  turingchain_testSeed() {
   412      seed=""
   413      turingchain_GenSeed
   414      turingchain_SaveSeed
   415      turingchain_GetSeed
   416  }
   417  
   418  turingchain_GetWalletStatus() {
   419      http_req '{"method":"Turingchain.GetWalletStatus","params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result| [has("isWalletLock", "isAutoMining", "isHasSeed", "isTicketLock"), true] | unique | length == 1)' "$FUNCNAME"
   420  }
   421  
   422  turingchain_GetBalance() {
   423      http_req '{"method":"Turingchain.GetBalance","params":[{"addresses" : ["14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"], "execer" : "coins"}]}' ${MAIN_HTTP} '(.error|not) and (.result[0] | [has("balance", "frozen"), true] | unique | length == 1)' "$FUNCNAME"
   424  }
   425  
   426  turingchain_GetAllExecBalance() {
   427      resok='(.error|not) and (.result| [has("addr", "execAccount"), true] | unique | length == 1) and (.result.execAccount | [map(has("execer", "account")), true] | flatten | unique | length == 1) and ([.result.execAccount[].account] | [map(has("balance", "frozen")), true] | flatten | unique | length == 1)'
   428      http_req '{"method":"Turingchain.GetAllExecBalance", "params":[{"addr" : "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"}]}' ${MAIN_HTTP} "$resok" "$FUNCNAME"
   429  }
   430  
   431  turingchain_ExecWallet() {
   432      req='{"method":"Turingchain.ExecWallet", "params":[{"funcName" : "NewAccountByIndex", "payload" : {"data" : 100000009}, "stateHash" : "", "execer" : "wallet" }]}'
   433      http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result | has("data"))' "$FUNCNAME"
   434  }
   435  
   436  turingchain_Query() {
   437      http_req '{"method":"Turingchain.Query", "params":[{ "execer":"coins", "funcName": "GetTxsByAddr", "payload" : {"addr" : "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]}' ${MAIN_HTTP} '(. | has("result"))' "$FUNCNAME"
   438  }
   439  
   440  turingchain_Version() {
   441      http_req '{"method":"Turingchain.Version", "params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result)' "$FUNCNAME"
   442  }
   443  
   444  turingchain_GetTotalCoins() {
   445      http_req '{"method":"Turingchain.GetTotalCoins", "params":[{"symbol" : "trc", "stateHash":"", "startKey":"", "count":2, "execer":"coins"}]}' ${MAIN_HTTP} '(.error|not) and (.result| has("count"))' "$FUNCNAME"
   446  }
   447  
   448  turingchain_IsSync() {
   449      http_req '{"method":"Turingchain.IsSync", "params":[{}]}' ${MAIN_HTTP} '(.error|not) and (. | has("result"))' "$FUNCNAME"
   450  }
   451  
   452  turingchain_IsNtpClockSync() {
   453      http_req '{"method":"Turingchain.IsNtpClockSync", "params":[{}]}' ${MAIN_HTTP} '(.error|not) and (. | has("result"))' "$FUNCNAME"
   454  }
   455  
   456  run_testcases() {
   457      #    set -x
   458      set +e
   459      IS_PARA=$(echo '"'"${1}"'"' | jq '.|contains("8901")')
   460      echo "ipara=$IS_PARA"
   461  
   462      turingchain_lock
   463      turingchain_unlock
   464  
   465      turingchain_WalletTxList "$1"
   466      turingchain_ImportPrivkey "$1"
   467      turingchain_DumpPrivkey "$1"
   468      turingchain_DumpPrivkeysFile "$1"
   469      turingchain_ImportPrivkeysFile "$1"
   470      turingchain_SendToAddress "$1"
   471      turingchain_SetTxFee "$1"
   472      turingchain_SetLabl "$1"
   473      turingchain_GetPeerInfo "$1"
   474      turingchain_GetHeaders "$1"
   475      turingchain_GetLastMemPool "$1"
   476      turingchain_GetProperFee "$1"
   477      turingchain_GetBlockOverview "$1"
   478      turingchain_GetAddrOverview "$1"
   479  
   480      turingchain_QueryTotalFee
   481      turingchain_GetNetInfo
   482      turingchain_GetFatalFailure
   483      turingchain_DecodeRawTransaction
   484      turingchain_GetTimeStatus
   485      turingchain_GetLastBlockSequence
   486      turingchain_GetBlockSequences
   487      turingchain_GetBlockByHashes
   488      turingchain_ConvertExectoAddr
   489      turingchain_GetExecBalance
   490      turingchain_AddPushSubscribe
   491      turingchain_ListPushes
   492      turingchain_GetPushSeqLastNum
   493      turingchain_GetCoinSymbol
   494  
   495      turingchain_GetHexTxByHash
   496      turingchain_QueryTransaction
   497      turingchain_GetBlocks
   498      turingchain_GetLastHeader
   499      turingchain_GetTxByAddr
   500      turingchain_GetTxByHashes
   501      turingchain_GetMempool
   502      turingchain_GetAccountsV2
   503      turingchain_GetAccounts
   504      turingchain_NewAccount
   505  
   506      turingchain_CreateRawTransaction
   507      turingchain_CreateTransaction
   508      turingchain_ReWriteRawTx
   509      turingchain_CreateRawTxGroup
   510      turingchain_SignRawTx
   511      turingchain_SendTransaction
   512      turingchain_CreateNoBalanceTransaction
   513  
   514      turingchain_GetBlockHash
   515      turingchain_testSeed
   516      turingchain_GetWalletStatus
   517      turingchain_GetBalance
   518      turingchain_GetAllExecBalance
   519      turingchain_ExecWallet
   520      turingchain_Query
   521      turingchain_Version
   522      turingchain_GetTotalCoins
   523      turingchain_IsSync
   524      turingchain_IsNtpClockSync
   525  
   526      #这两个测试放在最后
   527      turingchain_SetPasswd "$1"
   528      turingchain_MergeBalance "$1"
   529      set -e
   530  }
   531  
   532  function system_test_rpc() {
   533      MAIN_HTTP=$1
   534      echo "=========== # system rpc test ============="
   535      echo "ip=$1"
   536  
   537      run_testcases "$1"
   538  
   539      if [ -n "$CASE_ERR" ]; then
   540          echo -e "${RED}======system rpc test fail=======${NOC}"
   541          exit 1
   542      else
   543          echo -e "${GRE}======system rpc test pass=======${NOC}"
   544      fi
   545  }