-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-3258] fwk test chaincode functionality Part2
First test to test basic framework using chaincode_example02 1. A script to create and join channels. 2. A script to install/instantiate chaincode + perform invokes. 3. Base script to launch network + run test. Change-Id: Ibb21e7a5845ab6a02eaa4e6e2f1d20f40c107094 Signed-off-by: nishi.nidamarty <nishi.nidamarty@itpeoplecorp.com>
- Loading branch information
Showing
5 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
A framework to verify Hyperledger-Fabric functionality using chaincodes and CLI | ||
|
||
Multiple tests spanning multiple chaincodes can be run. | ||
Supports XML Reporting for each test run | ||
|
||
|
||
Write and Test Chaincodes | ||
---------------------------------------------------------- | ||
Users can write their own GO chaincodes that implements one or more fabric features. | ||
These chaincode calls can then be verified using e2e CLI bash scripts | ||
|
||
|
||
How to test your chaincode | ||
---------------------------------------------------------------------- | ||
|
||
* Place your "Go" chaincode under test/regression/daily/chaincodeTests/fabricFeatureChaincodes/go | ||
* Place your CLI shell script under test/regression/daily/chaincodeTests/fabricFeatureChaincodes | ||
* Add a new definition for your test script inside test/regression/daily/chaincodeTests/envsetup/scripts/fabricFeaturerChaincodeTestiRuns.py | ||
|
||
cd test/regression/daily/chaincodeTests | ||
./runChaincodes.sh | ||
|
||
=========================================================================== | ||
|
||
|
||
runChaincodes.sh calls network_setup.sh under test/regression/daily/chaincodeTests/envsetup | ||
|
||
|
||
.. code:: bash | ||
./network_setup.sh <up|down|retstart> [channel-name] [num-channels] [num-chaincodes] [endorsers count] [script_name] | ||
channel_name - channel prefix | ||
num-channels - default 1 | ||
num-chaincodes - default 1 | ||
endorsers count - 4 | ||
script_name - script that has test runs in it | ||
|
||
|
||
|
||
output of each of the steps when executing chaincode_example02 looks like | ||
|
||
.. code:: bash | ||
Running tests... | ||
---------------------------------------------------------------------- | ||
|
||
./scripts/e2e_test_example02.sh myc 1 1 4 create | ||
./scripts/e2e_test_example02.sh myc 1 1 4 join | ||
./scripts/e2e_test_example02.sh myc 1 1 4 install | ||
./scripts/e2e_test_example02.sh myc 1 1 4 instantiate | ||
./scripts/e2e_test_example02.sh myc 1 1 4 invokeQuery | ||
|
||
Ran 1 test in 135.392s | ||
|
||
|
||
|
||
OK | ||
|
||
|
||
|
||
To deactivate docker network | ||
|
||
cd envsetup | ||
|
||
.. code:: bash | ||
./network_setup.sh down | ||
95,1 97% | ||
168 changes: 168 additions & 0 deletions
168
test/regression/daily/chaincodeTests/fabricFeatureChaincodes/create_join_channel.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#!/bin/bash | ||
|
||
set +x | ||
set -e | ||
|
||
##### GLOBALS ###### | ||
CHANNEL_NAME="$1" | ||
CHANNELS="$2" | ||
CHAINCODES="$3" | ||
ENDORSERS="$4" | ||
fun="$5" | ||
LOG_FILE="scripts1/logs.txt" | ||
|
||
##### SET DEFAULT VALUES ##### | ||
: ${CHANNEL_NAME:="mychannel"} | ||
: ${CHANNELS:="1"} | ||
: ${CHAINCODES:="1"} | ||
: ${ENDORSERS:="4"} | ||
: ${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/cacerts/ca.example.com-cert.pem | ||
|
||
echo "Channel name : "$CHANNEL_NAME | ||
echo "Channels: "$CHANNELS | ||
echo "Chaincodes : "$CHAINCODES | ||
echo "Endorsers : "$ENDORSERS | ||
echo "FUN : "$fun | ||
|
||
verifyResult () { | ||
if [ $1 -ne 0 ] ; then | ||
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" | ||
echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" | ||
echo | ||
exit 1 | ||
fi | ||
} | ||
|
||
setGlobals () { | ||
|
||
if [ $1 -eq 0 -o $1 -eq 1 ] ; then | ||
export CORE_PEER_LOCALMSPID="Org1MSP" | ||
export 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 | ||
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp | ||
if [ $1 -eq 0 ]; then | ||
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 | ||
else | ||
export CORE_PEER_ADDRESS=peer1.org1.example.com:7051 | ||
fi | ||
else | ||
export CORE_PEER_LOCALMSPID="Org2MSP" | ||
export 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 | ||
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp | ||
if [ $1 -eq 2 ]; then | ||
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051 | ||
else | ||
export CORE_PEER_ADDRESS=peer1.org2.example.com:7051 | ||
fi | ||
fi | ||
|
||
env |grep CORE | ||
} | ||
|
||
createChannel() { | ||
echo "Inside create channel fun = $fun" | ||
setGlobals 0 | ||
CH_NUM=$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$CH_NUM -f ./channel-artifacts/channel$CH_NUM.tx >>$LOG_FILE | ||
else | ||
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME$CH_NUM -f ./channel-artifacts/channel$CH_NUM.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >>$LOG_FILE | ||
fi | ||
res=$? | ||
verifyResult $res "Channel creation failed" | ||
echo "===================== Channel \"$CHANNEL_NAME$CH_NUM\" is created successfully ===================== " | ||
echo | ||
} | ||
|
||
updateAnchorPeers() { | ||
PEER=$1 | ||
CH_NUM=$2 | ||
setGlobals $PEER | ||
|
||
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then | ||
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME$CH_NUM -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors$CH_NUM.tx >>$LOG_FILE | ||
else | ||
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME$CH_NUM -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors$CH_NUM.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >>$LOG_FILE | ||
fi | ||
res=$? | ||
verifyResult $res "Anchor peer update failed" | ||
echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== " | ||
echo | ||
} | ||
|
||
## Sometimes Join takes time hence RETRY atleast for 5 times | ||
joinWithRetry () { | ||
for (( i=0; $i<$CHANNELS; i++)) | ||
do | ||
peer channel join -b $CHANNEL_NAME$i.block >>$LOG_FILE | ||
res=$? | ||
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then | ||
COUNTER=` expr $COUNTER + 1` | ||
echo "PEER$1 failed to join the channel, Retry after 2 seconds" | ||
sleep 2 | ||
joinWithRetry $1 | ||
else | ||
COUNTER=1 | ||
fi | ||
verifyResult $res "After $MAX_RETRY attempts, PEER$ch has failed to Join the Channel" | ||
echo "===================== PEER$1 joined on the channel \"$CHANNEL_NAME$i\" ===================== " | ||
sleep 2 | ||
done | ||
} | ||
|
||
joinChannel () { | ||
for (( peer=0; $peer<$ENDORSERS; peer++)) | ||
do | ||
setGlobals $peer | ||
joinWithRetry $peer | ||
#echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== " | ||
sleep 2 | ||
echo | ||
done | ||
} | ||
|
||
validateArgs () { | ||
if [ -z "${fun}" ]; then | ||
echo "create/join not mentioned" | ||
printHelp | ||
exit 1 | ||
fi | ||
if [ "${fun}" == "create" -o "${fun}" == "join" ]; then | ||
return | ||
else | ||
echo "Invalid Argument" | ||
exit 1 | ||
fi | ||
} | ||
|
||
validateArgs | ||
|
||
if [ "${fun}" == "create" ]; then | ||
echo "************************ START: CREATE Channel" | ||
## Create channel | ||
for (( ch=0; $ch<$CHANNELS; ch++)) | ||
do | ||
createChannel $ch | ||
done | ||
|
||
elif [ "${fun}" == "join" ]; then | ||
#Join all the peers to all the channels | ||
echo "************************ START : JOIN Channel" | ||
joinChannel | ||
## Set the anchor peers for each org in the channel | ||
updateAnchorPeers 0 0 | ||
updateAnchorPeers 2 0 | ||
echo "===================== All GOOD, End-2-End for create_join channel ===================== " | ||
echo | ||
echo "Total execution time $(($(date +%s)-START_TIME)) secs" | ||
echo | ||
exit 0 | ||
|
||
else | ||
printHelp | ||
exit 1 | ||
fi |
Oops, something went wrong.