gpt4 book ai didi

node.js - Nodejs 测试 Hyperledger Composer v0.15 失败,错误为 : Card not found: PeerAdmin@hlfv1

转载 作者:太空宇宙 更新时间:2023-11-04 01:57:19 24 4
gpt4 key购买 nike

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

我试图在 Node.js 文档中找到(尚未找到)的是如何创建必要的卡片来完成这项工作,同时使用相同的方法。

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

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

我看到卡创建的唯一地方是在 Composer 客户端参与者注册表中,但这是第 22 条军规的情况,我必须连接才能创建卡,但我需要一张卡才能连接。正如我们在过去无数个 Hyperledger-Composer 版本中所做的那样,推荐的编写基于 mocha 的测试的方法是什么?

谢谢!

最佳答案

我认为,随着基于卡的 API 的建立,可能需要进行一些改进,但您应该仅使用 API 来查看类似的内容:

// 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() 返回的网络管理卡(正如我所输入的)正在添加到此问题中:hyperledger/composer#2753

CLI 命令已注册网络管理员身份并为此管理员输出一张卡,如果您想使用它而不是将其交给其他人,则可以导入该卡。

关于node.js - Nodejs 测试 Hyperledger Composer v0.15 失败,错误为 : Card not found: PeerAdmin@hlfv1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47393096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com