首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nodejs测试超级分类系统编写器v0.15失败,错误:卡未找到: PeerAdmin@hlfv1 1

nodejs测试超级分类系统编写器v0.15失败,错误:卡未找到: PeerAdmin@hlfv1 1
EN

Stack Overflow用户
提问于 2017-11-20 13:24:13
回答 2查看 696关注 0票数 1

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

代码语言:javascript
复制
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文档中找到(而且尚未找到)的是如何创建必要的卡片来完成这项工作,同时使用同样的方法。

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

代码语言:javascript
复制
        return adminConnection.createProfile('defaultProfile', {
            type: 'embedded'
        })
            .then(() => {
                return adminConnection.connect('defaultProfile', adminID, adminPW);
            })

我看到卡片创建的唯一地方是在作曲家-客户参与注册,但这是一个陷阱-22的情况下,我必须连接创建卡,但我需要一张卡来连接。我们建议编写基于摩卡的测试的方法是什么,就像我们过去对Hyperledger-Composer的无数版本所做的那样?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-21 22:02:08

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

代码语言:javascript
复制
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);
        });
    });
票数 0
EN

Stack Overflow用户

发布于 2017-11-21 15:46:06

我想,在建立基于卡的API时,可能需要进行一些改进,但是您应该只使用API来查看这样的内容:

代码语言:javascript
复制
// Embedded connection used for local testing
const connectionProfile = {
    name: 'embedded',
    type: 'embedded'
};
// Embedded connection does not need real credentials
const credentials = {
    certificate: 'FAKE CERTIFICATE',
    privateKey: 'FAKE PRIVATE KEY'
};

// 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);
deployerCard.setCredentials(credentials);

// In-memory card store for testing so cards are not persisted to the file system
const cardStore = new MemoryCardStore();
const adminConnection = new AdminConnection({ cardStore: cardStore });

const deployerCardName = 'PeerAdmin';
const adminUserName = 'admin';
let adminCardName;
let businessNetworkDefinition;

return adminConnection.importCard(deployerCardName, deployerCard).then(() => {
    return adminConnection.connect(deployerCardName);
}).then(() => {
    return BusinessNetworkDefinition.fromDirectory(path.resolve(__dirname, '..'));
}).then(definition => {
    businessNetworkDefinition = definition;
    // Install the Composer runtime for the new business network
    return adminConnection.install(businessNetworkDefinition.getName());
}).then(() => {
    // Start the business network and configure an network admin identity
    const startOptions = {
        networkAdmins: [
            {
                userName: adminUserName,
                enrollmentSecret: adminSecret
            }
        ]
    };
    return adminConnection.start(businessNetworkDefinition, startOptions);
}).then(adminCards => {
    // Import the network admin identity for us to use
    adminCardName = 'admin@' + businessNetworkDefinition.getName();
    return adminConnection.importCard(adminCardName, adminCards.get(adminUserName));
}).then(() => {
    // Connect to the business network using the network admin identity
    businessNetworkConnection = new BusinessNetworkConnection({ cardStore: cardStore });
    return businessNetworkConnection.connect(adminCardName);
});

要注意的是,从调用AdminConnection.start()返回的网络管理卡(如我所键入的)正在添加到这个问题中:超级分类账/作曲家#2753

CLI命令已经注册了网络管理标识,并为这个管理员输出了一张卡,如果您想要使用它,而不是给其他人,就可以导入它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47393096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档