github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/regression/daily/chaincodeTests/fabricFeatureChaincodes/e2e_test_example02.sh (about) 1 #!/bin/bash 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 9 START_TIME=$(date +%s) 10 11 ##### GLOBALS ###### 12 CHANNEL_NAME="$1" 13 CHANNELS="$2" 14 CHAINCODES="$3" 15 ENDORSERS="$4" 16 fun="$5" 17 18 ##### SET DEFAULT VALUES ##### 19 : ${CHANNEL_NAME:="mychannel"} 20 : ${CHANNELS:="1"} 21 : ${CHAINCODES:="1"} 22 : ${ENDORSERS:="4"} 23 : ${TIMEOUT:="60"} 24 COUNTER=1 25 MAX_RETRY=5 26 CHAINCODE_NAME="myccex02" 27 LOG_FILE="scripts1/logs.txt" 28 TEMP_LOG_FILE="scripts1/temp_logs.txt" 29 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 30 31 verifyResult () { 32 if [ $1 -ne 0 ] ; then 33 echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" >>$LOG_FILE 34 echo "================== ERROR !!! FAILED to execute End-2-End Scenario example02 ==================" >>$LOG_FILE 35 echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" 36 echo "================== ERROR !!! FAILED to execute End-2-End Scenario example02 ==================" 37 echo 38 exit 1 39 fi 40 } 41 42 setGlobals () { 43 if [ $1 -eq 0 -o $1 -eq 1 ] ; then 44 export CORE_PEER_LOCALMSPID="Org1MSP" 45 export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt 46 export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp 47 if [ $1 -eq 0 ]; then 48 export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 49 else 50 export CORE_PEER_ADDRESS=peer1.org1.example.com:7051 51 export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp 52 fi 53 else 54 export CORE_PEER_LOCALMSPID="Org2MSP" 55 export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt 56 export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp 57 if [ $1 -eq 2 ]; then 58 export CORE_PEER_ADDRESS=peer0.org2.example.com:7051 59 else 60 export CORE_PEER_ADDRESS=peer1.org2.example.com:7051 61 fi 62 fi 63 } 64 65 installChaincode () { 66 for (( i=0; $i<$ENDORSERS; i++)) 67 do 68 for (( ch=0; $ch<$CHAINCODES; ch++)) 69 do 70 PEER=$i 71 setGlobals $PEER 72 peer chaincode install -n $CHAINCODE_NAME$ch -v 1 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >>$LOG_FILE 73 res=$? 74 verifyResult $res "Chaincode '$CHAINCODE_NAME$ch' installation on remote peer PEER$PEER has Failed" 75 echo "===================== Chaincode '$CHAINCODE_NAME$ch' is installed on PEER$PEER successfully===================== " >>$LOG_FILE 76 echo "===================== Chaincode '$CHAINCODE_NAME$ch' is installed on PEER$PEER successfully===================== " 77 echo 78 done 79 done 80 } 81 82 instantiateChaincode () { 83 PEER=$1 84 for (( i=0; $i<$CHANNELS; i++)) 85 do 86 for (( ch=0; $ch<$CHAINCODES; ch++)) 87 do 88 setGlobals $PEER 89 if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then 90 peer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME$i -n $CHAINCODE_NAME$ch -v 1 -c '{"Args":["init","a","1000","b","2000"]}' -P "OR ('Org0MSP.member','Org1MSP.member')" >>$LOG_FILE 91 else 92 peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME$i -n $CHAINCODE_NAME$ch -v 1 -c '{"Args":["init","a","1000","b","2000"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >>$LOG_FILE 93 fi 94 res=$? 95 verifyResult $res "Chaincode '$CHAINCODE_NAME$ch' instantiation on PEER$PEER on channel '$CHANNEL_NAME$i' failed" 96 echo "===================== Chaincode '$CHAINCODE_NAME$ch' Instantiation on PEER$PEER on '$CHANNEL_NAME$i' is successful ===================== ">>$LOG_FILE 97 echo "===================== Chaincode '$CHAINCODE_NAME$ch' Instantiation on PEER$PEER on '$CHANNEL_NAME$i' is successful ===================== " 98 echo 99 done 100 done 101 } 102 103 chaincodeInvoke () { 104 local CH_NUM=$1 105 local CHAIN_NUM=$2 106 local PEER=$3 107 setGlobals $PEER 108 if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then 109 peer chaincode invoke -o ordere.example.com:7050 -C $CHANNEL_NAME$CH_NUM -n $CHAINCODE_NAME$CHAIN_NUM -c '{"Args":["invoke","a","b","10"]}' >>$LOG_FILE 110 else 111 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME$CH_NUM -n $CHAINCODE_NAME$CHAIN_NUM -c '{"Args":["invoke","a","b","10"]}' >>$LOG_FILE 112 fi 113 res=$? 114 verifyResult $res "Invoke execution on PEER$PEER failed " 115 echo "===================== Invoke transaction on PEER$PEER on $CHANNEL_NAME$CH_NUM/$CHAINCODE_NAME$CHAIN_NUM is successful ===================== ">>$LOG_FILE 116 echo "===================== Invoke transaction on PEER$PEER on $CHANNEL_NAME$CH_NUM/$CHAINCODE_NAME$CHAIN_NUM is successful ===================== " 117 echo 118 } 119 120 121 chaincodeQuery () { 122 local channel_num=$1 123 local chain_num=$2 124 local peer=$3 125 local res=$4 126 echo "===================== Querying on PEER$peer on $CHANNEL_NAME$channel_num/$CHAINCODE_NAME$chain_num... ===================== " 127 local rc=1 128 local starttime=$(date +%s) 129 130 # continue to poll 131 # we either get a successful response, or reach TIMEOUT 132 while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 133 do 134 sleep 3 135 echo "Attempting to Query PEER$peer ...$(($(date +%s)-starttime)) secs" >>$LOG_FILE 136 peer chaincode query -C $CHANNEL_NAME$channel_num -n $CHAINCODE_NAME$chain_num -c '{"Args":["query","a"]}' >$TEMP_LOG_FILE 137 cat $TEMP_LOG_FILE >>$LOG_FILE 138 test $? -eq 0 && VALUE=$(cat $TEMP_LOG_FILE | awk '/Query Result/ {print $NF}') 139 test "$VALUE" = "$res" && let rc=0 140 done 141 echo 142 if test $rc -eq 0 ; then 143 echo "===================== Query on PEER$peer on $CHANNEL_NAME$channel_num/$CHAINCODE_NAME$chain_num is successful ===================== " >>$LOG_FILE 144 echo "===================== Query on PEER$peer on $CHANNEL_NAME$channel_num/$CHAINCODE_NAME$chain_num is successful ===================== " 145 echo 146 else 147 echo "!!!!!!!!!!!!!!! Query result on PEER$peer is INVALID !!!!!!!!!!!!!!!!" >>$LOG_FILE 148 echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================">>$LOG_FILE 149 echo "!!!!!!!!!!!!!!! Query result on PEER$peer is INVALID !!!!!!!!!!!!!!!!" 150 echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" 151 echo 152 echo "Total execution time $(($(date +%s)-START_TIME)) secs">>$LOG_FILE 153 echo 154 exit 1 155 fi 156 } 157 158 validateArgs () { 159 echo "Inside Validate Args fun = $fun" 160 if [ -z "${fun}" ]; then 161 exit 1 162 fi 163 if [ "${fun}" = "install" -o "${fun}" == "instantiate" -o "${fun}" == "invokeQuery" ]; then 164 return 165 else 166 echo "Invalid Argument in validateArgs from e2e_test_example02">>$LOG_FILE 167 echo "Invalid Argument in validateArgs from e2e_test_example02" 168 exit 1 169 fi 170 } 171 172 validateArgs 173 if [ "${fun}" = "install" ]; then 174 ## Install chaincode on all peers 175 installChaincode 176 177 elif [ "${fun}" == "instantiate" ]; then 178 #Instantiate chaincode on Peer2/Org1 179 echo "Instantiating chaincode on all channels on PEER0 ..." 180 instantiateChaincode 2 181 182 elif [ "${fun}" == "invokeQuery" ]; then 183 #Invoke/Query on all chaincodes on all channels 184 echo "send Invokes/Queries on all channels ..." 185 for (( ch=0; $ch<$CHANNELS; ch++)) 186 do 187 for (( chain=0; $chain<$CHAINCODES; chain++)) 188 do 189 AVAL=1000 190 for (( peer_number=0;peer_number<4;peer_number++)) 191 do 192 setGlobals "$peer_number" 193 chaincodeQuery $ch $chain $peer_number "$AVAL" 194 chaincodeInvoke $ch $chain $peer_number 195 AVAL=` expr $AVAL - 10 ` 196 chaincodeQuery $ch $chain $peer_number "$AVAL" 197 done 198 done 199 done 200 echo "===================== End-2-End for chaincode example02 completed successfully ===================== " >>$LOG_FILE 201 echo "===================== End-2-End for chaincode example02 completed successfully ===================== " 202 echo 203 echo "Total execution time $(($(date +%s)-START_TIME)) secs" >>$LOG_FILE 204 echo 205 exit 0 206 else 207 exit 1 208 fi