Skip to content

Commit ec38f0c

Browse files
Support query command for docker setup (#597)
Co-authored-by: Tushar Saxena <019saxenatushar@gmail.com>
1 parent 9cd060f commit ec38f0c

16 files changed

+1154
-14
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
peers="$1"
4+
channel="$2"
5+
chaincode="$3"
6+
command="$4"
7+
expected="$5"
8+
transient_default="{}"
9+
transient="${6:-$transient_default}"
10+
11+
if [ -z "$expected" ]; then
12+
echo "Usage: ./expect-query.sh [peer[,peer]] [channel] [chaincode] [command] [expected_substring] [transient_data]"
13+
exit 1
14+
fi
15+
16+
label="Query $channel/$peers $command"
17+
echo ""
18+
echo "➜ testing: $label"
19+
20+
response="$(
21+
"$FABLO_HOME/fablo.sh" chaincode query "$peers" "$channel" "$chaincode" "$command" "$transient"
22+
)"
23+
24+
echo "$response"
25+
26+
if echo "$response" | grep -F "$expected"; then
27+
echo "✅ ok (cli): $label"
28+
else
29+
echo "❌ failed (cli): $label | expected: $expected"
30+
exit 1
31+
fi

e2e-network/docker/test-01-v2-simple.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ expectCommand() {
4242
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
4343
}
4444

45+
expectQuery() {
46+
(cd "$TEST_TMP" && sh ../expect-query-cli.sh "$1" "$2" "$3" "$4" "$5")
47+
}
48+
4549
trap networkDown EXIT
4650
trap 'networkDown ; echo "Test failed" ; exit 1' ERR SIGINT
4751

@@ -62,29 +66,29 @@ waitForContainer "peer1.org1.example.com" "Membership view has changed. peers we
6266
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
6367
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
6468
'{\"success\":\"OK\"}'
65-
expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \
69+
expectQuery "peer1.org1.example.com" "my-channel1" "chaincode1" \
6670
'{"Args":["KVContract:get", "name"]}' \
67-
'{\"success\":\"Willy Wonka\"}'
71+
'{"success":"Willy Wonka"}'
6872

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

7377
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 4 my-channel1 org1 peer1 "another.block")
7478
expectCommand "cat \"$TEST_TMP/another.block\"" "KVContract:put"
7579

7680
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch config my-channel1 org1 peer1 "channel-config.json")
7781
expectCommand "cat \"$TEST_TMP/channel-config.json\"" "\"mod_policy\": \"Admins\","
7882

79-
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":6"
83+
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":5"
8084

8185
# Reset and ensure the state is lost after reset
8286
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" reset)
8387
waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1"
8488
waitForChaincode "peer1.org1.example.com" "my-channel1" "chaincode1" "0.0.1"
85-
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
89+
expectQuery "peer0.org1.example.com" "my-channel1" "chaincode1" \
8690
'{"Args":["KVContract:get", "name"]}' \
87-
'{\"error\":\"NOT_FOUND\"}'
91+
'{"error":"NOT_FOUND"}'
8892

8993
# Put some data again
9094
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \

e2e-network/docker/test-05-v3.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ expectInvoke() {
4141
(cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "")
4242
}
4343

44+
expectQuery() {
45+
(cd "$TEST_TMP" && sh ../expect-query-cli.sh "$1" "$2" "$3" "$4" "$5")
46+
}
47+
4448
expectCommand() {
4549
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
4650
}
@@ -100,20 +104,20 @@ echo "🎉 Node.js Gateway client test complete 🎉"
100104
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
101105
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
102106
'{\"success\":\"OK\"}'
103-
expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \
107+
expectQuery "peer1.org1.example.com" "my-channel1" "chaincode1" \
104108
'{"Args":["KVContract:get", "name"]}' \
105-
'{\"success\":\"Willy Wonka\"}'
109+
'{"success":"Willy Wonka"}'
106110

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

111115
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 3 my-channel1 org1 peer1 "another.block")
112116
expectCommand "cat \"$TEST_TMP/another.block\"" "put"
113117

114118
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch config my-channel1 org1 peer1 "channel-config.json")
115119
expectCommand "cat \"$TEST_TMP/channel-config.json\"" "\"mod_policy\": \"Admins\","
116120

117-
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":6"
121+
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":5"
118122

119123
echo "🎉 Test passed! 🎉"

e2e-network/docker/test-06-v3-bft.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ expectInvoke() {
4141
(cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "")
4242
}
4343

44+
expectQuery() {
45+
(cd "$TEST_TMP" && sh ../expect-query-cli.sh "$1" "$2" "$3" "$4" "$5")
46+
}
47+
4448
expectCommand() {
4549
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
4650
}
@@ -68,20 +72,20 @@ waitForContainer "peer1.org1.example.com" "Membership view has changed. peers we
6872
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
6973
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
7074
'{\"success\":\"OK\"}'
71-
expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \
75+
expectQuery "peer1.org1.example.com" "my-channel1" "chaincode1" \
7276
'{"Args":["KVContract:get", "name"]}' \
73-
'{\"success\":\"Willy Wonka\"}'
77+
'{"success":"Willy Wonka"}'
7478

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

7983
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 3 my-channel1 org1 peer1 "another.block")
8084
expectCommand "cat \"$TEST_TMP/another.block\"" "KVContract:put"
8185

8286
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch config my-channel1 org1 peer1 "channel-config.json")
8387
expectCommand "cat \"$TEST_TMP/channel-config.json\"" "\"mod_policy\": \"Admins\","
8488

