如何使用Mocha进行测试时捕获事务

问题描述 投票:1回答:1

我正在使用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);。有人可以告诉我需要改变什么。任何文档/资源都会有所帮助。

hyperledger-composer
1个回答
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#L192

设置工件的示例,您需要设置这些工件以在此处使用真正的Fabric 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

© www.soinside.com 2019 - 2024. All rights reserved.