Skip to content

Commit

Permalink
[FAB-15649]Fix Fabcar to install Chaincode on all peers
Browse files Browse the repository at this point in the history
CI Fabcar javascript test fails because a query proposal is
sent to a peer which does not have Chaincode. The query handler
in fabric-network does not consider if Chaincode is installed on
target peers.

As a workaround, this CR adds steps installing Chaincode
on all peers during the setup.

Change-Id: Iaff0c5bde8c54cef12a176b55e13d70173ee8108
Signed-off-by: Yuki Kondo <yuki.kondo@hal.hitachi.com>
  • Loading branch information
yuki-kon committed Jun 12, 2019
1 parent 7c5f5d3 commit 779f8f3
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions fabcar/startFabric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ORG2_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/user
ORG2_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

PEER_ORG1="docker exec
PEER0_ORG1="docker exec
-e CORE_PEER_LOCALMSPID=Org1MSP
-e CORE_PEER_ADDRESS=peer0.org1.example.com:7051
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH}
Expand All @@ -61,7 +61,18 @@ peer
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
--orderer=orderer.example.com:7050"

PEER_ORG2="docker exec
PEER1_ORG1="docker exec
-e CORE_PEER_LOCALMSPID=Org1MSP
-e CORE_PEER_ADDRESS=peer1.org1.example.com:8051
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH}
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE}
cli
peer
--tls=true
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
--orderer=orderer.example.com:7050"

PEER0_ORG2="docker exec
-e CORE_PEER_LOCALMSPID=Org2MSP
-e CORE_PEER_ADDRESS=peer0.org2.example.com:9051
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH}
Expand All @@ -72,28 +83,43 @@ peer
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
--orderer=orderer.example.com:7050"

PEER1_ORG2="docker exec
-e CORE_PEER_LOCALMSPID=Org2MSP
-e CORE_PEER_ADDRESS=peer1.org2.example.com:10051
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH}
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE}
cli
peer
--tls=true
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
--orderer=orderer.example.com:7050"

echo "Packaging smart contract on peer0.org1.example.com"
${PEER_ORG1} lifecycle chaincode package \
${PEER0_ORG1} lifecycle chaincode package \
fabcar.tar.gz \
--path "$CC_SRC_PATH" \
--lang "$CC_RUNTIME_LANGUAGE" \
--label fabcarv1

echo "Installing smart contract on peer0.org1.example.com"
${PEER_ORG1} lifecycle chaincode install \
${PEER0_ORG1} lifecycle chaincode install \
fabcar.tar.gz

echo "Installing smart contract on peer1.org1.example.com"
${PEER1_ORG1} lifecycle chaincode install \
fabcar.tar.gz

echo "Determining package ID for smart contract on peer0.org1.example.com"
REGEX='Package ID: (.*), Label: fabcarv1'
if [[ `${PEER_ORG1} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
if [[ `${PEER0_ORG1} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
PACKAGE_ID_ORG1=${BASH_REMATCH[1]}
else
echo Could not find package ID for fabcarv1 chaincode on peer0.org1.example.com
exit 1
fi

echo "Approving smart contract for org1"
${PEER_ORG1} lifecycle chaincode approveformyorg \
${PEER0_ORG1} lifecycle chaincode approveformyorg \
--package-id ${PACKAGE_ID_ORG1} \
--channelID mychannel \
--name fabcar \
Expand All @@ -103,26 +129,29 @@ ${PEER_ORG1} lifecycle chaincode approveformyorg \
--waitForEvent

echo "Packaging smart contract on peer0.org2.example.com"
${PEER_ORG2} lifecycle chaincode package \
${PEER0_ORG2} lifecycle chaincode package \
fabcar.tar.gz \
--path "$CC_SRC_PATH" \
--lang "$CC_RUNTIME_LANGUAGE" \
--label fabcarv1

echo "Installing smart contract on peer0.org2.example.com"
${PEER_ORG2} lifecycle chaincode install fabcar.tar.gz
${PEER0_ORG2} lifecycle chaincode install fabcar.tar.gz

echo "Installing smart contract on peer1.org2.example.com"
${PEER1_ORG2} lifecycle chaincode install fabcar.tar.gz

echo "Determining package ID for smart contract on peer0.org2.example.com"
REGEX='Package ID: (.*), Label: fabcarv1'
if [[ `${PEER_ORG2} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
if [[ `${PEER0_ORG2} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
PACKAGE_ID_ORG2=${BASH_REMATCH[1]}
else
echo Could not find package ID for fabcarv1 chaincode on peer0.org2.example.com
exit 1
fi

echo "Approving smart contract for org2"
${PEER_ORG2} lifecycle chaincode approveformyorg \
${PEER0_ORG2} lifecycle chaincode approveformyorg \
--package-id ${PACKAGE_ID_ORG2} \
--channelID mychannel \
--name fabcar \
Expand All @@ -132,7 +161,7 @@ ${PEER_ORG2} lifecycle chaincode approveformyorg \
--waitForEvent

echo "Committing smart contract"
${PEER_ORG1} lifecycle chaincode commit \
${PEER0_ORG1} lifecycle chaincode commit \
--channelID mychannel \
--name fabcar \
--version 1.0 \
Expand All @@ -145,15 +174,20 @@ ${PEER_ORG1} lifecycle chaincode commit \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}

echo "Submitting initLedger transaction to smart contract on mychannel"
${PEER_ORG1} chaincode invoke \
echo "The transaction is sent to all of the peers so that chaincode is built before receiving the following requests"
${PEER0_ORG1} chaincode invoke \
-C mychannel \
-n fabcar \
-c '{"function":"initLedger","Args":[]}' \
--waitForEvent \
--waitForEventTimeout 300s \
--peerAddresses peer0.org1.example.com:7051 \
--peerAddresses peer1.org1.example.com:8051 \
--peerAddresses peer0.org2.example.com:9051 \
--peerAddresses peer1.org2.example.com:10051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE} \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}

cat <<EOF
Expand Down

0 comments on commit 779f8f3

Please sign in to comment.