github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/test_token.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 # Detecting whether can import the header file to render colorful cli output 10 if [ -f ./header.sh ]; then 11 source ./header.sh 12 elif [ -f scripts/header.sh ]; then 13 source scripts/header.sh 14 else 15 alias echo_r="echo" 16 alias echo_g="echo" 17 alias echo_b="echo" 18 fi 19 20 CHANNEL_NAME="$1" 21 : ${CHANNEL_NAME:="mychannel"} 22 : ${TIMEOUT:="60"} 23 COUNTER=0 24 MAX_RETRY=5 25 CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/token 26 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 27 28 echo_b "Chaincode Path : "$CC_PATH 29 echo_b "Channel name : "$CHANNEL_NAME 30 31 verifyResult () { 32 if [ $1 -ne 0 ] ; then 33 echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" 34 echo_r "================== ERROR !!! FAILED to execute MVE ==================" 35 echo 36 exit 1 37 fi 38 } 39 40 issueToken(){ 41 sleep 3 42 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'","1000000000000000000","18","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 43 res=$? 44 cat log.txt 45 verifyResult $res "Issue a new token using ascc has Failed." 46 echo_g "===================== A new token has been successfully issued======================= " 47 echo 48 } 49 50 issueToken2(){ 51 sleep 5 52 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ascc -c '{"Args":["registerAndIssueToken","CCToken0","100000","9","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 53 res=$? 54 cat log.txt 55 verifyResult $res "Issue a new token using ascc has Failed." 56 echo_g "===================== A new token has been successfully issued======================= " 57 echo 58 } 59 60 makeTransfer(){ 61 echo_b "pls wait 5 secs..." 62 sleep 5 63 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n token -c '{"Args":["transfer","i3c97f146e8de9807ef723538521fcecd5f64c79a","INK","10"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 64 res=$? 65 cat log.txt 66 verifyResult $res "Make transfer has Failed." 67 echo_g "===================== Make transfer success ======================= " 68 echo 69 } 70 71 chaincodeQueryA () { 72 echo_b "Attempting to Query account A's balance on peer " 73 sleep 3 74 peer chaincode query -C mychannel -n token -c '{"Args":["getBalance","i4230a12f5b0693dd88bb35c79d7e56a68614b199","INK"]}' >log.txt 75 res=$? 76 cat log.txt 77 verifyResult $res "query account A Failed." 78 } 79 80 chaincodeQueryB () { 81 echo_b "Attempting to query account B's balance on peer " 82 sleep 3 83 peer chaincode query -C mychannel -n token -c '{"Args":["getBalance","i3c97f146e8de9807ef723538521fcecd5f64c79a","INK"]}' >log.txt 84 res=$? 85 cat log.txt 86 verifyResult $res "query account B Failed." 87 88 } 89 90 queryToken(){ 91 # 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'","100","18","4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 92 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ascc -c '{"Args":["queryToken","INK","INK0","CCToken0","CCToken"]}' >log.txt 93 res=$? 94 cat log.txt 95 verifyResult $res "Issue a new token using ascc has Failed." 96 echo_g "===================== A new token has been successfully issued======================= " 97 echo 98 } 99 100 calcFee(){ 101 echo_b "Attempting to calc fee for operate" 102 sleep 3 103 peer chaincode query -C mychannel -n token -c '{"Args":["calcFee","test"]}' >log.txt 104 res=$? 105 cat log.txt 106 verifyResult $res "calc fee Failed." 107 } 108 109 echo_b "=====================6.Issue a token using ascc========================" 110 issueToken INK 111 issueToken2 112 113 echo_b "=====================7.Transfer 10 amount of INK=====================" 114 makeTransfer 115 116 echo_b "=====================8.Query transfer result of From account=====================" 117 #checkTransferRes1 118 chaincodeQueryA 119 120 echo_b "=====================9.Query transfer result of To account=====================" 121 #checkTransferRes2 122 chaincodeQueryB 123 124 echo_b "=====================10.Query token=====================" 125 queryToken 126 127 echo_b "=====================11.Calc fee=====================" 128 calcFee 129 130 echo 131 echo_g "=====================All GOOD, MVE Test completed ===================== " 132 echo 133 exit 0 134