mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 07:25:10 +00:00
test-network-nano-bash chaincode id and waitForEvent improvements (#1052)
- Use calculatepackageid to set CHAINCODE_ID - Use waitForEvent to wait for commit event intead of 2s sleep Signed-off-by: David Enyeart <enyeart@us.ibm.com>
This commit is contained in:
parent
81390fbbbf
commit
ae9e7e8df8
3 changed files with 21 additions and 22 deletions
|
|
@ -100,10 +100,12 @@ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/cha
|
|||
peer lifecycle chaincode install basic.tar.gz
|
||||
```
|
||||
|
||||
The chaincode install may take a minute since the `fabric-ccenv` chaincode builder docker image will be downloaded if not already available on your machine. Copy the returned chaincode package ID into an environment variable for use in subsequent commands (your ID may be different):
|
||||
The chaincode install may take a minute since the `fabric-ccenv` chaincode builder docker image will be downloaded if not already available on your machine.
|
||||
|
||||
Copy the returned chaincode package ID into a `CHAINCODE_ID` environment variable for use in subsequent commands, or better yet use the peer `calculatepackageid` command to set the environment variable:
|
||||
|
||||
```shell
|
||||
export CHAINCODE_ID=basic_1:faaa38f2fc913c8344986a7d1617d21f6c97bc8d85ee0a489c90020cd57af4a5
|
||||
export CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid basic.tar.gz) && echo $CHAINCODE_ID
|
||||
```
|
||||
|
||||
## 2. Running the chaincode as a service
|
||||
|
|
@ -121,7 +123,7 @@ cd ..
|
|||
peer lifecycle chaincode install chaincode-external/external-chaincode.tgz
|
||||
```
|
||||
|
||||
Copy the returned chaincode package ID into an environment variable for use in subsequent commands (your ID may be different):
|
||||
Set the CHAINCODE_ID environment variable for use in subsequent commands:
|
||||
|
||||
```shell
|
||||
export CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid chaincode-external/external-chaincode.tgz) && echo $CHAINCODE_ID
|
||||
|
|
@ -172,11 +174,11 @@ Invoke the chaincode to create an asset (only a single endorser is required base
|
|||
Then query the asset, update it, and query again to see the resulting asset changes on the ledger. Note that you need to wait a bit for invoke transactions to complete.
|
||||
|
||||
```shell
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||
|
||||
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}'
|
||||
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||
|
||||
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}'
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# The sleep commands were added because the queries depend on each other and have some latency.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
. peer1admin.sh
|
||||
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt >> ./logs/chaincode_interaction.log 2>&1
|
||||
sleep 2
|
||||
|
||||
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' >> ./logs/chaincode_interaction.log 2>&1
|
||||
sleep 2
|
||||
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt >> ./logs/chaincode_interaction.log 2>&1
|
||||
sleep 2
|
||||
|
||||
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' >> ./logs/chaincode_interaction.log 2>&1
|
||||
{
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}'
|
||||
peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}'
|
||||
} >> ./logs/chaincode_interaction.log 2>&1
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@
|
|||
|
||||
# look for binaries in local dev environment /build/bin directory and then in local samples /bin directory
|
||||
export PATH="${PWD}"/../../fabric/build/bin:"${PWD}"/../bin:"$PATH"
|
||||
|
||||
|
||||
|
||||
|
||||
. peer1admin.sh
|
||||
|
||||
# Install Chaincode on Peer1
|
||||
peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1 >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1
|
||||
peer lifecycle chaincode install basic.tar.gz >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1
|
||||
|
||||
# Extract the CHAINCODE_ID from the logs
|
||||
id=$(sed -n '2s/.*Chaincode code package identifier: //p' ./logs/install\&approve\&commit_chaincode_peer_1.log)
|
||||
export CHAINCODE_ID="$id"
|
||||
# Set the CHAINCODE_ID from the created chaincode package
|
||||
CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid basic.tar.gz)
|
||||
export CHAINCODE_ID
|
||||
|
||||
# Approve the chaincode using Peer1Admin
|
||||
peer lifecycle chaincode approveformyorg -o 127.0.0.1:6050 --channelID mychannel --name basic --version 1 --package-id "${CHAINCODE_ID}" --sequence 1 --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1
|
||||
|
|
|
|||
Loading…
Reference in a new issue