Advertisement
Guest User

Untitled

a guest
May 7th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo
  4. echo " ____    _____      _      ____    _____ "
  5. echo "/ ___|  |_   _|    / \    |  _ \  |_   _|"
  6. echo "\___ \    | |     / _ \   | |_) |   | |  "
  7. echo " ___) |   | |    / ___ \  |  _ <    | |  "
  8. echo "|____/    |_|   /_/   \_\ |_| \_\   |_|  "
  9. echo
  10. echo "Build your first network (BYFN) end-to-end test"
  11. echo
  12. CHANNEL_NAME="$1"
  13. DELAY="$2"
  14. LANGUAGE="$3"
  15. TIMEOUT="$4"
  16. VERBOSE="$5"
  17. : ${CHANNEL_NAME:="mychannel"}
  18. : ${DELAY:="3"}
  19. : ${LANGUAGE:="golang"}
  20. : ${TIMEOUT:="10"}
  21. : ${VERBOSE:="false"}
  22. LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]`
  23. COUNTER=1
  24. MAX_RETRY=5
  25.  
  26. CC_SRC_PATH="github.com/chaincode/go/"
  27. if [ "$LANGUAGE" = "node" ]; then
  28.     CC_SRC_PATH="/opt/gopath/src/github.com/chaincode/node/"
  29. fi
  30.  
  31. echo "Channel name : "$CHANNEL_NAME
  32.  
  33. # import utils
  34. . scripts/utils.sh
  35.  
  36. createChannel() {
  37.     setGlobals 0 1
  38.  
  39.     if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
  40.                 set -x
  41.         peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx >&log.txt
  42.         res=$?
  43.                 set +x
  44.     else
  45.                 set -x
  46.         peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt
  47.         res=$?
  48.                 set +x
  49.     fi
  50.     cat log.txt
  51.     verifyResult $res "Channel creation failed"
  52.     echo "===================== Channel '$CHANNEL_NAME' created ===================== "
  53.     echo
  54. }
  55.  
  56. joinChannel () {
  57.     for org in 1 2 3; do
  58.         for peer in 0 1; do
  59.         joinChannelWithRetry $peer $org
  60.         echo "===================== peer${peer}.org${org} joined channel '$CHANNEL_NAME' ===================== "
  61.         sleep $DELAY
  62.         echo
  63.         done
  64.     done
  65. }
  66.  
  67. ## Create channel
  68. echo "Creating channel..."
  69. createChannel
  70.  
  71. ## Join all the peers to the channel
  72. echo "Having all peers join the channel..."
  73. joinChannel
  74.  
  75. ## Set the anchor peers for each org in the channel
  76. echo "Updating anchor peers for org1..."
  77. updateAnchorPeers 0 1
  78. echo "Updating anchor peers for org2..."
  79. updateAnchorPeers 0 2
  80. echo "Updating anchor peers for org3..."
  81. updateAnchorPeers 0 3
  82.  
  83. ## Install chaincode on peer0.org1 and peer0.org2
  84. echo "Installing chaincode on peer0.org1..."
  85. installChaincode 0 1
  86. echo "Install chaincode on peer0.org2..."
  87. installChaincode 0 2
  88.  
  89. # Instantiate chaincode on peer0.org2
  90. echo "Instantiating chaincode on peer0.org2..."
  91. instantiateChaincode 0 2
  92.  
  93. # Query chaincode on peer0.org1
  94. echo "Querying chaincode on peer0.org1..."
  95. chaincodeQuery 0 1 100
  96.  
  97. # Invoke chaincode on peer0.org1 and peer0.org2
  98. echo "Sending invoke transaction on peer0.org1 peer0.org2..."
  99. chaincodeInvoke 0 1 0 2
  100.  
  101. ## Install chaincode on peer0.org3
  102. echo "Installing chaincode on peer0.org3..."
  103. installChaincode 0 3
  104.  
  105. # Query on chaincode on peer0.org3, check if the result is 90
  106. echo "Querying chaincode on peer0.org3..."
  107. chaincodeQuery 0 3 90
  108.  
  109. echo
  110. echo "========= All GOOD, BYFN execution completed =========== "
  111. echo
  112.  
  113. echo
  114. echo " _____   _   _   ____   "
  115. echo "| ____| | \ | | |  _ \  "
  116. echo "|  _|   |  \| | | | | | "
  117. echo "| |___  | |\  | | |_| | "
  118. echo "|_____| |_| \_| |____/  "
  119. echo
  120.  
  121. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement