diff --git a/first-network/scripts/script.sh b/first-network/scripts/script.sh index 7f9aa81cce..320c2aff2c 100755 --- a/first-network/scripts/script.sh +++ b/first-network/scripts/script.sh @@ -94,11 +94,21 @@ installChaincode 0 2 ## query whether the chaincode is installed queryInstalled 0 1 -## approve the definition for both orgs +## approve the definition for org1 approveForMyOrg 1 0 1 + +## query the approval status on both orgs, expect org1 to have approved and org2 not to +queryStatus 1 0 1 "\"Org1MSP\": true" "\"Org2MSP\": false" +queryStatus 1 0 2 "\"Org1MSP\": true" "\"Org2MSP\": false" + +## now approve also for org2 approveForMyOrg 1 0 2 -## commit the definition +## query the approval status on both orgs, expect them both to have approved +queryStatus 1 0 1 "\"Org1MSP\": true" "\"Org2MSP\": true" +queryStatus 1 0 2 "\"Org1MSP\": true" "\"Org2MSP\": true" + +## now that we know for sure both orgs have approved, commit the definition commitChaincodeDefinition 1 0 1 0 2 ## query on both orgs to see that the definition committed ok diff --git a/first-network/scripts/utils.sh b/first-network/scripts/utils.sh index c46ab96ed8..592cd249bc 100755 --- a/first-network/scripts/utils.sh +++ b/first-network/scripts/utils.sh @@ -170,11 +170,11 @@ approveForMyOrg() { if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then set -x - peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >&log.txt + peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${VERSION} --waitForEvent >&log.txt set +x else set -x - peer lifecycle chaincode approveformyorg --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >&log.txt + peer lifecycle chaincode approveformyorg --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${VERSION} --waitForEvent >&log.txt set +x fi cat log.txt @@ -196,12 +196,12 @@ commitChaincodeDefinition() { # it using the "-o" option if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then set -x - peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence 1 --init-required >&log.txt + peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --init-required >&log.txt res=$? set +x else set -x - peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence 1 --init-required >&log.txt + peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --init-required >&log.txt res=$? set +x fi @@ -211,6 +211,47 @@ commitChaincodeDefinition() { echo } +# queryStatus VERSION PEER ORG +queryStatus() { + VERSION=$1 + PEER=$2 + ORG=$3 + shift 3 + setGlobals $PEER $ORG + echo "===================== Querying approval status on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME'... ===================== " + local rc=1 + local starttime=$(date +%s) + + # continue to poll + # we either get a successful response, or reach TIMEOUT + while + test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0 + do + sleep $DELAY + echo "Attempting to Query approval status on peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs" + set -x + peer lifecycle chaincode queryapprovalstatus --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --init-required >&log.txt + res=$? + set +x + test $res -eq 0 || continue + let rc=0 + for var in "$@" + do + grep "$var" log.txt &>/dev/null || let rc=1 + done + done + echo + cat log.txt + if test $rc -eq 0; then + echo "===================== Query approval status successful on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== " + else + echo "!!!!!!!!!!!!!!! Query approval status result on peer${PEER}.org${ORG} is INVALID !!!!!!!!!!!!!!!!" + echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" + echo + exit 1 + fi +} + # queryCommitted VERSION PEER ORG queryCommitted() { VERSION=$1 @@ -228,7 +269,7 @@ queryCommitted() { test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0 do sleep $DELAY - echo "Attempting to Query peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs" + echo "Attempting to Query committed status on peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs" set -x peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name mycc >&log.txt res=$?