Merge pull request #44 from qiang0723/master

Split README and update auto-test script
pull/45/head
Baohua Yang 2017-05-11 10:35:48 +08:00 committed by GitHub
commit 8757ac25e0
3 changed files with 128 additions and 109 deletions

View File

@ -0,0 +1,72 @@
## [WIP]Usage of `cryptogen` and `configtxgen`
As we already put the `orderer.genesis.block` and `channel.tx` under `e2e_cli/channel-artifacts/`.
This step explains the creation of `orderer.genesis.block` (needed by orderer to bootup), `channel.tx` (needed by cli to create new channel) and crypto related configuration files.
### cryptogen
This tool will generate the x509 certificates used to identify and authenticate the various components in the network.
First boot MVE through `docker-compose-new-channel.yml`
```bash
$ docker-compose -f docker-compose-new-channel.yml up
```
This tool will generate dir `crypto-config`
```bash
cryptogen generate --config=./peer/crypto-config.yaml
```
### [configtxgen](http://hyperledger-fabric.readthedocs.io/en/latest/configtxgen.html?highlight=crypto#)
This tool will generate genesis block, channel configuration transaction and anchor peer update transactions.
Enter container `fabric-cli` first.
```
$ docker exec -it fabric-cli bash
```
The `configtxgen` tool is in `/go/bin/`, and when it's executed,
it will read profile `/etc/hyperledger/fabric/configtx.yaml`,
for example if we want to regenerate `orderer.genesis.block` and `channel.tx`, we should
replace `configtx.yaml` using our own configtx.yaml first, but now we use e2e test's configtx.yaml.
```bash
cp ./peer/configtx.yaml /etc/hyperledger/fabric
```
#### Create the genesis block
Generate the genesis block.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/orderer.genesis.block
```
> Note: Before execute this command, we must reboot MVE with new crypto-config generated by cryptogen tool.
> more details refe to Example2
#### Create the configuration tx
Create channel configuration transaction for the to-be-created `testchain`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./peer/channel-artifacts/channel.tx -channelID testchain
```
`channel.tx` is used for generating new channel `testchain`
### Example1: how to add or change channel
* 1 Regenerate `channel.tx`
* 2 Generating anchor peer for Org1MSP
```bash
$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org1MSPanchors.tx -channelID testchain -asOrg Org1MSP
```
### Example2: how to Add an organization or peer
* 1 Modify configtx.yaml and crypto-cnfig.yaml
* 2 Generate new crypto-config
* 3 Reboot MVE using new config
* 4 Create the genesis block
* 5 Create configuration tx
* 6 Generating anchor peer for each Org

View File

