diff --git a/hyperledger_fabric/1.0.4/scripts/func.sh b/hyperledger_fabric/1.0.4/scripts/func.sh index cad620db..a05d426a 100644 --- a/hyperledger_fabric/1.0.4/scripts/func.sh +++ b/hyperledger_fabric/1.0.4/scripts/func.sh @@ -13,44 +13,42 @@ else alias echo_b="echo" fi -CHANNEL_NAME="$1" -: ${CHANNEL_NAME:="businesschannel"} +# Define those global variables +if [ -f ./variables.sh ]; then + source ./variables.sh +elif [ -f scripts/variables.sh ]; then + source scripts/variables.sh +fi -CC_NAME=mycc - -: ${TIMEOUT:="60"} -COUNTER=1 -MAX_RETRY=5 - -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 +# Verify $1 is not 0, then output error msg $2 verifyResult () { if [ $1 -ne 0 ] ; then - echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" - echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" - echo - exit 1 + echo_b "$2" + echo_r "=== ERROR !!! FAILED to execute End-2-End Scenario ===" + exit 1 fi } +# Set global env variables for fabric usage setGlobals () { if [ $1 -eq 0 -o $1 -eq 1 ] ; then CORE_PEER_LOCALMSPID="Org1MSP" - 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 - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp + CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_PEER0_TLS_ROOTCERT} + CORE_PEER_MSPCONFIGPATH=${ORG1_ADMIN_MSP} if [ $1 -eq 0 ]; then - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + CORE_PEER_ADDRESS=${ORG1_PEER0_URL} else - CORE_PEER_ADDRESS=peer1.org1.example.com:7051 + CORE_PEER_ADDRESS=${ORG1_PEER1_URL} fi else CORE_PEER_LOCALMSPID="Org2MSP" - 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 - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp + CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_PEER0_TLS_ROOTCERT} + CORE_PEER_MSPCONFIGPATH=${ORG2_ADMIN_MSP} if [ $1 -eq 2 ]; then - CORE_PEER_ADDRESS=peer0.org2.example.com:7051 + CORE_PEER_ADDRESS=${ORG2_PEER0_URL} else - CORE_PEER_ADDRESS=peer1.org2.example.com:7051 + CORE_PEER_ADDRESS=${ORG2_PEER1_URL} fi fi @@ -60,8 +58,8 @@ setGlobals () { checkOSNAvailability() { #Use orderer's MSP for fetching system channel config block CORE_PEER_LOCALMSPID="OrdererMSP" - CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER_CA - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp + CORE_PEER_TLS_ROOTCERT_FILE=${ORDERER_TLS_CA} + CORE_PEER_MSPCONFIGPATH=${ORDERER_MSP} local rc=1 local starttime=$(date +%s) @@ -73,9 +71,9 @@ checkOSNAvailability() { sleep 3 echo "Attempting to fetch system channel 'testchainid' ...$(($(date +%s)-starttime)) secs" if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then - peer channel fetch 0 -o orderer.example.com:7050 -c "testchainid" >&log.txt + peer channel fetch 0 -o ${ORDERER_URL} -c "testchainid" >&log.txt else - peer channel fetch 0 -o orderer.example.com:7050 -c "testchainid" --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt + peer channel fetch 0 -o ${ORDERER_URL} -c "testchainid" --tls $CORE_PEER_TLS_ENABLED --cafile ${ORDERER_TLS_CA} >&log.txt fi test $? -eq 0 && VALUE=$(cat log.txt | awk '/Received block/ {print $NF}') test "$VALUE" = "0" && let rc=0 @@ -86,203 +84,261 @@ checkOSNAvailability() { echo } -# Use peer0/org1 to create a channel -channelCreate() { - CHANNEL_NAME=$1 - echo_b "=== Create Channel \"$CHANNEL_NAME\" === " - setGlobals 0 +# Internal func called by channelCreate +channelCreateAction(){ + local channel=$1 if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then peer channel create \ - -o orderer.example.com:7050 \ - -c $CHANNEL_NAME \ + -o ${ORDERER_URL} \ + -c ${channel} \ -f ./channel-artifacts/channel.tx \ --timeout $TIMEOUT \ >&log.txt else peer channel create \ - -o orderer.example.com:7050 \ - -c $CHANNEL_NAME \ + -o ${ORDERER_URL} \ + -c ${channel} \ -f ./channel-artifacts/channel.tx \ - --tls $CORE_PEER_TLS_ENABLED \ - --cafile $ORDERER_CA \ --timeout $TIMEOUT \ + --tls $CORE_PEER_TLS_ENABLED \ + --cafile ${ORDERER_TLS_CA} \ >&log.txt fi - res=$? + return $? +} + +# Use peer0/org1 to create a channel +channelCreate() { + local channel=$1 + local counter=0 + local res=1 + echo_b "=== Create Channel ${channel}\" === " + setGlobals 0 + while [ $counter -lt ${MAX_RETRY} -a ${res} -ne 0 ]; do + res=$(channelCreateAction ${channel}) + let counter=${counter}+1 + #COUNTER=` expr $COUNTER + 1` + echo_b "Fail to create channel ${channel}, Retry after 3 seconds" + sleep 3 + done cat log.txt - if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then - COUNTER=` expr $COUNTER + 1` - echo_b "Fail to create channel $CHANNEL_NAME, Retry after 3 seconds" - sleep 3 - channelCreate $CHANNEL_NAME - else - COUNTER=1 - fi - verifyResult $res "Channel creation failed" - echo_g "=== Channel \"$CHANNEL_NAME\" is created successfully === " + verifyResult ${res} "Channel creation failed" + echo_g "=== Channel ${channel} is created successfully === " echo } -updateAnchorPeers() { - CHANNEL_NAME=$1 - PEER=$2 - setGlobals $PEER - echo_b "=== Update Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" === " - if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then - peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx >&log.txt - else - peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt - fi - res=$? - cat log.txt - verifyResult $res "Anchor peer update failed" - echo_g "=== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully === " - sleep 5 - echo +# called by channelJoinWithRetry +channelJoinAction () { + local channel=$1 + peer channel join \ + -b ${channel}.block \ + >&log.txt } - ## Sometimes Join takes time hence RETRY atleast for 5 times channelJoinWithRetry () { - peer channel join -b $CHANNEL_NAME.block >&log.txt - res=$? - cat log.txt - if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then - COUNTER=` expr $COUNTER + 1` - echo_b "PEER$1 failed to join the channel, Retry after 2 seconds" + local channel=$1 + local peer=$2 + local counter=0 + local res=1 + while [ ${counter} -lt ${MAX_RETRY} -a ${res} -ne 0 ]; do + res=$(channelJoinAction ${channel}) + let counter=$counter+1 + echo_b "peer${peer} failed to join the channel, Retry after 2 seconds" sleep 2 - channelJoinWithRetry $1 - else - COUNTER=1 - fi - verifyResult $res "After $MAX_RETRY attempts, PEER$1 has failed to Join the Channel" + done + cat log.txt + verifyResult $res "After $MAX_RETRY attempts, peer${peer} has failed to Join the Channel" } # Join given (by default all) peers into the channel +# channelJoin 0 1 2 3 channelJoin () { - CHANNEL_NAME=$1 - echo_b "=== Join peers into the channel \"$CHANNEL_NAME\" === " + local channel=$1 + echo_b "=== Join peers into the channel ${channel} === " peers_to_join=$(seq 0 3) if [ $# -gt 1 ]; then peers_to_join=${@:2} fi for i in $peers_to_join; do setGlobals $i - channelJoinWithRetry $i - echo_g "=== PEER$i joined into the channel \"$CHANNEL_NAME\" === " - sleep 2 - echo + channelJoinWithRetry ${channel} $i + echo_g "=== peer$i joined into the channel \"${channel}\" === " + sleep 1 done } +# Update the anchor peer at given channel +# updateAnchorPeers channel peer +updateAnchorPeers() { + local channel=$1 + local peer=$2 + setGlobals $peer + echo_b "=== Update Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on ${channel} === " + if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + peer channel update \ + -o ${ORDERER_URL} \ + -c ${channel} \ + -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx \ + >&log.txt + else + peer channel update \ + -o ${ORDERER_URL} \ + -c ${channel} \ + -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx \ + --tls $CORE_PEER_TLS_ENABLED \ + --cafile ${ORDERER_TLS_CA} \ + >&log.txt + fi + res=$? + cat log.txt + verifyResult $res "Anchor peer update failed" + echo_g "=== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on ${channel} is updated successfully === " + sleep 2 +} + +# Install chaincode on specified peer node +# chaincodeInstall peer cc_name version path +chaincodeInstall () { + local peer=$1 + local name=$2 + local version=$3 + local path=$4 + echo_b "=== Install Chaincode $name:$version ($path) on peer$peer === " + setGlobals $peer + peer chaincode install \ + -n ${name} \ + -v $version \ + -p ${path} \ + >&log.txt + res=$? + cat log.txt + verifyResult $res "Chaincode installation on remote peer$peer has Failed" + echo_g "=== Chaincode is installed on remote peer$peer === " + echo +} + # Instantiate chaincode on specifized peer node +# chaincodeInstantiate channel peer name version args chaincodeInstantiate () { - CHANNEL_NAME=$1 - PEER=$2 - setGlobals $PEER - echo_b "=== chaincodeInstantiate for channel $CHANNEL_NAME on peer $PEER ====" + local channel=$1 + local peer=$2 + local name=$3 + local version=$4 + local args=$5 + setGlobals $peer + echo_b "=== chaincodeInstantiate for channel ${channel} on peer $peer ====" # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), # lets supply it directly as we know it using the "-o" option + set -x if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then peer chaincode instantiate \ - -o orderer.example.com:7050 \ - -C $CHANNEL_NAME \ - -n $CC_NAME \ - -v 1.0 \ - -c '{"Args":["init","a","100","b","200"]}' \ + -o ${ORDERER_URL} \ + -C ${channel} \ + -n ${name} \ + -v ${version} \ + -c ${args} \ -P "OR ('Org1MSP.member','Org2MSP.member')" \ >&log.txt else peer chaincode instantiate \ - -o orderer.example.com:7050 \ - -C $CHANNEL_NAME \ - -n $CC_NAME \ - -v 1.0 \ - -c '{"Args":["init","a","100","b","200"]}' \ + -o ${ORDERER_URL} \ + -C ${channel} \ + -n ${name} \ + -v ${version} \ + -c ${args} \ -P "OR ('Org1MSP.member','Org2MSP.member')" \ --tls $CORE_PEER_TLS_ENABLED \ - --cafile $ORDERER_CA \ + --cafile ${ORDERER_TLS_CA} \ >&log.txt fi res=$? cat log.txt - verifyResult $res "ChaincodeInstantiation on PEER$PEER in channel '$CHANNEL_NAME' failed" - echo_g "=== ChaincodeInstantiation on PEER$PEER in channel '$CHANNEL_NAME' is successful ===" + verifyResult $res "ChaincodeInstantiation on peer$peer in channel '${channel}' failed" + echo_g "=== ChaincodeInstantiation on peer$peer in channel '${channel}' is successful ===" echo } + +# channel peer name args +chaincodeInvoke () { + local channel=$1 + local peer=$2 + local name=$3 + local args=$4 + echo_g "=== Invoke transaction on peer$peer in channel '${channel}'=== " + setGlobals $peer + # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), + # lets supply it directly as we know it using the "-o" option + if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + peer chaincode invoke \ + -o ${ORDERER_URL} \ + -C ${channel} \ + -n ${name} \ + -c ${args} \ + >&log.txt + else + peer chaincode invoke \ + -o ${ORDERER_URL} \ + -C ${channel} \ + -n ${name} \ + -c ${args} \ + --tls $CORE_PEER_TLS_ENABLED \ + --cafile ${ORDERER_TLS_CA} \ + >&log.txt + fi + res=$? + cat log.txt + verifyResult $res "Invoke execution on peer$peer failed " + echo_g "=== Invoke transaction on peer$peer in channel '${channel}' is successful === " + echo +} + +# query channel peer name args expected_result chaincodeQuery () { - PEER=$1 - echo_b "=== Querying on PEER$PEER in channel '$CHANNEL_NAME'... === " - setGlobals $PEER + local channel=$1 + local peer=$2 + local name=$3 + local args=$4 + local expected_result=$5 + echo_b "=== Querying on peer$peer in channel '${channel}'... === " local rc=1 local starttime=$(date +%s) - # continue to poll + setGlobals $peer # we either get a successful response, or reach TIMEOUT while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 do sleep 3 - echo_b "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs" - peer chaincode query -C $CHANNEL_NAME -n $CC_NAME -c '{"Args":["query","a"]}' >&log.txt + echo_b "Attempting to Query peer$peer ...$(($(date +%s)-starttime)) secs" + peer chaincode query \ + -C ${channel} \ + -n ${name} \ + -c ${args} \ + >&log.txt test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') - test "$VALUE" = "$2" && let rc=0 + test "$VALUE" = "${expected_result}" && let rc=0 done echo cat log.txt if test $rc -eq 0 ; then - echo_g "=== Query on PEER$PEER in channel '$CHANNEL_NAME' is successful === " + echo_g "=== Query on peer$peer in channel '${channel}' is successful === " else - echo_r "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!" - echo_r "================== 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 } -chaincodeInvoke () { - PEER=$1 - echo_g "=== Invoke transaction on PEER$PEER in channel '$CHANNEL_NAME'=== " - setGlobals $PEER - # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), - # lets supply it directly as we know it using the "-o" option - if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then - peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n $CC_NAME -c '{"Args":["invoke","a","b","10"]}' >&log.txt - else - peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n $CC_NAME -c '{"Args":["invoke","a","b","10"]}' >&log.txt - fi - res=$? - cat log.txt - verifyResult $res "Invoke execution on PEER$PEER failed " - echo_g "=== Invoke transaction on PEER$PEER in channel '$CHANNEL_NAME' is successful === " - echo -} - -# Install chaincode on specifized peer node -chaincodeInstall () { - PEER=$1 - echo_b "=== Install Chaincode on remote peer PEER$PEER === " - VERSION=$2 - setGlobals $PEER - peer chaincode install \ - -n $CC_NAME \ - -v $VERSION \ - -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 \ - >&log.txt - res=$? - cat log.txt - verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed" - echo_g "=== Chaincode is installed on remote peer PEER$PEER === " - echo -} # Start chaincode with dev mode chaincodeStartDev () { - PEER=$1 - VERSION=$2 - setGlobals $PEER + local peer=$1 + local version=$2 + setGlobals $peer CORE_CHAINCODE_LOGLEVEL=debug \ - CORE_PEER_ADDRESS=peer${PEER}.org1.example.com:7052 \ - CORE_CHAINCODE_ID_NAME=mycc:${VERSION} \ + CORE_PEER_ADDRESS=peer${peer}.org1.example.com:7052 \ + CORE_CHAINCODE_ID_NAME=mycc:${version} \ nohup ./scripts/chaincode_example02 > chaincode_dev.log & res=$? cat log.txt @@ -291,50 +347,70 @@ chaincodeStartDev () { echo } -# chaincodeUpgrade 0 1.1 +# chaincodeUpgrade channel peer name version args chaincodeUpgrade () { - CHANNEL_NAME=$1 - PEER=$2 - VERSION=$3 - echo_b "=== Upgrade chaincode to version $VERSION on PEER$PEER in channel '$CHANNEL_NAME' === " - setGlobals $PEER + local channel=$1 + local peer=$2 + local name=$3 + local version=$4 + local args=$5 + echo_b "=== Upgrade chaincode to version $version on peer$peer in channel '${channel}' === " + + setGlobals $peer # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), # lets supply it directly as we know it using the "-o" option if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then - peer chaincode upgrade -o orderer.example.com:7050 -C $CHANNEL_NAME -n $CC_NAME -c '{"Args":["upgrade","a","100","b","200"]}' -v $VERSION >&log.txt + peer chaincode upgrade \ + -o ${ORDERER_URL} \ + -C ${channel} \ + -n ${name} \ + -v ${version} \ + -c ${args} \ + >&log.txt else - peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n $CC_NAME -c '{"Args":["upgrade","a","100","b","200"]}' -v $VERSION >&log.txt + peer chaincode upgrade \ + -o ${ORDERER_URL} \ + -C ${channel} \ + -n ${name} \ + -v ${version} \ + -c ${args} \ + --tls $CORE_PEER_TLS_ENABLED \ + --cafile ${ORDERER_TLS_CA} \ + >&log.txt fi res=$? cat log.txt - verifyResult $res "Upgrade execution on PEER$PEER failed " - echo_g "=== Upgrade transaction on PEER$PEER in channel '$CHANNEL_NAME' is successful === " + verifyResult $res "Upgrade execution on peer$peer failed " + echo_g "=== Upgrade transaction on peer$peer in channel '${channel}' is successful === " echo } +# Fetch some block from a given channel: channel, peer, blockNum channelFetch () { - PEER=$1 - BLOCK_NO=$2 - echo_b "=== Fetch block $BLOCK_NO on PEER$PEER in channel '$CHANNEL_NAME' === " - setGlobals $PEER + local channel=$1 + local peer=$2 + local blockNum=$3 + echo_b "=== Fetch block $blockNum on peer$peer in channel '$channel' === " + + setGlobals $peer # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), # lets supply it directly as we know it using the "-o" option if [ -z "${CORE_PEER_TLS_ENABLED}" -o "${CORE_PEER_TLS_ENABLED}" = "false" ]; then - peer channel fetch $BLOCK_NO block_${BLOCK_NO}.block \ - -o orderer.example.com:7050 \ - -c ${CHANNEL_NAME} \ + peer channel fetch $blockNum block_${blockNum}.block \ + -o ${ORDERER_URL} \ + -c ${channel} \ >&log.txt else - peer channel fetch $BLOCK_NO block_${BLOCK_NO}.block \ - -o orderer.example.com:7050 \ - -c $CHANNEL_NAME \ + peer channel fetch $blockNum block_${blockNum}.block \ + -o ${ORDERER_URL} \ + -c ${channel} \ --tls \ - --cafile $ORDERER_CA \ + --cafile ${ORDERER_TLS_CA} \ >&log.txt fi res=$? cat log.txt - verifyResult $res "Fetch block on PEER$PEER failed " - echo_g "=== Fetch block on PEER$PEER in channel '$CHANNEL_NAME' is successful === " + verifyResult $res "Fetch block on peer$peer failed" + echo_g "=== Fetch block on peer$peer in channel '$channel' is successful === " echo } \ No newline at end of file diff --git a/hyperledger_fabric/1.0.4/scripts/init_chaincode.sh b/hyperledger_fabric/1.0.4/scripts/init_chaincode.sh index 2e262619..44fe8685 100644 --- a/hyperledger_fabric/1.0.4/scripts/init_chaincode.sh +++ b/hyperledger_fabric/1.0.4/scripts/init_chaincode.sh @@ -9,16 +9,16 @@ fi ## Install chaincode on all peers echo_b "Installing chaincode on all 4 peers..." -chaincodeInstall 0 1.0 -chaincodeInstall 1 1.0 -chaincodeInstall 2 1.0 -chaincodeInstall 3 1.0 +chaincodeInstall 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} +chaincodeInstall 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} +chaincodeInstall 2 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} +chaincodeInstall 3 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} # Instantiate chaincode on all peers # Instantiate can only be executed once on any node echo_b "Instantiating chaincode on all 2 orgs (once for each org)..." -chaincodeInstantiate $CHANNEL_NAME 0 -chaincodeInstantiate $CHANNEL_NAME 2 +chaincodeInstantiate $CHANNEL_NAME 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS} +chaincodeInstantiate $CHANNEL_NAME 2 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS} echo echo_g "===================== Init chaincode done ===================== " diff --git a/hyperledger_fabric/1.0.4/scripts/init_channel.sh b/hyperledger_fabric/1.0.4/scripts/init_channel.sh index e2a58b9a..174b4b6a 100644 --- a/hyperledger_fabric/1.0.4/scripts/init_channel.sh +++ b/hyperledger_fabric/1.0.4/scripts/init_channel.sh @@ -8,9 +8,9 @@ elif [ -f scripts/func.sh ]; then fi ## Create channel -echo_b "Creating channel $CHANNEL_NAME..." -channelCreate $CHANNEL_NAME +echo_b "Creating channel ${CHANNEL_NAME}..." +channelCreate ${CHANNEL_NAME} ## Join all the peers to the channel -echo_b "Having all peers join the channel $CHANNEL_NAME..." -channelJoin $CHANNEL_NAME 0 1 2 3 \ No newline at end of file +echo_b "Having all peers join the channel ${CHANNEL_NAME}..." +channelJoin ${CHANNEL_NAME} 0 1 2 3 \ No newline at end of file diff --git a/hyperledger_fabric/1.0.4/scripts/initialize_peer0.sh b/hyperledger_fabric/1.0.4/scripts/initialize_peer0.sh index 0235ba57..402322ad 100644 --- a/hyperledger_fabric/1.0.4/scripts/initialize_peer0.sh +++ b/hyperledger_fabric/1.0.4/scripts/initialize_peer0.sh @@ -25,7 +25,7 @@ updateAnchorPeers $CHANNEL_NAME 0 ## Install chaincode on all peers echo_b "Installing chaincode on peer0..." -chaincodeInstall 0 1.0 +chaincodeInstall 0 ${CC_INIT_ARGS} # Instantiate chaincode on all peers # Instantiate can only be executed once on any node diff --git a/hyperledger_fabric/1.0.4/scripts/test_cc_all.sh b/hyperledger_fabric/1.0.4/scripts/test_cc_all.sh index c065794f..62869e53 100644 --- a/hyperledger_fabric/1.0.4/scripts/test_cc_all.sh +++ b/hyperledger_fabric/1.0.4/scripts/test_cc_all.sh @@ -11,39 +11,37 @@ echo_b "Channel name : "$CHANNEL_NAME #Query on chaincode on Peer0/Org1 echo_b "Querying chaincode on peer 3..." -chaincodeQuery 3 100 +chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 100 #Invoke on chaincode on Peer0/Org1 echo_b "Sending invoke transaction (transfer 10) on org1/peer0..." -chaincodeInvoke 0 +chaincodeInvoke ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_INVOKE_ARGS} #Query on chaincode on Peer1/Org2, check if the result is 90 echo_b "Querying chaincode on peer 1 and 3..." -chaincodeQuery 1 90 -chaincodeQuery 3 90 +chaincodeQuery ${CHANNEL_NAME} 1 ${CC_NAME} ${CC_QUERY_ARGS} 90 +chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 90 #Invoke on chaincode on Peer1/Org2 echo_b "Sending invoke transaction on org2/peer3..." -chaincodeInvoke 3 +chaincodeInvoke ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_INVOKE_ARGS} #Query on chaincode on Peer1/Org2, check if the result is 80 echo_b "Querying chaincode on all 4peers..." -chaincodeQuery 0 80 -chaincodeQuery 2 80 +chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 80 +chaincodeQuery ${CHANNEL_NAME} 2 ${CC_NAME} ${CC_QUERY_ARGS} 80 #Upgrade to new version -chaincodeInstall 0 1.1 -chaincodeInstall 1 1.1 -chaincodeInstall 2 1.1 -chaincodeInstall 3 1.1 +chaincodeInstall 0 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH} +chaincodeInstall 1 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH} +chaincodeInstall 2 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH} +chaincodeInstall 3 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH} -chaincodeUpgrade $CHANNEL_NAME 0 1.1 +chaincodeUpgrade ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_UPGRADE_ARGS} -chaincodeQuery 0 100 -chaincodeQuery 3 100 +chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 100 +chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 100 -echo echo_g "===================== All GOOD, End-2-End execution completed ===================== " -echo exit 0 diff --git a/hyperledger_fabric/1.0.4/scripts/test_cc_peer0.sh b/hyperledger_fabric/1.0.4/scripts/test_cc_peer0.sh index fa2a8038..353a8c12 100644 --- a/hyperledger_fabric/1.0.4/scripts/test_cc_peer0.sh +++ b/hyperledger_fabric/1.0.4/scripts/test_cc_peer0.sh @@ -7,20 +7,20 @@ elif [ -f scripts/func.sh ]; then source scripts/func.sh fi -echo_b "Channel name : "$CHANNEL_NAME +echo_b "Channel name: "$CHANNEL_NAME echo_b "====================Query the existing value of a====================================" -chaincodeQuery 0 100 +chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 100 sleep 1 echo_b "=====================Invoke a transaction to transfer 10 from a to b==================" -chaincodeInvoke 0 +chaincodeInvoke ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_INVOKE_ARGS} sleep 1 echo_b "=====================Check if the result of a is 90===================================" -chaincodeQuery 0 90 +chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 90 echo echo_g "=====================All GOOD, MVE Test completed ===================== " diff --git a/hyperledger_fabric/1.0.4/scripts/test_fetch.sh b/hyperledger_fabric/1.0.4/scripts/test_fetch.sh index a0c2b4b4..85b319bd 100644 --- a/hyperledger_fabric/1.0.4/scripts/test_fetch.sh +++ b/hyperledger_fabric/1.0.4/scripts/test_fetch.sh @@ -20,7 +20,7 @@ echo_b "Fetch block 1" channelFetch 0 1 echo_b "Fetch block 2" -channelFetch 0 2 +channelFetch ${CHANNEL_NAME} 0 2 echo_b "Fetch block 3" channelFetch 0 3 diff --git a/hyperledger_fabric/1.0.4/scripts/variables.sh b/hyperledger_fabric/1.0.4/scripts/variables.sh new file mode 100644 index 00000000..a03bdafa --- /dev/null +++ b/hyperledger_fabric/1.0.4/scripts/variables.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Define some global variables for usage. Will be included by func.sh. + +# Name of app channel, need to align with the gen_artifacts.sh +CHANNEL_NAME="businesschannel" + +# Client cmd execute timeout +TIMEOUT="60" + +MAX_RETRY=5 + +# MSP related paths +ORDERER_TLS_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +ORDERER_MSP=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp + +ORG1_PEER0_TLS_ROOTCERT=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +ORG2_PEER0_TLS_ROOTCERT=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +ORG1_ADMIN_MSP=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +ORG2_ADMIN_MSP=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp + + +# Node URLS +ORDERER_URL="orderer.example.com:7050" +ORG1_PEER0_URL="peer0.org1.example.com:7051" +ORG1_PEER1_URL="peer1.org1.example.com:7051" +ORG2_PEER0_URL="peer0.org2.example.com:7051" +ORG2_PEER1_URL="peer1.org2.example.com:7051" + + +# Chaincode related +CC_NAME="mycc" +CC_PATH="github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" +CC_INIT_ARGS='{"Args":["init","a","100","b","200"]}' +CC_INIT_VERSION=1.0 +CC_UPGRADE_ARGS='{"Args":["upgrade","a","100","b","200"]}' +CC_UPGRADE_VERSION=1.1 +CC_INVOKE_ARGS='{"Args":["invoke","a","b","10"]}' +CC_QUERY_ARGS='{"Args":["query","a"]}' + +# TLS config +: ${CORE_PEER_TLS_ENABLED:="false"}