From 47080f2e16d095c066efe2af326a661e9d5f159f Mon Sep 17 00:00:00 2001 From: jnjerin Date: Mon, 11 Sep 2023 15:50:00 +0300 Subject: [PATCH 1/4] created support for chaincodes list command (with TLS) Signed-off-by: jnjerin --- e2e-network/docker/test-02-raft-2orgs.sh | 20 ++++--- e2e-network/docker/wait-for-chaincode-tls.sh | 60 +++++++++---------- .../scripts/chaincode-functions-v2.sh | 22 ++++++- 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/e2e-network/docker/test-02-raft-2orgs.sh b/e2e-network/docker/test-02-raft-2orgs.sh index b9fdf939..916bc8dc 100755 --- a/e2e-network/docker/test-02-raft-2orgs.sh +++ b/e2e-network/docker/test-02-raft-2orgs.sh @@ -6,6 +6,8 @@ TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))" FABLO_HOME="$TEST_TMP/../../.." +export FABLO_HOME + CONFIG="$FABLO_HOME/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml" networkUp() { @@ -33,7 +35,7 @@ waitForContainer() { } waitForChaincode() { - sh "$TEST_TMP/../wait-for-chaincode-tls.sh" "$1" "$2" "$3" "$4" "$5" + (cd "$TEST_TMP" && sh ../wait-for-chaincode.sh "$1" "$2" "$3" "$4") } expectInvokeRest() { @@ -82,10 +84,10 @@ waitForContainer "peer1.org2.example.com" "Anchor peer for channel my-channel2 w waitForContainer "peer1.org2.example.com" "Membership view has changed. peers went online:.*peer1.org1.example.com:7062" # check if chaincodes are instantiated on peers -waitForChaincode "cli.org1.example.com" "peer0.org1.example.com:7061" "my-channel1" "chaincode1" "0.0.1" -waitForChaincode "cli.org2.example.com" "peer0.org2.example.com:7081" "my-channel1" "chaincode1" "0.0.1" -waitForChaincode "cli.org1.example.com" "peer1.org1.example.com:7062" "my-channel2" "chaincode2" "0.0.1" -waitForChaincode "cli.org2.example.com" "peer1.org2.example.com:7082" "my-channel2" "chaincode2" "0.0.1" +waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1" +waitForChaincode "peer0.org2.example.com" "my-channel1" "chaincode1" "0.0.1" +waitForChaincode "peer1.org1.example.com" "my-channel2" "chaincode2" "0.0.1" +waitForChaincode "peer1.org2.example.com" "my-channel2" "chaincode2" "0.0.1" fablo_rest_org1="localhost:8802" @@ -107,13 +109,13 @@ expectInvokeCli "cli.org2.example.com" "peer1.org2.example.com:7082" "my-channel # restart the network and wait for chaincodes (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" stop && "$FABLO_HOME/fablo.sh" start) -waitForChaincode "cli.org1.example.com" "peer0.org1.example.com:7061" "my-channel1" "chaincode1" "0.0.1" -waitForChaincode "cli.org2.example.com" "peer0.org2.example.com:7081" "my-channel1" "chaincode1" "0.0.1" +waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1" +waitForChaincode "peer0.org2.example.com" "my-channel1" "chaincode1" "0.0.1" # upgrade chaincode (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" chaincode upgrade "chaincode1" "0.0.2") -waitForChaincode "cli.org1.example.com" "peer0.org1.example.com:7061" "my-channel1" "chaincode1" "0.0.2" -waitForChaincode "cli.org2.example.com" "peer0.org2.example.com:7081" "my-channel1" "chaincode1" "0.0.2" +waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.2" +waitForChaincode "peer0.org2.example.com" "my-channel1" "chaincode1" "0.0.2" # check if state is kept after update expectInvokeRest "$fablo_rest_org1" "my-channel1" "chaincode1" \ diff --git a/e2e-network/docker/wait-for-chaincode-tls.sh b/e2e-network/docker/wait-for-chaincode-tls.sh index dbb3f55b..b16478fc 100755 --- a/e2e-network/docker/wait-for-chaincode-tls.sh +++ b/e2e-network/docker/wait-for-chaincode-tls.sh @@ -1,36 +1,36 @@ -#!/usr/bin/env bash +# #!/usr/bin/env bash -cli=$1 -peer=$2 -channel=$3 -chaincode=$4 -version=$5 -search_string="Name: $chaincode, Version: $version" +# cli=$1 +# peer=$2 +# channel=$3 +# chaincode=$4 +# version=$5 +# search_string="Name: $chaincode, Version: $version" -if [ -z "$version" ]; then - echo "Usage: ./wait-for-chaincode.sh [cli] [peer:port] [channel] [chaincode] [version]" - exit 1 -fi +# if [ -z "$version" ]; then +# echo "Usage: ./wait-for-chaincode.sh [cli] [peer:port] [channel] [chaincode] [version]" +# exit 1 +# fi -listChaincodes() { - docker exec -e CORE_PEER_ADDRESS="$peer" "$cli" peer lifecycle chaincode querycommitted \ - --channelID "$channel" \ - --tls \ - --cafile "/var/hyperledger/cli/crypto-orderer/tlsca.root.com-cert.pem" -} +# listChaincodes() { +# docker exec -e CORE_PEER_ADDRESS="$peer" "$cli" peer lifecycle chaincode querycommitted \ +# --channelID "$channel" \ +# --tls \ +# --cafile "/var/hyperledger/cli/crypto-orderer/tlsca.root.com-cert.pem" +# } -for i in $(seq 1 90); do - echo "➜ verifying if chaincode ($chaincode/$version) is committed on $channel/$cli/$peer ($i)..." +# for i in $(seq 1 90); do +# echo "➜ verifying if chaincode ($chaincode/$version) is committed on $channel/$cli/$peer ($i)..." - if listChaincodes 2>&1 | grep "$search_string"; then - echo "✅ ok: Chaincode $chaincode/$version is ready on $channel/$cli/$peer!" - exit 0 - else - sleep 1 - fi -done +# if listChaincodes 2>&1 | grep "$search_string"; then +# echo "✅ ok: Chaincode $chaincode/$version is ready on $channel/$cli/$peer!" +# exit 0 +# else +# sleep 1 +# fi +# done -#timeout -echo "❌ failed: Failed to verify chaincode $chaincode/$version on $channel/$cli/$peer" -listChaincodes -exit 1 +# #timeout +# echo "❌ failed: Failed to verify chaincode $chaincode/$version on $channel/$cli/$peer" +# listChaincodes +# exit 1 diff --git a/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh b/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh index 2af77272..6a24c908 100644 --- a/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh +++ b/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh @@ -307,8 +307,26 @@ peerChaincodeList() { --channelID "$CHANNEL_NAME" } +# peerChaincodeListTls() { +# echo "Chaincode list with TLS is not supported yet" +# exit 1 +# } + peerChaincodeListTls() { - echo "Chaincode list with TLS is not supported yet" - exit 1 + local CLI_NAME=$1 + local PEER_ADDRESS=$2 + local CHANNEL_NAME=$3 + local CA_CERT=$4 + + echo "Chaincodes list:" + inputLog "PEER_ADDRESS: $PEER_ADDRESS" + inputLog "CHANNEL_NAME: $CHANNEL_NAME" + inputLog "CA_CERT: $CA_CERT" + + + docker exec -e CORE_PEER_ADDRESS="$PEER_ADDRESS" "$CLI_NAME" peer lifecycle chaincode querycommitted \ + --channelID "$CHANNEL_NAME" \ + --tls \ + --cafile "/var/hyperledger/cli/$CA_CERT" } From 5e3a23b90e0bcfb599fb413dd0f32fadff16465d Mon Sep 17 00:00:00 2001 From: jnjerin Date: Mon, 11 Sep 2023 16:54:46 +0300 Subject: [PATCH 2/4] cleanup:Deleted wait-for-chaincode-tls script Signed-off-by: jnjerin --- e2e-network/docker/wait-for-chaincode-tls.sh | 36 ------------------- .../scripts/chaincode-functions-v2.sh | 4 --- 2 files changed, 40 deletions(-) delete mode 100755 e2e-network/docker/wait-for-chaincode-tls.sh diff --git a/e2e-network/docker/wait-for-chaincode-tls.sh b/e2e-network/docker/wait-for-chaincode-tls.sh deleted file mode 100755 index b16478fc..00000000 --- a/e2e-network/docker/wait-for-chaincode-tls.sh +++ /dev/null @@ -1,36 +0,0 @@ -# #!/usr/bin/env bash - -# cli=$1 -# peer=$2 -# channel=$3 -# chaincode=$4 -# version=$5 -# search_string="Name: $chaincode, Version: $version" - -# if [ -z "$version" ]; then -# echo "Usage: ./wait-for-chaincode.sh [cli] [peer:port] [channel] [chaincode] [version]" -# exit 1 -# fi - -# listChaincodes() { -# docker exec -e CORE_PEER_ADDRESS="$peer" "$cli" peer lifecycle chaincode querycommitted \ -# --channelID "$channel" \ -# --tls \ -# --cafile "/var/hyperledger/cli/crypto-orderer/tlsca.root.com-cert.pem" -# } - -# for i in $(seq 1 90); do -# echo "➜ verifying if chaincode ($chaincode/$version) is committed on $channel/$cli/$peer ($i)..." - -# if listChaincodes 2>&1 | grep "$search_string"; then -# echo "✅ ok: Chaincode $chaincode/$version is ready on $channel/$cli/$peer!" -# exit 0 -# else -# sleep 1 -# fi -# done - -# #timeout -# echo "❌ failed: Failed to verify chaincode $chaincode/$version on $channel/$cli/$peer" -# listChaincodes -# exit 1 diff --git a/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh b/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh index 6a24c908..0e11d6a0 100644 --- a/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh +++ b/src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh @@ -307,10 +307,6 @@ peerChaincodeList() { --channelID "$CHANNEL_NAME" } -# peerChaincodeListTls() { -# echo "Chaincode list with TLS is not supported yet" -# exit 1 -# } peerChaincodeListTls() { local CLI_NAME=$1 From 1abd0fc8a840fa2b9364abdd33d27e30dc329cf4 Mon Sep 17 00:00:00 2001 From: jnjerin Date: Mon, 11 Sep 2023 17:04:26 +0300 Subject: [PATCH 3/4] update CHANGELOG and snapshots Signed-off-by: jnjerin --- CHANGELOG.md | 6 +++--- ...rg-1chaincode-raft-explorer.json.test.ts.snap | 16 ++++++++++++++-- ...config-hlf2-1org-1chaincode.json.test.ts.snap | 16 ++++++++++++++-- ...hlf2-2orgs-2chaincodes-raft.yaml.test.ts.snap | 16 ++++++++++++++-- ...gs-1chaincode-raft-explorer.json.test.ts.snap | 16 ++++++++++++++-- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e1377fa..9e4045c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ ### Features * Initial support for Kubernetes -* Basic support for chaincode invoke command -* Support for `chaincodes list command` - +* Basic support for `chaincode invoke` command +* Support for `chaincodes list` command (tls and non-tls) + ### Fixes * Remove unsupported test library and dependencies * Updated Node.js version from 12 to 16 in chaincode diff --git a/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-raft-explorer.json.test.ts.snap b/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-raft-explorer.json.test.ts.snap index 327a13bf..cb37d94a 100644 --- a/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-raft-explorer.json.test.ts.snap +++ b/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-raft-explorer.json.test.ts.snap @@ -2778,8 +2778,20 @@ peerChaincodeList() { } peerChaincodeListTls() { - echo \\"Chaincode list with TLS is not supported yet\\" - exit 1 + local CLI_NAME=$1 + local PEER_ADDRESS=$2 + local CHANNEL_NAME=$3 + local CA_CERT=$4 + + echo \\"Chaincodes list:\\" + inputLog \\"PEER_ADDRESS: $PEER_ADDRESS\\" + inputLog \\"CHANNEL_NAME: $CHANNEL_NAME\\" + inputLog \\"CA_CERT: $CA_CERT\\" + + docker exec -e CORE_PEER_ADDRESS=\\"$PEER_ADDRESS\\" \\"$CLI_NAME\\" peer lifecycle chaincode querycommitted \\\\ + --channelID \\"$CHANNEL_NAME\\" \\\\ + --tls \\\\ + --cafile \\"/var/hyperledger/cli/$CA_CERT\\" } " `; diff --git a/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode.json.test.ts.snap b/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode.json.test.ts.snap index 05f9d766..5ac84f3b 100644 --- a/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode.json.test.ts.snap +++ b/e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode.json.test.ts.snap @@ -2656,8 +2656,20 @@ peerChaincodeList() { } peerChaincodeListTls() { - echo \\"Chaincode list with TLS is not supported yet\\" - exit 1 + local CLI_NAME=$1 + local PEER_ADDRESS=$2 + local CHANNEL_NAME=$3 + local CA_CERT=$4 + + echo \\"Chaincodes list:\\" + inputLog \\"PEER_ADDRESS: $PEER_ADDRESS\\" + inputLog \\"CHANNEL_NAME: $CHANNEL_NAME\\" + inputLog \\"CA_CERT: $CA_CERT\\" + + docker exec -e CORE_PEER_ADDRESS=\\"$PEER_ADDRESS\\" \\"$CLI_NAME\\" peer lifecycle chaincode querycommitted \\\\ + --channelID \\"$CHANNEL_NAME\\" \\\\ + --tls \\\\ + --cafile \\"/var/hyperledger/cli/$CA_CERT\\" } " `; diff --git a/e2e/__snapshots__/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.test.ts.snap b/e2e/__snapshots__/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.test.ts.snap index 95e45a94..8b030998 100644 --- a/e2e/__snapshots__/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.test.ts.snap +++ b/e2e/__snapshots__/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.test.ts.snap @@ -4967,8 +4967,20 @@ peerChaincodeList() { } peerChaincodeListTls() { - echo \\"Chaincode list with TLS is not supported yet\\" - exit 1 + local CLI_NAME=$1 + local PEER_ADDRESS=$2 + local CHANNEL_NAME=$3 + local CA_CERT=$4 + + echo \\"Chaincodes list:\\" + inputLog \\"PEER_ADDRESS: $PEER_ADDRESS\\" + inputLog \\"CHANNEL_NAME: $CHANNEL_NAME\\" + inputLog \\"CA_CERT: $CA_CERT\\" + + docker exec -e CORE_PEER_ADDRESS=\\"$PEER_ADDRESS\\" \\"$CLI_NAME\\" peer lifecycle chaincode querycommitted \\\\ + --channelID \\"$CHANNEL_NAME\\" \\\\ + --tls \\\\ + --cafile \\"/var/hyperledger/cli/$CA_CERT\\" } " `; diff --git a/e2e/__snapshots__/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.test.ts.snap b/e2e/__snapshots__/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.test.ts.snap index 3232dcab..6ee33269 100644 --- a/e2e/__snapshots__/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.test.ts.snap +++ b/e2e/__snapshots__/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.test.ts.snap @@ -5466,8 +5466,20 @@ peerChaincodeList() { } peerChaincodeListTls() { - echo \\"Chaincode list with TLS is not supported yet\\" - exit 1 + local CLI_NAME=$1 + local PEER_ADDRESS=$2 + local CHANNEL_NAME=$3 + local CA_CERT=$4 + + echo \\"Chaincodes list:\\" + inputLog \\"PEER_ADDRESS: $PEER_ADDRESS\\" + inputLog \\"CHANNEL_NAME: $CHANNEL_NAME\\" + inputLog \\"CA_CERT: $CA_CERT\\" + + docker exec -e CORE_PEER_ADDRESS=\\"$PEER_ADDRESS\\" \\"$CLI_NAME\\" peer lifecycle chaincode querycommitted \\\\ + --channelID \\"$CHANNEL_NAME\\" \\\\ + --tls \\\\ + --cafile \\"/var/hyperledger/cli/$CA_CERT\\" } " `; From 9e69f48e978e05affeee8b11933848b4e26be97b Mon Sep 17 00:00:00 2001 From: jnjerin Date: Tue, 12 Sep 2023 16:01:58 +0300 Subject: [PATCH 4/4] included new changes on chaincodes list with tls on snapshot test Signed-off-by: jnjerin --- e2e-network/docker/test-04-snapshot.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/e2e-network/docker/test-04-snapshot.sh b/e2e-network/docker/test-04-snapshot.sh index a5db68e1..a952d6fa 100755 --- a/e2e-network/docker/test-04-snapshot.sh +++ b/e2e-network/docker/test-04-snapshot.sh @@ -6,6 +6,8 @@ TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))" FABLO_HOME="$TEST_TMP/../../.." +export FABLO_HOME + CONFIG="$FABLO_HOME/samples/fablo-config-hlf2-1org-1chaincode-raft-explorer.json" networkUp() { @@ -30,7 +32,7 @@ waitForContainer() { } waitForChaincode() { - sh "$TEST_TMP/../wait-for-chaincode-tls.sh" "$1" "$2" "$3" "$4" "$5" + (cd "$TEST_TMP" && sh ../wait-for-chaincode.sh "$1" "$2" "$3" "$4") } expectInvokeRest() { @@ -55,7 +57,7 @@ waitForContainer "couchdb.peer0.org1.example.com" "Apache CouchDB has started. T waitForContainer "peer0.org1.example.com" "Joining gossip network of channel my-channel1 with 1 organizations" waitForContainer "db.explorer.example.com" "database system is ready to accept connections" "200" waitForContainer "explorer.example.com" "Successfully created channel event hub for \[my-channel1\]" "200" -waitForChaincode "cli.org1.example.com" "peer0.org1.example.com:7041" "my-channel1" "chaincode1" "0.0.1" +waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1" fablo_rest_org1="localhost:8801" snapshot_name="fablo-snapshot-$(date -u +"%Y%m%d%H%M%S")" @@ -111,7 +113,7 @@ hook_command="perl -i -pe 's/FABRIC_VERSION=2\.3\.3/FABRIC_VERSION=2\.4\.2/g' ./ "$FABLO_HOME/fablo.sh" restore "$snapshot_name" "$hook_command" && "$FABLO_HOME/fablo.sh" start ) -waitForChaincode "cli.org1.example.com" "peer0.org1.example.com:7041" "my-channel1" "chaincode1" "0.0.1" +waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1" sleep 5