我正在使用Mocha编写针对特定区块链网络用例的单元/行为测试。基于我所看到的,这些测试并没有达到实际的结构,换句话说,它们似乎在某种模拟环境中运行。我没有看到作为测试的一部分发生的任何交易。有人可以告诉我,是否有可能捕获作为摩卡测试的一部分发生的交易?
我的代码的初始部分如下:
describe('A Network', () => {
// In-memory card store for testing so cards are not persisted to the file system
const cardStore = require('composer-common').NetworkCardStoreManager.getCardStore( { type: 'composer-wallet-inmemory' } );
let adminConnection;
let businessNetworkConnection;
let businessNetworkDefinition;
let businessNetworkName;
let factory;
//let clock;
// Embedded connection used for local testing
const connectionProfile = {
name: 'hlfv1',
'x-type': 'hlfv1',
'version': '1.0.0'
};
before(async () => {
// Generate certificates for use with the embedded connection
const credentials = CertificateUtil.generate({ commonName: 'admin' });
// PeerAdmin identity used with the admin connection to deploy business networks
const deployerMetadata = {
version: 1,
userName: 'PeerAdmin',
roles: [ 'PeerAdmin', 'ChannelAdmin' ]
};
const deployerCard = new IdCard(deployerMetadata, connectionProfile);
console.log("line 63")
const deployerCardName = 'PeerAdmin';
deployerCard.setCredentials(credentials);
console.log("line 65")
// setup admin connection
adminConnection = new AdminConnection({ cardStore: cardStore });
console.log("line 69")
await adminConnection.importCard(deployerCardName, deployerCard);
console.log("line 70")
await adminConnection.connect(deployerCardName);
console.log("line 71")
});
之前,我的连接配置文件使用的是嵌入式模式,在查看下面的答案后,我将其更改为hlfv1
。现在,我收到错误:Error: the string "Failed to import identity. Error: Client.createUser parameter 'opts mspid' is required." was thrown, throw an Error :)
。这来自于
await adminConnection.importCard(deployerCardName, deployerCard);
。有人可以告诉我需要改变什么。任何文档/资源都会有所帮助。
答案 0 :(得分:1)
是的,您可以使用真正的Fabric。这意味着您可以使用测试框架或其他方式(如REST或Playground等)与创建的事务进行交互。
在Composer自己的测试设置中,在其设置中使用针对hlfv1
Fabric环境进行测试的选项(即,您是否要使用嵌入式,Web或真正的Fabric) - >见https://github.com/hyperledger/composer/blob/master/packages/composer-tests-functional/systest/historian.js#L120
在此处设置您需要设置以使用真实结构的工件的示例 https://github.com/hyperledger/composer/blob/master/packages/composer-tests-functional/systest/testutil.js#L247
另请参阅此博客以获取更多指南 - > https://medium.com/@mrsimonstone/debug-your-blockchain-business-network-using-hyperledger-composer-9bea20b49a74