Update testing scripts

pull/139/head
Baohua Yang 2021-08-18 14:19:57 -07:00
parent ee10e60386
commit 936e8cae03
13 changed files with 469 additions and 21 deletions

View File

@ -1,2 +1,25 @@
bash fetch-config-block.sh dhanNodeOUf1 testchainid dhannodeouf1-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20003 #bash fetch-config-block.sh dhanNodeOUf1 testchainid dhannodeouf1-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20003
bash fetch-config-block.sh dhanNodeOUf1 nodeouchannel01 dhannodeouf1-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20003 #bash fetch-config-block.sh dhanNodeOUf1 nodeouchannel01 dhannodeouf1-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20003
mspId=AutoF4970445621
endorPolicy="OR('dh0728fab2f3.member')"
peerAddr=autof4970445621-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20009
#peerAddr=autop4970512879-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20009
ordererAddr=autof4970445621-bcsnativetest-iad.blockchain.test.ocp.oc-test.com:20003
channelId=volvotestmultiorg3
ccName=volvooriginal3
ccVersion=v1
ccLabel=${ccName}_${ccVersion}
ccPkg=${ccName}.tar.gz
packageId="${ccName}:bed6b22c90562f2f87d2303895064718c6fa98566a637b58b4037c5082f52777"
#bash cc-package.sh ${mspId} ${ccName} $PWD/${ccName} ${ccLabel}
#bash cc-install.sh ${mspId} ${peerAddr} ${ccPkg}
#bash cc-approve.sh ${mspId} ${channelId} ${peerAddr} ${ordererAddr} ${ccName} ${ccVersion} ${packageId} ${endorPolicy}
#bash cc-commit.sh ${mspId} ${channelId} ${peerAddr} ${ordererAddr} ${ccName} ${ccVersion} ${endorPolicy}
#bash cc-invoke.sh ${mspId} ${channelId} ${peerAddr} ${ordererAddr} ${ccName}
#bash cc-list-installed.sh ${mspId} ${peerAddr}
#bash cc-list-instantiated.sh ${mspId} ${channelId} ${peerAddr}
#bash cc-getData.sh ${mspId} ${channelId} ${peerAddr} ${ccName}
bash discover.sh ${mspId} ${channelId} ${peerAddr} ${ccName}
#bash cc-marble-test.sh ${mspId} ${channelId} ${peerAddr} ${ordererAddr} ${ccName}

View File

