Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions e2e-network/docker/expect-query-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

peers="$1"
channel="$2"
chaincode="$3"
command="$4"
expected="$5"
transient_default="{}"
transient="${6:-$transient_default}"

if [ -z "$expected" ]; then
echo "Usage: ./expect-query.sh [peer[,peer]] [channel] [chaincode] [command] [expected_substring] [transient_data]"
exit 1
fi

label="Query $channel/$peers $command"
echo ""
echo "➜ testing: $label"

response="$(
"$FABLO_HOME/fablo.sh" chaincode query "$peers" "$channel" "$chaincode" "$command" "$transient"
)"

echo "$response"

if echo "$response" | grep -F "$expected"; then
echo "✅ ok (cli): $label"
else
echo "❌ failed (cli): $label | expected: $expected"
exit 1
fi
16 changes: 10 additions & 6 deletions e2e-network/docker/test-01-v2-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ expectCommand() {
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
}

expectQuery() {
(cd "$TEST_TMP" && sh ../expect-query-cli.sh "$1" "$2" "$3" "$4" "$5")
}

trap networkDown EXIT
trap 'networkDown ; echo "Test failed" ; exit 1' ERR SIGINT

Expand All @@ -62,29 +66,29 @@ waitForContainer "peer1.org1.example.com" "Membership view has changed. peers we
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
'{\"success\":\"OK\"}'
expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \
expectQuery "peer1.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:get", "name"]}' \
'{\"success\":\"Willy Wonka\"}'
'{"success":"Willy Wonka"}'

# Verify channel query scripts
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch newest my-channel1 org1 peer1)
expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:get"
expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:put"

(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 4 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" \
expectQuery "peer0.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:get", "name"]}' \
'{\"error\":\"NOT_FOUND\"}'
'{"error":"NOT_FOUND"}'

# Put some data again
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
Expand Down
12 changes: 8 additions & 4 deletions e2e-network/docker/test-05-v3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ expectInvoke() {
(cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "")
}

expectQuery() {
(cd "$TEST_TMP" && sh ../expect-query-cli.sh "$1" "$2" "$3" "$4" "$5")
}

expectCommand() {
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
}
Expand Down Expand Up @@ -100,20 +104,20 @@ echo "🎉 Node.js Gateway client test complete 🎉"
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
'{\"success\":\"OK\"}'
expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \
expectQuery "peer1.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:get", "name"]}' \
'{\"success\":\"Willy Wonka\"}'
'{"success":"Willy Wonka"}'

# Verify channel query scripts
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch newest my-channel1 org1 peer1)
expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:get"
expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:put"

(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 3 my-channel1 org1 peer1 "another.block")
expectCommand "cat \"$TEST_TMP/another.block\"" "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"

echo "🎉 Test passed! 🎉"
12 changes: 8 additions & 4 deletions e2e-network/docker/test-06-v3-bft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ expectInvoke() {
(cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "")
}

expectQuery() {
(cd "$TEST_TMP" && sh ../expect-query-cli.sh "$1" "$2" "$3" "$4" "$5")
}

expectCommand() {
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
}
Expand Down Expand Up @@ -68,20 +72,20 @@ waitForContainer "peer1.org1.example.com" "Membership view has changed. peers we
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
'{\"success\":\"OK\"}'
expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \
expectQuery "peer1.org1.example.com" "my-channel1" "chaincode1" \
'{"Args":["KVContract:get", "name"]}' \
'{\"success\":\"Willy Wonka\"}'
'{"success":"Willy Wonka"}'

# Verify channel query scripts
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch newest my-channel1 org1 peer1)
expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:get"
expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:put"

