Skip to content

Commit e38711c

Browse files
authored
Merge branch 'main' into fix-hyperledger-labs#340
2 parents 67a054c + ec38f0c commit e38711c

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
@@ -1419,6 +1419,8 @@ elif [ "$1" = "chaincode" ] && [ "$2" = "dev" ]; then
14191419
runDevModeChaincode "$3" "$4"
14201420
elif [ "$1" = "chaincode" ] && [ "$2" = "invoke" ]; then
14211421
chaincodeInvoke "$3" "$4" "$5" "$6" "$7"
1422+
elif [ "$1" = "chaincode" ] && [ "$2" = "query" ]; then
1423+
chaincodeQuery "$3" "$4" "$5" "$6" "$7"
14221424
elif [ "$1" = "chaincodes" ] && [ "$2" = "list" ]; then
14231425
chaincodeList "$3" "$4"
14241426
elif [ "$1" = "channel" ]; then
@@ -1521,6 +1523,44 @@ chaincodeInvoke() {
15211523
15221524
peerChaincodeInvoke "$cli" "$peer_addresses" "$2" "$3" "$4" "$5"
15231525
}
1526+
1527+
# Function to perform chaincode query for single peer
1528+
# Accepts 4-5 parameters:
1529+
# 1. single peer domain
1530+
# 2. channel name
1531+
# 3. chaincode name
1532+
# 4. chaincode command
1533+
# 5. transient data (optional)
1534+
chaincodeQuery() {
1535+
if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
1536+
echo "Expected 4 or 5 parameters for chaincode query, but got: $*"
1537+
echo "Usage: fablo chaincode query <peer_domain> <channel_name> <chaincode_name> <command> [transient]"
1538+
exit 1
1539+
fi
1540+
1541+
peer_domain="$1"
1542+
channel_name="$2"
1543+
chaincode_name="$3"
1544+
command="$4"
1545+
transient="$5"
1546+
1547+
cli=""
1548+
peer_address=""
1549+
1550+
if [ "$peer_domain" = "peer0.org1.example.com" ]; then
1551+
cli="cli.org1.example.com"
1552+
peer_address="peer0.org1.example.com:7041"
1553+
1554+
fi
1555+
1556+
if [ -z "$peer_address" ]; then
1557+
echo "Unknown peer: $peer_domain"
1558+
exit 1
1559+
fi
1560+
1561+
peerChaincodeQuery "$cli" "$peer_address" "$channel_name" "$chaincode_name" "$command" "$transient"
1562+
1563+
}
15241564
"
15251565
`;
15261566
@@ -2899,6 +2939,70 @@ peerChaincodeInvokeTls() {
28992939
--cafile "/var/hyperledger/cli/$CA_CERT" \\
29002940
2>&1
29012941
}
2942+
2943+
peerChaincodeQuery() {
2944+
local CLI="$1"
2945+
local PEER="$2"
2946+
local CHANNEL="$3"
2947+
local CHAINCODE="$4"
2948+
local COMMAND="$5"
2949+
local TRANSIENT="$6"
2950+
2951+
echo "Chaincode query:"
2952+
inputLog "CLI: $CLI"
2953+
inputLog "PEER: $PEER"
2954+
inputLog "CHANNEL: $CHANNEL"
2955+
inputLog "CHAINCODE: $CHAINCODE"
2956+
inputLog "COMMAND: $COMMAND"
2957+
inputLog "TRANSIENT: $TRANSIENT"
2958+
2959+
PEER_ADDRESS="--peerAddresses $PEER"
2960+
2961+
# shellcheck disable=SC2086
2962+
docker exec "$CLI" peer chaincode query \\
2963+
$PEER_ADDRESS \\
2964+
-C "$CHANNEL" \\
2965+
-n "$CHAINCODE" \\
2966+
-c "$COMMAND" \\
2967+
--transient "$TRANSIENT" \\
2968+
2>&1
2969+
}
2970+
2971+
peerChaincodeQueryTls() {
2972+
local CLI="$1"
2973+
local PEER="$2"
2974+
local CHANNEL="$3"
2975+
local CHAINCODE="$4"
2976+
local COMMAND="$5"
2977+
local TRANSIENT="$6"
2978+
local PEER_CERT="$7"
2979+
local CA_CERT="$8"
2980+
2981+
echo "Chaincode query:"
2982+
inputLog "CLI: $CLI"
2983+
inputLog "PEER: $PEER"
2984+
inputLog "CHANNEL: $CHANNEL"
2985+
inputLog "CHAINCODE: $CHAINCODE"
2986+
inputLog "COMMAND: $COMMAND"
2987+
inputLog "TRANSIENT: $TRANSIENT"
2988+
inputLog "PEER_CERTS: $PEER_CERT"
2989+
inputLog "CA_CERT: $CA_CERT"
2990+
2991+
PEER_ADDRESS="--peerAddresses $PEER"
2992+
2993+
TLS_ROOT_CERT_FILES="--tlsRootCertFiles /var/hyperledger/cli/$PEER_CERT"
2994+
# shellcheck disable=SC2086
2995+
docker exec "$CLI" peer chaincode query \\
2996+
$PEER_ADDRESS \\
2997+
$TLS_ROOT_CERT_FILES \\
2998+
-C "$CHANNEL" \\
2999+
-n "$CHAINCODE" \\
3000+
-c "$COMMAND" \\
3001+
--transient "$TRANSIENT" \\
3002+
--tls \\
3003+
--cafile "/var/hyperledger/cli/$CA_CERT" \\
3004+
2>&1
3005+
}
29023006
"
29033007
`;
29043008

0 commit comments

Comments
 (0)