nodejs 测试 hyperledger composer v0.15 失败并出现错误:找不到卡:PeerAdmin@hlfv1 [英] nodejs test hyperledger composer v0.15 fails with Error: Card not found: PeerAdmin@hlfv1

查看:10
本文介绍了nodejs 测试 hyperledger composer v0.15 失败并出现错误:找不到卡:PeerAdmin@hlfv1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 v0.15 中卡片的实现,使用配置文件的先前版本的测试例程(显然)将无法工作.但是,我找不到 SDK 方法来创建运行测试所需的卡片.我的测试从 v0.14 开始的之前"部分代码如下所示,它使用嵌入式配置文件,创建网络的临时实例并运行测试:

With the implementation of cards in v0.15, previous versions of test routines which used profiles (obviously) won't work. However, I cannot find an SDK approach to create the necessary cards to run tests. The 'before' section of code up through v0.14 for my tests has looked like the following, which uses an embedded profile, creates a temporary instance of the network and runs the tests:

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 文档中找到(但还没有)是如何创建必要的卡片来完成这项工作,同时使用相同的方法.

What I'm trying to find (and haven't yet) in the nodejs documentation is how to create the necessary cards to make this work, while using this same approach.

我希望将以下代码行替换为创建必要卡片的代码:

I expect to replace the following lines of code with something that creates the necessary cards:

        return adminConnection.createProfile('defaultProfile', {
            type: 'embedded'
        })
            .then(() => {
                return adminConnection.connect('defaultProfile', adminID, adminPW);
            })

我看到卡片创建的唯一地方是 composer-client Participant Registry,但这是 Catch-22 的情况,我必须连接才能创建卡片,但我需要一张卡片才能连接.像我们在过去无数版本的 Hyperledger-Composer 中所做的那样,编写基于 mocha 的测试的推荐方法是什么?

The only place where I see card creation is in composer-client Participant Registry, but it's a Catch-22 situation where I have to be connected to create the card, but I need a card to get connected. What is the recommended approach for writing mocha-based testing as we have been doing for the past umpteen releases of Hyperledger-Composer?

谢谢!

推荐答案

经过几天的试验,我找到了解决这个问题的方法.以下代码序列使用作为 v0.15 版本的一部分创建的 PeerAdmin 卡.我导入该卡,并在 adminConnect 之后更新卡元数据中的 businessNetwork 元素,然后在重新导入卡后,部署并连接到业务网络.

After a couple of days of experimenting, I've found a way to solve this problem. The following code sequence uses the PeerAdmin card created as part of the v0.15 release. I import that card and, after adminConnect, update the businessNetwork element in the card's metadata and then, after re-importing the card, deploy and connect to the business network.

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);
        });
    });

这篇关于nodejs 测试 hyperledger composer v0.15 失败并出现错误:找不到卡:PeerAdmin@hlfv1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