Skip to content

Commit f0aa7fd

Browse files
2016NishiNishi Nidamarty
authored and
Nishi Nidamarty
committed
[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 <[email protected]>
1 parent 5b926ce commit f0aa7fd

File tree

5 files changed

+448
-0
lines changed

5 files changed

+448
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
A framework to verify Hyperledger-Fabric functionality using chaincodes and CLI
2+
3+
Multiple tests spanning multiple chaincodes can be run.
4+
Supports XML Reporting for each test run
5+
6+
7+
Write and Test Chaincodes
8+
----------------------------------------------------------
9+
Users can write their own GO chaincodes that implements one or more fabric features.
10+
These chaincode calls can then be verified using e2e CLI bash scripts
11+
12+
13+
How to test your chaincode
14+
----------------------------------------------------------------------
15+
16+
* Place your "Go" chaincode under test/regression/daily/chaincodeTests/fabricFeatureChaincodes/go
17+
* Place your CLI shell script under test/regression/daily/chaincodeTests/fabricFeatureChaincodes
18+
* Add a new definition for your test script inside test/regression/daily/chaincodeTests/envsetup/scripts/fabricFeaturerChaincodeTestiRuns.py
19+
20+
cd test/regression/daily/chaincodeTests
21+
./runChaincodes.sh
22+
23+
===========================================================================
24+
25+
26+
runChaincodes.sh calls network_setup.sh under test/regression/daily/chaincodeTests/envsetup
27+
28+
29+
.. code:: bash
30+
31+
./network_setup.sh <up|down|retstart> [channel-name] [num-channels] [num-chaincodes] [endorsers count] [script_name]
32+
33+
channel_name - channel prefix
34+
num-channels - default 1
35+
num-chaincodes - default 1
36+
endorsers count - 4
37+
script_name - script that has test runs in it
38+
39+
40+
41+
output of each of the steps when executing chaincode_example02 looks like
42+
43+
.. code:: bash
44+
45+
Running tests...
46+
----------------------------------------------------------------------
47+
48+
./scripts/e2e_test_example02.sh myc 1 1 4 create
49+
./scripts/e2e_test_example02.sh myc 1 1 4 join
50+
./scripts/e2e_test_example02.sh myc 1 1 4 install
51+
./scripts/e2e_test_example02.sh myc 1 1 4 instantiate
52+
./scripts/e2e_test_example02.sh myc 1 1 4 invokeQuery
53+
54+
Ran 1 test in 135.392s
55+
56+
57+
58+
OK
59+
60+
61+
62+
To deactivate docker network
63+
64+
cd envsetup
65+
66+
.. code:: bash
67+
68+
./network_setup.sh down
69+
95,1 97%
70+
71+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/bin/bash
2+
3+
set +x
4+
set -e
5+
6+
##### GLOBALS ######
7+
CHANNEL_NAME="$1"
8+
CHANNELS="$2"
9+
CHAINCODES="$3"
10+
ENDORSERS="$4"
11+
fun="$5"
12+
LOG_FILE="scripts1/logs.txt"
13+
14+
##### SET DEFAULT VALUES #####
15+
: ${CHANNEL_NAME:="mychannel"}
16+
: ${CHANNELS:="1"}
17+
: ${CHAINCODES:="1"}
18+
: ${ENDORSERS:="4"}
19+
: ${TIMEOUT:="60"}
20+
COUNTER=1
21+
MAX_RETRY=5
22+
23+
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
24+
25+
echo "Channel name : "$CHANNEL_NAME
26+
echo "Channels: "$CHANNELS
27+
echo "Chaincodes : "$CHAINCODES
28+
echo "Endorsers : "$ENDORSERS
29+
echo "FUN : "$fun
30+
31+
verifyResult () {
32+
if [ $1 -ne 0 ] ; then
33+
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
34+
echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
35+
echo
36+
exit 1
37+
fi
38+
}
39+
40+
setGlobals () {
41+
42+
if [ $1 -eq 0 -o $1 -eq 1 ] ; then
43+
export CORE_PEER_LOCALMSPID="Org1MSP"
44+
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
45+
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
46+
if [ $1 -eq 0 ]; then
47+
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
48+
else
49+
export CORE_PEER_ADDRESS=peer1.org1.example.com:7051
50+
fi
51+
else
52+
export CORE_PEER_LOCALMSPID="Org2MSP"
53+
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
54+
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
55+
if [ $1 -eq 2 ]; then
56+
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
57+
else
58+
export CORE_PEER_ADDRESS=peer1.org2.example.com:7051
59+
fi
60+
fi
61+
62+
env |grep CORE
63+
}
64+
65+
createChannel() {
66+
echo "Inside create channel fun = $fun"
67+
setGlobals 0
68+
CH_NUM=$1
69+
70+
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
71+
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME$CH_NUM -f ./channel-artifacts/channel$CH_NUM.tx >>$LOG_FILE
72+
else
73+
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
74+
fi
75+
res=$?
76+
verifyResult $res "Channel creation failed"
77+
echo "===================== Channel \"$CHANNEL_NAME$CH_NUM\" is created successfully ===================== "
78+
echo
79+
}
80+
81+
updateAnchorPeers() {
82+
PEER=$1
83+
CH_NUM=$2
84+
setGlobals $PEER
85+
86+
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
87+
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
88+
else
89+
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
90+
fi
91+
res=$?
92+
verifyResult $res "Anchor peer update failed"
93+
echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== "
94+
echo
95+
}
96+
97+
## Sometimes Join takes time hence RETRY atleast for 5 times
98+
joinWithRetry () {
99+
for (( i=0; $i<$CHANNELS; i++))
100+
do
101+
peer channel join -b $CHANNEL_NAME$i.block >>$LOG_FILE
102+
res=$?
103+
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
104+
COUNTER=` expr $COUNTER + 1`
105+
echo "PEER$1 failed to join the channel, Retry after 2 seconds"
106+
sleep 2
107+
joinWithRetry $1
108+
else
109+
COUNTER=1
110+
fi
111+
verifyResult $res "After $MAX_RETRY attempts, PEER$ch has failed to Join the Channel"
112+
echo "===================== PEER$1 joined on the channel \"$CHANNEL_NAME$i\" ===================== "
113+
sleep 2
114+
done
115+
}
116+
117+
joinChannel () {
118+
for (( peer=0; $peer<$ENDORSERS; peer++))
119+
do
120+
setGlobals $peer
121+
joinWithRetry $peer
122+
#echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== "
123+
sleep 2
124+
echo
125+
done
126+
}
127+
128+
validateArgs () {
129+
if [ -z "${fun}" ]; then
130+
echo "create/join not mentioned"
131+
printHelp
132+
exit 1
133+
fi
134+
if [ "${fun}" == "create" -o "${fun}" == "join" ]; then
135+
return
136+
else
137+
echo "Invalid Argument"
138+
exit 1
139+
fi
140+
}
141+
142+
validateArgs
143+
144+
if [ "${fun}" == "create" ]; then
145+
echo "************************ START: CREATE Channel"
146+
## Create channel
147+
for (( ch=0; $ch<$CHANNELS; ch++))
148+
do
149+
createChannel $ch
150+
done
151+
152+
elif [ "${fun}" == "join" ]; then
153+
#Join all the peers to all the channels
154+
echo "************************ START : JOIN Channel"
155+
joinChannel
156+
## Set the anchor peers for each org in the channel
157+
updateAnchorPeers 0 0
158+
updateAnchorPeers 2 0
159+
echo "===================== All GOOD, End-2-End for create_join channel ===================== "
160+
echo
161+
echo "Total execution time $(($(date +%s)-START_TIME)) secs"
162+
echo
163+
exit 0
164+
165+
else
166+
printHelp
167+
exit 1
168+
fi

0 commit comments

Comments
 (0)