diff --git a/e2e-network/docker/test-05.sh b/e2e-network/docker/test-05.sh index 808b6336..94fa6280 100755 --- a/e2e-network/docker/test-05.sh +++ b/e2e-network/docker/test-05.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-hlf3-1orgs-1chaincode.json" networkUp() { @@ -36,7 +38,7 @@ waitForChaincode() { } expectInvoke() { - (cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "$6") + (cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "") } expectCommand() { @@ -49,8 +51,8 @@ trap 'networkDown ; echo "Test failed" ; exit 1' ERR SIGINT # start the network networkUp -waitForContainer "orderer0.group1.orderer.example.com" "Created and started new.*my-channel1" -waitForContainer "ca.org1.example.com" "Listening on http://0.0.0.0:7054" +waitForContainer "orderer0.group1.orderer.example.com" "Starting raft node as part of a new channel channel=my-channel1" +waitForContainer "ca.org1.example.com" "Listening on https://0.0.0.0:7054" waitForContainer "peer0.org1.example.com" "Joining gossip network of channel my-channel1 with 1 organizations" waitForContainer "peer1.org1.example.com" "Joining gossip network of channel my-channel1 with 1 organizations" waitForContainer "peer0.org1.example.com" "Learning about the configured anchor peers of Org1MSP for channel my-channel1" @@ -71,23 +73,12 @@ expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \ (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch newest my-channel1 org1 peer1) expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:get" -(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 4 my-channel1 org1 peer1 "another.block") +(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 3 my-channel1 org1 peer1 "another.block") expectCommand "cat \"$TEST_TMP/another.block\"" "KVContract:put" (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch config my-channel1 org1 peer1 "channel-config.json") expectCommand "cat \"$TEST_TMP/channel-config.json\"" "\"mod_policy\": \"Admins\"," -expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":6" +expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":5" -# Reset and ensure the state is lost after reset -(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" reset) -waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1" -waitForChaincode "peer1.org1.example.com" "my-channel1" "chaincode1" "0.0.1" -expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \ - '{"Args":["KVContract:get", "name"]}' \ - '{\"error\":\"NOT_FOUND\"}' - -# Put some data again -expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \ - '{"Args":["KVContract:put", "name", "James Bond"]}' \ - '{\"success\":\"OK\"}' \ No newline at end of file +echo "🎉 Test passed! 🎉" \ No newline at end of file diff --git a/src/setup-docker/index.ts b/src/setup-docker/index.ts index 762b3f56..36711d82 100644 --- a/src/setup-docker/index.ts +++ b/src/setup-docker/index.ts @@ -213,7 +213,7 @@ export default class SetupDockerGenerator extends Generator { } _copyUtilityScripts(capabilities: Capabilities): void { - this.fs.copyTpl(this.templatePath(`fabric-docker-${capabilities.isV3? "v3": "v2"}.sh`), this.destinationPath("fabric-docker.sh")); + this.fs.copyTpl(this.templatePath(`fabric-docker.sh`), this.destinationPath("fabric-docker.sh")); this.fs.copyTpl( this.templatePath(`fabric-docker/scripts/cli/channel_fns-${capabilities.isV3? "v3": "v2"}.sh`), diff --git a/src/setup-docker/templates/fabric-docker-v3.sh b/src/setup-docker/templates/fabric-docker-v3.sh deleted file mode 100755 index db605e0a..00000000 --- a/src/setup-docker/templates/fabric-docker-v3.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -FABLO_NETWORK_ROOT="$(cd "$(dirname "$0")" && pwd)" - -source "$FABLO_NETWORK_ROOT/fabric-docker/scripts/base-help.sh" -source "$FABLO_NETWORK_ROOT/fabric-docker/scripts/base-functions.sh" -source "$FABLO_NETWORK_ROOT/fabric-docker/scripts/chaincode-functions.sh" -source "$FABLO_NETWORK_ROOT/fabric-docker/channel-query-scripts.sh" -source "$FABLO_NETWORK_ROOT/fabric-docker/snapshot-scripts.sh" -source "$FABLO_NETWORK_ROOT/fabric-docker/commands-generated.sh" -source "$FABLO_NETWORK_ROOT/fabric-docker/.env" -source "$FABLO_NETWORK_ROOT/fabric-docker/chaincode-scripts.sh" - - -networkUp() { - generateArtifacts - startNetwork - generateChannelsArtifacts - installChannels - installChaincodes - printStartSuccessInfo -} - -if [ "$1" = "up" ]; then - networkUp -elif [ "$1" = "down" ]; then - networkDown -elif [ "$1" = "reset" ]; then - networkDown - networkUp -elif [ "$1" = "start" ]; then - startNetwork -elif [ "$1" = "stop" ]; then - stopNetwork -elif [ "$1" = "chaincodes" ] && [ "$2" = "install" ]; then - installChaincodes -elif [ "$1" = "chaincode" ] && [ "$2" = "install" ]; then - installChaincode "$3" "$4" -elif [ "$1" = "chaincode" ] && [ "$2" = "upgrade" ]; then - upgradeChaincode "$3" "$4" -elif [ "$1" = "chaincode" ] && [ "$2" = "dev" ]; then - runDevModeChaincode "$3" "$4" -elif [ "$1" = "chaincode" ] && [ "$2" = "invoke" ]; then - chaincodeInvoke "$3" "$4" "$5" "$6" "$7" -elif [ "$1" = "chaincodes" ] && [ "$2" = "list" ]; then - chaincodeList "$3" "$4" -elif [ "$1" = "channel" ]; then - channelQuery "${@:2}" -elif [ "$1" = "snapshot" ]; then - createSnapshot "$2" -elif [ "$1" = "clone-to" ]; then - cloneSnapshot "$2" "${3:-""}" -elif [ "$1" = "help" ]; then - printHelp -elif [ "$1" = "--help" ]; then - printHelp -else - echo "No command specified" - echo "Basic commands are: up, down, start, stop, reset" - echo "To list channel query helper commands type: 'fablo channel --help'" - echo "Also check: 'chaincode install'" - echo "Use 'help' or '--help' for more information" -fi \ No newline at end of file diff --git a/src/setup-docker/templates/fabric-docker-v2.sh b/src/setup-docker/templates/fabric-docker.sh similarity index 100% rename from src/setup-docker/templates/fabric-docker-v2.sh rename to src/setup-docker/templates/fabric-docker.sh diff --git a/src/setup-docker/templates/fabric-docker/commands-generated.sh b/src/setup-docker/templates/fabric-docker/commands-generated.sh index 5842909e..8d1f81fe 100644 --- a/src/setup-docker/templates/fabric-docker/commands-generated.sh +++ b/src/setup-docker/templates/fabric-docker/commands-generated.sh @@ -13,9 +13,14 @@ generateArtifacts() { <% }) -%> <%_ ordererGroups.forEach((ordererGroup) => { _%> + + <% if(!global.capabilities.isV3) {%> printItalics "Generating genesis block for group <%= ordererGroup.name %>" "U1F3E0" genesisBlockCreate "$FABLO_NETWORK_ROOT/fabric-config" "$FABLO_NETWORK_ROOT/fabric-config/config" "<%= ordererGroup.profileName %>" - + <% } else { %> + echo "System channel not supported for Fabric version 3" + <% } %> + <%_ }) _%> # Create directory for chaincode packages to avoid permission errors on linux mkdir -p "$FABLO_NETWORK_ROOT/fabric-config/chaincode-packages" @@ -179,6 +184,7 @@ upgradeChaincode() { } notifyOrgsAboutChannels() { + <% if(!global.capabilities.isV3) { %> printHeadline "Creating new channel config blocks" "U1F537" <% channels.forEach((channel) => { -%> <% channel.orgs.forEach((org) => { -%> @@ -219,6 +225,11 @@ notifyOrgsAboutChannels() { deleteNewChannelUpdateTx "<%= channel.name %>" "<%= org.mspName %>" "<%= org.cli.address %>" <% }) -%> <% }) -%> + + <% } else { %> + echo "" + <% } %> + } printStartSuccessInfo() { diff --git a/src/setup-docker/templates/fabric-docker/scripts/base-functions-v3.sh b/src/setup-docker/templates/fabric-docker/scripts/base-functions-v3.sh index f24fce65..27f572e3 100644 --- a/src/setup-docker/templates/fabric-docker/scripts/base-functions-v3.sh +++ b/src/setup-docker/templates/fabric-docker/scripts/base-functions-v3.sh @@ -77,7 +77,8 @@ createChannelTx() { local CONFIG_PATH=$2 local CONFIG_PROFILE=$3 local OUTPUT_PATH=$4 - local CHANNEL_TX_PATH="$OUTPUT_PATH/$CHANNEL_NAME".pb + local CHANNEL_TX_PATH="$OUTPUT_PATH/$CHANNEL_NAME.pb" + echo CHNANEL_TX_PATH: $CHANNEL_TX_PATH echo "Creating channelTx for $CHANNEL_NAME..." inputLog "CONFIG_PATH: $CONFIG_PATH" @@ -91,17 +92,20 @@ createChannelTx() { exit 1 fi - docker run -i -d -w="/" --name $CONTAINER_NAME hyperledger/fabric-tools:"${FABRIC_VERSION}" bash || removeContainer $CONTAINER_NAME - docker cp "$CONFIG_PATH" $CONTAINER_NAME:/fabric-config || removeContainer $CONTAINER_NAME - - docker exec -i $CONTAINER_NAME mkdir /config || removeContainer $CONTAINER_NAME + docker run --rm \ + --name $CONTAINER_NAME \ + -v "$CONFIG_PATH":/fabric-config \ + -v "$OUTPUT_PATH":/output \ + hyperledger/fabric-tools:"${FABRIC_VERSION}" \ + bash -c "mkdir -p /output && configtxgen --configPath /fabric-config -profile ${CONFIG_PROFILE} -outputBlock /output/$CHANNEL_NAME.pb -channelID ${CHANNEL_NAME}" - docker exec -i $CONTAINER_NAME configtxgen --configPath ./fabric-config -profile "${CONFIG_PROFILE}" -outputBlock ./config/channel.pb -channelID "${CHANNEL_NAME}" - docker cp $CONTAINER_NAME:/config/channel.pb "$CHANNEL_TX_PATH" || removeContainer $CONTAINER_NAME - + if [ $? -ne 0 ]; then + echo "Failed to create channel configuration transaction." + exit 1 + fi + echo "Channel configuration created at $CHANNEL_TX_PATH" - removeContainer $CONTAINER_NAME } createNewChannelUpdateTx() {