github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/test_cat_invoke.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  #
     4  #Copyright Ziggurat Corp. 2017 All Rights Reserved.
     5  #
     6  #SPDX-License-Identifier: Apache-2.0
     7  #
     8  
     9  #system account
    10  #07caf88941eafcaaa3370657fccc261acb75dfba
    11  #70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4
    12  
    13  #user account
    14  #a5ff00eb44bf19d5dfbde501c90e286badb58df4
    15  #344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5
    16  
    17  # Detecting whether can import the header file to render colorful cli output
    18  if [ -f ./header.sh ]; then
    19   source ./header.sh
    20  elif [ -f scripts/header.sh ]; then
    21   source scripts/header.sh
    22  else
    23   alias echo_r="echo"
    24   alias echo_g="echo"
    25   alias echo_b="echo"
    26  fi
    27  
    28  CHANNEL_NAME="$1"
    29  : ${CHANNEL_NAME:="mychannel"}
    30  : ${TIMEOUT:="60"}
    31  COUNTER=0
    32  MAX_RETRY=5
    33  
    34  ORDERER_CA=/opt/gopath/src/github.com/inklabsfoundation/inkchain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    35  
    36  echo_b "Chaincode Path : "$CC_PATH
    37  echo_b "Channel name : "$CHANNEL_NAME
    38  
    39  verifyResult () {
    40      if [ $1 -ne 0 ] ; then
    41          echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
    42          echo_r "================== ERROR !!! FAILED to execute MVE =================="
    43          echo
    44          exit 1
    45      fi
    46  }
    47  
    48  issueToken(){
    49      peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ascc -c '{"Args":["registerAndIssueToken","'$1'","1000000000000000","18","i07caf88941eafcaaa3370657fccc261acb75dfba"]}' >log.txt
    50      res=$?
    51      cat log.txt
    52      verifyResult $res "Issue a new token using ascc has Failed."
    53      echo_g "===================== A new token has been successfully issued======================= "
    54      echo
    55  }
    56  
    57  makeTransfer(){
    58      echo_b "pls wait 5 secs..."
    59      sleep 5
    60      peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n token -c '{"Args":["transfer","ia5ff00eb44bf19d5dfbde501c90e286badb58df4","INK","50000000000000"]}' -i "1000000000" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >log.txt
    61      res=$?
    62      cat log.txt
    63      verifyResult $res "Make transfer has Failed."
    64      echo_g "===================== Make transfer success ======================= "
    65      echo
    66  }
    67  
    68  catSystemInit(){
    69      sleep 3
    70      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["initSystemCat", "'$1'"]}' -i "1000000000" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >&log.txt
    71      res=$?
    72      cat log.txt
    73      verifyResult $res "cat invoke has Failed."
    74      echo_g "===================== cat invoke successfully======================= "
    75      echo
    76  }
    77  
    78  catDel(){
    79      echo_b "Attempting to delete cat"
    80      sleep 3
    81      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["delete","7918"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt
    82      res=$?
    83      cat log.txt
    84      verifyResult $res "cat invoke has Failed."
    85      echo_g "===================== cat delete successfully======================= "
    86      echo
    87  }
    88  
    89  saleState(){
    90      echo_b "Attempting to set cat saleState"
    91      sleep 3
    92      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["setState","7918","0","1"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt
    93      res=$?
    94      cat log.txt
    95      verifyResult $res "cat invoke has Failed."
    96      echo_g "===================== cat setSaleStae successfully======================= "
    97      echo
    98  }
    99  
   100  mateState(){
   101      echo_b "Attempting to set cat mateState"
   102      sleep 3
   103      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["setState","7918","2","1"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt
   104      res=$?
   105      cat log.txt
   106      verifyResult $res "cat invoke has Failed."
   107      echo_g "===================== cat setMateStae successfully======================= "
   108      echo
   109  }
   110  
   111  salePrice(){
   112      echo_b "Attempting to set cat salePrice"
   113      sleep 3
   114      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["setState","7918","1","4"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt
   115      res=$?
   116      cat log.txt
   117      verifyResult $res "cat invoke has Failed."
   118      echo_g "===================== cat setSalePrice successfully======================= "
   119      echo
   120  }
   121  
   122  matePrice(){
   123      echo_b "Attempting to set cat matePrice"
   124      sleep 3
   125      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["setState","7918","3","5"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt
   126      res=$?
   127      cat log.txt
   128      verifyResult $res "cat invoke has Failed."
   129      echo_g "===================== cat setMalePrice successfully======================= "
   130      echo
   131  }
   132  
   133  catBreed(){
   134      echo_b "Attempting to cat breed"
   135      sleep 3
   136      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["breed","5060","7918","2108"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt
   137      res=$?
   138      cat log.txt
   139      verifyResult $res "cat invoke has Failed."
   140      echo_g "===================== cat breed successfully======================= "
   141      echo
   142  }
   143  
   144  catBuyA(){
   145      echo_b "Attempting to buy cat A"
   146      sleep 3
   147      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["buy","7918"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >log.txt
   148      res=$?
   149      cat log.txt
   150      verifyResult $res "buyCat has Failed."
   151      echo_g "===================== buycat success ======================= "
   152      echo
   153  }
   154  
   155  catBuyB(){
   156      echo_b "Attempting to buy cat B"
   157      sleep 3
   158      peer chaincode invoke -C mychannel -n cat --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["buy","5060"]}' -i "1000000000" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >log.txt
   159      res=$?
   160      cat log.txt
   161      verifyResult $res "buyCat has Failed."
   162      echo_g "===================== buycat success ======================= "
   163      echo
   164  }
   165  
   166  echo_b "=====================register token======================="
   167  issueToken INK
   168  makeTransfer
   169  
   170  echo_b "=====================1.cat init======================="
   171  catSystemInit 7918
   172  catSystemInit 5060
   173  
   174  echo_b "=====================2.cat delete======================="
   175  #catDel
   176  
   177  echo_b "=====================3.cat buy======================="
   178  catBuyA
   179  
   180  echo_b "=====================4.cat buy======================="
   181  catBuyB
   182  
   183  echo_b "=====================5.cat sale state====================="
   184  saleState
   185  
   186  echo_b "=====================6.cat mate state====================="
   187  mateState
   188  
   189  echo_b "=====================7.cat sale price====================="
   190  salePrice
   191  
   192  echo_b "=====================8.cat mate price====================="
   193  matePrice
   194  
   195  echo_b "=====================9.cat breed====================="
   196  catBreed
   197  
   198  echo
   199  echo_g "=====================All GOOD, MVE Test completed ===================== "
   200  echo
   201  exit 0
   202