|
1 |
| -A framework to verify Hyperledger-Fabric functionality using chaincodes and CLI |
| 1 | +Chaincode Test Framework |
| 2 | +========================================================================== |
2 | 3 |
|
3 |
| -Multiple tests spanning multiple chaincodes can be run. |
4 |
| -Supports XML Reporting for each test run |
| 4 | +Framework Capabilities |
| 5 | +------------------------------------------------------------------------ |
5 | 6 |
|
| 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 |
6 | 11 |
|
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 Plug In *YourChaincode* |
| 14 | +--------------------------------------------------------------------------- |
12 | 15 |
|
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/* |
15 | 18 |
|
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 |
19 | 22 |
|
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* |
22 | 24 |
|
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 |
32 | 26 |
|
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 | +=========================================================================== |
44 | 28 |
|
45 |
| -Running tests... |
46 |
| ----------------------------------------------------------------------- |
47 | 29 |
|
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 | +------------------------------------------------------------------------ |
53 | 32 |
|
54 |
| -Ran 1 test in 135.392s |
| 33 | + ``$ cd fabric/test/regression/daily/chaincodeTests`` |
| 34 | + ``$ ./runChaincodes.sh`` |
55 | 35 |
|
| 36 | + *runChaincodes.sh* calls *testYourChaincode.py* |
56 | 37 |
|
| 38 | + ``py.test -v --junitxml YourChaincodeResults.xml testYourChaincode.py`` |
57 | 39 |
|
58 |
| -OK |
| 40 | + The output should look like the following: |
59 | 41 |
|
| 42 | + :: |
60 | 43 |
|
| 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 |
61 | 54 |
|
62 |
| -To deactivate docker network |
63 | 55 |
|
64 |
| -cd envsetup |
| 56 | +Logs |
| 57 | +------------------------------------------------------------------------------- |
| 58 | +Logs from each test script are redirected and stored at envsetup/scripts/output.log |
65 | 59 |
|
66 |
| -.. code:: bash |
67 | 60 |
|
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: |
70 | 65 |
|
| 66 | + ``cd /path/to/fabric/test/regression/daily/chaincodeTests/envsetup`` |
| 67 | + ``./network_setup.sh down`` |
71 | 68 |
|
0 commit comments