mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-19 08:15:08 +00:00
Introduce automated tests for the fabcar sample, that deploy the new sample contracts and submit the initLedger transaction using the "peer" CLI. Additional changes will follow to drive the new sample apps to ensure that they work as well (but the apps aren't there yet!). Change-Id: Ie42d139eb1dc1cf0f7c16f41f54bb5f40309921c Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
57 lines
2.8 KiB
Bash
Executable file
57 lines
2.8 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Copyright IBM Corp All Rights Reserved
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Exit on first error
|
|
set -e
|
|
|
|
# don't rewrite paths for Windows Git Bash users
|
|
export MSYS_NO_PATHCONV=1
|
|
starttime=$(date +%s)
|
|
CC_SRC_LANGUAGE=${1:-"go"}
|
|
CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
|
|
if [ "$CC_SRC_LANGUAGE" = "go" -o "$CC_SRC_LANGUAGE" = "golang" ]; then
|
|
CC_RUNTIME_LANGUAGE=golang
|
|
CC_SRC_PATH=github.com/fabcar/go
|
|
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
|
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
|
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/javascript
|
|
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
|
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
|
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/typescript
|
|
echo Compiling TypeScript code into JavaScript ...
|
|
pushd ../chaincode/fabcar/typescript
|
|
npm install
|
|
npm run build
|
|
popd
|
|
echo Finished compiling TypeScript code into JavaScript
|
|
else
|
|
echo The chaincode language ${CC_SRC_LANGUAGE} is not supported by this script
|
|
echo Supported chaincode languages are: go, javascript, and typescript
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# clean the keystore
|
|
rm -rf ./hfc-key-store
|
|
|
|
# launch network; create channel and join peer to channel
|
|
cd ../basic-network
|
|
./start.sh
|
|
|
|
# Now launch the CLI container in order to install, instantiate chaincode
|
|
# and prime the ledger with our 10 cars
|
|
docker-compose -f ./docker-compose.yml up -d cli
|
|
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n fabcar -v 1.0 -p "$CC_SRC_PATH" -l "$CC_RUNTIME_LANGUAGE"
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$CC_RUNTIME_LANGUAGE" -v 1.0 -c '{"Args":[]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
|
|
sleep 10
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[]}'
|
|
|
|
printf "\nTotal setup execution time : $(($(date +%s) - starttime)) secs ...\n\n\n"
|
|
printf "Start by installing required packages run 'npm install'\n"
|
|
printf "Then run 'node enrollAdmin.js', then 'node registerUser'\n\n"
|
|
printf "The 'node invoke.js' will fail until it has been updated with valid arguments\n"
|
|
printf "The 'node query.js' may be run at anytime once the user has been registered\n\n"
|