随着v0.15中卡的实现,使用概要文件的测试例程的早期版本(显然)将无法工作。但是,我找不到SDK方法来创建运行测试所需的卡。通过v0.14进行测试的代码的“之前”部分如下所示,该部分使用嵌入式配置文件,创建网络的临时实例并运行测试:
describe('Finance Network', () => { // let adminConnection; let businessNetworkConnection; before(() => { BrowserFS.initialize(new BrowserFS.FileSystem.InMemory()); const adminConnection = new AdminConnection({ fs: bfs_fs }); return adminConnection.createProfile('defaultProfile', { type: 'embedded' }) .then(() => { return adminConnection.connect('defaultProfile', adminID, adminPW); }) .then(() => { return BusinessNetworkDefinition.fromDirectory(path.resolve(__dirname, '..')); }) .then((businessNetworkDefinition) => { return adminConnection.deploy(businessNetworkDefinition); }) .then(() => { businessNetworkConnection = new BusinessNetworkConnection({ fs: bfs_fs }); return businessNetworkConnection.connect('defaultProfile', network, adminID, adminPW); }); });
我试图在Nodejs文档中找到(并且还没有发现)的是如何在使用相同方法的同时创建必要的卡来完成这项工作。
我希望将以下代码行替换为可创建必要卡片的内容:
return adminConnection.createProfile('defaultProfile', { type: 'embedded' }) .then(() => { return adminConnection.connect('defaultProfile', adminID, adminPW); })
我看到卡创建的唯一地方是composer-client Participant Registry,但这是Catch-22的情况,必须连接才能创建卡,但是需要连接卡。像我们过去对Hyperledger- Composer的众多发行版所做的那样,建议编写基于摩卡的测试的推荐方法是什么?
谢谢!
经过几天的试验,我找到了解决此问题的方法。以下代码序列使用在v0.15版本中创建的PeerAdmin卡。我导入该卡,并在adminConnect之后,更新卡的元数据中的businessNetwork元素,然后在重新导入卡后,部署并连接到业务网络。
describe('Finance Network', function () { this.timeout(_timeout); let businessNetworkConnection; let peerName = 'PeerAdmin@hlfv1'; before(function () { const adminConnection = new AdminConnection(); let idPeer; return hlc_idCard.fromDirectory(_home+'/.composer/cards/'+peerName) .then ((_idPeer) => { idPeer = _idPeer; return adminConnection.importCard(peerName, idPeer); }) .then(() => { return adminConnection.connect(peerName); }) .then(() => { return BusinessNetworkDefinition.fromDirectory(path.resolve(__dirname, '..')); }) .then((businessNetworkDefinition) => { idPeer.metadata.businessNetwork = network; return adminConnection.importCard(peerName, idPeer) .then(() => { return adminConnection.deploy(businessNetworkDefinition,{'card': idPeer}); }); }) .then(() => { businessNetworkConnection = new BusinessNetworkConnection(); return businessNetworkConnection.connect(peerName); }); });