Skip to content

Commit 112ff0c

Browse files
committed
[FAB-3507] Chaincode Tests
Calling network_setup.sh from inside python script. Invoking commands on CLI container from python as well. Running whole setup as a python test to get results in xml. Change-Id: I3a5a9d18e5b5c865cbd0983420275edc5eadf416 Signed-off-by: Latitia M Haskins <[email protected]> Signed-off-by: nishi.nidamarty <[email protected]>
1 parent 2470d35 commit 112ff0c

File tree

8 files changed

+327
-189
lines changed

8 files changed

+327
-189
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,68 @@
1-
A framework to verify Hyperledger-Fabric functionality using chaincodes and CLI
1+
Chaincode Test Framework
2+
==========================================================================
23

3-
Multiple tests spanning multiple chaincodes can be run.
4-
Supports XML Reporting for each test run
4+
Framework Capabilities
5+
------------------------------------------------------------------------
56

7+
* Verifies Hyperledger-Fabric features by executing your chaincode
8+
* Supports any chaincodes written in **GO**
9+
* Spins up a docker network and runs CLI test scripts
10+
* Tests all contributed chaincodes as part of our daily Continuous Integration (CI) test suite, and displays XML Reports for each chaincodee
611

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
1112

13+
How to Plug In *YourChaincode*
14+
---------------------------------------------------------------------------
1215

