github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/test_asset_init.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 # 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 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'","100","18","i07caf88941eafcaaa3370657fccc261acb75dfba"]}' >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 makeTransfer(){ 51 echo_b "pls wait 5 secs..." 52 sleep 5 53 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","30"]}' -i "1" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >log.txt 54 # peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n token -c '{"Args":["transfer","3c97f146e8de9807ef723538521fcecd5f64c79a","INK","10"]}' -i "1" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 55 56 res=$? 57 cat log.txt 58 verifyResult $res "Make transfer has Failed." 59 echo_g "===================== Make transfer success ======================= " 60 echo 61 } 62 63 chaincodeQueryA () { 64 echo_b "Attempting to Query account A's balance on peer " 65 sleep 3 66 peer chaincode query -C mychannel -n token -c '{"Args":["getBalance","i07caf88941eafcaaa3370657fccc261acb75dfba","INK"]}' >log.txt 67 # peer chaincode query -C mychannel -n token -c '{"Args":["getBalance","4230a12f5b0693dd88bb35c79d7e56a68614b199","INK"]}' >log.txt 68 69 res=$? 70 cat log.txt 71 verifyResult $res "query account A Failed." 72 } 73 74 chaincodeQueryB () { 75 echo_b "Attempting to query account B's balance on peer " 76 sleep 3 77 peer chaincode query -C mychannel -n token -c '{"Args":["getBalance","ia5ff00eb44bf19d5dfbde501c90e286badb58df4","INK"]}' >log.txt 78 res=$? 79 cat log.txt 80 verifyResult $res "query account B Failed." 81 82 } 83 84 # for init asset 85 assetInvoke_AddUser01(){ 86 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["addUser","Daniel","18"]}' -i "10" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >&log.txt 87 res=$? 88 cat log.txt 89 verifyResult $res "asset invoke: addUser has Failed." 90 echo_g "===================== asset invoke successfully======================= " 91 echo 92 } 93 94 assetInvoke_AddUser02(){ 95 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["addUser","Rose","16"]}' -i "10" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt 96 res=$? 97 cat log.txt 98 verifyResult $res "asset invoke: addUser has Failed." 99 echo_g "===================== asset invoke successfully======================= " 100 echo 101 } 102 103 assetQuery_User01 () { 104 echo_b "Attempting to Query user " 105 sleep 3 106 peer chaincode query -C mychannel -n asset -c '{"Args":["queryUser","Daniel"]}' >log.txt 107 108 res=$? 109 cat log.txt 110 verifyResult $res "query user: Dainel Failed." 111 } 112 113 assetQuery_User02 () { 114 echo_b "Attempting to Query user " 115 sleep 3 116 peer chaincode query -C mychannel -n asset -c '{"Args":["queryUser","Rose"]}' >log.txt 117 118 res=$? 119 cat log.txt 120 verifyResult $res "query user: Dainel Failed." 121 } 122 123 assetInvoke_AddAsset(){ 124 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["addAsset","Blockchain Guide","BOOK","a book on blockchain.","CCToken","10","Daniel"]}' -i "10" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >&log.txt 125 res=$? 126 cat log.txt 127 verifyResult $res "asset invoke: addAsset has Failed." 128 echo_g "===================== asset invoke successfully======================= " 129 echo 130 } 131 132 assetInvoke_AddAsset2(){ 133 sleep 3 134 135 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["addAsset","Blockchain Guide2","BOOK","a book on blockchain 2.","INK","100","Daniel"]}' -i "10" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >&log.txt 136 res=$? 137 cat log.txt 138 verifyResult $res "asset invoke: addAsset has Failed." 139 echo_g "===================== asset invoke successfully======================= " 140 echo 141 } 142 143 assetInvoke_AddAsset3(){ 144 sleep 3 145 146 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["addAsset","Z Blockchain Guide3","BOOK","a book on blockchain 3.","INK","1000","Daniel"]}' -i "10" -z 70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4 >&log.txt 147 res=$? 148 cat log.txt 149 verifyResult $res "asset invoke: addAsset has Failed." 150 echo_g "===================== asset invoke successfully======================= " 151 echo 152 } 153 154 assetQuery_Asset () { 155 echo_b "Attempting to Query asset " 156 sleep 3 157 peer chaincode query -C mychannel -n asset -c '{"Args":["readAsset","Blockchain Guide"]}' >log.txt 158 159 res=$? 160 cat log.txt 161 verifyResult $res "query asset: To The Moon Failed." 162 } 163 164 echo_b "=====================6.Issue a token using ascc========================" 165 issueToken INK 166 167 echo_b "=====================7.Transfer 10 amount of INK=====================" 168 makeTransfer 169 170 echo_b "=====================8.Query transfer result of From account=====================" 171 chaincodeQueryA 172 173 echo_b "=====================9.Query transfer result of To account=====================" 174 chaincodeQueryB 175 176 echo_b "=====================0. Init for test Asset=====================" 177 echo_b "=====================0.1 add 2 user=======================" 178 assetInvoke_AddUser01 179 assetInvoke_AddUser02 180 181 echo_b "=====================0.2 query 2 user=======================" 182 assetQuery_User01 183 assetQuery_User02 184 185 186 echo_b "=====================0.3 add asset=======================" 187 assetInvoke_AddAsset 188 assetInvoke_AddAsset2 189 assetInvoke_AddAsset3 190 191 echo_b "=====================0.4 query asset=====================" 192 assetQuery_Asset 193 194 195 echo 196 echo_g "=====================All GOOD, MVE Test completed ===================== " 197 echo 198 exit 0 199