From 09b0726eae39dc5fc4867f499955f395a7cdb616 Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Thu, 7 Dec 2017 13:55:24 +0800 Subject: [PATCH] Fix docs and scripts --- hyperledger_fabric/README.md | 52 ++++++--- hyperledger_fabric/docs/event_listener.md | 7 +- hyperledger_fabric/docs/steps.md | 107 ++++++++++++------ hyperledger_fabric/latest/Makefile | 8 +- hyperledger_fabric/latest/kafka/README.md | 11 +- hyperledger_fabric/latest/scripts/func.sh | 2 +- hyperledger_fabric/latest/solo/README.md | 8 +- hyperledger_fabric/v1.0.4/Makefile | 11 +- hyperledger_fabric/v1.0.4/kafka/README.md | 11 +- .../{test_fetch.sh => test_fetch_blocks.sh} | 0 hyperledger_fabric/v1.0.4/solo/README.md | 8 +- 11 files changed, 138 insertions(+), 87 deletions(-) rename hyperledger_fabric/v1.0.4/scripts/{test_fetch.sh => test_fetch_blocks.sh} (100%) diff --git a/hyperledger_fabric/README.md b/hyperledger_fabric/README.md index 56c819db..656f20a2 100644 --- a/hyperledger_fabric/README.md +++ b/hyperledger_fabric/README.md @@ -12,25 +12,47 @@ If you're not familiar with Docker and Blockchain, can have a look at these book ## Getting Started -### Pick up a fabric version to test +### Pick up a fabric version -Take fabric latest stable code for example +Enter the subdir of specific version, e.g., ```bash -$ cd 1.0.5 # -$ HLF_MODE=solo make -$ HLF_MODE=kafka make -$ HLF_MODE=couchdb make -$ HLF_MODE=dev make +$ cd 1.0.5 # select a fabric version ``` -## Supported Releases +### Quick Test -* [Fabric v0.6.0](v0.6.0/): stable with fabric v0.6.0 code. -* [Fabric v1.0.0](v1.0.0/): stable with fabric v1.0.0 code. -* [Fabric v1.0.2](v1.0.2/): deprecated, test fabric v1.0.2 code. -* [Fabric v1.0.3](v1.0.3/): deprecated, test fabric v1.0.3 code. -* [Fabric v1.0.4](v1.0.4/): test fabric v1.0.4 code. -* [Fabric v1.0.5](v1.0.5/): latest stable fabric code with v1.0.5. -* [Fabric Latest](latest/): experimental with latest fabric code, unstable. +The following command will run the entire process (start a fabric network, create channel, test chaincode and stop it.) pass-through. +```bash +$ make setup # Install docker/compose, and pull required images +$ make test # Test with default fabric solo mode +``` + +### Test with more modes + +```bash +$ HLF_MODE=solo make test # in solo mode +$ HLF_MODE=kafka make test # in kafka mode +$ HLF_MODE=couchdb make test # solo+couchdb support, web UI is at `http://localhost:5984/_utils` +$ HLF_MODE=event make test # Enable eventhub listener +``` + +### Detailed Steps + +See [detailed steps](docs/steps.md) + +## Supported Fabric Releases + +Fabric Release | Description +--- | --- +[Fabric v0.6.0](v0.6.0/) | stable with fabric v0.6.0 code. +[Fabric v1.0.0](v1.0.0/) | stable with fabric v1.0.0 code. +[Fabric v1.0.2](v1.0.2/) | deprecated, test fabric v1.0.2 code. +[Fabric v1.0.4](v1.0.4/) | test fabric v1.0.4 code. +[Fabric v1.0.5](v1.0.5/) | latest stable fabric code with v1.0.5. +[Fabric Latest](latest/) | experimental with latest fabric code, unstable. + +## Acknowledgement +* [Hyperledger Fabric](https://github.com/hyperledger/fabric/) project. +* [Hyperledger Fabric Getting Started](http://hyperledger-fabric.readthedocs.io/en/latest/getting_started.html). diff --git a/hyperledger_fabric/docs/event_listener.md b/hyperledger_fabric/docs/event_listener.md index 8149403f..3cf25d38 100644 --- a/hyperledger_fabric/docs/event_listener.md +++ b/hyperledger_fabric/docs/event_listener.md @@ -3,7 +3,8 @@ Events didn't support TLS, so make sure TLS has been disabled by setting *_TLS_E Next, start the network with following command: ```bash -$ HLF_MODE=event make restart +$ HLF_MODE=event +$ make restart ``` when the network starts successfully, we started a block-listener in container `fabric-event-listener`. @@ -18,8 +19,8 @@ $ docker logs -f fabric-event-listener And init channels and chaincodes. ```bash -$ HLF_MODE=event make test_channel_create test_channel_join -$ HFL_MODE=event make test_cc_install test_cc_instantiate test_cc_invoke_query # Enable eventhub listener +$ make test_channel_create test_channel_join +$ make test_cc_install test_cc_instantiate test_cc_invoke_query # Enable eventhub listener ``` Then we will get some events at listening terminal looks like following: diff --git a/hyperledger_fabric/docs/steps.md b/hyperledger_fabric/docs/steps.md index b095ef20..8a310ff6 100644 --- a/hyperledger_fabric/docs/steps.md +++ b/hyperledger_fabric/docs/steps.md @@ -1,4 +1,6 @@ -## Environment Setup +## Detailed Steps + +### Environment Setup The following scripts will setup the environment by installing Docker, Docker-Compose and download required docker images. @@ -8,13 +10,24 @@ $ make setup # setup environment If you want to setup the environment manually, then have a look at [manually setup](docs/setup.md). -## Bootup Fabric Network +### Generate crypto-config and channel-artifacts + +```bash +$ make gen_config +``` + +The cmd actually calls `scripts/gen_config.sh` to generate the `crypto-config` and `channel-artifacts`. + +More details can be found at [Config Generation](docs/config_generation.md). + +### Bootup Fabric Network Start a 4 peer (belonging to 2 organizations) fabric network. ```sh $ make start # Start a fabric network ``` + The script actually uses docker-compose to boot up the fabric network with several containers. There will be 7 running containers, include 4 peers, 1 cli, 1 ca and 1 orderer. @@ -30,35 +43,39 @@ c6c5f69f2d53 yeasy/hyperledger-fabric-peer:1.0.4 "peer node start" ba1f00a9c83c hyperledger/fabric-orderer:x86_64-1.0.4 "orderer start" 6 seconds ago Up 14 seconds 0.0.0.0:7050->7050/tcp orderer.example.com ``` -### Initialize Fabric network +### Create Application Channel ```bash -$ make init # Start a fabric network +$ make test_channel_create ``` -The command actually calls the `./scripts/initialize.sh` script in the `fabric-cli` container to: +The command actually calls the `scripts/test_channel_create.sh` script in the `fabric-cli` container, to create a new application channel with default name of `businesschannel`. -* create a new application channel `businesschannel` -* join all peers into the channel -* install and instantiate chaincode `example02` for testing -This script only needs to be executed once. - -You should see result like the following if the initialization is successful. +### Join Peers into Application Channel ```bash -============================================== -==========initialize businesschannel========== -============================================== - -Channel name: businesschannel -Creating channel... - -... - -===================== All GOOD, initialization completed ===================== +$ make test_channel_join ``` +The command actually calls the `scripts/test_channel_join.sh` script in the `fabric-cli` container, to join all peers into the channel. + +### Intall Chaincode to All Peers + +```bash +$ make test_cc_install +``` + +The command actually calls the `scripts/test_cc_install.sh` script in the `fabric-cli` container, to install chaincode `example02` for testing. + +### Instantiate Chaincode in the Application Channel + +```bash +$ make test_cc_instantiate +``` + +The command actually calls the `scripts/test_cc_instantiate.sh` script in the `fabric-cli` container, to instantiate chaincode `example02`. + And there will be new chaincode container generated in the system, looks like ```bash @@ -69,24 +86,48 @@ e3092961b81b dev-peer1.org1.example.com-mycc-1.0 "chaincode -peer.a..." 57d3555f56e5 dev-peer0.org2.example.com-mycc-1.0 "chaincode -peer.a..." About a minute ago Up About a minute dev-peer0.org2.example.com-mycc-1.0 c9974dbc21d9 dev-peer0.org1.example.com-mycc-1.0 "chaincode -peer.a..." 23 minutes ago Up 23 minutes dev-peer0.org1.example.com-mycc-1.0 ``` - - -## Test Chaincode +### Test Chaincode ```bash -$ make test_cc # test invoke and query with chaincode +$ make test_cc_invoke_query ``` -More details, see [chaincode test](docs/chaincode_test.md). +The command actually calls the `scripts/test_cc_invoke_query.sh` script in the `fabric-cli` container, to test chaincode `example02` with invoke and query. +### Test System Chaincode -## Stop the network +```bash +$ make test_lscc # test LSCC +$ make test_qscc # test QSCC +``` + +The command actually calls the `scripts/test_lscc.sh` and `scripts/test_qscc.sh` script in the `fabric-cli` container, to test LSCC and QSCC. + +### Test Fetch Blocks + +```bash +$ make test_fetch_blocks # test fetch blocks +``` + +The command actually calls the `scripts/test_fetch_blocks.sh` script in the `fabric-cli` container, to test fetching blocks from channels. + +### Test Configtxlator + +```bash +$ make test_configtxlator +``` + +The command actually calls the `scripts/test_configtxlator.sh` script in the `fabric-cli` container, to test configtxlator to change the channel configuration. + +More details can be found at [Configtxlator](docs/configtxlator.md). + +### Stop the network ```bash $ make stop # stop the fabric network ``` -## Clean environment +### Clean environment Clean all related containers and images. @@ -94,7 +135,12 @@ Clean all related containers and images. $ make clean # clean the environment ``` -## More to learn + +### Enable Event Listener + +See [Event Listener](docs/event_listener.md). + +### More to learn Topics | Description -- | -- @@ -108,6 +154,3 @@ Topics | Description [WIP] [Some verification tests](docs/verification_test.md) | -## Acknowledgement -* [Hyperledger Fabric](https://github.com/hyperledger/fabric/) project. -* [Hyperledger Fabric Getting Started](http://hyperledger-fabric.readthedocs.io/en/latest/getting_started.html). diff --git a/hyperledger_fabric/latest/Makefile b/hyperledger_fabric/latest/Makefile index 37b4579a..e78d2933 100644 --- a/hyperledger_fabric/latest/Makefile +++ b/hyperledger_fabric/latest/Makefile @@ -18,7 +18,9 @@ else ifeq ($(HLF_MODE),dev) COMPOSE_FILE="docker-compose-1orgs-1peers-dev.yaml" endif -all: +all: test + +test: @echo "Run test with $(COMPOSE_FILE)" @echo "Please make sure u have setup Docker and pulled images by 'make setup'." @@ -113,7 +115,7 @@ test_lscc: # test lscc quries # FIXME: docker doesn't support wildcard in cp right now test_fetch_blocks: # test fetching channel blocks fetch @echo "Test fetching block files" - docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch.sh" + docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch_blocks.sh" ################## Env setup related, no need to see usually ################ @@ -178,7 +180,7 @@ download: # download required images docker pull yeasy/hyperledger-fabric-peer:latest docker pull yeasy/hyperledger-fabric-orderer:latest docker pull yeasy/hyperledger-fabric-ca:latest - docker pull yeasy/hyperledger-fabric-kafka:0.10.2.0 # official repo does not provide the latest image currently + docker pull yeasy/hyperledger-fabric-kafka:0.10.2.0 # TODO:official repo does not provide the latest image currently docker pull hyperledger/fabric-baseos:x86_64-0.4.2 docker pull hyperledger/fabric-zookeeper:x86_64-1.1.0-preview docker pull hyperledger/fabric-kafka:x86_64-1.1.0-preview diff --git a/hyperledger_fabric/latest/kafka/README.md b/hyperledger_fabric/latest/kafka/README.md index 97bbc6ae..1222cf5a 100644 --- a/hyperledger_fabric/latest/kafka/README.md +++ b/hyperledger_fabric/latest/kafka/README.md @@ -1,13 +1,8 @@ ## Start a network base on kafka -### Quick testing with kafka +### Quick testing + ```bash -$ KAFKA_ENABLED=true make +$ HLF_MODE=kafka make ``` When the fabric-network fully started, it takes about 30~60s to finish all the test. - -## Generate crypto-config and channel-artifacts - -```bash -$ make gen_kafka -``` diff --git a/hyperledger_fabric/latest/scripts/func.sh b/hyperledger_fabric/latest/scripts/func.sh index b1669ebe..1257ba85 100644 --- a/hyperledger_fabric/latest/scripts/func.sh +++ b/hyperledger_fabric/latest/scripts/func.sh @@ -254,7 +254,7 @@ chaincodeInstantiate () { res=$? cat log.txt verifyResult $res "ChaincodeInstantiation on peer$peer in channel ${channel} failed" - echo_g "=== ChaincodeInstantiation on peer$peer in channel ${channel} is successful ===" + echo_g "=== Chaincode Instantiated in channel ${channel} by peer$peer ===" } diff --git a/hyperledger_fabric/latest/solo/README.md b/hyperledger_fabric/latest/solo/README.md index ad9fa2f6..6dde3c1b 100644 --- a/hyperledger_fabric/latest/solo/README.md +++ b/hyperledger_fabric/latest/solo/README.md @@ -1,13 +1,7 @@ ## Start a network base on solo -### Quick testing with solo +### Quick testing ```bash $ HLF_MODE=solo make ``` When the fabric-network fully started, it takes about 30~60s to finish all the test. - -## Generate crypto-config and channel-artifacts - -```bash -$ make gen_solo gen_kafka -``` diff --git a/hyperledger_fabric/v1.0.4/Makefile b/hyperledger_fabric/v1.0.4/Makefile index 657ab19b..9dc3069b 100644 --- a/hyperledger_fabric/v1.0.4/Makefile +++ b/hyperledger_fabric/v1.0.4/Makefile @@ -18,7 +18,9 @@ else ifeq ($(HLF_MODE),dev) COMPOSE_FILE="docker-compose-1orgs-1peers-dev.yaml" endif -all: +all: test + +test: @echo "Run test with $(COMPOSE_FILE)" @echo "Please make sure u have setup Docker and pulled images by 'make setup'." @@ -29,15 +31,18 @@ all: ready: # create/join channel, install/instantiate cc make gen_config # Will ignore if local config path exists make restart + make test_channel_create make test_channel_join # make update_anchors + make test_cc_install make test_cc_instantiate - make test_cc_invoke_query + make test_lscc # test lscc operations make test_qscc # test qscc operations + make test_fetch_blocks # fetch block files make logs_save @@ -110,7 +115,7 @@ test_lscc: # test lscc quries # FIXME: docker doesn't support wildcard in cp right now test_fetch_blocks: # test fetching channel blocks fetch @echo "Test fetching block files" - docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch.sh" + docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch_blocks.sh" ################## Env setup related, no need to see usually ################ diff --git a/hyperledger_fabric/v1.0.4/kafka/README.md b/hyperledger_fabric/v1.0.4/kafka/README.md index 97bbc6ae..1222cf5a 100644 --- a/hyperledger_fabric/v1.0.4/kafka/README.md +++ b/hyperledger_fabric/v1.0.4/kafka/README.md @@ -1,13 +1,8 @@ ## Start a network base on kafka -### Quick testing with kafka +### Quick testing + ```bash -$ KAFKA_ENABLED=true make +$ HLF_MODE=kafka make ``` When the fabric-network fully started, it takes about 30~60s to finish all the test. - -## Generate crypto-config and channel-artifacts - -```bash -$ make gen_kafka -``` diff --git a/hyperledger_fabric/v1.0.4/scripts/test_fetch.sh b/hyperledger_fabric/v1.0.4/scripts/test_fetch_blocks.sh similarity index 100% rename from hyperledger_fabric/v1.0.4/scripts/test_fetch.sh rename to hyperledger_fabric/v1.0.4/scripts/test_fetch_blocks.sh diff --git a/hyperledger_fabric/v1.0.4/solo/README.md b/hyperledger_fabric/v1.0.4/solo/README.md index ad9fa2f6..6dde3c1b 100644 --- a/hyperledger_fabric/v1.0.4/solo/README.md +++ b/hyperledger_fabric/v1.0.4/solo/README.md @@ -1,13 +1,7 @@ ## Start a network base on solo -### Quick testing with solo +### Quick testing ```bash $ HLF_MODE=solo make ``` When the fabric-network fully started, it takes about 30~60s to finish all the test. - -## Generate crypto-config and channel-artifacts - -```bash -$ make gen_solo gen_kafka -```