github.com/turingchain2020/turingchain@v1.1.21/build/autotest/jerkinsci/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  # ./run-autotest.sh build
    14  
    15  PWD=$(cd "$(dirname "$0")" && pwd)
    16  export PATH="$PWD:$PATH"
    17  
    18  PROJECT_NAME="${1}"
    19  if [[ ${PROJECT_NAME} == "" ]]; then
    20      PROJECT_NAME="build"
    21  fi
    22  
    23  NODE3="${PROJECT_NAME}_autotest_1"
    24  CLI="docker exec ${NODE3} /root/turingchain-cli"
    25  TEMP_CI_DIR=ci-"${PROJECT_NAME}"
    26  
    27  sedfix=""
    28  if [ "$(uname)" == "Darwin" ]; then
    29      sedfix=".bak"
    30  fi
    31  
    32  turingchainConfig="turingchain.test.toml"
    33  turingchainBlockTime=1
    34  autoTestConfig="autotest.toml"
    35  autoTestCheckTimeout=10
    36  
    37  function config_turingchain() {
    38  
    39      # shellcheck disable=SC2015
    40      echo "# config turingchain solo test"
    41      # update test environment
    42      sed -i $sedfix 's/^Title.*/Title="local"/g' ${turingchainConfig}
    43      # grep -q '^TestNet' ${turingchainConfig} && sed -i $sedfix 's/^TestNet.*/TestNet=true/' ${turingchainConfig} || sed -i '/^Title/a TestNet=true' ${turingchainConfig}
    44  
    45      if grep -q '^TestNet' ${turingchainConfig}; then
    46          sed -i $sedfix 's/^TestNet.*/TestNet=true/' ${turingchainConfig}
    47      else
    48          sed -i $sedfix '/^Title/a TestNet=true' ${turingchainConfig}
    49      fi
    50  }
    51  
    52  function config_autotest() {
    53  
    54      echo "# config autotest"
    55      sed -i $sedfix 's/^checkTimeout.*/checkTimeout='${autoTestCheckTimeout}'/' ${autoTestConfig}
    56  }
    57  
    58  function start_turingchain() {
    59  
    60      # create and run docker-compose container
    61      docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml up --build -d
    62  
    63      local SLEEP=2
    64      sleep ${SLEEP}
    65  
    66      # docker-compose ps
    67      docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml ps
    68  
    69      # query node run status
    70      ${CLI} block last_header
    71  
    72      echo "=========== # save seed to wallet ============="
    73      result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
    74      if [ "${result}" = "false" ]; then
    75          echo "save seed to wallet error seed, result: ${result}"
    76          exit 1
    77      fi
    78  
    79      echo "=========== # unlock wallet ============="
    80      result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
    81      if [ "${result}" = "false" ]; then
    82          exit 1
    83      fi
    84  
    85      echo "=========== # import private key returnAddr ============="
    86      result=$(${CLI} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label")
    87      echo "${result}"
    88      if [ -z "${result}" ]; then
    89          exit 1
    90      fi
    91  
    92      echo "=========== # import private key mining ============="
    93      result=$(${CLI} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label")
    94      echo "${result}"
    95      if [ -z "${result}" ]; then
    96          exit 1
    97      fi
    98  
    99      echo "=========== #transfer to miner addr ============="
   100      hash=$(${CLI} send coins transfer -a 10000 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
   101      echo "${hash}"
   102      sleep ${turingchainBlockTime}
   103      result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
   104      if [[ ${result} != '"ExecOk"' ]]; then
   105          echo "Failed"
   106          ${CLI} tx query -s "${hash}" | jq '.' | cat
   107          exit 1
   108      fi
   109  
   110      echo "=========== #transfer to token amdin ============="
   111      hash=$(${CLI} send coins transfer -a 10 -n test -t 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
   112  
   113      echo "${hash}"
   114      sleep ${turingchainBlockTime}
   115      result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
   116      if [[ ${result} != '"ExecOk"' ]]; then
   117          echo "Failed"
   118          ${CLI} tx query -s "${hash}" | jq '.' | cat
   119          exit 1
   120      fi
   121  
   122      echo "=========== #config token blacklist ============="
   123      rawData=$(${CLI} config config_tx -c token-blacklist -o add -v BTC)
   124      signData=$(${CLI} wallet sign -d "${rawData}" -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
   125      hash=$(${CLI} wallet send -d "${signData}")
   126  
   127      echo "${hash}"
   128      sleep ${turingchainBlockTime}
   129      result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
   130      if [[ ${result} != '"ExecOk"' ]]; then
   131          echo "Failed"
   132          ${CLI} tx query -s "${hash}" | jq '.' | cat
   133          exit 1
   134      fi
   135  
   136  }
   137  
   138  function start_autotest() {
   139  
   140      echo "=========== #start auto-test program ============="
   141      docker exec "${NODE3}" /root/autotest
   142  
   143  }
   144  
   145  function stop_turingchain() {
   146  
   147      rv=$?
   148      echo "=========== #stop docker-compose ============="
   149      docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml down
   150      echo "=========== #remove related images ============"
   151      docker rmi "${PROJECT_NAME}"_autotest || true
   152      pwd
   153      cd ../ && rm -rf ./"$TEMP_CI_DIR"
   154      exit ${rv}
   155  }
   156  
   157  function main() {
   158  
   159      if [[ -d $TEMP_CI_DIR ]]; then
   160          rm -rf ./"$TEMP_CI_DIR"
   161      fi
   162      mkdir "$TEMP_CI_DIR" && cd "$TEMP_CI_DIR"
   163      mv ../autotest ../*.toml ./ && mv ../turingchain* ./
   164      cp ../compose-autotest.yml ../Dockerfile-autotest ./
   165  
   166      config_turingchain
   167      config_autotest
   168      start_turingchain
   169      start_autotest
   170  }
   171  
   172  #trap exit
   173  trap "stop_turingchain" INT TERM EXIT
   174  
   175  # run script
   176  main