@ -210,59 +210,25 @@ CONTAINER ID IMAGE COMMAND CREATE
bea1154c7162 hyperledger/fabric-ca "fabric-ca-server ..." About a minute ago Up About a minute 7054/tcp, 0.0.0.0:8888->8888/tcp fabric-ca
```
#### [WIP]Create genesis block and configuration transaction
#### Auto chaincode operation
Run this script will check whether the MVE bootstrap success.
```bash
$ docker exec -it fabric-cli bash
root@cli:/go/src/github.com/hyperledger/fabric# ./peer/scripts/new-channel-auto-test.sh
```
#### Manually create artifacts
This step explains the creation of `orderer.genesis.block` (needed by orderer to bootup), `channel.tx` (needed by cli to create new channel) and crypto related configuration files.
Detailed steps refer to [GenerateArtifacts](./GenerateArtifacts.md)
**Skip this step**, as we already put the `orderer.genesis.block` and `channel.tx` under `e2e_cli/channel-artifacts/`.
This step explains the creation of `orderer.genesis.block` (needed by orderer to bootup) and `channel.tx` (needed by cli to create new channel).
##### Create the genesis block
Enter the `fabric-cli` container, and run the following cmd to use the e2e test's configtx.yaml.
```bash
$ docker exec -it fabric-cli bash
root@cli:/go/src/github.com/hyperledger/fabric# cp ./peer/configtx.yaml /etc/hyperledger/fabric
```
Generate the genesis block.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# configtxgen -profile TwoOrgs -outputBlock orderer.block
Loading configuration
Looking for configtx.yaml in: /etc/hyperledger/fabric
Found configtx.yaml there
Checking for MSPDir at: .
Checking for MSPDir at: .
Checking for MSPDir at: .
Generating genesis block
Writing genesis block
root@cli:/go/src/github.com/hyperledger/fabric# ls orderer.block
orderer.block
```
##### Create the configuration tx
Create channel configuration transaction for the to-be-created `newchannel`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# CHANNEL_NAME="newchannel"
root@cli:/go/src/github.com/hyperledger/fabric# configtxgen -profile TwoOrgs -outputCreateChannelTx channel.tx -channelID ${CHANNEL_NAME}
Loading configuration
Looking for configtx.yaml in: /etc/hyperledger/fabric
Found configtx.yaml there
Checking for MSPDir at: .
Checking for MSPDir at: .
Checking for MSPDir at: .
Generating new channel configtx
Creating no-op MSP instance
Obtaining default signing identity
Creating no-op signing identity instance
Serialinzing identity
signing message
signing message
Writing new channel tx
root@cli:/go/src/github.com/hyperledger/fabric# ls channel.tx
channel.tx
```
#### Create new channel
@ -315,16 +281,16 @@ The `configtx.yaml` file contains the definitions for our sample network and pre
components - three members (OrdererOrg, Org1 & Org2), But in this MVE, we just use OrdererOrg and Org1,
org1 has only peer(pee0.org1), and chose it as anchor peers for Org1.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer channel create -o orderer.example.com:7050 -c mychannel -f ./peer/channel-artifacts/Org1MSPanchors.tx
root@cli:/go/src/github.com/hyperledger/fabric# peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./peer/channel-artifacts/Org1MSPanchors.tx
```
#### Install&Instantiate
First `install` a chaincode named `test_cc` to `peer0`.
First `install` a chaincode named `mycc` to `peer0`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
```
This will take a while, and the result may look like following.
@ -338,7 +304,7 @@ UTC [main] main -> INFO 006 Exiting.....
Then `instantiate` the chaincode mycc on channel `mychannel`, with initial args and the endorsement policy.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member')"
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode instantiate -o orderer.example.com:7050 -C ${CHANNEL_NAME} -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member')"
```
This will take a while, and the result may look like following:
@ -366,7 +332,7 @@ c87095528f76 hyperledger/fabric-ca "fabric-ca-server ..."
Query the existing value of `a` and `b`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}'
```
The result may look like following, with a payload value of `100`.
@ -376,7 +342,7 @@ Query Result: 100
```
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}'
```
The result may look like following, with a payload value of `200`.
@ -392,7 +358,7 @@ Query Result: 200
Inside the container, invoke a transaction to transfer `10` from `a` to `b`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode invoke -o orderer.example.com:7050 -C ${CHANNEL_NAME} -n mycc -c '{"Args":["invoke","a","b","10"]}'
```
The result may look like following:
@ -408,7 +374,7 @@ And then query the value of `a` and `b`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}'
```
```bash
@ -419,7 +385,7 @@ The value of `a` should be `90`.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
root@cli:/go/src/github.com/hyperledger/fabric# peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","b"]}'
```
The value of `b` should be `210`
@ -446,13 +412,6 @@ Query Response:{"Name":"a","Amount":"90"}
```
### [WIP]Run the auto-test with shell
As the shell shown, it will auto execute test steps.
```bash
root@cli:/go/src/github.com/hyperledger/fabric# ./peer/scripts/new-channel-auto-test.sh
```
## Acknowledgement
* [Hyperledger Fabric](https://github.com/hyperledger/fabric/) project.

View File

@ -1,7 +1,7 @@
#!/bin/bash
CHANNEL_NAME="$1"
: ${CHANNEL_NAME:="newchannel"}
: ${CHANNEL_NAME:="mychannel"}
: ${TIMEOUT:="60"}
COUNTER=0
MAX_RETRY=5
@ -18,21 +18,8 @@ verifyResult () {
fi
}
setGlobals () {
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig
CORE_PEER_ADDRESS=peer0:7051
CORE_PEER_LOCALMSPID="Org0MSP"
#env |grep CORE
}
createChannel() {
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/orderer/localMspConfig
CORE_PEER_LOCALMSPID="OrdererMSP"
env|grep CORE_PEER_MSPCONFIGPATH
env|grep CORE_PEER_LOCALMSPID
peer channel create -c ${CHANNEL_NAME} -o orderer0:7050 -f peer/crypto/orderer/channel.tx >&log.txt
peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./peer/channel-artifacts/channel.tx >&log.txt
res=$?
cat log.txt
@ -40,7 +27,7 @@ createChannel() {
echo
# verify file newchannel.block exist
if [ -s newchannel.block ]; then
if [ -s mychannel.block ]; then
res=$?
verifyResult $res "Channel created failed"
fi
@ -51,11 +38,7 @@ createChannel() {
joinChannel () {
echo "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== "
setGlobals
env|grep CORE_PEER_MSPCONFIGPATH
env|grep CORE_PEER_LOCALMSPID
env|grep CORE_PEER_ADDRESS
peer channel join -b ${CHANNEL_NAME}.block -o orderer0:7050 >&log.txt
peer channel join -b ${CHANNEL_NAME}.block -o orderer.example.com:7050 >&log.txt
res=$?
cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
@ -69,9 +52,17 @@ joinChannel () {
verifyResult $res "After $MAX_RETRY attempts, PEER0 has failed to Join the Channel"
}
updateAnchorPeers() {
peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./peer/channel-artifacts/Org1MSPanchors.tx >&log.txt
res=$?
cat log.txt
verifyResult $res "Anchor peer update failed"
echo "==== Anchor peers for org1 on mychannel is updated successfully======"
echo
}
installChaincode () {
setGlobals
peer chaincode install -n test_cc -p ${CC_PATH} -v 1.0 -o orderer0:7050 >&log.txt
peer chaincode install -n mycc -v 1.0 -p ${CC_PATH} -o orderer.example.com:7050 >&log.txt
res=$?
cat log.txt
verifyResult $res "Chaincode installation on remote peer0 has Failed"
@ -80,49 +71,46 @@ installChaincode () {
}
instantiateChaincode () {
setGlobals
local starttime=$(date +%s)
peer chaincode instantiate -o orderer0:7050 -C ${CHANNEL_NAME} -n test_cc -v 1.0 -p ${CC_PATH} -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org0MSP.member','Org1MSP.member')" >&log.txt
peer chaincode instantiate -o orderer.example.com:7050 -C ${CHANNEL_NAME} -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member')" >&log.txt
res=$?
cat log.txt
verifyResult $res "Chaincode instantiation on PEER0 on channel '$CHANNEL_NAME' failed"
echo "=========== Chaincode Instantiation on PEER0 on channel '$CHANNEL_NAME' is successful ========== "
verifyResult $res "Chaincode instantiation on pee0.org1 on channel '$CHANNEL_NAME' failed"
echo "=========== Chaincode Instantiation on peer0.org1 on channel '$CHANNEL_NAME' is successful ========== "
echo "Instantiate spent $(($(date +%s)-starttime)) secs"
echo
}
chaincodeQuery () {
setGlobals
local rc=1
local starttime=$(date +%s)
while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0
do
sleep 3
echo "Attempting to Query PEER0 ...$(($(date +%s)-starttime)) secs"
peer chaincode query -C ${CHANNEL_NAME} -n test_cc -c '{"Args":["query","a"]}' >&log.txt
echo "Attempting to Query peer0.org1 ...$(($(date +%s)-starttime)) secs"
peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}' >&log.txt
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
test "$VALUE" = "$1" && let rc=0
done
echo
cat log.txt
if test $rc -eq 0 ; then
echo "===================== Query on PEER0 on channel '$CHANNEL_NAME' is successful ===================== "
echo "===================== Query on peer0.org1 on channel '$CHANNEL_NAME' is successful ===================== "
else
echo "!!!!!!!!!!!!!!! Query result on PEER0 is INVALID !!!!!!!!!!!!!!!!"
echo "!!!!!!!!!!!!!!! Query result on peer0.org1 is INVALID !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute MVE test =================="
echo
fi
}
chaincodeInvoke () {
setGlobals
peer chaincode invoke -o orderer0:7050 -C ${CHANNEL_NAME} -n test_cc -c '{"Args":["invoke","a","b","10"]}' >&log.txt
peer chaincode invoke -o orderer.example.com:7050 -C ${CHANNEL_NAME} -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txt
res=$?
cat log.txt
verifyResult $res "Invoke execution on PEER0 failed "
echo "========= Invoke transaction on PEER0 on channel '$CHANNEL_NAME' is successful ===== "
verifyResult $res "Invoke execution on peer0.org1 failed "
echo "========= Invoke transaction on peer0.org1 on channel '$CHANNEL_NAME' is successful ===== "
echo
}
@ -132,25 +120,25 @@ createChannel
echo "====================2.Join pee0 to the channel ======================================"
joinChannel
echo "=====================3.Install chaincode test_cc on Peer0/Org0========================"
echo "====================3.set anchor peers for org1 in the channel==========================="
updateAnchorPeers
echo "=====================4.Install chaincode test_cc on Peer0/Org0========================"
installChaincode
echo "=====================4.Instantiate chaincode, this will take a while, pls waiting...==="
echo "=====================5.Instantiate chaincode, this will take a while, pls waiting...==="
instantiateChaincode
echo "====================5.Query the existing value of a===================================="
echo "====================6.Query the existing value of a===================================="
chaincodeQuery 100
#Query b on chaincode
#chaincodeQuery b 200
echo "=====================6.Invoke a transaction to transfer 10 from a to b=================="
echo "=====================7.Invoke a transaction to transfer 10 from a to b=================="
chaincodeInvoke
echo "=====================7.Check if the result of a is 90==================================="
echo "=====================8.Check if the result of a is 90==================================="
chaincodeQuery 90
echo
echo "=====================8.All GOOD, MVE Test completed ===================== "
echo "=====================9.All GOOD, MVE Test completed ===================== "
echo
exit 0