首先把这个例子 跑起来
https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html#
./byfn.sh up
成功之后 然后执行
./byfn.sh down
关闭这个网络
下面开始搭建 基础环境
https://github.com/hyperledger/fabric-samples/
这些命令 都在 fabric-samples/first-network 这个目录下 执行
export FABRIC_CFG_PATH=$PWD
export CHANNEL_NAME=mychannel
cryptogen generate --config=./crypto-config.yaml
configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
docker-compose -f docker-compose-cli.yaml up -d
这些命令 还是上面那个链接中的 不过是手动搭建网络的部分 到启动网络 部分停止
到此 基础环境 准备完毕
https://github.com/hyperledger/fabric-sdk-go
这个是go的sdk go get 或者 下载下来
然后 进入到
fabric-sdk-go/test/integration/e2e 这个目录 下面
咱们一般都是在本地跑示例
go test -args testLocal=true
执行 这一步的时候 会有几个报错 都很简单 看提示 就可以处理
后面的参数 意思是加载 测试本地配置文件 路径是
hyperledger/fabric-sdk-go/blob/master/test/fixtures/config/overrides/local_entity_matchers.yaml
entityMatchers:
peer:
- pattern: peer0.org1.example.(\w+)
urlSubstitutionExp: localhost:7051
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: peer0.org1.example.com
- pattern: peer1.org1.example.(\w+)
urlSubstitutionExp: localhost:7151
sslTargetOverrideUrlSubstitutionExp: peer1.org1.example.com
mappedHost: peer1.org1.example.com
- pattern: peer0.org2.example.(\w+)
urlSubstitutionExp: localhost:8051
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
mappedHost: peer0.org2.example.com
- pattern: peer1.org2.example.(\w+)
urlSubstitutionExp: localhost:9051
sslTargetOverrideUrlSubstitutionExp: peer1.org2.example.com
mappedHost: peer1.org2.example.com
- pattern: (\w+).org1.example.(\w+):(\d+)
urlSubstitutionExp: localhost:${2}
sslTargetOverrideUrlSubstitutionExp: ${1}.org1.example.com
mappedHost: ${1}.org1.example.com
- pattern: (\w+).org2.example.(\w+):(\d+)
urlSubstitutionExp: localhost:${2}
sslTargetOverrideUrlSubstitutionExp: ${1}.org2.example.com
mappedHost: ${1}.org2.example.com
- pattern: (\w+):7051
urlSubstitutionExp: localhost:7051
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: peer0.org1.example.com
- pattern: (\w+):7151
urlSubstitutionExp: localhost:7151
sslTargetOverrideUrlSubstitutionExp: peer1.org1.example.com
mappedHost: peer1.org1.example.com
- pattern: (\w+):8051
urlSubstitutionExp: localhost:8051
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
mappedHost: peer0.org2.example.com
- pattern: (\w+):9051
urlSubstitutionExp: localhost:9051
sslTargetOverrideUrlSubstitutionExp: peer1.org2.example.com
mappedHost: peer1.org2.example.com
orderer:
- pattern: (\w+).example.(\w+)
urlSubstitutionExp: localhost:7050
sslTargetOverrideUrlSubstitutionExp: orderer.example.com
mappedHost: orderer.example.com
- pattern: (\w+).example.(\w+):(\d+)
urlSubstitutionExp: localhost:7050
sslTargetOverrideUrlSubstitutionExp: orderer.example.com
mappedHost: orderer.example.com
certificateAuthority:
- pattern: (\w+).org1.example.(\w+)
urlSubstitutionExp: https://localhost:7054
sslTargetOverrideUrlSubstitutionExp: ca.org1.example.com
mappedHost: ca.org1.example.com
- pattern: (\w+).org2.example.(\w+)
urlSubstitutionExp: https://localhost:8054
sslTargetOverrideUrlSubstitutionExp: ca.org2.example.com
mappedHost: ca.org2.example.com
省略了注释部分 这里面的节点端口号 都要改成自己的
config_e2e.yaml 修改这个文件中的证书和秘钥路径
你和我路径可能有偏差 一定要改成你自己的
cryptoconfig:
path:
F
A
B
R
I
C
S
D
K
G
O
P
R
O
J
E
C
T
P
A
T
H
/
{FABRIC_SDK_GO_PROJECT_PATH}/
FABRICSDKGOPROJECTPATH/{CRYPTOCONFIG_FIXTURES_PATH}
关于两个变量的问题 查看代码 可以发现 这个是由 go程序替换的
这个函数的 注释说明了 变量的用法 以及 缺省值 是什么
如果出现连接超时的问题 就是端口没有改正确
问题汇总:
mychannel.tx 文件不存在
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID $CHANNEL_NAME
这个命令 会在 生成一个 mychannel.tx 然后复制到 对应目录 就可以
genesis.block 不存在 同理 直接 复制到 对应的目录就行
还有就是 通道重复创建问题 所以 如果 失败就要 重新准备一次 初始环境
还是先 down 关闭网络 然后在执行上面的命令 如果感觉麻烦 可以写一个shell脚本 执行
这个例子可能有些瑕疵 欢迎大家在评论区 讨论和提问