(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\":5"
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":4"

echo "🎉 Test passed! 🎉"
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,8 @@ elif [ "$1" = "chaincode" ] && [ "$2" = "dev" ]; then
runDevModeChaincode "$3" "$4"
elif [ "$1" = "chaincode" ] && [ "$2" = "invoke" ]; then
chaincodeInvoke "$3" "$4" "$5" "$6" "$7"
elif [ "$1" = "chaincode" ] && [ "$2" = "query" ]; then
chaincodeQuery "$3" "$4" "$5" "$6" "$7"
elif [ "$1" = "chaincodes" ] && [ "$2" = "list" ]; then
chaincodeList "$3" "$4"
elif [ "$1" = "channel" ]; then
Expand Down Expand Up @@ -1497,6 +1499,44 @@ chaincodeInvoke() {

peerChaincodeInvoke "$cli" "$peer_addresses" "$2" "$3" "$4" "$5"
}

# Function to perform chaincode query for single peer
# Accepts 4-5 parameters:
# 1. single peer domain
# 2. channel name
# 3. chaincode name
# 4. chaincode command
# 5. transient data (optional)
chaincodeQuery() {
if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
echo "Expected 4 or 5 parameters for chaincode query, but got: $*"
echo "Usage: fablo chaincode query <peer_domain> <channel_name> <chaincode_name> <command> [transient]"
exit 1
fi

peer_domain="$1"
channel_name="$2"
chaincode_name="$3"
command="$4"
transient="$5"

cli=""
peer_address=""

if [ "$peer_domain" = "peer0.org1.example.com" ]; then
cli="cli.org1.example.com"
peer_address="peer0.org1.example.com:7041"

fi

if [ -z "$peer_address" ]; then
echo "Unknown peer: $peer_domain"
exit 1
fi

peerChaincodeQuery "$cli" "$peer_address" "$channel_name" "$chaincode_name" "$command" "$transient"

}
"
`;

Expand Down Expand Up @@ -2875,6 +2915,70 @@ peerChaincodeInvokeTls() {
--cafile "/var/hyperledger/cli/$CA_CERT" \\
2>&1
}

peerChaincodeQuery() {
local CLI="$1"
local PEER="$2"
local CHANNEL="$3"
local CHAINCODE="$4"
local COMMAND="$5"
local TRANSIENT="$6"

echo "Chaincode query:"
inputLog "CLI: $CLI"
inputLog "PEER: $PEER"
inputLog "CHANNEL: $CHANNEL"
inputLog "CHAINCODE: $CHAINCODE"
inputLog "COMMAND: $COMMAND"
inputLog "TRANSIENT: $TRANSIENT"

PEER_ADDRESS="--peerAddresses $PEER"

# shellcheck disable=SC2086
docker exec "$CLI" peer chaincode query \\
$PEER_ADDRESS \\
-C "$CHANNEL" \\
-n "$CHAINCODE" \\
-c "$COMMAND" \\
--transient "$TRANSIENT" \\
2>&1
}

peerChaincodeQueryTls() {
local CLI="$1"
local PEER="$2"
local CHANNEL="$3"
local CHAINCODE="$4"
local COMMAND="$5"
local TRANSIENT="$6"
local PEER_CERT="$7"
local CA_CERT="$8"

echo "Chaincode query:"
inputLog "CLI: $CLI"
inputLog "PEER: $PEER"
inputLog "CHANNEL: $CHANNEL"
inputLog "CHAINCODE: $CHAINCODE"
inputLog "COMMAND: $COMMAND"
inputLog "TRANSIENT: $TRANSIENT"
inputLog "PEER_CERTS: $PEER_CERT"
inputLog "CA_CERT: $CA_CERT"

PEER_ADDRESS="--peerAddresses $PEER"

TLS_ROOT_CERT_FILES="--tlsRootCertFiles /var/hyperledger/cli/$PEER_CERT"
# shellcheck disable=SC2086
docker exec "$CLI" peer chaincode query \\
$PEER_ADDRESS \\
$TLS_ROOT_CERT_FILES \\
-C "$CHANNEL" \\
-n "$CHAINCODE" \\
-c "$COMMAND" \\
--transient "$TRANSIENT" \\
--tls \\
--cafile "/var/hyperledger/cli/$CA_CERT" \\
2>&1
}
"
`;

Expand Down
Loading
Loading