|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +echo |
| 4 | +echo " ____ _____ _ ____ _____ " |
| 5 | +echo "/ ___| |_ _| / \ | _ \ |_ _|" |
| 6 | +echo "\___ \ | | / _ \ | |_) | | | " |
| 7 | +echo " ___) | | | / ___ \ | _ < | | " |
| 8 | +echo "|____/ |_| /_/ \_\ |_| \_\ |_| " |
| 9 | +echo |
| 10 | +echo "Upgrade your first network (BYFN) from v1.0.x to v1.1 end-to-end test" |
| 11 | +echo |
| 12 | +CHANNEL_NAME="$1" |
| 13 | +DELAY="$2" |
| 14 | +LANGUAGE="$3" |
| 15 | +TIMEOUT="$4" |
| 16 | +: ${CHANNEL_NAME:="mychannel"} |
| 17 | +: ${DELAY:="5"} |
| 18 | +: ${LANGUAGE:="golang"} |
| 19 | +: ${TIMEOUT:="10"} |
| 20 | +LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]` |
| 21 | +COUNTER=1 |
| 22 | +MAX_RETRY=5 |
| 23 | +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 |
| 24 | + |
| 25 | +CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/" |
| 26 | +if [ "$LANGUAGE" = "node" ]; then |
| 27 | + CC_SRC_PATH="/opt/gopath/src/github.com/chaincode/chaincode_example02/node/" |
| 28 | +fi |
| 29 | + |
| 30 | +echo "Channel name : "$CHANNEL_NAME |
| 31 | + |
| 32 | +# import utils |
| 33 | +. scripts/utils.sh |
| 34 | + |
| 35 | +# addCapabilityToChannel <channel_id> <capabilities_group> |
| 36 | +# This function pulls the current channel config, modifies it with capabilities |
| 37 | +# for the specified group, computes the config update, signs, and submits it. |
| 38 | +addCapabilityToChannel() { |
| 39 | + CH_NAME=$1 |
| 40 | + GROUP=$2 |
| 41 | + |
| 42 | + setOrdererGlobals |
| 43 | + |
| 44 | + # Get the current channel config, decode and write it to config.json |
| 45 | + fetchChannelConfig $CH_NAME config.json |
| 46 | + |
| 47 | + # Modify the correct section of the config based on capabilities group |
| 48 | + if [ $GROUP == "orderer" ]; then |
| 49 | + jq -s '.[0] * {"channel_group":{"groups":{"Orderer": {"values": {"Capabilities": .[1]}}}}}' config.json ./scripts/capabilities.json > modified_config.json |
| 50 | + elif [ $GROUP == "channel" ]; then |
| 51 | + jq -s '.[0] * {"channel_group":{"values": {"Capabilities": .[1]}}}' config.json ./scripts/capabilities.json > modified_config.json |
| 52 | + elif [ $GROUP == "application" ]; then |
| 53 | + jq -s '.[0] * {"channel_group":{"groups":{"Application": {"values": {"Capabilities": .[1]}}}}}' config.json ./scripts/capabilities.json > modified_config.json |
| 54 | + fi |
| 55 | + |
| 56 | + # Create a config updated for this channel based on the differences between config.json and modified_config.json |
| 57 | + # write the output to config_update_in_envelope.pb |
| 58 | + createConfigUpdate "$CH_NAME" config.json modified_config.json config_update_in_envelope.pb |
| 59 | + |
| 60 | + # Sign, and set the correct identity for submission. |
| 61 | + if [ $CH_NAME != "testchainid" ] ; then |
| 62 | + if [ $GROUP == "orderer" ]; then |
| 63 | + # Modifying the orderer group requires only the Orderer admin to sign. |
| 64 | + # Prepare to sign the update as the OrdererOrg.Admin |
| 65 | + setOrdererGlobals |
| 66 | + elif [ $GROUP == "channel" ]; then |
| 67 | + # Modifying the channel group requires a majority of application admins and the orderer admin to sign. |
| 68 | + # Sign with PeerOrg1.Admin |
| 69 | + signConfigtxAsPeerOrg 1 config_update_in_envelope.pb |
| 70 | + # Sign with PeerOrg2.Admin |
| 71 | + signConfigtxAsPeerOrg 2 config_update_in_envelope.pb |
| 72 | + # Prepare to sign the update as the OrdererOrg.Admin |
| 73 | + setOrdererGlobals |
| 74 | + elif [ $GROUP == "application" ]; then |
| 75 | + # Modifying the application group requires a majority of application admins to sign. |
| 76 | + # Sign with PeerOrg1.Admin |
| 77 | + signConfigtxAsPeerOrg 1 config_update_in_envelope.pb |
| 78 | + # Prepare to sign the update as the PeerOrg2.Admin |
| 79 | + setGlobals 0 2 |
| 80 | + fi |
| 81 | + else |
| 82 | + # For the orderer system channel, only the orderer admin needs sign |
| 83 | + # which will be attached during the update |
| 84 | + setOrdererGlobals |
| 85 | + fi |
| 86 | + |
| 87 | + if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then |
| 88 | + peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --cafile $ORDERER_CA |
| 89 | + else |
| 90 | + peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA |
| 91 | + fi |
| 92 | + res=$? |
| 93 | + verifyResult $res "Config update for \"$GROUP\" on \"$CH_NAME\" failed" |
| 94 | + echo "===================== Config update for \"$GROUP\" on \"$CH_NAME\" is completed ===================== " |
| 95 | + |
| 96 | +} |
| 97 | + |
| 98 | +echo "Installing jq" |
| 99 | +apt-get update |
| 100 | +apt-get install -y jq |
| 101 | + |
| 102 | +sleep $DELAY |
| 103 | + |
| 104 | +#Config update for /Channel/Orderer on testchainid |
| 105 | +echo "Config update for /Channel/Orderer on testchainid" |
| 106 | +addCapabilityToChannel testchainid orderer |
| 107 | + |
| 108 | +sleep $DELAY |
| 109 | + |
| 110 | +#Config update for /Channel on testchainid |
| 111 | +echo "Config update for /Channel on testchainid" |
| 112 | +addCapabilityToChannel testchainid channel |
| 113 | + |
| 114 | +sleep $DELAY |
| 115 | + |
| 116 | +#Config update for /Channel/Orderer |
| 117 | +echo "Config update for /Channel/Orderer on \"$CHANNEL_NAME\"" |
| 118 | +addCapabilityToChannel $CHANNEL_NAME orderer |
| 119 | + |
| 120 | +sleep $DELAY |
| 121 | + |
| 122 | +#Config update for /Channel/Application |
| 123 | +echo "Config update for /Channel/Application on \"$CHANNEL_NAME\"" |
| 124 | +addCapabilityToChannel $CHANNEL_NAME application |
| 125 | + |
| 126 | +sleep $DELAY |
| 127 | + |
| 128 | +#Config update for /Channel |
| 129 | +echo "Config update for /Channel on \"$CHANNEL_NAME\"" |
| 130 | +addCapabilityToChannel $CHANNEL_NAME channel |
| 131 | + |
| 132 | +#Query on chaincode on Peer0/Org1 |
| 133 | +echo "Querying chaincode on org1/peer0..." |
| 134 | +chaincodeQuery 0 1 90 |
| 135 | + |
| 136 | +#Invoke on chaincode on Peer0/Org1 |
| 137 | +echo "Sending invoke transaction on org1/peer0..." |
| 138 | +chaincodeInvoke 0 1 |
| 139 | + |
| 140 | +sleep $DELAY |
| 141 | + |
| 142 | +#Query on chaincode on Peer0/Org1 |
| 143 | +echo "Querying chaincode on org1/peer0..." |
| 144 | +chaincodeQuery 0 1 80 |
| 145 | + |
| 146 | +##Invoke on chaincode on Peer0/Org2 |
| 147 | +echo "Sending invoke transaction on org2/peer0..." |
| 148 | +chaincodeInvoke 0 2 |
| 149 | + |
| 150 | +sleep $DELAY |
| 151 | + |
| 152 | +#Query on chaincode on Peer0/Org2 |
| 153 | +echo "Querying chaincode on org2/peer0..." |
| 154 | +chaincodeQuery 0 2 70 |
| 155 | + |
| 156 | +echo |
| 157 | +echo "===================== All GOOD, End-2-End UPGRADE Scenario execution completed ===================== " |
| 158 | +echo |
| 159 | + |
| 160 | +echo |
| 161 | +echo " _____ _ _ ____ _____ ____ _____ " |
| 162 | +echo "| ____| | \ | | | _ \ | ____| |___ \ | ____|" |
| 163 | +echo "| _| | \| | | | | | _____ | _| __) | | _| " |
| 164 | +echo "| |___ | |\ | | |_| | |_____| | |___ / __/ | |___ " |
| 165 | +echo "|_____| |_| \_| |____/ |_____| |_____| |_____|" |
| 166 | +echo |
| 167 | + |
| 168 | +exit 0 |
0 commit comments