github.com/turingchain2020/turingchain@v1.1.21/system/dapp/coins/cmd/build/fork-test.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  coinsTxHashs1=("")
     4  #coinsTxHashs2=("")
     5  coinsgStr=""
     6  coinsRepeatTx=1 #重复发送交易次数
     7  coinsTotalAmount1="0"
     8  coinsTxAmount="5" #每次发送交易数
     9  #defaultTxFee="0.001"
    10  coinsAddr1=""
    11  coinsTxSign=("")
    12  
    13  function initCoinsAccount() {
    14  
    15      name="${CLI}"
    16      label="coinstest1"
    17      createAccount "${name}" $label
    18      coinsAddr1=$coinsgStr
    19  
    20      sleep 1
    21  
    22      name="${CLI}"
    23      fromAdd="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
    24      showCoinsBalance "${name}" $fromAdd
    25      coinsTotalAmount1=$coinsgStr
    26  
    27      shouAccountList "${name}"
    28  }
    29  
    30  function genFirstChainCoinstx() {
    31      echo "====== 发送coins交易 ======"
    32      name=$CLI
    33      echo "当前链为:${name}"
    34  
    35      for ((i = 0; i < coinsRepeatTx; i++)); do
    36          From="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
    37          to=$coinsAddr1
    38          note="coinstx"
    39          amount=$coinsTxAmount
    40  
    41          genCoinsTx "${name}" $From $to $note $amount
    42          coinsTxSign[$i]="${coinsgStr}"
    43  
    44          block_wait_timeout "${CLI}" 1 20
    45  
    46          #发送交易
    47          sendCoinsTxHash "${name}" "${coinsgStr}"
    48          coinsTxHashs1[$i]="${coinsgStr}"
    49  
    50          sleep 1
    51          height=$(${name} block last_header | jq ".height")
    52          printf '发送第 %d 笔交易当前高度 %s \n' $i "${height}"
    53      done
    54  }
    55  
    56  function genSecondChainCoinstx() {
    57      echo "====== 发送交易 ======"
    58      name=$CLI
    59      echo "当前链为:${name}"
    60  
    61      #将第一条链产生的签名交易发送出去
    62      for ((i = 0; i < ${#coinsTxSign[*]}; i++)); do
    63          #发送交易
    64          sign="${coinsTxSign[$i]}"
    65          sendCoinsTxHash "${name}" "${sign}"
    66  
    67          sleep 1
    68          height=$(${name} block last_header | jq ".height")
    69          printf '发送第 %d 笔交易当前高度 %s \n' $i "${height}"
    70      done
    71  }
    72  
    73  function checkCoinsResult() {
    74      name=$CLI
    75  
    76      echo "====================检查第一组docker运行结果================="
    77  
    78      totalCoinsTxAmount="0"
    79  
    80      for ((i = 0; i < ${#coinsTxHashs1[*]}; i++)); do
    81          txHash=${coinsTxHashs1[$i]}
    82          echo $txHash
    83          txQuery "${name}" $txHash
    84          result=$?
    85          if [ $result -eq 0 ]; then
    86              #coinsTxFee1=$(echo "$coinsTxFee1 + $defaultTxFee" | bc)
    87              totalCoinsTxAmount=$(echo "$totalCoinsTxAmount + $coinsTxAmount" | bc)
    88          fi
    89          sleep 1
    90      done
    91  
    92      sleep 1
    93  
    94      fromAdd="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
    95      showCoinsBalance "${name}" $fromAdd
    96      value1=$coinsgStr
    97  
    98      sleep 1
    99  
   100      fromAdd=$coinsAddr1
   101      showCoinsBalance "${name}" $fromAdd
   102      value2=$coinsgStr
   103  
   104      actTotal=$(echo "$value1 + $value2 " | bc)
   105      echo "${name} 实际金额:$actTotal"
   106  
   107      #if [ `echo "${actTotal} > ${coinsTotalAmount1}" | bc` -eq 1 ]; then
   108      if [ "$(echo "${actTotal} > ${coinsTotalAmount1}" | bc)" -eq 1 ]; then
   109          echo "${name} 出现双花"
   110          exit 1
   111      else
   112          echo "${name} 未出现双花"
   113      fi
   114  }
   115  
   116  function sendcoinsTx() {
   117      name=$1
   118      fromAdd=$2
   119      toAdd=$3
   120      note=$4
   121      amount=$5
   122  
   123      #组合形式交易
   124      #hash=$(sudo docker exec -it $1 ./turingchain-cli coins transfer -t $2 -a $5 -n $4 | tr '\r' ' ')
   125      #echo $hash
   126      #sign=$(sudo docker exec -it $1 ./turingchain-cli wallet sign -a $3 -d $hash | tr '\r' ' ')
   127      #echo $sign
   128      #sudo docker exec -it $1 ./turingchain-cli wallet send -d $sign
   129  
   130      #单个命令形式交易
   131      #sudo docker exec -it $1 ./turingchain-cli send coins transfer -a $5 -n $4 -t $2 -k $From
   132      result=$($name send coins transfer -a "${amount}" -n "${note}" -t "${toAdd}" -k "${fromAdd}" | tr '\r' ' ')
   133      echo "hash: $result"
   134      coinsgStr=$result
   135  }
   136  
   137  function genCoinsTx() {
   138      name=$1
   139      fromAdd=$2
   140      toAdd=$3
   141      note=$4
   142      amount=$5
   143      expire="600s"
   144  
   145      #组合形式交易
   146      hash=$(${name} coins transfer -t "${toAdd}" -a "${amount}" -n "${note}" | tr '\r' ' ')
   147      echo "${hash}"
   148      sign=$(${name} wallet sign -a "${fromAdd}" -d "${hash}" -e "${expire}" | tr '\r' ' ')
   149      echo "sign: $sign"
   150      coinsgStr=$sign
   151  
   152  }
   153  
   154  function sendCoinsTxHash() {
   155      name=$1
   156      sign=$2
   157      result=$(${name} wallet send -d "${sign}" | tr '\r' ' ')
   158      echo "hash: $result"
   159      coinsgStr=$result
   160  }
   161  
   162  function showCoinsBalance() {
   163      name=$1
   164      fromAdd=$2
   165      printf '==========showCoinBalance name=%s addr=%s==========\n' "${name}" "${fromAdd}"
   166      result=$($name account balance -e coins -a "${fromAdd}" | jq -r ".balance")
   167      printf 'balance %s \n' "${result}"
   168      coinsgStr=$result
   169  }
   170  
   171  function createAccount() {
   172      name=$1
   173      label=$2
   174      printf '==========CreateAccount name=%s ==========\n' "${name}"
   175      result=$($name account create -l "${label}" | jq -r ".acc.addr")
   176      printf 'New account addr %s \n' "${result}"
   177      coinsgStr=$result
   178  }
   179  
   180  function shouAccountList() {
   181      name=$1
   182      printf '==========shouAccountList name=%s ==========\n' "${name}"
   183      $name account list
   184  }