85-
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":5"
89+
expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":4"
8690

8791
echo "🎉 Test passed! 🎉"

e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.test.ts.snap

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,8 @@ elif [ "$1" = "chaincode" ] && [ "$2" = "dev" ]; then
13951395
runDevModeChaincode "$3" "$4"
13961396
elif [ "$1" = "chaincode" ] && [ "$2" = "invoke" ]; then
13971397
chaincodeInvoke "$3" "$4" "$5" "$6" "$7"
1398+
elif [ "$1" = "chaincode" ] && [ "$2" = "query" ]; then
1399+
chaincodeQuery "$3" "$4" "$5" "$6" "$7"
13981400
elif [ "$1" = "chaincodes" ] && [ "$2" = "list" ]; then
13991401
chaincodeList "$3" "$4"
14001402
elif [ "$1" = "channel" ]; then
@@ -1497,6 +1499,44 @@ chaincodeInvoke() {
14971499
14981500
peerChaincodeInvoke "$cli" "$peer_addresses" "$2" "$3" "$4" "$5"
14991501
}
1502+
1503+
# Function to perform chaincode query for single peer
1504+
# Accepts 4-5 parameters:
1505+
# 1. single peer domain
1506+
# 2. channel name
1507+
# 3. chaincode name
1508+
# 4. chaincode command
1509+
# 5. transient data (optional)
1510+
chaincodeQuery() {
1511+
if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
1512+
echo "Expected 4 or 5 parameters for chaincode query, but got: $*"
1513+
echo "Usage: fablo chaincode query <peer_domain> <channel_name> <chaincode_name> <command> [transient]"
1514+
exit 1
1515+
fi
1516+
1517+
peer_domain="$1"
1518+
channel_name="$2"
1519+
chaincode_name="$3"
1520+
command="$4"
1521+
transient="$5"
1522+
1523+
cli=""
1524+
peer_address=""
1525+
1526+
if [ "$peer_domain" = "peer0.org1.example.com" ]; then
1527+
cli="cli.org1.example.com"
1528+
peer_address="peer0.org1.example.com:7041"
1529+
1530+
fi
1531+
1532+
if [ -z "$peer_address" ]; then
1533+
echo "Unknown peer: $peer_domain"
1534+
exit 1
1535+
fi
1536+
1537+
peerChaincodeQuery "$cli" "$peer_address" "$channel_name" "$chaincode_name" "$command" "$transient"
1538+
1539+
}
15001540
"
15011541
`;
15021542
@@ -2875,6 +2915,70 @@ peerChaincodeInvokeTls() {
28752915
--cafile "/var/hyperledger/cli/$CA_CERT" \\
28762916
2>&1
28772917
}
2918+
2919+
peerChaincodeQuery() {
2920+
local CLI="$1"
2921+
local PEER="$2"
2922+
local CHANNEL="$3"
2923+
local CHAINCODE="$4"
2924+
local COMMAND="$5"
2925+
local TRANSIENT="$6"
2926+
2927+
echo "Chaincode query:"
2928+
inputLog "CLI: $CLI"
2929+
inputLog "PEER: $PEER"
2930+
inputLog "CHANNEL: $CHANNEL"
2931+
inputLog "CHAINCODE: $CHAINCODE"
2932+
inputLog "COMMAND: $COMMAND"
2933+
inputLog "TRANSIENT: $TRANSIENT"
2934+
2935+
PEER_ADDRESS="--peerAddresses $PEER"
2936+
2937+
# shellcheck disable=SC2086
2938+
docker exec "$CLI" peer chaincode query \\
2939+
$PEER_ADDRESS \\
2940+
-C "$CHANNEL" \\
2941+
-n "$CHAINCODE" \\
2942+
-c "$COMMAND" \\
2943+
--transient "$TRANSIENT" \\
2944+
2>&1
2945+
}
2946+
2947+
peerChaincodeQueryTls() {
2948+
local CLI="$1"
2949+
local PEER="$2"
2950+
local CHANNEL="$3"
2951+
local CHAINCODE="$4"
2952+
local COMMAND="$5"
2953+
local TRANSIENT="$6"
2954+
local PEER_CERT="$7"
2955+
local CA_CERT="$8"
2956+
2957+
echo "Chaincode query:"
2958+
inputLog "CLI: $CLI"
2959+
inputLog "PEER: $PEER"
2960+
inputLog "CHANNEL: $CHANNEL"
2961+
inputLog "CHAINCODE: $CHAINCODE"
2962+
inputLog "COMMAND: $COMMAND"
2963+
inputLog "TRANSIENT: $TRANSIENT"
2964+
inputLog "PEER_CERTS: $PEER_CERT"
2965+
inputLog "CA_CERT: $CA_CERT"
2966+
2967+
PEER_ADDRESS="--peerAddresses $PEER"
2968+
2969+
TLS_ROOT_CERT_FILES="--tlsRootCertFiles /var/hyperledger/cli/$PEER_CERT"
2970+
# shellcheck disable=SC2086
2971+
docker exec "$CLI" peer chaincode query \\
2972+
$PEER_ADDRESS \\
2973+
$TLS_ROOT_CERT_FILES \\
2974+
-C "$CHANNEL" \\
2975+
-n "$CHAINCODE" \\
2976+
-c "$COMMAND" \\
2977+
--transient "$TRANSIENT" \\
2978+
--tls \\
2979+
--cafile "/var/hyperledger/cli/$CA_CERT" \\
2980+
2>&1
2981+
}
28782982
"
28792983
`;
28802984

0 commit comments

Comments
 (0)