13-
How to test your chaincode
14-
----------------------------------------------------------------------
16+
* Using **GO** language, write *YourChaincode* and place it at *fabric/test/regression/daily/chaincodeTests/fabricFeatureChaincodes/go/<YourChaincodeDir>/<YourChaincode.go>*
17+
* Write a CLI bash script such as *e2e_test_<YourChaincode>.sh* to execute invokes and queries using your chaincode API, and place it under *fabric/test/regression/daily/chaincodeTests/fabricFeatureChaincodes/*
1518

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+
* Simply model it after others, such as *e2e_test_example02.sh*
20+
* During the install step, give the path to chaincode as *github.com/hyperledger/fabric/test/regression/daily/chaincodeTests/fabricFeatureChaincodes/go/<YourChaincodeDir>*
21+
* Note: **test_AFAB3843_Create_Join_Channel** must be run as first test step
1922

20-
cd test/regression/daily/chaincodeTests
21-
./runChaincodes.sh
23+
* Add a few lines to define your new test inside *test/regression/daily/chaincodeTests/envsetup/testYourChaincode.py*
2224

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]
25+
* Copy the few lines from another example such as 'def test_example02', and simply change the name and path
3226

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
27+
===========================================================================
4428

45-
Running tests...
46-
----------------------------------------------------------------------
4729

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
30+
How to Run the Chaincode Tests
31+
------------------------------------------------------------------------
5332

54-
Ran 1 test in 135.392s
33+
``$ cd fabric/test/regression/daily/chaincodeTests``
34+
``$ ./runChaincodes.sh``
5535

36+
*runChaincodes.sh* calls *testYourChaincode.py*
5637

38+
``py.test -v --junitxml YourChaincodeResults.xml testYourChaincode.py``
5739

58-
OK
40+
The output should look like the following:
5941

42+
::
6043

44+
=========================
45+
test session starts
46+
=========================
47+
platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- /usr/bin/python
48+
cachedir: .cache
49+
rootdir: /opt/gopath/src/github.com/hyperledger/fabric/test/regression/daily/chaincodeTests/envsetup, inifile:
50+
collected 3 items
51+
testYourChaincode.py::ChaincodeAPI::test_AFAB3843_Create_Join_Channel PASSED
52+
testYourChaincode.py::ChaincodeAPI::test_FAB3791_example03 PASSED
53+
testYourChaincode.py::ChaincodeAPI::test_FAB3792_marbles02 PASSED
6154

62-
To deactivate docker network
6355

64-
cd envsetup
56+
Logs
57+
-------------------------------------------------------------------------------
58+
Logs from each test script are redirected and stored at envsetup/scripts/output.log
6559

66-
.. code:: bash
6760

68-
./network_setup.sh down
69-
95,1 97%
61+
Deactivate Network
62+
-------------------------------------------------------------------------------
63+
The network is automatically deactivated as part of the teardown step after running all tests.
64+
In case of trouble, here is how to deactivate docker network manually:
7065

66+
``cd /path/to/fabric/test/regression/daily/chaincodeTests/envsetup``
67+
``./network_setup.sh down``
7168

test/regression/daily/chaincodeTests/envsetup/docker-compose.yaml

+2-5
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,14 @@ services:
4949
- 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
5050
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
5151
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
52-
#command: /bin/bash -c 'apt-get update && apt-get install && scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60'
53-
command: /bin/bash -c 'apt-get update && apt-get install -y python python-xmlrunner && scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60'
54-
#command: /bin/bash -c ' echo "NOW RUN SCRIPT ${SCRIPT_NAME}" apt-get update && apt-get install -y python python-pytest python-xmlrunner && python -m py.test -v --junitxml scripts1/results.xml ./scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60'
55-
#command: /bin/bash -c 'apt-get update && apt-get install -y python python-pytest python-xmlrunner && py.test -v --junitxml scripts1/results.xml scripts1/${SCRIPT_NAME}; sleep 60'
52+
command: /bin/bash -c 'sleep 600000000000'
5653
volumes:
5754
- /var/run/:/host/var/run/
5855
- ../../../../../examples/chaincode/go:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
5956
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
6057
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto
6158
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts1
62-
- ../fabricFeatureChaincodes:/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/fabricFeatureChaincodes
59+
- ../fabricFeatureChaincodes:/opt/gopath/src/github.com/hyperledger/fabric/test/regression/daily/chaincodeTests/fabricFeatureChaincodes
6360
depends_on:
6461
- orderer.example.com
6562
- peer0.org1.example.com

test/regression/daily/chaincodeTests/envsetup/network_setup.sh

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ CH_NAME=$2
55
CHANNELS=$3
66
CHAINCODES=$4
77
ENDORSERS=$5
8-
SCRIPT_NAME=$6
98

109
: ${CH_NAME:="mychannel"}
1110
: ${CHANNELS:="1"}
@@ -14,7 +13,7 @@ SCRIPT_NAME=$6
1413
COMPOSE_FILE=docker-compose.yaml
1514

1615
function printHelp () {
17-
echo "Usage: ./network_setup.sh <up|down|retstart> [channel-name] [total-channels [chaincodes] [endorsers count] [SCRIPT_NAME]"
16+
echo "Usage: ./network_setup.sh <up|down|retstart> [channel-name] [total-channels [chaincodes] [endorsers count]"
1817
}
1918

2019
function validateArgs () {
@@ -45,21 +44,18 @@ function removeUnwantedImages() {
4544

4645
function networkUp () {
4746
CurrentDIR=$PWD
48-
cd ./configTx
4947
echo "ch_name $CH_NAME"
5048
echo "Num channels $CHANNELS"
5149
echo "Num chaincodes $CHAINCODES"
5250
echo "Num of endorsers/peers $ENDORSERS"
53-
echo "Running Script $SCRIPT_NAME"
5451
source generateCfgTrx.sh $CH_NAME $CHANNELS
5552
cd $CurrentDIR
5653

57-
CHANNEL_NAME=$CH_NAME CHANNELS_NUM=$CHANNELS CHAINCODES_NUM=$CHAINCODES ENDORSERS_NUM=$ENDORSERS SCRIPT_NAME=$SCRIPT_NAME docker-compose -f $COMPOSE_FILE up -d 2>&1
54+
docker-compose -f $COMPOSE_FILE up -d 2>&1
5855
if [ $? -ne 0 ]; then
5956
echo "ERROR !!!! Unable to pull the images "
6057
exit 1
6158
fi
62-
docker logs -f cli
6359
}
6460

6561
function networkDown () {
@@ -69,7 +65,7 @@ function networkDown () {
6965
#Cleanup images
7066
removeUnwantedImages
7167
#remove orderer and config txn
72-
rm -rf channel-artifacts/* crypto-config crypto-config.yaml configtx.yaml scripts/__pycache__ scripts/results.xml scripts/logs.txt scripts/.cache base
68+
rm -rf channel-artifacts/* crypto-config crypto-config.yaml configtx.yaml __pycache__ results.xml scripts/.cache base
7369
}
7470

7571
validateArgs

test/regression/daily/chaincodeTests/envsetup/scripts/fabricFeatureChaincodeTestRuns.py

-74
This file was deleted.

0 commit comments

Comments
 (0)