github.com/turingchain2020/turingchain@v1.1.21/build/autotest/local/autotest.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e
     4  set -o pipefail
     5  #set -o verbose
     6  #set -o xtrace
     7  
     8  # os: ubuntu16.04 x64
     9  # first, you must install jq tool of json
    10  # sudo apt-get install jq
    11  # sudo apt-get install shellcheck, in order to static check shell script
    12  # sudo apt-get install parallel
    13  
    14  PWD=$(cd "$(dirname "$0")" && pwd)
    15  export PATH="$PWD:$PATH"
    16  
    17  CLI="./turingchain-cli"
    18  
    19  sedfix=""
    20  if [ "$(uname)" == "Darwin" ]; then
    21      sedfix=".bak"
    22  fi
    23  
    24  turingchainConfig="turingchain.test.toml"
    25  turingchainBlockTime=1
    26  autoTestCheckTimeout=10
    27  
    28  function config_turingchain() {
    29  
    30      # shellcheck disable=SC2015
    31      echo "# config turingchain solo test"
    32      # update test environment
    33      sed -i $sedfix 's/^Title.*/Title="local"/g' ${turingchainConfig}
    34      # grep -q '^TestNet' ${turingchainConfig} && sed -i $sedfix 's/^TestNet.*/TestNet=true/' ${turingchainConfig} || sed -i '/^Title/a TestNet=true' ${turingchainConfig}
    35  
    36      if grep -q '^TestNet' ${turingchainConfig}; then
    37          sed -i $sedfix 's/^TestNet.*/TestNet=true/' ${turingchainConfig}
    38      else
    39          sed -i $sedfix '/^Title/a TestNet=true' ${turingchainConfig}
    40      fi
    41  
    42      #update fee
    43      #    sed -i $sedfix 's/Fee=.*/Fee=100000/' ${turingchainConfig}
    44  
    45      #update wallet store driver
    46      #    sed -i $sedfix '/^\[wallet\]/,/^\[wallet./ s/^driver.*/driver="leveldb"/' ${turingchainConfig}
    47  }
    48  
    49  autotestConfig="autotest.toml"
    50  autotestTempConfig="autotest.temp.toml"
    51  function config_autotest() {
    52  
    53      echo "# config autotest"
    54      #delete all blank lines
    55      #    sed -i $sedfix '/^\s*$/d' ${autotestConfig}
    56  
    57      if [[ $1 == "" ]] || [[ $1 == "all" ]]; then
    58          cp ${autotestConfig} ${autotestTempConfig}
    59          sed -i $sedfix 's/^checkTimeout.*/checkTimeout='${autoTestCheckTimeout}'/' ${autotestTempConfig}
    60      else
    61          #copy config before [
    62          # sed -n '/^\[\[/!p;//q' ${autotestConfig} >${autotestTempConfig}
    63          #pre config auto test
    64          {
    65  
    66              echo 'cliCmd="./turingchain-cli"'
    67              echo "checkTimeout=${autoTestCheckTimeout}"
    68          } >${autotestTempConfig}
    69  
    70          #specific dapp config
    71          for dapp in "$@"; do
    72              {
    73                  echo "[[TestCaseFile]]"
    74                  echo "dapp=\"$dapp\""
    75                  echo "filename=\"$dapp.toml\""
    76              } >>${autotestTempConfig}
    77  
    78          done
    79      fi
    80  }
    81  
    82  function start_turingchain() {
    83  
    84      echo "# start solo turingchain"
    85      rm -rf ../local/datadir ../local/logs ../local/grpc33.log
    86      ./turingchain -f turingchain.test.toml >/dev/null 2>&1 &
    87      local SLEEP=1
    88      sleep ${SLEEP}
    89  
    90      # query node run status
    91      ${CLI} block last_header
    92  
    93      echo "=========== # save seed to wallet ============="
    94      result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
    95      if [ "${result}" = "false" ]; then
    96          echo "save seed to wallet error seed, result: ${result}"
    97          exit 1
    98      fi
    99  
   100      echo "=========== # unlock wallet ============="
   101      result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
   102      if [ "${result}" = "false" ]; then
   103          exit 1
   104      fi
   105  
   106      echo "=========== # import private key returnAddr ============="
   107      result=$(${CLI} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label")
   108      echo "${result}"
   109      if [ -z "${result}" ]; then
   110          exit 1
   111      fi
   112  
   113      echo "=========== # import private key mining ============="
   114      result=$(${CLI} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label")
   115      echo "${result}"
   116      if [ -z "${result}" ]; then
   117          exit 1
   118      fi
   119  
   120      echo "=========== #transfer to miner addr ============="
   121      hash=$(${CLI} send coins transfer -a 10000 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
   122      echo "${hash}"
   123      sleep ${turingchainBlockTime}
   124      result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
   125      if [[ ${result} != '"ExecOk"' ]]; then
   126          echo "Failed"
   127          ${CLI} tx query -s "${hash}" | jq '.' | cat
   128          exit 1
   129      fi
   130  
   131      echo "=========== #transfer to token amdin ============="
   132      hash=$(${CLI} send coins transfer -a 10 -n test -t 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
   133  
   134      echo "${hash}"
   135      sleep ${turingchainBlockTime}
   136      result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
   137      if [[ ${result} != '"ExecOk"' ]]; then
   138          echo "Failed"
   139          ${CLI} tx query -s "${hash}" | jq '.' | cat
   140          exit 1
   141      fi
   142  
   143      echo "=========== #config token blacklist ============="
   144      rawData=$(${CLI} config config_tx -c token-blacklist -o add -v BTC)
   145      signData=$(${CLI} wallet sign -d "${rawData}" -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
   146      hash=$(${CLI} wallet send -d "${signData}")
   147  
   148      echo "${hash}"
   149      sleep ${turingchainBlockTime}
   150      result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
   151      if [[ ${result} != '"ExecOk"' ]]; then
   152          echo "Failed"
   153          ${CLI} tx query -s "${hash}" | jq '.' | cat
   154          exit 1
   155      fi
   156  
   157  }
   158  
   159  function start_autotest() {
   160  
   161      echo "=========== #run autotest, make sure saving autotest.last.log file============="
   162  
   163      if [ -e autotest.log ]; then
   164          cat autotest.log >autotest.last.log
   165          rm autotest.log
   166      fi
   167  
   168      ./autotest -f ${autotestTempConfig}
   169  
   170  }
   171  
   172  function stop_turingchain() {
   173  
   174      rv=$?
   175      echo "=========== #stop turingchain ============="
   176      ${CLI} close || true
   177      #wait close
   178      sleep ${turingchainBlockTime}
   179      echo "==========================================local-auto-test-shell-end========================================================="
   180      exit ${rv}
   181  }
   182  
   183  function main() {
   184      echo "==========================================local-auto-test-shell-begin========================================================"
   185      config_autotest "$@"
   186      config_turingchain
   187      start_turingchain
   188      start_autotest
   189  
   190  }
   191  
   192  trap "stop_turingchain" INT TERM EXIT
   193  
   194  main "$@"