Skip to content

Commit 7e05364

Browse files
committed
fixup! Scripting improvement
Signed-off-by: michael steiner <[email protected]>
1 parent bab8419 commit 7e05364

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

fabric/bin/lib/common_ledger.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,33 @@ ledger_shutdown() {
182182

183183
# Check the chaincode's response (ResponseData) of
184184
# peer chaincode invoke/query
185-
# (executed via 'try_r' macro) against expected result.
185+
# (executed via 'try_r/try_out_r' macro) against expected result.
186186
# In case of failures, tries to increment integer variable NUM_FAILURES. Increment in all cases NUM_TESTS
187187
check_result() {
188-
if [[ ${RESPONSE} == "$1" ]]; then
188+
if [ "${RESPONSE_TYPE}" == "out+err" ]; then
189+
CI_RESPONSE=$(parse_invoke_result_from_log "${RESPONSE}")
190+
CONTEXT=" context: '${RESPONSE}'"
191+
else
192+
CI_RESPONSE="${RESPONSE}"
193+
CONTEXT=""
194+
fi
195+
196+
if [[ ${CI_RESPONSE} == "$1" ]]; then
189197
gecho "PASSED"
190198
else
191-
recho "FAILED (expected '${1}', got '${RESPONSE}')"
199+
recho "FAILED (expected '${1}', got '${CI_RESPONSE}'${CONTEXT})"
192200
export NUM_FAILURES=$(($NUM_FAILURES+1))
193201
fi
194202
export NUM_TESTS=$(($NUM_TESTS+1))
195203
}
196204

205+
parse_invoke_result_from_log() {
206+
RESPONSE="$1"
207+
RESPONSE=${RESPONSE##*payload:\"}
208+
RESPONSE=${RESPONSE%%\"*}
209+
echo "${RESPONSE}"
210+
}
211+
197212

198213
# "Main"
199214
parse_fabric_config "${FABRIC_CFG_PATH}"

fabric/bin/lib/common_utils.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ try_fail() {
7575
# Variant of try which stores commands stdout and stderr (or only stdout) in variable RESPONSE
7676
try_r() {
7777
say "$@"
78-
export RESPONSE=$("$@" 2>&1) || die "test failed: $*"
78+
export RESPONSE=$("$@" 2>&1) RESPONSE_TYPE="out+err" || die "test failed: $*"
7979
}
8080

8181
try_out_r() {
8282
say "$@"
83-
export RESPONSE=$("$@") || die "test failed: $*"
83+
export RESPONSE=$("$@") RESPONSE_TYPE="out" || die "test failed: $*"
8484
}
8585

fabric/bin/peer.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ handle_chaincode_call() {
666666
if [ ! -z ${DO_WAIT_TIMEOUT+x} ]; then
667667
opt_arg="--waitForEvent ${opt_arg}"
668668
fi
669-
try_out_r $RUN ${FABRIC_BIN_DIR}/peer chaincode invoke "${OTHER_ARGS[@]}" ${opt_arg} -C ${CHAN_ID} -n ${CC_ID} -c '{"Args":["__endorse", "'${encrypted_response}'"]}'
670-
endorse_response="${RESPONSE}"
671-
[ ${endorse_response} == "OK" ] || die "endorsement failed: '${endorse_response}'"
669+
try_r $RUN ${FABRIC_BIN_DIR}/peer chaincode invoke "${OTHER_ARGS[@]}" ${opt_arg} -C ${CHAN_ID} -n ${CC_ID} -c '{"Args":["__endorse", "'${encrypted_response}'"]}'
670+
endorse_response=$(parse_invoke_result_from_log "${RESPONSE}")
671+
[ "${endorse_response}" == "OK" ] || die "endorsement failed: '${endorse_response}'"
672672
[ -z ${DEBUG+x} ] || say "endorsement returned '${endorse_response}'"
673673
fi
674674
# - return decrypted response

0 commit comments

Comments
 (0)