github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/test_student.sh (about) 1 #!/usr/bin/env bash 2 3 # 4 #Copyright Ziggurat Corp. 2017 All Rights Reserved. 5 # 6 #SPDX-License-Identifier: Apache-2.0 7 # 8 9 # Detecting whether can import the header file to render colorful cli output 10 if [ -f ./header.sh ]; then 11 source ./header.sh 12 elif [ -f scripts/header.sh ]; then 13 source scripts/header.sh 14 else 15 alias echo_r="echo" 16 alias echo_g="echo" 17 alias echo_b="echo" 18 fi 19 20 CHANNEL_NAME="$1" 21 : ${CHANNEL_NAME:="mychannel"} 22 : ${TIMEOUT:="60"} 23 COUNTER=0 24 MAX_RETRY=5 25 CC_ID=student 26 CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/student 27 ORDERER_CA=/opt/gopath/src/github.com/inklabsfoundation/inkchain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 28 29 echo_b "Chaincode Path : "$CC_PATH 30 echo_b "Channel name : "$CHANNEL_NAME 31 32 verifyResult () { 33 if [ $1 -ne 0 ] ; then 34 echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" 35 echo_r "================== ERROR !!! FAILED to execute MVE ==================" 36 echo 37 exit 1 38 fi 39 } 40 41 issueToken(){ 42 sleep 3 43 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ascc -c '{"Args":["registerAndIssueToken","'$1'","1000000000000000000","18","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 44 res=$? 45 cat log.txt 46 verifyResult $res "Issue a new token using ascc has Failed." 47 echo_g "===================== A new token has success======================= " 48 echo 49 } 50 51 registerSchool(){ 52 sleep 3 53 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["registerSchool","100099999","Tsinghua University","北京","1","long times ago"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 54 res=$? 55 cat log.txt 56 verifyResult $res "Register a school has Failed." 57 echo_g "=====================A new school been success=======================" 58 echo 59 } 60 61 querySchoolInfo(){ 62 sleep 3 63 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["querySchoolInfo","100099999"]}' >log.txt 64 res=$? 65 cat log.txt 66 verifyResult $res "Query school info has failed." 67 echo_g "=====================Query school info success=======================" 68 echo 69 } 70 71 registerStudent(){ 72 sleep 3 73 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["registerStudent","330381199342105115115","TestStudent","26","1"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 74 res=$? 75 cat log.txt 76 verifyResult $res "Register a student has Failed." 77 echo_g "=====================A new student success=======================" 78 echo 79 } 80 81 queryStudentInfo(){ 82 sleep 3 83 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryStudentInfo","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 84 res=$? 85 cat log.txt 86 verifyResult $res "Query student info has failed." 87 echo_g "=====================Query student info success=======================" 88 echo 89 } 90 91 enrolment(){ 92 sleep 3 93 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["enrolment","100099999","i4230a12f5b0693dd88bb35c79d7e56a68614b199","2010届","210711A","210711A054","1"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 94 res=$? 95 cat log.txt 96 verifyResult $res "Student enrolment has Failed." 97 echo_g "=====================Student enrolment success=======================" 98 echo 99 } 100 101 graduate(){ 102 sleep 3 103 peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["graduate","100099999","i4230a12f5b0693dd88bb35c79d7e56a68614b199","表现良好,允许毕业","9999999999","40"]}' -i "1000000000" -z bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe >log.txt 104 res=$? 105 cat log.txt 106 verifyResult $res "Student graduate has Failed." 107 echo_g "=====================Student graduate success=======================" 108 echo 109 } 110 111 queryStudentStudyLog(){ 112 sleep 3 113 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryStudentStudyLog","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 114 res=$? 115 cat log.txt 116 verifyResult $res "Query student study log has failed." 117 echo_g "=====================Query student study log success=======================" 118 echo 119 } 120 121 queryStudentGraduationLog(){ 122 sleep 3 123 peer chaincode query -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n ${CC_ID} -c '{"Args":["queryStudentGraduationLog","i4230a12f5b0693dd88bb35c79d7e56a68614b199"]}' >log.txt 124 res=$? 125 cat log.txt 126 verifyResult $res "Query student study log has failed." 127 echo_g "=====================Query student graduation log success=======================" 128 echo 129 } 130 131 echo_b "=====================5.Issue a token using ascc========================" 132 issueToken INK 133 134 echo_b "=====================6.Register a school================================" 135 registerSchool 136 137 echo_b "=====================7.Query school info================================" 138 querySchoolInfo 139 140 echo_b "=====================8.Register a student================================" 141 registerStudent 142 143 echo_b "=====================7.Query student info================================" 144 queryStudentInfo 145 146 echo_b "=====================8.Student enrolment================================" 147 enrolment 148 149 echo_b "=====================9.Query student info================================" 150 queryStudentInfo 151 152 echo_b "=====================10.Student graduate================================" 153 graduate 154 155 echo_b "=====================11.Query student info================================" 156 queryStudentInfo 157 158 echo_b "=====================12.Query student study log================================" 159 queryStudentStudyLog 160 161 echo_b "=====================13.Query student graduate log================================" 162 queryStudentGraduationLog 163 164 echo 165 echo_g "=====================All GOOD, MVE Test completed ===================== " 166 echo 167 exit 0