[英]nodejs test hyperledger composer v0.15 fails with Error: Card not found: PeerAdmin@hlfv1
隨着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);
});
});
我試圖在Nodejs文檔中找到(並且尚未發現)的是如何在使用相同方法的同時創建必要的卡來完成這項工作。
我希望將以下代碼行替換為可創建所需卡的內容:
return adminConnection.createProfile('defaultProfile', {
type: 'embedded'
})
.then(() => {
return adminConnection.connect('defaultProfile', adminID, adminPW);
})
我看到卡創建的唯一地方是composer-client Participant Registry,但這是Catch-22的情況,必須連接才能創建卡,但是需要連接卡。 像我們過去對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);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.