Skip to content

Commit

Permalink
Merge pull request #403 from jnjerin/invoke-command-update
Browse files Browse the repository at this point in the history
Initial step to implementing support for invoke command
  • Loading branch information
dzikowski authored Aug 22, 2023
2 parents 6d8c9e6 + 9b037fa commit f653b64
Show file tree
Hide file tree
Showing 19 changed files with 1,619 additions and 6,719 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

### Features
* Initial support for Kubernetes
* Basic support for chaincode invoke command

### Fixes
* Remove unsupported test library and dependencies
* Updated Node.js version from 12 to 16 in chaincode

## 1.1.0

Expand Down
16 changes: 3 additions & 13 deletions e2e-network/docker/expect-invoke-cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

cli="$1"
peer="$2"
peers="$2"
channel="$3"
chaincode="$4"
command="$5"
Expand All @@ -14,23 +14,13 @@ if [ -z "$expected" ]; then
exit 1
fi

label="Invoke $channel/$cli/$peer $command"
label="Invoke $channel/$cli/$peers $command"
echo ""
echo "➜ testing: $label"

peerAddresses="--peerAddresses $(echo "$peer" | sed 's/,/ --peerAddresses /g')"

response="$(
# shellcheck disable=SC2086
docker exec "$cli" peer chaincode invoke \
$peerAddresses \
-C "$channel" \
-n "$chaincode" \
-c "$command" \
--transient "$transient" \
--waitForEvent \
--waitForEventTimeout 90s \
2>&1
"$FABLO_HOME/fablo.sh" chaincode invoke "$channel" "$chaincode" "$peers" "$command" "$transient"
)"

echo "$response"
Expand Down
7 changes: 5 additions & 2 deletions e2e-network/docker/test-01-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

set -e


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

