From a83a419258103429979d5507ab9ea987c0687521 Mon Sep 17 00:00:00 2001 From: qiang0723 Date: Wed, 14 Jun 2017 13:30:12 +0800 Subject: [PATCH] add colorful cmd for test scripts --- hyperledger/1.0/scripts/initialize.sh | 40 +++++++++++---------- hyperledger/1.0/scripts/test_1peer.sh | 50 +++++++++++++------------- hyperledger/1.0/scripts/test_4peers.sh | 32 ++++++++++------- 3 files changed, 66 insertions(+), 56 deletions(-) diff --git a/hyperledger/1.0/scripts/initialize.sh b/hyperledger/1.0/scripts/initialize.sh index 147f496c..10bbeb54 100644 --- a/hyperledger/1.0/scripts/initialize.sh +++ b/hyperledger/1.0/scripts/initialize.sh @@ -6,6 +6,8 @@ echo " ==========initialize businesschannel========== " echo " ============================================== " echo +source scripts/header.sh + CHANNEL_NAME="$1" : ${CHANNEL_NAME:="businesschannel"} : ${TIMEOUT:="60"} @@ -13,12 +15,12 @@ COUNTER=1 MAX_RETRY=5 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem -echo "Channel name : "$CHANNEL_NAME +echo_b "Channel name : "$CHANNEL_NAME verifyResult () { if [ $1 -ne 0 ] ; then - echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" - echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" + echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" + echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo exit 1 fi @@ -61,7 +63,7 @@ createChannel() { res=$? cat log.txt verifyResult $res "Channel creation failed" - echo "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== " + echo_g "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== " echo } @@ -77,7 +79,7 @@ updateAnchorPeers() { res=$? cat log.txt verifyResult $res "Anchor peer update failed" - echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== " + echo_g "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== " echo } @@ -88,7 +90,7 @@ joinWithRetry () { cat log.txt if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then COUNTER=` expr $COUNTER + 1` - echo "PEER$1 failed to join the channel, Retry after 2 seconds" + echo_b "PEER$1 failed to join the channel, Retry after 2 seconds" sleep 2 joinWithRetry $1 else @@ -101,7 +103,7 @@ joinChannel () { for ch in 0 1 2 3; do setGlobals $ch joinWithRetry $ch - echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== " + echo_g "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== " sleep 2 echo done @@ -114,7 +116,7 @@ installChaincode () { res=$? cat log.txt verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed" - echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== " + echo_g "===================== Chaincode is installed on remote peer PEER$PEER ===================== " echo } @@ -131,46 +133,46 @@ instantiateChaincode () { res=$? cat log.txt verifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed" - echo "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " + echo_g "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " echo } ## Create channel -echo "Creating channel..." +echo_b "Creating channel..." createChannel ## Join all the peers to the channel -echo "Having all peers join the channel..." +echo_b "Having all peers join the channel..." joinChannel ## Set the anchor peers for each org in the channel -echo "Updating anchor peers for org1..." +echo_b "Updating anchor peers for org1..." updateAnchorPeers 0 -echo "Updating anchor peers for org2..." +echo_b "Updating anchor peers for org2..." updateAnchorPeers 2 ## Install chaincode on Peer0/Org1 and Peer2/Org2 -echo "Installing chaincode on org1/peer0..." +echo_b "Installing chaincode on org1/peer0..." installChaincode 0 -echo "Install chaincode on org1/peer1..." +echo_b "Install chaincode on org1/peer1..." installChaincode 1 -echo "Install chaincode on org2/peer0..." +echo_b "Install chaincode on org2/peer0..." installChaincode 2 -echo "Install chaincode on org2/peer1..." +echo_b "Install chaincode on org2/peer1..." installChaincode 3 # Instantiate chaincode on Peer0/Org2 # Instantiate can only be executed once on any node -echo "Instantiating chaincode on peer0/org2..." +echo_b "Instantiating chaincode on peer0/org2..." instantiateChaincode 2 echo -echo "===================== All GOOD, initialization completed ===================== " +echo_g "===================== All GOOD, initialization completed ===================== " echo echo diff --git a/hyperledger/1.0/scripts/test_1peer.sh b/hyperledger/1.0/scripts/test_1peer.sh index e9806f23..246aa37d 100644 --- a/hyperledger/1.0/scripts/test_1peer.sh +++ b/hyperledger/1.0/scripts/test_1peer.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/header.sh + CHANNEL_NAME="$1" : ${CHANNEL_NAME:="businesschannel"} : ${TIMEOUT:="60"} @@ -7,12 +9,12 @@ COUNTER=0 MAX_RETRY=5 CC_PATH=github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -echo "Channel name : "$CHANNEL_NAME +echo_b "Channel name : "$CHANNEL_NAME verifyResult () { if [ $1 -ne 0 ] ; then - echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" - echo "================== ERROR !!! FAILED to execute MVE ==================" + echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" + echo_r "================== ERROR !!! FAILED to execute MVE ==================" echo exit 1 fi @@ -31,19 +33,19 @@ createChannel() { res=$? verifyResult $res "Channel created failed" fi - echo "================channel \"$CHANNEL_NAME\" is created successfully ===============" + echo_g "================channel \"$CHANNEL_NAME\" is created successfully ===============" } ## Sometimes Join takes time hence RETRY atleast for 5 times joinChannel () { - echo "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== " + echo_b "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== " peer channel join -b ${CHANNEL_NAME}.block -o orderer.example.com:7050 >&log.txt res=$? cat log.txt if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then COUNTER=` expr $COUNTER + 1` - echo "PEER0 failed to join the channel, Retry after 2 seconds" + echo_r "PEER0 failed to join the channel, Retry after 2 seconds" sleep 2 joinWithRetry else @@ -57,7 +59,7 @@ updateAnchorPeers() { res=$? cat log.txt verifyResult $res "Anchor peer update failed" - echo "==== Anchor peers for org1 on mychannel is updated successfully======" + echo_g "==== Anchor peers for org1 on mychannel is updated successfully======" echo } @@ -66,7 +68,7 @@ installChaincode () { res=$? cat log.txt verifyResult $res "Chaincode installation on remote peer0 has Failed" - echo "===================== Chaincode is installed success on remote peer0===================== " + echo_g "===================== Chaincode is installed success on remote peer0===================== " echo } @@ -76,8 +78,8 @@ instantiateChaincode () { res=$? cat log.txt verifyResult $res "Chaincode instantiation on pee0.org1 on channel '$CHANNEL_NAME' failed" - echo "=========== Chaincode Instantiation on peer0.org1 on channel '$CHANNEL_NAME' is successful ========== " - echo "Instantiate spent $(($(date +%s)-starttime)) secs" + echo_g "=========== Chaincode Instantiation on peer0.org1 on channel '$CHANNEL_NAME' is successful ========== " + echo_b "Instantiate spent $(($(date +%s)-starttime)) secs" echo } @@ -88,7 +90,7 @@ chaincodeQuery () { while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 do sleep 3 - echo "Attempting to Query peer0.org1 ...$(($(date +%s)-starttime)) secs" + echo_b "Attempting to Query peer0.org1 ...$(($(date +%s)-starttime)) secs" peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}' >&log.txt test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') test "$VALUE" = "$1" && let rc=0 @@ -96,11 +98,11 @@ chaincodeQuery () { echo cat log.txt if test $rc -eq 0 ; then - echo "===================== Query on peer0.org1 on channel '$CHANNEL_NAME' is successful ===================== " + echo_g "===================== Query on peer0.org1 on channel '$CHANNEL_NAME' is successful ===================== " else - echo "!!!!!!!!!!!!!!! Query result on peer0.org1 is INVALID !!!!!!!!!!!!!!!!" - echo "================== ERROR !!! FAILED to execute MVE test ==================" + echo_r "!!!!!!!!!!!!!!! Query result on peer0.org1 is INVALID !!!!!!!!!!!!!!!!" + echo_r "================== ERROR !!! FAILED to execute MVE test ==================" echo fi } @@ -110,35 +112,35 @@ chaincodeInvoke () { res=$? cat log.txt verifyResult $res "Invoke execution on peer0.org1 failed " - echo "========= Invoke transaction on peer0.org1 on channel '$CHANNEL_NAME' is successful ===== " + echo_g "========= Invoke transaction on peer0.org1 on channel '$CHANNEL_NAME' is successful ===== " echo } -echo "====================1.Create channel(default newchannel) =============================" +echo_b "====================1.Create channel(default newchannel) =============================" createChannel -echo "====================2.Join pee0 to the channel ======================================" +echo_b "====================2.Join pee0 to the channel ======================================" joinChannel -echo "====================3.set anchor peers for org1 in the channel===========================" +echo_b "====================3.set anchor peers for org1 in the channel===========================" updateAnchorPeers -echo "=====================4.Install chaincode test_cc on Peer0/Org0========================" +echo_b "=====================4.Install chaincode test_cc on Peer0/Org0========================" installChaincode -echo "=====================5.Instantiate chaincode, this will take a while, pls waiting...===" +echo_b "=====================5.Instantiate chaincode, this will take a while, pls waiting...===" instantiateChaincode -echo "====================6.Query the existing value of a====================================" +echo_b "====================6.Query the existing value of a====================================" chaincodeQuery 100 -echo "=====================7.Invoke a transaction to transfer 10 from a to b==================" +echo_b "=====================7.Invoke a transaction to transfer 10 from a to b==================" chaincodeInvoke -echo "=====================8.Check if the result of a is 90===================================" +echo_b "=====================8.Check if the result of a is 90===================================" chaincodeQuery 90 echo -echo "=====================9.All GOOD, MVE Test completed ===================== " +echo_g "=====================9.All GOOD, MVE Test completed ===================== " echo exit 0 diff --git a/hyperledger/1.0/scripts/test_4peers.sh b/hyperledger/1.0/scripts/test_4peers.sh index 068b2668..acebf439 100644 --- a/hyperledger/1.0/scripts/test_4peers.sh +++ b/hyperledger/1.0/scripts/test_4peers.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/header.sh + echo echo " ______ __ __ _ _____ ____ _ ______ ______ ______ _____ " echo " / _____| | | | | / \ |_ _| | |\ \ | | / _____| / ______ \ | ___\ \ | ____|" @@ -16,12 +18,12 @@ COUNTER=1 MAX_RETRY=5 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem -echo "Channel name : "$CHANNEL_NAME +echo_b "Channel name : "$CHANNEL_NAME verifyResult () { if [ $1 -ne 0 ] ; then - echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" - echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" + echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" + echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo exit 1 fi @@ -55,7 +57,7 @@ setGlobals () { chaincodeQuery () { PEER=$1 - echo "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== " + echo_b "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== " setGlobals $PEER local rc=1 local starttime=$(date +%s) @@ -65,7 +67,7 @@ chaincodeQuery () { while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 do sleep 3 - echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs" + echo_b "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs" peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') test "$VALUE" = "$2" && let rc=0 @@ -73,10 +75,10 @@ chaincodeQuery () { echo cat log.txt if test $rc -eq 0 ; then - echo "===================== Query on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " + echo_g "===================== Query on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " else - echo "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!" - echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" + echo_r "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!" + echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo exit 1 fi @@ -95,29 +97,33 @@ chaincodeInvoke () { res=$? cat log.txt verifyResult $res "Invoke execution on PEER$PEER failed " - echo "===================== Invoke transaction on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " + echo_g "===================== Invoke transaction on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " echo } #Query on chaincode on Peer0/Org1 -echo "Querying chaincode on org1/peer0..." +echo_b "Querying chaincode on org1/peer0..." chaincodeQuery 2 100 #Invoke on chaincode on Peer0/Org1 -echo "Sending invoke transaction on org1/peer0..." +echo_b "Sending invoke transaction on org1/peer0..." chaincodeInvoke 1 #Query on chaincode on Peer1/Org2, check if the result is 90 -echo "Querying chaincode on org2/peer1..." +echo_b "Querying chaincode on org2/peer1..." chaincodeQuery 3 90 +#Invoke on chaincode on Peer1/Org2 +echo_b "Sending invoke transaction on org2/peer1..." chaincodeInvoke 3 +#Query on chaincode on Peer1/Org2, check if the result is 80 +echo_b "Querying chaincode on org2/peer1..." chaincodeQuery 3 80 echo -echo "===================== All GOOD, End-2-End execution completed ===================== " +echo_g "===================== All GOOD, End-2-End execution completed ===================== " echo echo