github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/test_asset_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 # 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 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 assetQuery_Asset () { 41 echo_b "Attempting to Query asset " 42 sleep 3 43 peer chaincode query -C mychannel -n asset -c '{"Args":["readAsset","Blockchain Guide"]}' >log.txt 44 45 res=$? 46 cat log.txt 47 verifyResult $res "query asset: Failed." 48 } 49 50 chaincodeQueryBuyer () { 51 echo_b "Attempting to query account B's balance on peer " 52 sleep 3 53 peer chaincode query -C mychannel -n token -c '{"Args":["getBalance","i07caf88941eafcaaa3370657fccc261acb75dfba","INK"]}' >log.txt 54 res=$? 55 cat log.txt 56 verifyResult $res "query account B Failed." 57 58 } 59 60 assetInvoke_Buy () { 61 echo_b "Attempting to buy asset " 62 sleep 3 63 64 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["buyAsset","Blockchain Guide","Rose"]}' -i "10" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt 65 66 res=$? 67 cat log.txt 68 verifyResult $res "query asset: To The Moon Failed." 69 } 70 71 assetInvoke_Delete () { 72 echo_b "Attempting to delete asset " 73 sleep 3 74 75 peer chaincode invoke -C mychannel -n asset --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -c '{"Args":["deleteAsset","Blockchain Guide"]}' -i "10" -z 344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5 >&log.txt 76 77 res=$? 78 cat log.txt 79 verifyResult $res "query asset: To The Moon Failed." 80 } 81 82 assetQueryRange_Asset () { 83 echo_b "Attempting to Query asset " 84 sleep 3 85 peer chaincode query -C mychannel -n asset -c '{"Args":["readAssetByRange","",""]}' >log.txt 86 87 res=$? 88 cat log.txt 89 verifyResult $res "range query asset failed." 90 } 91 92 echo_b "=====================Test Asset's buyAsset invoke=====================" 93 echo_b "=====================1.query asset=====================" 94 assetQuery_Asset 95 96 echo_b "=====================2.0 query balance before transfer asset=====================" 97 chaincodeQueryBuyer 98 99 echo_b "=====================2.1 transfer asset=====================" 100 assetInvoke_Buy 101 102 echo_b "=====================2.2 query balance after transfer asset=====================" 103 chaincodeQueryBuyer 104 105 echo_b "=====================3. query asset=====================" 106 assetQuery_Asset 107 108 echo_b "=====================Test Asset's delete invoke=====================" 109 echo_b "=====================4.delete asset=====================" 110 assetInvoke_Delete 111 112 113 echo_b "=====================5. query all the assets=====================" 114 assetQueryRange_Asset 115 116 echo 117 echo_g "=====================All GOOD, MVE Test completed ===================== " 118 echo 119 exit 0 120