networkUp() {
"$FABLO_HOME/fablo-build.sh"
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" init node)
Expand Down Expand Up @@ -33,7 +36,7 @@ waitForChaincode() {
}

expectInvoke() {
sh "$TEST_TMP/../expect-invoke-cli.sh" "$1" "$2" "$3" "$4" "$5" "$6" "$7"
(cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "$6" "$7")
}

expectCommand() {
Expand Down Expand Up @@ -87,4 +90,4 @@ expectInvoke "cli.org1.example.com" "peer0.org1.example.com:7041" "my-channel1"
# Put some data again
expectInvoke "cli.org1.example.com" "peer0.org1.example.com:7041" "my-channel1" "chaincode1" \
'{"Args":["KVContract:put", "name", "James Bond"]}' \
'{\"success\":\"OK\"}'
'{\"success\":\"OK\"}'
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,7 @@ 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
Expand Down Expand Up @@ -2060,6 +2061,8 @@ 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\\" = \\"channel\\" ]; then
channelQuery \\"\${@:2}\\"
elif [ \\"$1\\" = \\"snapshot\\" ]; then
Expand Down Expand Up @@ -2119,6 +2122,63 @@ ORG2_CA_ADMIN_PASSWORD=adminpw
"
`;
exports[`samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json should create proper e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/chaincode-scripts.sh from samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json 1`] = `
"#!/usr/bin/env bash
# Function to perform chaincode invoke
chaincodeInvoke() {
local CHANNEL=\\"$1\\"
local CHAINCODE=\\"$2\\"
local PEERS=\\"$3\\"
local COMMAND=\\"$4\\"
local TRANSIENT=\\"$5\\"
echo \\"-> Chaincode invoke:\\"
inputLog \\"CHANNEL: $CHANNEL\\"
inputLog \\"CHAINCODE: $CHAINCODE\\"
inputLog \\"PEERS: $PEERS\\"
inputLog \\"COMMAND: $COMMAND\\"
inputLog \\"TRANSIENT: $TRANSIENT\\"
# Validate the input parameters
if [[ -z $CHANNEL || -z $CHAINCODE || -z $PEERS || -z $COMMAND || -z $TRANSIENT ]]; then
echo \\"Error: Insufficient arguments provided.\\"
echo \\"Usage: fablo chaincode invoke <channel_name> <chaincode_name> <peers_domains_comma_separated> <command> <transient>\\"
return 1
fi
PEER_ADDRESSES=\\"--peerAddresses $(echo \\"$PEERS\\" | sed 's/,/ --peerAddresses /g')\\"
CLI=\\"\\"
if [ \\"$PEERS\\" = \\"peer0.org1.example.com:7041\\" ]; then
CLI=\\"cli.org1.example.com\\"
fi
if [ \\"$PEERS\\" = \\"peer1.org1.example.com:7042\\" ]; then
CLI=\\"cli.org1.example.com\\"
fi
if [ \\"$PEERS\\" = \\"peer0.org2.example.com:7061\\" ]; then
CLI=\\"cli.org2.example.com\\"
fi
if [ -z \\"$CLI\\" ]; then
echo \\"Unknown peer: $PEERS\\"
exit 1
fi
# shellcheck disable=SC2086
docker exec \\"$CLI\\" peer chaincode invoke \\\\
$PEER_ADDRESSES \\\\
-C \\"$CHANNEL\\" \\\\
-n \\"$CHAINCODE\\" \\\\
-c \\"$COMMAND\\" \\\\
--transient \\"$TRANSIENT\\" \\\\
--waitForEvent \\\\
--waitForEventTimeout 90s \\\\
2>&1
}
"
`;
exports[`samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json should create proper e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/channel-query-scripts.sh from samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json 1`] = `
"#!/usr/bin/env bash
Expand Down Expand Up @@ -3700,6 +3760,7 @@ Array [
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-config/fabric-ca-server-config/org2.example.com/fabric-ca-server-config.yaml",
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/.env",
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/chaincode-scripts.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/channel-query-scripts.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/commands-generated.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.3-2orgs-1chaincode-private-data.json.tmpdir/fablo-target/fabric-docker/docker-compose.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ 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
Expand Down Expand Up @@ -1471,6 +1472,8 @@ 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\\" = \\"channel\\" ]; then
channelQuery \\"\${@:2}\\"
elif [ \\"$1\\" = \\"snapshot\\" ]; then
Expand Down Expand Up @@ -1527,6 +1530,60 @@ ORG1_CA_ADMIN_PASSWORD=adminpw
"
`;
exports[`samples/fablo-config-hlf1.4-1org-1chaincode-raft.json should create proper e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/chaincode-scripts.sh from samples/fablo-config-hlf1.4-1org-1chaincode-raft.json 1`] = `
"#!/usr/bin/env bash
# Function to perform chaincode invoke
chaincodeInvoke() {
local CHANNEL=\\"$1\\"
local CHAINCODE=\\"$2\\"
local PEERS=\\"$3\\"
local COMMAND=\\"$4\\"
local TRANSIENT=\\"$5\\"
echo \\"-> Chaincode invoke:\\"
inputLog \\"CHANNEL: $CHANNEL\\"
inputLog \\"CHAINCODE: $CHAINCODE\\"
inputLog \\"PEERS: $PEERS\\"
inputLog \\"COMMAND: $COMMAND\\"
inputLog \\"TRANSIENT: $TRANSIENT\\"
# Validate the input parameters
if [[ -z $CHANNEL || -z $CHAINCODE || -z $PEERS || -z $COMMAND || -z $TRANSIENT ]]; then
echo \\"Error: Insufficient arguments provided.\\"
echo \\"Usage: fablo chaincode invoke <channel_name> <chaincode_name> <peers_domains_comma_separated> <command> <transient>\\"
return 1
fi
PEER_ADDRESSES=\\"--peerAddresses $(echo \\"$PEERS\\" | sed 's/,/ --peerAddresses /g')\\"
CLI=\\"\\"
if [ \\"$PEERS\\" = \\"peer0.org1.example.com:7041\\" ]; then
CLI=\\"cli.org1.example.com\\"
fi
if [ \\"$PEERS\\" = \\"peer1.org1.example.com:7042\\" ]; then
CLI=\\"cli.org1.example.com\\"
fi
if [ -z \\"$CLI\\" ]; then
echo \\"Unknown peer: $PEERS\\"
exit 1
fi
# shellcheck disable=SC2086
docker exec \\"$CLI\\" peer chaincode invoke \\\\
$PEER_ADDRESSES \\\\
-C \\"$CHANNEL\\" \\\\
-n \\"$CHAINCODE\\" \\\\
-c \\"$COMMAND\\" \\\\
--transient \\"$TRANSIENT\\" \\\\
--waitForEvent \\\\
--waitForEventTimeout 90s \\\\
2>&1
}
"
`;
exports[`samples/fablo-config-hlf1.4-1org-1chaincode-raft.json should create proper e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/channel-query-scripts.sh from samples/fablo-config-hlf1.4-1org-1chaincode-raft.json 1`] = `
"#!/usr/bin/env bash
Expand Down Expand Up @@ -2992,6 +3049,7 @@ Array [
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-config/fabric-ca-server-config/org1.example.com/fabric-ca-server-config.yaml",
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/.env",
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/chaincode-scripts.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/channel-query-scripts.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/commands-generated.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-1org-1chaincode-raft.json.tmpdir/fablo-target/fabric-docker/docker-compose.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,7 @@ 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
Expand Down Expand Up @@ -2086,6 +2087,8 @@ 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\\" = \\"channel\\" ]; then
channelQuery \\"\${@:2}\\"
elif [ \\"$1\\" = \\"snapshot\\" ]; then
Expand Down Expand Up @@ -2145,6 +2148,66 @@ ORG2_CA_ADMIN_PASSWORD=adminpw
"
`;
exports[`samples/fablo-config-hlf1.4-2orgs-1chaincode.json should create proper e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/chaincode-scripts.sh from samples/fablo-config-hlf1.4-2orgs-1chaincode.json 1`] = `
"#!/usr/bin/env bash
# Function to perform chaincode invoke
chaincodeInvoke() {
local CHANNEL=\\"$1\\"
local CHAINCODE=\\"$2\\"
local PEERS=\\"$3\\"
local COMMAND=\\"$4\\"
local TRANSIENT=\\"$5\\"
echo \\"-> Chaincode invoke:\\"
inputLog \\"CHANNEL: $CHANNEL\\"
inputLog \\"CHAINCODE: $CHAINCODE\\"
inputLog \\"PEERS: $PEERS\\"
inputLog \\"COMMAND: $COMMAND\\"
inputLog \\"TRANSIENT: $TRANSIENT\\"
# Validate the input parameters
if [[ -z $CHANNEL || -z $CHAINCODE || -z $PEERS || -z $COMMAND || -z $TRANSIENT ]]; then
echo \\"Error: Insufficient arguments provided.\\"
echo \\"Usage: fablo chaincode invoke <channel_name> <chaincode_name> <peers_domains_comma_separated> <command> <transient>\\"
return 1
fi
PEER_ADDRESSES=\\"--peerAddresses $(echo \\"$PEERS\\" | sed 's/,/ --peerAddresses /g')\\"
CLI=\\"\\"
if [ \\"$PEERS\\" = \\"peer0.org1.example.com:7041\\" ]; then
CLI=\\"cli.org1.example.com\\"
fi
if [ \\"$PEERS\\" = \\"peer1.org1.example.com:7042\\" ]; then
CLI=\\"cli.org1.example.com\\"
fi
if [ \\"$PEERS\\" = \\"peer0.org2.example.com:7061\\" ]; then
CLI=\\"cli.org2.example.com\\"
fi
if [ \\"$PEERS\\" = \\"peer1.org2.example.com:7062\\" ]; then
CLI=\\"cli.org2.example.com\\"
fi
if [ -z \\"$CLI\\" ]; then
echo \\"Unknown peer: $PEERS\\"
exit 1
fi
# shellcheck disable=SC2086
docker exec \\"$CLI\\" peer chaincode invoke \\\\
$PEER_ADDRESSES \\\\
-C \\"$CHANNEL\\" \\\\
-n \\"$CHAINCODE\\" \\\\
-c \\"$COMMAND\\" \\\\
--transient \\"$TRANSIENT\\" \\\\
--waitForEvent \\\\
--waitForEventTimeout 90s \\\\
2>&1
}
"
`;
exports[`samples/fablo-config-hlf1.4-2orgs-1chaincode.json should create proper e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/channel-query-scripts.sh from samples/fablo-config-hlf1.4-2orgs-1chaincode.json 1`] = `
"#!/usr/bin/env bash
Expand Down Expand Up @@ -3798,6 +3861,7 @@ Array [
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-config/fabric-ca-server-config/org2.example.com/fabric-ca-server-config.yaml",
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/.env",
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/chaincode-scripts.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/channel-query-scripts.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/commands-generated.sh",
"e2e/__tmp__/samples/fablo-config-hlf1.4-2orgs-1chaincode.json.tmpdir/fablo-target/fabric-docker/docker-compose.yaml",
Expand Down
Loading

0 comments on commit f653b64

Please sign in to comment.