Support func params

pull/108/head
Baohua Yang 2017-11-14 15:29:27 +08:00
parent 450aae69a4
commit f07362d832
8 changed files with 319 additions and 203 deletions

View File

@ -13,44 +13,42 @@ else
alias echo_b="echo" alias echo_b="echo"
fi fi
CHANNEL_NAME="$1" # Define those global variables
: ${CHANNEL_NAME:="businesschannel"} 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 () { verifyResult () {
if [ $1 -ne 0 ] ; then if [ $1 -ne 0 ] ; then
echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" echo_b "$2"
echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo_r "=== ERROR !!! FAILED to execute End-2-End Scenario ==="
echo
exit 1 exit 1
fi fi
} }
# Set global env variables for fabric usage
setGlobals () { setGlobals () {
if [ $1 -eq 0 -o $1 -eq 1 ] ; then if [ $1 -eq 0 -o $1 -eq 1 ] ; then
CORE_PEER_LOCALMSPID="Org1MSP" 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_TLS_ROOTCERT_FILE=${ORG1_PEER0_TLS_ROOTCERT}
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_MSPCONFIGPATH=${ORG1_ADMIN_MSP}
if [ $1 -eq 0 ]; then if [ $1 -eq 0 ]; then
CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_ADDRESS=${ORG1_PEER0_URL}
else else
CORE_PEER_ADDRESS=peer1.org1.example.com:7051 CORE_PEER_ADDRESS=${ORG1_PEER1_URL}
fi fi
else else
CORE_PEER_LOCALMSPID="Org2MSP" 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_TLS_ROOTCERT_FILE=${ORG2_PEER0_TLS_ROOTCERT}
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_MSPCONFIGPATH=${ORG2_ADMIN_MSP}
if [ $1 -eq 2 ]; then if [ $1 -eq 2 ]; then
CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_ADDRESS=${ORG2_PEER0_URL}
else else
CORE_PEER_ADDRESS=peer1.org2.example.com:7051 CORE_PEER_ADDRESS=${ORG2_PEER1_URL}
fi fi
fi fi
@ -60,8 +58,8 @@ setGlobals () {
checkOSNAvailability() { checkOSNAvailability() {
#Use orderer's MSP for fetching system channel config block #Use orderer's MSP for fetching system channel config block
CORE_PEER_LOCALMSPID="OrdererMSP" CORE_PEER_LOCALMSPID="OrdererMSP"
CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER_CA CORE_PEER_TLS_ROOTCERT_FILE=${ORDERER_TLS_CA}
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp CORE_PEER_MSPCONFIGPATH=${ORDERER_MSP}
local rc=1 local rc=1
local starttime=$(date +%s) local starttime=$(date +%s)
@ -73,9 +71,9 @@ checkOSNAvailability() {
sleep 3 sleep 3
echo "Attempting to fetch system channel 'testchainid' ...$(($(date +%s)-starttime)) secs" echo "Attempting to fetch system channel 'testchainid' ...$(($(date +%s)-starttime)) secs"
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then 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 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 fi
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Received block/ {print $NF}') test $? -eq 0 && VALUE=$(cat log.txt | awk '/Received block/ {print $NF}')
test "$VALUE" = "0" && let rc=0 test "$VALUE" = "0" && let rc=0
@ -86,203 +84,261 @@ checkOSNAvailability() {
echo echo
} }
# 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_URL} \
-c ${channel} \
-f ./channel-artifacts/channel.tx \
--timeout $TIMEOUT \
>&log.txt
else
peer channel create \
-o ${ORDERER_URL} \
-c ${channel} \
-f ./channel-artifacts/channel.tx \
--timeout $TIMEOUT \
--tls $CORE_PEER_TLS_ENABLED \
--cafile ${ORDERER_TLS_CA} \
>&log.txt
fi
return $?
}
# Use peer0/org1 to create a channel # Use peer0/org1 to create a channel
channelCreate() { channelCreate() {
CHANNEL_NAME=$1 local channel=$1
echo_b "=== Create Channel \"$CHANNEL_NAME\" === " local counter=0
local res=1
echo_b "=== Create Channel ${channel}\" === "
setGlobals 0 setGlobals 0
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then while [ $counter -lt ${MAX_RETRY} -a ${res} -ne 0 ]; do
peer channel create \ res=$(channelCreateAction ${channel})
-o orderer.example.com:7050 \ let counter=${counter}+1
-c $CHANNEL_NAME \ #COUNTER=` expr $COUNTER + 1`
-f ./channel-artifacts/channel.tx \ echo_b "Fail to create channel ${channel}, Retry after 3 seconds"
--timeout $TIMEOUT \
>&log.txt
else
peer channel create \
-o orderer.example.com:7050 \
-c $CHANNEL_NAME \
-f ./channel-artifacts/channel.tx \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
--timeout $TIMEOUT \
>&log.txt
fi
res=$?
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 sleep 3
channelCreate $CHANNEL_NAME done
else
COUNTER=1
fi
verifyResult $res "Channel creation failed"
echo_g "=== Channel \"$CHANNEL_NAME\" 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 cat log.txt
verifyResult $res "Anchor peer update failed" verifyResult ${res} "Channel creation failed"
echo_g "=== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully === " echo_g "=== Channel ${channel} is created successfully === "
sleep 5
echo 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 ## Sometimes Join takes time hence RETRY atleast for 5 times
channelJoinWithRetry () { channelJoinWithRetry () {
peer channel join -b $CHANNEL_NAME.block >&log.txt local channel=$1
res=$? local peer=$2
cat log.txt local counter=0
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then local res=1
COUNTER=` expr $COUNTER + 1` while [ ${counter} -lt ${MAX_RETRY} -a ${res} -ne 0 ]; do
echo_b "PEER$1 failed to join the channel, Retry after 2 seconds" res=$(channelJoinAction ${channel})
let counter=$counter+1
echo_b "peer${peer} failed to join the channel, Retry after 2 seconds"
sleep 2 sleep 2
channelJoinWithRetry $1 done
else cat log.txt
COUNTER=1 verifyResult $res "After $MAX_RETRY attempts, peer${peer} has failed to Join the Channel"
fi
verifyResult $res "After $MAX_RETRY attempts, PEER$1 has failed to Join the Channel"
} }
# Join given (by default all) peers into the channel # Join given (by default all) peers into the channel
# channelJoin 0 1 2 3
channelJoin () { channelJoin () {
CHANNEL_NAME=$1 local channel=$1
echo_b "=== Join peers into the channel \"$CHANNEL_NAME\" === " echo_b "=== Join peers into the channel ${channel} === "
peers_to_join=$(seq 0 3) peers_to_join=$(seq 0 3)
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
peers_to_join=${@:2} peers_to_join=${@:2}
fi fi
for i in $peers_to_join; do for i in $peers_to_join; do
setGlobals $i setGlobals $i
channelJoinWithRetry $i channelJoinWithRetry ${channel} $i
echo_g "=== PEER$i joined into the channel \"$CHANNEL_NAME\" === " echo_g "=== peer$i joined into the channel \"${channel}\" === "
sleep 2 sleep 1
echo
done done
} }
# Instantiate chaincode on specifized peer node # Update the anchor peer at given channel
chaincodeInstantiate () { # updateAnchorPeers channel peer
CHANNEL_NAME=$1 updateAnchorPeers() {
PEER=$2 local channel=$1
setGlobals $PEER local peer=$2
echo_b "=== chaincodeInstantiate for channel $CHANNEL_NAME on peer $PEER ====" setGlobals $peer
# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), echo_b "=== Update Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on ${channel} === "
# 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 if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer chaincode instantiate \ peer channel update \
-o orderer.example.com:7050 \ -o ${ORDERER_URL} \
-C $CHANNEL_NAME \ -c ${channel} \
-n $CC_NAME \ -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx \
-v 1.0 \
-c '{"Args":["init","a","100","b","200"]}' \
-P "OR ('Org1MSP.member','Org2MSP.member')" \
>&log.txt >&log.txt
else else
peer chaincode instantiate \ peer channel update \
-o orderer.example.com:7050 \ -o ${ORDERER_URL} \
-C $CHANNEL_NAME \ -c ${channel} \
-n $CC_NAME \ -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx \
-v 1.0 \
-c '{"Args":["init","a","100","b","200"]}' \
-P "OR ('Org1MSP.member','Org2MSP.member')" \
--tls $CORE_PEER_TLS_ENABLED \ --tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \ --cafile ${ORDERER_TLS_CA} \
>&log.txt >&log.txt
fi fi
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "ChaincodeInstantiation on PEER$PEER in channel '$CHANNEL_NAME' failed" verifyResult $res "Anchor peer update failed"
echo_g "=== ChaincodeInstantiation on PEER$PEER in channel '$CHANNEL_NAME' is successful ===" 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 echo
} }
# Instantiate chaincode on specifized peer node
# chaincodeInstantiate channel peer name version args
chaincodeInstantiate () {
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_URL} \
-C ${channel} \
-n ${name} \
-v ${version} \
-c ${args} \
-P "OR ('Org1MSP.member','Org2MSP.member')" \
>&log.txt
else
peer chaincode instantiate \
-o ${ORDERER_URL} \
-C ${channel} \
-n ${name} \
-v ${version} \
-c ${args} \
-P "OR ('Org1MSP.member','Org2MSP.member')" \
--tls $CORE_PEER_TLS_ENABLED \
--cafile ${ORDERER_TLS_CA} \
>&log.txt
fi
res=$?
cat log.txt
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 () { chaincodeQuery () {
PEER=$1 local channel=$1
echo_b "=== Querying on PEER$PEER in channel '$CHANNEL_NAME'... === " local peer=$2
setGlobals $PEER local name=$3
local args=$4
local expected_result=$5
echo_b "=== Querying on peer$peer in channel '${channel}'... === "
local rc=1 local rc=1
local starttime=$(date +%s) local starttime=$(date +%s)
# continue to poll setGlobals $peer
# we either get a successful response, or reach TIMEOUT # we either get a successful response, or reach TIMEOUT
while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0
do do
sleep 3 sleep 3
echo_b "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 $CC_NAME -c '{"Args":["query","a"]}' >&log.txt peer chaincode query \
-C ${channel} \
-n ${name} \
-c ${args} \
>&log.txt
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') 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 done
echo echo
cat log.txt cat log.txt
if test $rc -eq 0 ; then 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 else
echo_r "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!" echo_r "!!!!!!!!!!!!!!! Query result on peer$peer is INVALID !!!!!!!!!!!!!!!!"
echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo echo
exit 1 exit 1
fi 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 # Start chaincode with dev mode
chaincodeStartDev () { chaincodeStartDev () {
PEER=$1 local peer=$1
VERSION=$2 local version=$2
setGlobals $PEER setGlobals $peer
CORE_CHAINCODE_LOGLEVEL=debug \ CORE_CHAINCODE_LOGLEVEL=debug \
CORE_PEER_ADDRESS=peer${PEER}.org1.example.com:7052 \ CORE_PEER_ADDRESS=peer${peer}.org1.example.com:7052 \
CORE_CHAINCODE_ID_NAME=mycc:${VERSION} \ CORE_CHAINCODE_ID_NAME=mycc:${version} \
nohup ./scripts/chaincode_example02 > chaincode_dev.log & nohup ./scripts/chaincode_example02 > chaincode_dev.log &
res=$? res=$?
cat log.txt cat log.txt
@ -291,50 +347,70 @@ chaincodeStartDev () {
echo echo
} }
# chaincodeUpgrade 0 1.1 # chaincodeUpgrade channel peer name version args
chaincodeUpgrade () { chaincodeUpgrade () {
CHANNEL_NAME=$1 local channel=$1
PEER=$2 local peer=$2
VERSION=$3 local name=$3
echo_b "=== Upgrade chaincode to version $VERSION on PEER$PEER in channel '$CHANNEL_NAME' === " local version=$4
setGlobals $PEER 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), # 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 # 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 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 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 fi
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Upgrade execution on PEER$PEER failed " verifyResult $res "Upgrade execution on peer$peer failed "
echo_g "=== Upgrade transaction on PEER$PEER in channel '$CHANNEL_NAME' is successful === " echo_g "=== Upgrade transaction on peer$peer in channel '${channel}' is successful === "
echo echo
} }
# Fetch some block from a given channel: channel, peer, blockNum
channelFetch () { channelFetch () {
PEER=$1 local channel=$1
BLOCK_NO=$2 local peer=$2
echo_b "=== Fetch block $BLOCK_NO on PEER$PEER in channel '$CHANNEL_NAME' === " local blockNum=$3
setGlobals $PEER 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), # 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 # 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 if [ -z "${CORE_PEER_TLS_ENABLED}" -o "${CORE_PEER_TLS_ENABLED}" = "false" ]; then
peer channel fetch $BLOCK_NO block_${BLOCK_NO}.block \ peer channel fetch $blockNum block_${blockNum}.block \
-o orderer.example.com:7050 \ -o ${ORDERER_URL} \
-c ${CHANNEL_NAME} \ -c ${channel} \
>&log.txt >&log.txt
else else
peer channel fetch $BLOCK_NO block_${BLOCK_NO}.block \ peer channel fetch $blockNum block_${blockNum}.block \
-o orderer.example.com:7050 \ -o ${ORDERER_URL} \
-c $CHANNEL_NAME \ -c ${channel} \
--tls \ --tls \
--cafile $ORDERER_CA \ --cafile ${ORDERER_TLS_CA} \
>&log.txt >&log.txt
fi fi
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Fetch block on PEER$PEER failed " verifyResult $res "Fetch block on peer$peer failed"
echo_g "=== Fetch block on PEER$PEER in channel '$CHANNEL_NAME' is successful === " echo_g "=== Fetch block on peer$peer in channel '$channel' is successful === "
echo echo
} }

View File

@ -9,16 +9,16 @@ fi
## Install chaincode on all peers ## Install chaincode on all peers
echo_b "Installing chaincode on all 4 peers..." echo_b "Installing chaincode on all 4 peers..."
chaincodeInstall 0 1.0 chaincodeInstall 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
chaincodeInstall 1 1.0 chaincodeInstall 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
chaincodeInstall 2 1.0 chaincodeInstall 2 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
chaincodeInstall 3 1.0 chaincodeInstall 3 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
# Instantiate chaincode on all peers # Instantiate chaincode on all peers
# Instantiate can only be executed once on any node # Instantiate can only be executed once on any node
echo_b "Instantiating chaincode on all 2 orgs (once for each org)..." echo_b "Instantiating chaincode on all 2 orgs (once for each org)..."
chaincodeInstantiate $CHANNEL_NAME 0 chaincodeInstantiate $CHANNEL_NAME 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
chaincodeInstantiate $CHANNEL_NAME 2 chaincodeInstantiate $CHANNEL_NAME 2 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
echo echo
echo_g "===================== Init chaincode done ===================== " echo_g "===================== Init chaincode done ===================== "

View File

@ -8,9 +8,9 @@ elif [ -f scripts/func.sh ]; then
fi fi
## Create channel ## Create channel
echo_b "Creating channel $CHANNEL_NAME..." echo_b "Creating channel ${CHANNEL_NAME}..."
channelCreate $CHANNEL_NAME channelCreate ${CHANNEL_NAME}
## Join all the peers to the channel ## Join all the peers to the channel
echo_b "Having all peers join the channel $CHANNEL_NAME..." echo_b "Having all peers join the channel ${CHANNEL_NAME}..."
channelJoin $CHANNEL_NAME 0 1 2 3 channelJoin ${CHANNEL_NAME} 0 1 2 3

View File

@ -25,7 +25,7 @@ updateAnchorPeers $CHANNEL_NAME 0
## Install chaincode on all peers ## Install chaincode on all peers
echo_b "Installing chaincode on peer0..." echo_b "Installing chaincode on peer0..."
chaincodeInstall 0 1.0 chaincodeInstall 0 ${CC_INIT_ARGS}
# Instantiate chaincode on all peers # Instantiate chaincode on all peers
# Instantiate can only be executed once on any node # Instantiate can only be executed once on any node

View File

@ -11,39 +11,37 @@ echo_b "Channel name : "$CHANNEL_NAME
#Query on chaincode on Peer0/Org1 #Query on chaincode on Peer0/Org1
echo_b "Querying chaincode on peer 3..." 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 #Invoke on chaincode on Peer0/Org1
echo_b "Sending invoke transaction (transfer 10) on org1/peer0..." 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 #Query on chaincode on Peer1/Org2, check if the result is 90
echo_b "Querying chaincode on peer 1 and 3..." echo_b "Querying chaincode on peer 1 and 3..."
chaincodeQuery 1 90 chaincodeQuery ${CHANNEL_NAME} 1 ${CC_NAME} ${CC_QUERY_ARGS} 90
chaincodeQuery 3 90 chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 90
#Invoke on chaincode on Peer1/Org2 #Invoke on chaincode on Peer1/Org2
echo_b "Sending invoke transaction on org2/peer3..." 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 #Query on chaincode on Peer1/Org2, check if the result is 80
echo_b "Querying chaincode on all 4peers..." echo_b "Querying chaincode on all 4peers..."
chaincodeQuery 0 80 chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 80
chaincodeQuery 2 80 chaincodeQuery ${CHANNEL_NAME} 2 ${CC_NAME} ${CC_QUERY_ARGS} 80
#Upgrade to new version #Upgrade to new version
chaincodeInstall 0 1.1 chaincodeInstall 0 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
chaincodeInstall 1 1.1 chaincodeInstall 1 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
chaincodeInstall 2 1.1 chaincodeInstall 2 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
chaincodeInstall 3 1.1 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 ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 100
chaincodeQuery 3 100 chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 100
echo
echo_g "===================== All GOOD, End-2-End execution completed ===================== " echo_g "===================== All GOOD, End-2-End execution completed ===================== "
echo
exit 0 exit 0

View File

@ -7,20 +7,20 @@ elif [ -f scripts/func.sh ]; then
source scripts/func.sh source scripts/func.sh
fi fi
echo_b "Channel name : "$CHANNEL_NAME echo_b "Channel name: "$CHANNEL_NAME
echo_b "====================Query the existing value of a====================================" echo_b "====================Query the existing value of a===================================="
chaincodeQuery 0 100 chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 100
sleep 1 sleep 1
echo_b "=====================Invoke a transaction to transfer 10 from a to b==================" 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 sleep 1
echo_b "=====================Check if the result of a is 90===================================" 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
echo_g "=====================All GOOD, MVE Test completed ===================== " echo_g "=====================All GOOD, MVE Test completed ===================== "

View File

@ -20,7 +20,7 @@ echo_b "Fetch block 1"
channelFetch 0 1 channelFetch 0 1
echo_b "Fetch block 2" echo_b "Fetch block 2"
channelFetch 0 2 channelFetch ${CHANNEL_NAME} 0 2
echo_b "Fetch block 3" echo_b "Fetch block 3"
channelFetch 0 3 channelFetch 0 3

View File

@ -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"}