超级账本test-network测试工作流程

   日期:2020-09-30     浏览:128    评论:0    
核心提示:一、启动测试网络1.进入test-network目录cd fabric-samples/test-network2.在test-network目录中,运行以下命令删除先前运行的所有容器或工程./network.sh down3.过执行以下命令来启动网络./network.sh up此命令创建一个由两个peer节点和一个order节点组成的Fabric网络二、测试网络的组成部分运行以下命令以列出所有正在您的计算机上运行的Docker容器docker ps -a三、创建一个通道

一、启动测试网络

1.进入test-network目录

cd fabric-samples/test-network

2.在test-network目录中,运行以下命令删除先前运行的所有容器或工程

./network.sh down

3.过执行以下命令来启动网络

./network.sh up

此命令创建一个由两个peer节点和一个order节点组成的Fabric网络

二、测试网络的组成部分

运行以下命令以列出所有正在您的计算机上运行的Docker容器

docker ps -a

三、创建一个通道

  1. 运行以下命令以创建一个默认名称为“ mychannel”的通道
./network.sh createChannel

四、在channel启动一个链码

1.使用以下命令在通道上启动链码

./network.sh deployCC

五、与网络交互

1.使用以下命令将这些二进制文件添加到您的CLI路径

export PATH=${PWD}/../bin:$PATH

2.还需要将fabric-samples代码库中的FABRIC_CFG_PATH设置为指向其中的core.yaml文件

export FABRIC_CFG_PATH=$PWD/../config/

3.设置环境变量,以允许您作为Org1操作peer CLI

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

4.运行以下命令以获取已添加到通道账本中的汽车列表

peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'

运行上面指令前需要执行如下:
新开一个命令窗口
执行启动指令:cd fabric-samples/fabcar后,
执行./startFabric.sh,等待完成即可。
最后再继续运行之前的指令

peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'

可以得到如下结果:

[{ "Key":"CAR0","Record":{ "make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{ "Key":"CAR1","Record":{ "make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{ "Key":"CAR2","Record":{ "make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{ "Key":"CAR3","Record":{ "make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{ "Key":"CAR4","Record":{ "make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{ "Key":"CAR5","Record":{ "make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{ "Key":"CAR6","Record":{ "make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{ "Key":"CAR7","Record":{ "make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{ "Key":"CAR8","Record":{ "make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{ "Key":"CAR9","Record":{ "make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}]

5.使用以下命令调用fabcar链码来更改账本上汽车的所有者

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"changeCarOwner","Args":["CAR9","Dave"]}'

如果命令成功,应该看到以下响应:

2020-9-04 17:38:21.048 EST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200

6.设置以下环境变量以作为Org2进行操作

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051

7.现在可以查询运行在peer0.org2.example.com的fabcar链码

peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryCar","CAR9"]}'

结果将显示"CAR9"已转移到Dave:

{ "make":"Holden","model":"Barina","colour":"brown","owner":"Dave"}

六、关停网络

使用完测试网络后,您可以使用以下命令关闭网络

./network.sh down
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服