nodejs test hyperledger composer v0.15 fails with Error: Card not found: PeerAdmin@hlfv1
nodejs test hyperledger composer v0.15 fails with Error: Card not found: PeerAdmin@hlfv1
随着 v0.15 中卡片的实现,以前版本的使用配置文件的测试例程(显然)将无法工作。但是,我找不到一种 SDK 方法来为 运行 测试创建必要的卡片。我的测试的 'before' 到 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);
});
});
我试图在 nodejs 文档中找到(但尚未找到)的是如何创建必要的卡片来完成这项工作,同时使用相同的方法。
我希望用创建必要卡片的代码替换以下代码行:
return adminConnection.createProfile('defaultProfile', {
type: 'embedded'
})
.then(() => {
return adminConnection.connect('defaultProfile', adminID, adminPW);
})
我看到卡片创建的唯一地方是在 composer-client Participant Registry 中,但这是一个 Catch-22 情况,我必须连接才能创建卡片,但我需要一张卡片才能连接。编写基于 mocha 的测试的推荐方法是什么,就像我们在过去无数次发布的 Hyperledger-Composer 中所做的那样?
谢谢!
我想随着基于卡片的 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 命令已经注册了网络管理员身份并为此管理员输出了一张卡片,如果您想使用它而不是交给其他人,您可以导入它。
经过几天的试验,我找到了解决这个问题的方法。以下代码序列使用作为 v0.15 版本的一部分创建的 PeerAdmin 卡。我导入该卡,并在 adminConnect 之后更新卡元数据中的 businessNetwork 元素,然后在重新导入卡后,部署并连接到业务网络。
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);
});
});
随着 v0.15 中卡片的实现,以前版本的使用配置文件的测试例程(显然)将无法工作。但是,我找不到一种 SDK 方法来为 运行 测试创建必要的卡片。我的测试的 'before' 到 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);
});
});
我试图在 nodejs 文档中找到(但尚未找到)的是如何创建必要的卡片来完成这项工作,同时使用相同的方法。
我希望用创建必要卡片的代码替换以下代码行:
return adminConnection.createProfile('defaultProfile', {
type: 'embedded'
})
.then(() => {
return adminConnection.connect('defaultProfile', adminID, adminPW);
})
我看到卡片创建的唯一地方是在 composer-client Participant Registry 中,但这是一个 Catch-22 情况,我必须连接才能创建卡片,但我需要一张卡片才能连接。编写基于 mocha 的测试的推荐方法是什么,就像我们在过去无数次发布的 Hyperledger-Composer 中所做的那样?
谢谢!
我想随着基于卡片的 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 命令已经注册了网络管理员身份并为此管理员输出了一张卡片,如果您想使用它而不是交给其他人,您可以导入它。
经过几天的试验,我找到了解决这个问题的方法。以下代码序列使用作为 v0.15 版本的一部分创建的 PeerAdmin 卡。我导入该卡,并在 adminConnect 之后更新卡元数据中的 businessNetwork 元素,然后在重新导入卡后,部署并连接到业务网络。
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);
});
});