github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/test_guide.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_ID=guide 26 CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/guide_credit 27 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 28 29 echo_b "Chaincode Path : "$CC_PATH 30 echo_b "Channel name : "$CHANNEL_NAME 31 32 verifyResult () { 33 if [ $1 -ne 0 ] ; then 34 echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" 35 echo_r "================== ERROR !!! FAILED to execute MVE ==================" 36 echo 37 exit 1 38 fi 39 } 40 41 issueToken(){ 42 sleep 3 43 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 44 res=$? 45 cat log.txt 46 verifyResult $res "Issue a new token using ascc has Failed." 47 echo_g "===================== A new token has been successfully issued======================= " 48 echo 49 } 50 51 registerGuide(){ 52 sleep 3 53 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["registerGuide","100099999","evans","true","23"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 54 res=$? 55 cat log.txt 56 verifyResult $res "Issue a new token using ascc has Failed." 57 echo_g "=====================A new guide been successfully registered======================= " 58 echo 59 } 60 61 registerCompany(){ 62 sleep 3 63 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["registerCompany","test","china","999999"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 64 res=$? 65 cat log.txt 66 verifyResult $res "Register a new guide has Failed." 67 echo_g "===================== A new company has been successfully registered======================= " 68 echo 69 } 70 71 addGuide(){ 72 sleep 3 73 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["addGuide","i4230a12f5b0693dd88bb35c79d7e56a68614b199",""]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 74 res=$? 75 cat log.txt 76 verifyResult $res "Register a new guide has Failed." 77 echo_g "===================== A new company has been successfully registered======================= " 78 echo 79 } 80 81 queryGuideInfo(){ 82 sleep 3 83 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryGuideInfo","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 84 res=$? 85 cat log.txt 86 verifyResult $res "Query guide info has Failed." 87 echo_g "===================== Query guide info has been successfully ======================= " 88 echo 89 } 90 91 queryCompanyInfo(){ 92 sleep 3 93 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryCompanyInfo","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 94 res=$? 95 cat log.txt 96 verifyResult $res "Query guide info has Failed." 97 echo_g "===================== Query guide info has been successfully ======================= " 98 echo 99 } 100 101 setGuideToBlackList(){ 102 sleep 3 103 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["setGuideToBlackList","i4230a12f5b0693dd88bb35c79d7e56a68614b199","nothing"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 104 res=$? 105 cat log.txt 106 verifyResult $res "Register a new guide has Failed." 107 echo_g "===================== A new company has been successfully registered======================= " 108 echo 109 } 110 111 queryOperateLogs(){ 112 sleep 3 113 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryOperateLog","i4230a12f5b0693dd88bb35c79d7e56a68614b199","0"]}' >log.txt 114 res=$? 115 cat log.txt 116 verifyResult $res "Query operate logs has Failed." 117 echo_g "===================== Query operate logs has been successfully ======================= " 118 echo 119 } 120 121 queryBlackList(){ 122 sleep 3 123 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryBlackList","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 124 res=$? 125 cat log.txt 126 verifyResult $res "Query black list has Failed." 127 echo_g "===================== Query black list has been successfully ======================= " 128 echo 129 } 130 131 removeFromCompany(){ 132 sleep 3 133 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["removeFromCompany","i4230a12f5b0693dd88bb35c79d7e56a68614b199","just remove"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 134 res=$? 135 cat log.txt 136 verifyResult $res "Remove a guide from company has Failed." 137 echo_g "===================== Remove a guide from company has been successfully registered======================= " 138 echo 139 } 140 141 queryGuideWorkList(){ 142 sleep 3 143 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryGuideWorkList","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 144 res=$? 145 cat log.txt 146 verifyResult $res "Query guide work list has Failed." 147 echo_g "===================== Query guide work list has been successfully ======================= " 148 echo 149 } 150 151 queryGuideLeaveLogs(){ 152 sleep 3 153 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryLeaveLogs","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 154 res=$? 155 cat log.txt 156 verifyResult $res "Query guide leave logs has Failed." 157 echo_g "===================== Query guide leave logs has been successfully ======================= " 158 echo 159 } 160 161 echo_b "=====================5.Issue a token using ascc========================" 162 issueToken INK 163 164 echo_b "=====================6.Register a guide================================" 165 registerGuide 166 167 echo_b "=====================7.Register a company==============================" 168 registerCompany 169 170 echo_b "=====================8.Add a guide to company==========================" 171 addGuide 172 173 echo_b "=====================9.Query a guide info==============================" 174 queryGuideInfo 175 176 echo_b "=====================10.Query a company info===========================" 177 queryCompanyInfo 178 179 echo_b "=====================11.Add a guide into black list========================" 180 setGuideToBlackList 181 182 echo_b "=====================12.Query a guide info=============================" 183 queryGuideInfo 184 185 echo_b "=====================13.Query operate log info=========================" 186 queryOperateLogs 187 188 echo_b "=====================14.Query black list info=========================" 189 queryBlackList 190 191 echo_b "=====================15.Remove guide from company=========================" 192 removeFromCompany 193 194 echo_b "=====================16.Query a guide info=============================" 195 queryGuideInfo 196 197 echo_b "=====================17.Query guide work list=============================" 198 queryGuideWorkList 199 200 echo_b "=====================18.Query guide leave logs=============================" 201 queryGuideLeaveLogs 202 203 echo 204 echo_g "=====================All GOOD, MVE Test completed ===================== " 205 echo 206 exit 0