@ -0,0 +1,49 @@
#!/bin/bash
# Approve a chaincode definition
# Usage: ./script mspId channelID peerAddr ordererAddr ccName ccVersion packageId endorPolicy mspPath=${PWD}/msp-mspId
# Entry function
main() {
if [ $# -lt 8 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId channelID peerAddr ordererAddr ccName ccVersion packageId endorPolicy mspPath=${PWD}/msp-mspId"
exit 1
fi
local mspId=$1
local channelID=$2
local peerAddr=$3
local ordererAddr=$4
local ccName=$5
local ccVersion=$6
local packageId=$7
local endorPolicy=$8
local mspPath=${9:-${PWD}/msp-${mspId}} # Suppose the local msp named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
echo "approve chaincode definition peerAddr=${peerAddr}, channelID=${channelID}, ccVersion=${ccVersion}, packageId=${packageId}, endorPolicy=${endorPolicy}, ordererAddr=${ordererAddr}"
peer lifecycle chaincode approveformyorg \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
--channelID ${channelID} \
--name ${ccName} \
--version ${ccVersion} \
--init-required \
--package-id ${packageId} \
--sequence 1 \
--signature-policy "${endorPolicy}" \
--waitForEvent \
--orderer ${ordererAddr} \
--tls true \
--cafile ${CORE_PEER_TLS_ROOTCERT_FILE}
exit 0
}
main "$@"

View File

@ -0,0 +1,54 @@
#!/bin/bash
# Commit a chaincode definition
# Usage: ./script mspId peerAddr channelId ccName ccVersion endorPolicy ordererAddr mspPath=${PWD}/msp-mspId
# Entry function
main() {
if [ $# -lt 7 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId peerAddr channelId ccName ccVersion endorPolicy ordererAddr mspPath=${PWD}/msp-mspId"
exit 1
fi
local mspId=$1
local channelId=$2
local peerAddr=$3
local ordererAddr=$4
local ccName=$5
local ccVersion=$6
local endorPolicy=$7
local mspPath=${8:-${PWD}/msp-${mspId}} # Suppose the local msp named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
echo "commit chaincode definition peerAddr=${peerAddr}, channelId=${channelId}, ccVersion=${ccVersion}, endorPolicy=${endorPolicy}, ordererAddr=${ordererAddr}"
peer lifecycle chaincode commit \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
--channelID ${channelId} \
--name ${ccName} \
--version ${ccVersion} \
--init-required \
--sequence 1 \
--signature-policy "${endorPolicy}" \
--waitForEvent \
--orderer ${ordererAddr} \
--tls true \
--cafile ${CORE_PEER_TLS_ROOTCERT_FILE}
peer lifecycle chaincode querycommitted \
--peerAddresses ${peerAddr} \
--tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} \
--channelID ${channelId} \
--output json \
--name ${ccName}
exit 0
}
main "$@"

View File

@ -0,0 +1,77 @@
#!/bin/bash
# Get the chaincode data
# Usage: ./script mspId channelID peerAddr ccName
setupChaincode() {
local channelID=$1
local peerAddr=$2
local tlsca_file=$3
peer chaincode instantiate \
-o "dhnodeouf5-bcsnativepreprod-iad.blockchain.ocp.oc-test.com:20003" \
-C ${channelID} \
-n "exp02" \
-v "v1" \
-c '{"Args":["init","a","100","b","200"]}' \
-P "OR ('dhnodeOUf5.peer','dhnodeOUf6.peer')" \
--tls \
--cafile ${tlsca_file} \
--peerAddr ${peerAddr} \
--tlsRootCertFiles ${tlsca_file}
}
# getChaincodeData get the instantiated chaincode information
# Usage: getChaincodeData channelID peerAddr ccName
getChaincodeData() {
local channelID=$1
local peerAddr=$2
local ccName=$3
local tlsca_file=$4
peer chaincode query \
--connTimeout 10s \
--channelID ${channelID} \
-n "lscc" \
-c '{"Args":["getccdata","'${channelID}'","'${ccName}'"]}' \
--tls \
--peerAddresses ${peerAddr} \
--tlsRootCertFiles ${tlsca_file} \
> chaincode.ccdata
peer chaincode query \
--connTimeout 10s \
--channelID ${channelID} \
-n "lscc" \
-c '{"Args":["getdepspec","'${channelID}'","'${ccName}'"]}' \
--tls \
--peerAddresses ${peerAddr} \
--tlsRootCertFiles ${tlsca_file} \
> chaincode.depspec
}
if [ $# -eq 0 ]; then
echo "Please use the <mspId> <channelID> <ordererURL> as the argument"
exit
fi
mspId=$1
channelID=$2
peerAddr=$3
ccName=$4
echo "mspId=${mspId}"
echo "channelID=${channelID}"
echo "peerAddr=${peerAddr}"
echo "ccName=${ccName}"
msp_path=${PWD}/msp-${mspId} # Suppose the local msp path named as msp-${mspId}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_LOCALMSPID=${mspId}
#export CORE_PEER_ADDRESS=${peerAddr}
export CORE_PEER_MSPCONFIGPATH=${msp_path}
export CORE_PEER_TLS_ROOTCERT_FILE=${msp_path}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
#setupChaincode ${channelID} ${peerAddr} ${msp_path}/tlscacerts/tlsca.cert
getChaincodeData ${channelID} ${peerAddr} ${ccName} ${msp_path}/tlscacerts/tlsca.cert

View File

@ -0,0 +1,41 @@
#!/bin/bash
# Install a chaincode
# Usage: ./script mspId peerAddr mspPath=${PWD}/msp-mspId name version path
# Entry function
main() {
if [ $# -lt 5 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId peerAddr mspPath=${PWD}/msp-mspId name version path"
exit 1
fi
local mspId=$1
local peerAddr=$2
local mspPath=${3:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
local name=$4
local version=$5
local path=$6
local lang="golang"
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
#export GRPC_GO_REQUIRE_HANDSHAKE=off
peer chaincode install \
-n ${name} \
-v $version \
-p ${path} \
-l ${lang} \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}"
exit 0
}
main "$@"

View File

@ -0,0 +1,41 @@
#!/bin/bash
# Install a chaincode from package
# Usage: ./script mspId peerAddr ccPkg mspPath=${PWD}/msp-mspId
# Entry function
main() {
if [ $# -lt 3 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId peerAddr ccPkg mspPath=${PWD}/msp-mspId"
exit 1
fi
local mspId=$1
local peerAddr=$2
local ccPkg=$3
local mspPath=${4:-${PWD}/msp-${mspId}} # Suppose the local msp named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
echo "installing chaincode to peer=${peerAddr}"
peer lifecycle chaincode install \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
${ccPkg}
exit 0
peer lifecycle chaincode queryinstalled \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
--output json
exit 0
}
main "$@"

View File

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/bash
# Invoke a chaincode # Invoke a chaincode
# Usage: ./script mspId channel ordererAddr peerAddr ccName mspPath=${PWD}/msp-mspId # Usage: ./script mspId channelId peerAddr ordererAddr ccName mspPath=${PWD}/msp-mspId
# Entry function # Entry function
main() { main() {
if [ $# -lt 5 ]; then if [ $# -lt 5 ]; then
echo "Not enough argument supplied" echo "Not enough argument supplied"
echo "$(basename $0) mspId channel ordererAddr peerAddr ccName mspPath=${PWD}/msp-mspId" echo "$(basename $0) mspId channelId peerAddr ordererAddr ccName mspPath=${PWD}/msp-mspId"
exit 1 exit 1
fi fi
local mspId=$1 local mspId=$1
local channel=$2 local channelId=$2
local ordererAddr=$3 local peerAddr=$3
local peerAddr=$4 local ordererAddr=$4
local ccName=$5 local ccName=$5
local mspPath=${6:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id} local mspPath=${6:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
@ -27,23 +27,23 @@ main() {
peer chaincode invoke \ peer chaincode invoke \
--connTimeout="30s" \ --connTimeout="30s" \
-o "${ordererAddr}" \ -o "${ordererAddr}" \
-C "${channel}" \ -C "${channelId}" \
-n "${ccName}" \ -n "${ccName}" \
--peerAddresses "${peerAddr}" \ --peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \ --tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
-c '{"Args":["invoke","a","b","10"]}' \ -c '{"Args":["Init","a","100","b","100"]}' \
--isInit \
--tls \ --tls \
--cafile "${CORE_PEER_TLS_ROOTCERT_FILE}" --cafile "${CORE_PEER_TLS_ROOTCERT_FILE}"
#-c '{"Args":["invoke","a","b","10"]}' \
exit 0
peer chaincode query \ peer chaincode query \
--connTimeout=30s \ --connTimeout=30s \
-C "${channel}" \ -C "${channelId}" \
-n "${ccName}" \ -n "${ccName}" \
--peerAddresses "${peerAddr}" \ --peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \ --tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
-c '{"Args":["query","b"]}' -c '{"Args":["query","a"]}'
} }
main "$@" main "$@"

View File

@ -29,12 +29,6 @@ main() {
--peerAddresses "${peerAddr}" \ --peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" --tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}"
peer chaincode list \
--connTimeout=30s \
--instantiated \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}"
exit 0 exit 0
} }

View File

@ -0,0 +1,35 @@
#!/bin/bash
# Invoke a chaincode
# Usage: ./script mspId channelID peerAddr mspPath=${PWD}/msp-mspId
# Entry function
main() {
if [ $# -lt 2 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId channelID peerAddr mspPath=${PWD}/msp-mspId"
exit 1
fi
local mspId=$1
local channelID=$2
local peerAddr=$3
local mspPath=${4:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
peer chaincode list \
--connTimeout=30s \
--channelID "${channelID}" \
--instantiated \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}"
exit 0
}
main "$@"

View File

@ -0,0 +1,63 @@
#!/bin/bash
# Invoke a chaincode
# Usage: ./script mspId channelId peerAddr ordererAddr ccName mspPath=${PWD}/msp-mspId
# Entry function
main() {
if [ $# -lt 5 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId channelId peerAddr ordererAddr ccName mspPath=${PWD}/msp-mspId"
exit 1
fi
local mspId=$1
local channelId=$2
local peerAddr=$3
local ordererAddr=$4
local ccName=$5
local mspPath=${6:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="info"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
for i in {550..1000}
do
export MARBLE=$(echo -n "{\"name\":\"test02-marble$i\",\"color\":\"blue\",\"size\":35,\"owner\":\"tom\",\"price\":99}" | base64 | tr -d \\n)
echo $MARBLE | base64 --decode
peer chaincode invoke \
--connTimeout="30s" \
-o "${ordererAddr}" \
-C "${channelId}" \
-n "${ccName}" \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
-c '{"Args":["initMarble"]}' \
--transient "{\"marble\":\"$MARBLE\"}" \
--tls \
--cafile "${CORE_PEER_TLS_ROOTCERT_FILE}"
#-c '{"Args":["invoke","a","b","10"]}' \
done
exit 0
peer chaincode query \
--connTimeout="30s" \
-C "${channelId}" \
-n "${ccName}" \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
-c '{"Args":["readMarblePrivateDetails","test-marble03"]}' \
--tls \
--cafile "${CORE_PEER_TLS_ROOTCERT_FILE}"
#-c '{"Args":["readMarble","test-marble1"]}' \
exit 0
}
main "$@"

View File

@ -0,0 +1,35 @@
#!/bin/bash
# Package a chaincode
# Usage: ./script mspId ccName ccPath ccLabel ccLang=golang mspPath=${PWD}/msp-mspId
# Entry function
main() {
if [ $# -lt 4 ]; then
echo "Not enough argument supplied"
echo "$(basename $0) mspId ccName ccPath ccLabel ccLang=golang mspPath=${PWD}/msp-mspId"
exit 1
fi
local mspId=$1
local ccName=$2
local ccPath=$3
local ccLabel=$4
local ccLang=${5:-golang}
local mspPath=${6:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
echo "packaging chaincode=${ccName} with path=${ccPath}, label=${ccLabel}, lang=${ccLang}"
peer lifecycle chaincode package ${ccName}.tar.gz \
--path ${ccPath} \
--label ${ccLabel} \
--lang ${ccLang}
exit 0
}
main "$@"

View File

@ -16,13 +16,36 @@ main() {
local ccName=$4 local ccName=$4
local mspPath=${5:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id} local mspPath=${5:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug" export FABRIC_LOGGING_SPEC="info"
export CORE_PEER_ADDRESS="${peerAddr}" export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId} export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath} export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true export CORE_PEER_TLS_ENABLED=true
for i in {1..1000}; do
echo "round $i"
discover \
--peerTLSCA "${CORE_PEER_TLS_ROOTCERT_FILE}" \
--userKey ${mspPath}/keystore/${mspId}-key \
--userCert ${mspPath}/signcerts/${mspId}-cert.pem \
--MSP "${mspId}" \
peers \
--channel "${channel}" \
--server "${peerAddr}" > peers.json
if [ $(jq length peers.json) == 2 ]; then
echo "2"
else
cat peers.json
cp peers.json peers-${i}.json
fi
sleep 1
done
exit 0
for i in {1..1000}; do
echo "round $i"
discover \ discover \
--peerTLSCA "${CORE_PEER_TLS_ROOTCERT_FILE}" \ --peerTLSCA "${CORE_PEER_TLS_ROOTCERT_FILE}" \
--userKey ${mspPath}/keystore/${mspId}-key \ --userKey ${mspPath}/keystore/${mspId}-key \
@ -31,7 +54,17 @@ main() {
endorsers \ endorsers \
--channel "${channel}" \ --channel "${channel}" \
--chaincode "${ccName}" \ --chaincode "${ccName}" \
--server "${peerAddr}" --server "${peerAddr}" > endorsers.json
if [ $(jq '.[0].EndorsersByGroups|length' endorsers.json) == 2 ]; then
echo "2"
else
cat endorsers.json
cp endorsers.json endorsers-1.json
fi
sleep 1
done
#--tlsCert tls/client.crt \ #--tlsCert tls/client.crt \
#--tlsKey tls/client.key \ #--tlsKey tls/client.key \
} }

View File

@ -34,3 +34,6 @@ jq -r .certs.cacert "${cert_file}" > "msp-${mspId}/cacerts/ca.cert"
echo "Get admincerts from ${admin_dir}" echo "Get admincerts from ${admin_dir}"
cp "${admin_dir}/${mspId}-cert.pem" "msp-${mspId}/admincerts/" cp "${admin_dir}/${mspId}-cert.pem" "msp-${mspId}/admincerts/"
echo "Clean the temp dir of ${mspId}-admin-credential"
rm -rf ${mspId}-admin-credential