|
| 1 | +# Makefile to bootup the network, and do testing with channel, chaincode |
| 2 | +# Run `make test` will pass all testing cases, and delete the network |
| 3 | +# Run `make ready` will create a network, pass testing cases, and stand there for manual test, e.g., make test_channel_list |
| 4 | + |
| 5 | + |
| 6 | +# support advanced bash grammar |
| 7 | +SHELL:=/bin/bash |
| 8 | + |
| 9 | +# mode of the network: raft only for 2.x |
| 10 | +HLF_MODE ?= raft |
| 11 | + |
| 12 | +# mode of db: golevel, couchdb |
| 13 | +DB_MODE ?= golevel |
| 14 | + |
| 15 | +# mode of dev |
| 16 | +DEV_MODE ?= non-dev |
| 17 | + |
| 18 | +NETWORK_INIT_WAIT ?= 2 # time to wait the fabric network finish initialization |
| 19 | + |
| 20 | +COMPOSE_FILE ?= "docker-compose-2orgs-4peers-raft.yaml" |
| 21 | + |
| 22 | +ifeq ($(HLF_MODE),raft) |
| 23 | + NETWORK_INIT_WAIT=5 |
| 24 | +else |
| 25 | + NETWORK_INIT_WAIT=30 |
| 26 | +endif |
| 27 | + |
| 28 | +COMPOSE_FILE="docker-compose-2orgs-4peers-$(HLF_MODE).yaml" |
| 29 | + |
| 30 | +LOG_PATH ?= $(HLF_MODE)/logs |
| 31 | + |
| 32 | +ifeq ($(DB_MODE),couchdb) |
| 33 | + COMPOSE_FILE="docker-compose-2orgs-4peers-couchdb.yaml" |
| 34 | +endif |
| 35 | + |
| 36 | +ifeq ($(DEV_MODE),dev) |
| 37 | + COMPOSE_FILE="docker-compose-2orgs-4peers-dev.yaml" |
| 38 | +endif |
| 39 | + |
| 40 | +all: test |
| 41 | + |
| 42 | +test: |
| 43 | + @echo "Run test with $(COMPOSE_FILE)" |
| 44 | + @echo "Please make sure u have setup Docker and pulled images by 'make setup download'." |
| 45 | + make ready # Run all testing till ready |
| 46 | + |
| 47 | + make stop clean |
| 48 | + |
| 49 | +ready: # create/join channel, install/instantiate cc |
| 50 | + make stop |
| 51 | + |
| 52 | + # make clean_config_channel # Remove existing channel artifacts |
| 53 | + make gen_config_crypto # Will ignore if local config path exists |
| 54 | + make gen_config_channel # Will ignore if local config path exists |
| 55 | + |
| 56 | + make start |
| 57 | + |
| 58 | + sleep ${NETWORK_INIT_WAIT} |
| 59 | + |
| 60 | + make channel_test |
| 61 | + |
| 62 | + make update_anchors |
| 63 | + |
| 64 | + make cc_test # test_cc_install test_cc_approveformyorg test_cc_checkcommitreadiness test_cc_commit test_cc_querycommitted test_cc_invoke_query |
| 65 | + |
| 66 | + # make test_lscc # test lscc operations, in v2.0, legacy lscc won't work |
| 67 | + make test_qscc # test qscc operations |
| 68 | + make test_cscc # test cscc operations |
| 69 | + |
| 70 | + make test_fetch_blocks # fetch block files |
| 71 | + |
| 72 | + make test_gen_add_org3_tx |
| 73 | + make test_channel_update |
| 74 | + |
| 75 | + make test_fetch_blocks # fetch block files again |
| 76 | + make test_configtxlator |
| 77 | + |
| 78 | + make test_channel_list |
| 79 | + make test_channel_getinfo |
| 80 | + |
| 81 | + # make logs_save |
| 82 | + |
| 83 | + @echo "Now the fabric network is ready to play" |
| 84 | + @echo "* run 'make cli' to enter into the fabric-cli container." |
| 85 | + @echo "* run 'make stop' when done." |
| 86 | + |
| 87 | +# channel related operations |
| 88 | +channel_test: test_channel_create test_channel_join test_channel_list test_channel_getinfo |
| 89 | + |
| 90 | +# chaincode related operations |
| 91 | +cc_test: test_cc_install test_cc_queryinstalled test_cc_approveformyorg test_cc_queryapproved test_cc_checkcommitreadiness test_cc_commit test_cc_querycommitted test_cc_invoke_query |
| 92 | + |
| 93 | +restart: stop start |
| 94 | + |
| 95 | +start: # bootup the fabric network |
| 96 | + @echo "Start a fabric network with ${COMPOSE_FILE}..." |
| 97 | + @make clean |
| 98 | + @echo "Make sure the local hlf_net docker bridge exists" |
| 99 | + docker network ls|grep hlf_net > /dev/null || docker network create hlf_net |
| 100 | + @docker-compose -f ${COMPOSE_FILE} up -d # Start a fabric network |
| 101 | + |
| 102 | +stop: # stop the fabric network |
| 103 | + @echo "Stop the fabric network with ${COMPOSE_FILE}..." |
| 104 | + @docker-compose -f ${COMPOSE_FILE} down >& /tmp/docker-compose.log |
| 105 | + |
| 106 | +chaincode_dev: restart chaincode_init test_cc_peer0 stop |
| 107 | + |
| 108 | +################## Channel testing operations ################ |
| 109 | + |
| 110 | +test_channel_list: # List the channel that peer joined |
| 111 | + @echo "List the joined channels" |
| 112 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_list.sh" |
| 113 | + |
| 114 | +test_channel_getinfo: # Get info of a channel |
| 115 | + @echo "Get info of the app channel" |
| 116 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_getinfo.sh" |
| 117 | + |
| 118 | +test_channel_create: # Init the channel |
| 119 | + @echo "Create channel on the fabric network" |
| 120 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_create.sh" |
| 121 | + |
| 122 | +test_channel_join: # Init the channel |
| 123 | + @echo "Join channel" |
| 124 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_join.sh" |
| 125 | + |
| 126 | +update_anchors: # Update the anchor peer |
| 127 | + @echo "Update anchors on the fabric network" |
| 128 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_update_anchors.sh" |
| 129 | + |
| 130 | +test_channel_update: # send the channel update transaction |
| 131 | + @echo "Test channel update with adding new org" |
| 132 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_update.sh" |
| 133 | + |
| 134 | +################## Configtxlator testing operations ################ |
| 135 | +test_configtxlator: # Test change config using configtxlator |
| 136 | + @echo "Testing decoding and encoding with configtxlator" |
| 137 | + bash scripts/test_configtxlator.sh ${HLF_MODE} |
| 138 | + @echo "Flattening the json files of all blocks" |
| 139 | + python3 scripts/json_flatter.py ${HLF_MODE}/channel-artifacts/ |
| 140 | + |
| 141 | +test_gen_add_org3_tx: # Test change config to add new org |
| 142 | + bash scripts/test_gen_add_org3_tx.sh ${HLF_MODE} |
| 143 | + |
| 144 | +################## Chaincode testing operations ################ |
| 145 | +test_cc: # test chaincode, deprecated |
| 146 | + if [ "$(HLF_MODE)" = "dev" ]; then \ |
| 147 | + make test_cc_peer0; \ |
| 148 | + else \ |
| 149 | + make test_cc_invoke_query; \ |
| 150 | + fi |
| 151 | + |
| 152 | +test_cc_install: # Install the chaincode |
| 153 | + @echo "Install chaincode to all peers" |
| 154 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_install.sh" |
| 155 | + |
| 156 | +test_cc_queryinstalled: # Query the installed chaincodes |
| 157 | + @echo "Query the installed chaincode" |
| 158 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_queryinstalled.sh" |
| 159 | + |
| 160 | +test_cc_getinstalled: # Get the installed chaincodes package |
| 161 | + @echo "Get the installed chaincode package" |
| 162 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_getinstalled.sh" |
| 163 | + |
| 164 | +test_cc_approveformyorg: # Approve the chaincode definition |
| 165 | + @echo "Approve the chaincode by all orgs" |
| 166 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_approveformyorg.sh" |
| 167 | + |
| 168 | +test_cc_queryapproved: # Query the approved chaincode definition |
| 169 | + @echo "Query the approved status of chaincode" |
| 170 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_queryapproved.sh" |
| 171 | + |
| 172 | +test_cc_checkcommitreadiness: # Query the approval status of chaincode |
| 173 | + @echo "Query the chaincode approval status by all orgs" |
| 174 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_checkcommitreadiness.sh" |
| 175 | + |
| 176 | +test_cc_commit: # Commit the chaincode definition |
| 177 | + @echo "Commit the chaincode by any org" |
| 178 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_commit.sh" |
| 179 | + |
| 180 | +test_cc_querycommitted: # Query the commit status of the chaincode definition |
| 181 | + @echo "Query the commit status of chaincode" |
| 182 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_querycommitted.sh" |
| 183 | + |
| 184 | +test_cc_instantiate: # Instantiate the chaincode |
| 185 | + @echo "Instantiate chaincode on the fabric network" |
| 186 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_instantiate.sh" |
| 187 | + |
| 188 | +test_cc_upgrade: # Upgrade the chaincode |
| 189 | + @echo "Upgrade chaincode on the fabric network" |
| 190 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_upgrade.sh" |
| 191 | + |
| 192 | +test_cc_list: # List the chaincode |
| 193 | + @echo "List chaincode information (installed and instantited)" |
| 194 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_list.sh" |
| 195 | + |
| 196 | +test_cc_invoke_query: # test user chaincode on all peers |
| 197 | + @echo "Invoke and query cc example02 on all peers" |
| 198 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_invoke_query.sh" |
| 199 | + |
| 200 | +test_cscc: # test cscc queries |
| 201 | + @echo "Test CSCC query" |
| 202 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cscc.sh" |
| 203 | + |
| 204 | +test_qscc: # test qscc queries |
| 205 | + @echo "Test QSCC query" |
| 206 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_qscc.sh" |
| 207 | + |
| 208 | +test_lscc: # test lscc quries |
| 209 | + @echo "Test LSCC query" |
| 210 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_lscc.sh" |
| 211 | + |
| 212 | +# FIXME: docker doesn't support wildcard in cp right now |
| 213 | +test_fetch_blocks: # test fetching channel blocks fetch |
| 214 | + @echo "Test fetching block files" |
| 215 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch_blocks.sh" |
| 216 | + |
| 217 | +test_eventsclient: # test get event notification in a loop |
| 218 | + @echo "Test fetching event notification" |
| 219 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/start_eventsclient.sh" |
| 220 | + |
| 221 | +test_sidedb: # test sideDB/private data feature |
| 222 | + @echo "Test sideDB" |
| 223 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_sideDB.sh" |
| 224 | + |
| 225 | +temp: # test temp instructions, used for experiment |
| 226 | + @echo "Test experimental instructions" |
| 227 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_temp.sh" |
| 228 | + |
| 229 | +################## Env setup related, no need to see usually ################ |
| 230 | + |
| 231 | +setup: # setup the environment |
| 232 | + bash scripts/env_setup.sh # Installing Docker and Docker-Compose |
| 233 | + |
| 234 | +check: # Check shell scripts grammar |
| 235 | + @echo "Check shell scripts grammar" |
| 236 | + [ `which shellcheck` ] && shellcheck scripts/*.sh |
| 237 | + |
| 238 | +clean: # clean up containers and chaincode images |
| 239 | + @echo "Clean all HLF containers and chaincode images" |
| 240 | + @-docker ps -a | awk '{ print $$1,$$2 }' | grep "hyperledger/fabric" | awk '{ print $$1 }' | xargs -r -I {} docker rm -f {} |
| 241 | + @-docker ps -a | awk '$$2 ~ /dev-peer/ { print $$1 }' | xargs -r -I {} docker rm -f {} |
| 242 | + @-docker images | awk '$$1 ~ /dev-peer/ { print $$3 }' | xargs -r -I {} docker rmi -f {} |
| 243 | + echo "May clean the config: HLF_MODE=${HLF_MODE} make clean_config_channel" |
| 244 | + |
| 245 | +# Clean deeply by removing all generated files: container, artifacts, credentials |
| 246 | +purge: clean |
| 247 | + HLF_MODE=raft make clean_config_channel |
| 248 | + make clean_config_crypto |
| 249 | + |
| 250 | +env_clean: # clean up Docker environment |
| 251 | + @echo "Clean all images and containers" |
| 252 | + bash scripts/env_clean.sh |
| 253 | + |
| 254 | +cli: # enter the cli container |
| 255 | + docker exec -it fabric-cli bash |
| 256 | + |
| 257 | +sdk_node: # enter the sdk-node container |
| 258 | + docker exec -it sdk-node bash |
| 259 | + |
| 260 | +gateway_java: # enter the gateway-java container |
| 261 | + docker exec -it gateway-java bash |
| 262 | + |
| 263 | +orderer: orderer0 |
| 264 | + |
| 265 | +orderer0: # enter the orderer0 container |
| 266 | + docker exec -it orderer0.example.com bash |
| 267 | + |
| 268 | +orderer1: # enter the orderer0 container |
| 269 | + docker exec -it orderer1.example.com bash |
| 270 | + |
| 271 | +peer: peer0 |
| 272 | + |
| 273 | +peer0: # enter the peer container |
| 274 | + docker exec -it peer0.org1.example.com bash |
| 275 | + |
| 276 | +peer1: # enter the peer container |
| 277 | + docker exec -it peer1.org1.example.com bash |
| 278 | + |
| 279 | +ps: # show existing docker images |
| 280 | + docker ps -a |
| 281 | + |
| 282 | +logs: # show logs |
| 283 | + docker-compose -f ${COMPOSE_FILE} logs -f --tail 200 |
| 284 | + |
| 285 | +logs_check: logs_save logs_view |
| 286 | + |
| 287 | +logs_save: # save logs |
| 288 | + @echo "All tests done, saving logs locally" |
| 289 | + [ -d $(LOG_PATH) ] || mkdir -p $(LOG_PATH) |
| 290 | + docker logs peer0.org1.example.com >& $(LOG_PATH)/dev_peer0.log |
| 291 | + docker logs orderer0.example.com >& $(LOG_PATH)/dev_orderer.log |
| 292 | + docker-compose -f ${COMPOSE_FILE} logs >& $(LOG_PATH)/dev_all.log |
| 293 | + |
| 294 | +logs_view: # view logs |
| 295 | + less $(LOG_PATH)/dev_peer.log |
| 296 | + |
| 297 | +elk: # insert logs into elk |
| 298 | + # curl -XDELETE http://localhost:9200/logstash-\* |
| 299 | + nc localhost 5000 < $(LOG_PATH)/dev_all.log |
| 300 | + |
| 301 | +gen_config_crypto: # generate crypto config |
| 302 | + bash scripts/gen_crypto_artifacts.sh |
| 303 | + |
| 304 | +gen_config_channel: # generate channel artifacts |
| 305 | + bash scripts/gen_channel_artifacts.sh ${HLF_MODE} |
| 306 | + |
| 307 | +clean_config_channel: # clean channel related artifacts |
| 308 | + rm -rf ${HLF_MODE}/channel-artifacts/* |
| 309 | + |
| 310 | +clean_config_crypto: # clean config artifacts |
| 311 | + echo "Warning: Cleaning credentials will affect artifacts in raft mode" |
| 312 | + rm -rf crypto-config/* |
| 313 | + rm -rf org3/crypto-config/* |
| 314 | + |
| 315 | +download: # download required images |
| 316 | + @echo "Download Docker images" |
| 317 | + bash scripts/download_images.sh |
| 318 | + |
| 319 | +################## chaincode dev mode ################ |
| 320 | +chaincode_init: # start chaincode in dev mode and do install/instantiate |
| 321 | + @echo "Install and instantiate cc example02 on the fabric dev network" |
| 322 | + @docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/init_chaincode_dev.sh" |
0 commit comments