From 2a3ee9c6a7e34f3f55354020ca822f2d76279be8 Mon Sep 17 00:00:00 2001 From: Marcus Brandenburger Date: Fri, 26 Jul 2024 16:22:33 +0200 Subject: [PATCH] Add test-network sample test Signed-off-by: Marcus Brandenburger --- go.mod | 2 +- go.sum | 12 ++ samples/deployment/test-network/Makefile | 38 ++--- samples/deployment/test-network/README.md | 55 ++++--- .../{docker-compose.yml => compose.yaml} | 0 samples/deployment/test-network/installFPC.sh | 2 + samples/deployment/test-network/setup.sh | 13 +- samples/deployment/test-network/test.sh | 151 ++++++++++++++++++ .../test-network/update-connection.sh | 8 +- 9 files changed, 218 insertions(+), 63 deletions(-) rename samples/deployment/test-network/{docker-compose.yml => compose.yaml} (100%) create mode 100755 samples/deployment/test-network/test.sh diff --git a/go.mod b/go.mod index 0150ae9b2..aedbf53fa 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/hyperledger/fabric-contract-api-go v1.2.1 github.com/hyperledger/fabric-protos-go v0.3.0 github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20230505123407-84f9ba1dc4ec - github.com/hyperledger/fabric-sdk-go v1.0.1-0.20221020141211-7af45cede6af + github.com/hyperledger/fabric-sdk-go v1.0.1-0.20240123083657-5d6ca326e01b github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1 github.com/onsi/ginkgo v1.16.5 github.com/onsi/ginkgo/v2 v2.11.0 diff --git a/go.sum b/go.sum index c8b6029d2..d1f239398 100644 --- a/go.sum +++ b/go.sum @@ -260,13 +260,18 @@ github.com/hyperledger/fabric-contract-api-go v1.2.1/go.mod h1:BhWve0gz1iH+Xc+cO github.com/hyperledger/fabric-lib-go v1.0.0 h1:UL1w7c9LvHZUSkIvHTDGklxFv2kTeva1QI2emOVc324= github.com/hyperledger/fabric-lib-go v1.0.0/go.mod h1:H362nMlunurmHwkYqR5uHL2UDWbQdbfz74n8kbCFsqc= github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0= +github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0= github.com/hyperledger/fabric-protos-go v0.0.0-20211118165945-23d738fc3553/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0= github.com/hyperledger/fabric-protos-go v0.3.0 h1:MXxy44WTMENOh5TI8+PCK2x6pMj47Go2vFRKDHB2PZs= github.com/hyperledger/fabric-protos-go v0.3.0/go.mod h1:WWnyWP40P2roPmmvxsUXSvVI/CF6vwY1K1UFidnKBys= github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20230505123407-84f9ba1dc4ec h1:drq6iuHjLc3H41zGfvljRZky45aLsWfc/J/lc52KjLY= github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20230505123407-84f9ba1dc4ec/go.mod h1:Y4ClFGIk5nmTlFOtryAY+sC55tYCpA6YZItPaKwPY6s= +github.com/hyperledger/fabric-sdk-go v1.0.0 h1:NRu0iNbHV6u4nd9jgYghAdA1Ll4g0Sri4hwMEGiTbyg= +github.com/hyperledger/fabric-sdk-go v1.0.0/go.mod h1:qWE9Syfg1KbwNjtILk70bJLilnmCvllIYFCSY/pa1RU= github.com/hyperledger/fabric-sdk-go v1.0.1-0.20221020141211-7af45cede6af h1:/DGxnlhN6Cg1PKj/5K01GUt4X1wN8nRVkZiJiQ05sCw= github.com/hyperledger/fabric-sdk-go v1.0.1-0.20221020141211-7af45cede6af/go.mod h1:JRplpKBeAvXjsBhOCCM/KvMRUbdDyhsAh80qbXzKc10= +github.com/hyperledger/fabric-sdk-go v1.0.1-0.20240123083657-5d6ca326e01b h1:ioSmXcO2r9+Sf7QbeaCQkWuTy5uHd+4u5CtFKLJhvRU= +github.com/hyperledger/fabric-sdk-go v1.0.1-0.20240123083657-5d6ca326e01b/go.mod h1:JRplpKBeAvXjsBhOCCM/KvMRUbdDyhsAh80qbXzKc10= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= @@ -314,6 +319,7 @@ github.com/lib/pq v0.0.0-20180201184707-88edab080323/go.mod h1:5WUZQaWbwv1U+lTRe github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= @@ -413,6 +419,7 @@ github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIw github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.8.0/go.mod h1:D6yutnOGMveHEPV7VQOuvI/gXY61bv+9bAOTRnLElKs= github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= @@ -432,6 +439,7 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= @@ -444,12 +452,14 @@ github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cY github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= @@ -479,6 +489,7 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.3.1/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -644,6 +655,7 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/samples/deployment/test-network/Makefile b/samples/deployment/test-network/Makefile index d676ae50d..34dc36177 100644 --- a/samples/deployment/test-network/Makefile +++ b/samples/deployment/test-network/Makefile @@ -6,30 +6,7 @@ TOP = ../../.. include $(TOP)/build.mk -ifeq ($(CC_ID),) - $(error CC_ID is not set) -endif -ifeq ($(CC_PATH),) - $(error CC_PATH is not set) -endif - -build: ercc-container ecc-container - -ercc-container: - make -C ${FPC_PATH}/ercc all docker - -ecc-container: - if [ "${SGX_MODE}" = "HW" ]; then \ - export HW_EXTENSION="-hw" ; \ - fi && \ - if [ "${WITH_GO}" = "YES" ]; then \ - export ECC_PATH=${CC_PATH}/mrenclave ; \ - else \ - export ECC_PATH=${CC_PATH}/_build/lib ; \ - fi && \ - make -C ${CC_PATH} && \ - make -C ${FPC_PATH}/ecc DOCKER_IMAGE=fpc/fpc-${CC_ID}$${HW_EXTENSION} DOCKER_ENCLAVE_SO_PATH=${ECC_PATH} all docker - +.PHONY: ercc-ecc-start ercc-ecc-start: if [ ! -z "${DOCKERD_FPC_PATH}" ]; then \ export SGX_CREDENTIALS_PATH="${DOCKERD_FPC_PATH}/integration/config/ias"; \ @@ -40,10 +17,19 @@ ercc-ecc-start: SGX_DEVICE_PATH=$$(if [ -e "/dev/isgx" ]; then echo "/dev/isgx"; elif [ -e "/dev/sgx/enclave" ]; then echo "/dev/sgx/enclave"; else echo "none"; fi) && \ [ "$${SGX_DEVICE_PATH}" != "none" ] || ( echo "ERROR: SGX_MODE is HW but no sgx device found"; exit 1; ) \ fi && \ - env CC_ID=${CC_ID} FPC_VERSION=${FPC_VERSION} ${DOCKER_COMPOSE} up -d + env FPC_VERSION=${FPC_VERSION} ${DOCKER_COMPOSE} up -d +.PHONY: ercc-ecc-start ercc-ecc-stop: - env CC_ID=${CC_ID} FPC_VERSION=${FPC_VERSION} ${DOCKER_COMPOSE} down + ${DOCKER_COMPOSE} down clobber: + docker compose down + ./fabric-samples/test-network/network.sh down || true rm -rf blockchain-explorer fabric-samples .env + docker system prune --force + docker network prune --force + docker volume prune --force + +test: + ./test.sh diff --git a/samples/deployment/test-network/README.md b/samples/deployment/test-network/README.md index 8b921c054..ebb34f98d 100644 --- a/samples/deployment/test-network/README.md +++ b/samples/deployment/test-network/README.md @@ -2,13 +2,11 @@ This guide shows how to deploy and run a FPC Chaincode on test-network provided by [fabric-samples](https://github.com/hyperledger/fabric-samples). -Before moving forward, follow the main [README](../../../README.md) to set up your environment. +Before moving forward, follow the main [README](../../../README.md) to set up your environment and build the project. This guide works also with the FPC Dev docker container. ## Prepare FPC Containers -[//]: # (TODO lets work this section) - FPC requires a special docker container to execute a FPC chaincode, similar to Fabric's `ccenv` container image but with additional support for Intel SGX. You can pull the FPC chaincode environment image (`fabric-private-chaincode-ccenv`) from our Github repository or build them manually as follows: @@ -20,27 +18,31 @@ make -C $FPC_PATH/utils/docker pull make -C $FPC_PATH/utils/docker build ``` -Next, we package the FPC components as docker images (building on top of `fabric-private-chaincode-ccenv`) which are deployed on our test network. -Use `CC_ID` and `CC_PATH` to define the FPC Chaincode you want to build. +Next, we package the FPC chaincode as a docker image which are deployed on the test-network using the chaincode as a service method. +The following snippet builds the `echo-go` FPC chaincode. +Note that we export `CC_ID`, `CC_NAME`, and `CC_VER` variables, which we will need ```bash -cd $FPC_PATH/samples/deployment/test-network -export CC_ID=echo -export CC_PATH=$FPC_PATH/samples/chaincode/echo -# TODO this needs to be changed! -export CC_VER=$(cat CC_PATH/) -make build +export CC_ID=echo-go +export CC_NAME=fpc-echo-go +make -C $FPC_PATH/samples/chaincode/echo-go build docker +export CC_VER=$(cat $FPC_PATH/samples/chaincode/echo-go/mrenclave) ``` -Note: If you want to build with [mock-enclave](../../../ecc/chaincode/enclave/mock_enclave.go) rather than the real enclave-based one, build with -`make build GOTAGS="-tags mock_ecc"` instead. +Please verify that the `fpc/fpc-echo-go` image exists using `docker images | grep fpc-echo-go`. + +Finally, make sure you have the FPC Enclave Registry container image already build (see the main [README](../../../README.md)), otherwise you can build it as follows: + +```bash +make -C ${FPC_PATH}/ercc all docker +``` ## Prepare the Test Network Next, we set up the Fabric samples [test-network](https://github.com/hyperledger/fabric-samples/tree/main/test-network). -Since the Fabric samples test network uses docker (and docker-compose) to run the Fabric components, we need to make sure that it works within our FPC dev container environment. +Since the Fabric samples test network uses docker (and docker compose) to run the Fabric components, we need to make sure that it works within our FPC dev container environment. In particular, as we use the host docker daemon, there may be issues with docker mounts. For convenience, we provide a `setup.sh` script that clones the fabric samples repository, downloads all required fabric container images and binaries, and replaces all relative mount paths in the compose files with absolute path on the host system. @@ -57,7 +59,7 @@ Let's start the Fabric-Samples test network. ```bash cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network -./network.sh up createChannel -ca -c mychannel +./network.sh up createChannel -c mychannel ``` @@ -80,7 +82,7 @@ Make sure you have set `CC_ID` to the same chaincode ID as used in the earlier s ```bash # Start FPC container -make ercc-ecc-start +make -C $FPC_PATH/samples/deployment/test-network ercc-ecc-start ``` You should see two instances of the FPC Echo chaincode and two instances of the FPC Enclave Registry chaincode running such as in the following example: @@ -100,7 +102,7 @@ ercc.peer0.org1.example.com | 2021-05-11 16:11:32.199 UTC [ercc] main -> INFO ``` The FPC Chaincode is now up and running, ready for processing invocations! -Note that the containers are running in foreground in your terminal using docker-compose. +Note that the containers are running in the background in your terminal using docker-compose. ## Interact with the FPC Chaincode @@ -130,7 +132,7 @@ In order to initiate the FPC Chaincode enclave and register it with the FPC Encl export SGX_CREDENTIALS_PATH=$FPC_PATH/config/ias cd $FPC_PATH/samples/application/simple-go -CC_ID=echo ORG_NAME=Org1 go run . -withLifecycleInitEnclave +CC_ID=echo-go ORG_NAME=Org1 go run . -withLifecycleInitEnclave ``` Note that we execute the go app as `Org1`, thereby creating and registering the FPC Chaincode enclave at `peer0.org1.example.com`. Alternatively, we could run this as `Org2` to initiate the enclave at `peer0.org2.example.com`. @@ -139,8 +141,8 @@ Afterwards you _must_ run the application without the `withLifecycleInitEnclave` ```bash cd $FPC_PATH/samples/application/simple-go -CC_ID=echo ORG_NAME=Org1 go run . -CC_ID=echo ORG_NAME=Org2 go run . +CC_ID=echo-go ORG_NAME=Org1 go run . +CC_ID=echo-go ORG_NAME=Org2 go run . ``` ### How to use simple-cli-go @@ -153,7 +155,7 @@ cd $FPC_PATH/samples/application/simple-cli-go make # export fpcclient settings -export CC_NAME=echo +export CC_NAME=echo-go export CHANNEL_NAME=mychannel export CORE_PEER_ADDRESS=localhost:7051 export CORE_PEER_ID=peer0.org1.example.com @@ -182,8 +184,6 @@ export SGX_CREDENTIALS_PATH=$FPC_PATH/config/ias Since we opened a new terminal to interact with the FPC Chaincode, to be able to shutdown the FPC chaincode you need to define the environment variables that set the chaincode name and path. ```bash -export CC_ID=echo -export CC_PATH=$FPC_PATH/samples/chaincode/echo make -C $FPC_PATH/samples/deployment/test-network ercc-ecc-stop cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network ./network.sh down @@ -191,13 +191,18 @@ cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network ## Using HelloWorld chaincode on the test-network -In this section we show how you can run a different FPC chaincode on the test network. For example, you can use the [HelloWorld](../../chaincode/helloworld/README.md) code instead of the echo code. To do so you have to change the values of the environment variables set at the beginning `CC_ID` and `CC_PATH`. +In this section we show how you can run a different FPC chaincode on the test network. For example, you can use the [HelloWorld](../../chaincode/helloworld/README.md) code instead of the echo-go code. +To do so you have to build the chaincode as follows: ```bash export CC_ID=helloworld -export CC_PATH=$FPC_PATH/samples/chaincode/helloworld +export CC_NAME=fpc-helloworld +make -C $FPC_PATH/samples/chaincode/helloworld build docker +export CC_VER=$(cat $FPC_PATH/samples/chaincode/helloworld/_build/lib/mrenclave) ``` +Repeat the process of starting the test-network and deployment as described above. + Afterwards to test you would use [simple-cli-go](#How-to-use-simple-cli-go). You would need to verify that the `CC_NAME` variable is set to helloworld and then to interact you would execute the chaincode as follows: ```bash diff --git a/samples/deployment/test-network/docker-compose.yml b/samples/deployment/test-network/compose.yaml similarity index 100% rename from samples/deployment/test-network/docker-compose.yml rename to samples/deployment/test-network/compose.yaml diff --git a/samples/deployment/test-network/installFPC.sh b/samples/deployment/test-network/installFPC.sh index 64139df6c..3e77c6d4a 100755 --- a/samples/deployment/test-network/installFPC.sh +++ b/samples/deployment/test-network/installFPC.sh @@ -42,6 +42,8 @@ ORG1_ECC_PKG_ID=$(${NETWORK_CMD} cc list -org 1 | grep "Label: ${CC_ID}_${CC_VER ORG2_ECC_PKG_ID=$(${NETWORK_CMD} cc list -org 2 | grep "Label: ${CC_ID}_${CC_VER}" | awk '{print $3}' | sed 's/.$//') cat > .env << EOF +CC_ID="$CC_ID" +CC_VER="${CC_VER}" ORG1_ECC_PKG_ID="${ORG1_ECC_PKG_ID}" ORG1_ERCC_PKG_ID="${ORG1_ERCC_PKG_ID}" ORG2_ECC_PKG_ID="${ORG2_ECC_PKG_ID}" diff --git a/samples/deployment/test-network/setup.sh b/samples/deployment/test-network/setup.sh index 8b7ae3c31..8fdb650bc 100755 --- a/samples/deployment/test-network/setup.sh +++ b/samples/deployment/test-network/setup.sh @@ -55,19 +55,18 @@ else fi echo "set FPC_PATH_HOST = ${FPC_PATH_HOST}" -FABRIC_SAMPLES_HOST=${FPC_PATH}/samples/deployment/test-network/fabric-samples -DOCKERD_FABRIC_SAMPLES_HOST=${FPC_PATH_HOST}samples/deployment/test-network/fabric-samples +FABRIC_SAMPLES_HOST=${FPC_PATH_HOST}/samples/deployment/test-network/fabric-samples TEST_NETWORK_HOST=${FABRIC_SAMPLES_HOST}/test-network -DOCKERD_TEST_NETWORK_HOST=${DOCKERD_FABRIC_SAMPLES_HOST}/test-network +TEST_NETWORK=${FABRIC_SAMPLES}/test-network -echo "set DOCKERD_TEST_NETWORK_HOST = ${DOCKERD_TEST_NETWORK_HOST}" +echo "set FABRIC_SAMPLES_HOST = ${FABRIC_SAMPLES_HOST}" echo "set TEST_NETWORK_HOST = ${TEST_NETWORK_HOST}" echo "Resolving relative docker volume paths" # replace "../" with absolute path -find "${TEST_NETWORK_HOST}/compose" -maxdepth 1 \( -name '*compose*.yaml' -o -name '*compose*.yml' \) -exec sed -i -E 's+(- )(\.\.)(/)+\1'"${DOCKERD_TEST_NETWORK_HOST}"'\3+g' {} \; +find "${TEST_NETWORK}/compose" -maxdepth 1 \( -name '*compose*.yaml' -o -name '*compose*.yml' \) -exec sed -i -E 's+(- )(\.\.)(/)+\1'"${TEST_NETWORK_HOST}"'\3+g' {} \; # replace "./" with absolute path -find "${TEST_NETWORK_HOST}/compose" -mindepth 2 -maxdepth 2 \( -name '*compose*.yaml' -o -name '*compose*.yml' \) -exec sed -i -E 's+(- )(\.)(/)+\1'"${DOCKERD_TEST_NETWORK_HOST}/compose"'\3+g' {} \; +find "${TEST_NETWORK}/compose" -mindepth 2 -maxdepth 2 \( -name '*compose*.yaml' -o -name '*compose*.yml' \) -exec sed -i -E 's+(- )(\.)(/)+\1'"${TEST_NETWORK_HOST}/compose"'\3+g' {} \; ############################################################################################## @@ -104,7 +103,7 @@ wget -O "${BE_DOCKER_COMPOSE}" https://raw.githubusercontent.com/hyperledger/blo cat > "${BE_PATH}/.env" << EOF EXPLORER_CONFIG_FILE_PATH=${BE_PATH_HOST}/config.json EXPLORER_PROFILE_DIR_PATH=${BE_PATH_HOST}/connection-profile -FABRIC_CRYPTO_PATH=${DOCKERD_TEST_NETWORK_HOST}/organizations +FABRIC_CRYPTO_PATH=${TEST_NETWORK_HOST}/organizations EOF diff --git a/samples/deployment/test-network/test.sh b/samples/deployment/test-network/test.sh new file mode 100755 index 000000000..197ccc3a1 --- /dev/null +++ b/samples/deployment/test-network/test.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env bash + +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 + +set -Eeuo pipefail + +# test settings +CC_PATH="$FPC_PATH/samples/chaincode/echo-go" +CC_ID=echo-go +CHANNEL_NAME=mychannel + +trap cleanup SIGINT SIGTERM ERR EXIT +function cleanup() { + # reset traps + trap - SIGINT SIGTERM ERR EXIT + + echo "########################################" + echo "Cleanup" + echo "########################################" + + make -C "$FPC_PATH/samples/deployment/test-network" clobber +} + +function test_network_setup() { + echo "########################################" + echo "Run setup" + echo "########################################" + + cd "$FPC_PATH/samples/deployment/test-network" + ./setup.sh + + echo "########################################" + echo "start test-netowrk" + echo "########################################" + + cd fabric-samples/test-network + ./network.sh up createChannel -c $CHANNEL_NAME + + docker ps +} + +function test_deploy() { + echo "########################################" + echo "build $CC_ID" + echo "########################################" + + export CC_ID=$CC_ID + export FPC_CCENV_IMAGE=ubuntu:22.04 + export ERCC_GOTAGS= + + # build ercc + GOOS=linux make -C "$FPC_PATH/ercc" build docker + + # build fpc chaincode + GOOS=linux CC_NAME=fpc-$CC_ID make -C "$CC_PATH" with_go docker + + local ccver + ccver=$(cat "$CC_PATH/mrenclave") + + export CC_VER=$ccver + + echo "########################################" + echo "install FPC chaincode" + echo "########################################" + + cd "$FPC_PATH/samples/deployment/test-network" + ./installFPC.sh + + echo "########################################" + echo "Run chaincodes ..." + echo "########################################" + + cd "$FPC_PATH/samples/deployment/test-network" + make ercc-ecc-start + + docker ps + + echo "########################################" + echo "Update connection details ..." + echo "########################################" + + cd "$FPC_PATH/samples/deployment/test-network" + ./update-connection.sh +} + +function test_simple_go() { + echo "########################################" + echo "run simple_go" + echo "########################################" + + cd "$FPC_PATH/samples/application/simple-go" + CC_ID=$CC_ID ORG_NAME=Org1 go run . -withLifecycleInitEnclave + + CC_ID=$CC_ID ORG_NAME=Org1 go run . + CC_ID=$CC_ID ORG_NAME=Org2 go run . +} + +function test_simple_cli() { + echo "########################################" + echo "run simple_cli" + echo "########################################" + + cd "$FPC_PATH/samples/application/simple-cli-go" + make + + export CC_NAME=$CC_ID + export CHANNEL_NAME=$CHANNEL_NAME + export CORE_PEER_ADDRESS=localhost:7051 + export CORE_PEER_ID=peer0.org1.example.com + export CORE_PEER_LOCALMSPID=Org1MSP + export CORE_PEER_MSPCONFIGPATH="$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" + export CORE_PEER_TLS_CERT_FILE="$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt" + export CORE_PEER_TLS_ENABLED="true" + export CORE_PEER_TLS_KEY_FILE="$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key" + export CORE_PEER_TLS_ROOTCERT_FILE="$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" + export ORDERER_CA="$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" + export GATEWAY_CONFIG="$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml" + export SGX_CREDENTIALS_PATH="$FPC_PATH/config/ias" + + # note that we skip the init here as this is done in test_simple_go already + #./fpcclient init $CORE_PEER_ID + + ./fpcclient invoke foo + ./fpcclient query foo +} + +function test_blockchain_explorer() { + echo "########################################" + echo "start blockchain explorer" + echo "########################################" + + cd "$FPC_PATH/samples/deployment/test-network/blockchain-explorer" + docker compose up -d + + curl http://localhost:8080/ +} + +function test_shutdown() { + make -C "$FPC_PATH/samples/deployment/test-network" ercc-ecc-stop + cd "$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network" + ./network.sh down +} + +test_network_setup +test_deploy +test_simple_go +test_simple_cli +test_blockchain_explorer +test_shutdown diff --git a/samples/deployment/test-network/update-connection.sh b/samples/deployment/test-network/update-connection.sh index f2f37c57c..8df34d756 100755 --- a/samples/deployment/test-network/update-connection.sh +++ b/samples/deployment/test-network/update-connection.sh @@ -5,7 +5,7 @@ # # SPDX-License-Identifier: Apache-2.0 -set -euo pipefail +set -Eeuo pipefail if [[ -z "${FPC_PATH}" ]]; then echo "Error: FPC_PATH not set" @@ -77,21 +77,21 @@ EOF # add channels and entity matcher yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i "${CONNECTIONS_PATH}" "${temp_yaml}" + yq "${CONNECTIONS_PATH}" > /dev/null # fetch all peers from connections - yq ".peers" "${CONNECTIONS_PATH}" >> "${tmp_dir}/peers-${org}.yaml" + yq '(.peers) as $item ireduce({}; setpath($item | path; $item))' "${CONNECTIONS_PATH}" >> "${tmp_dir}/peers-${org}.yaml" done # consolidate all collected peers in a single peers.yaml yq eval-all '. as $item ireduce ({}; . * $item )' ${tmp_dir}/peers-*.yaml >> "${tmp_dir}/peers.yaml" -yq 'true' "${tmp_dir}/peers.yaml" > /dev/null # merge peers.yaml into all connection files for org in "${orgs[@]}"; do ORG_PATH="${FPC_PATH}/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/${org}.example.com" CONNECTIONS_PATH="${ORG_PATH}/connection-${org}.yaml" yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml" - yq 'true' "${CONNECTIONS_PATH}" > /dev/null + yq "${CONNECTIONS_PATH}" > /dev/null done echo "Updated!"