为什么摩卡中事务的测试结果是错误的,但在 REST 测试中可以正常工作?



我用hyperledger-fabric编写一个事务,并在摩卡上为它实现一个测试单元。事务应设置资产的标题属性。 使用assetRegistry.updade函数更新后,资产标题值不会更改,但是当我在 REST 中进行测试时,它可以正常工作。

首席技术官文件

transaction TestOnChat {
--> Chat chat
}
asset Chat identified by chatId {
o String chatId
o String title
o DateTime createAt
o ChatType type
o Member[] memberList
o Message[] messageList
}

权限.asl

rule Test{
description: "Member can expel other member chat"
participant: "org.miluxas.chatnet2.User"
operation: ALL
resource: "org.miluxas.chatnet2.TestOnChat"
action: ALLOW
}

逻辑.js

/**
* 
* @param {org.miluxas.chatnet2.TestOnChat} testOnChat - the teropooo
* @transaction
*/
async function testOnChat(ex){
ex.chat.title='fdfdfdf';
const memberRegistry = await getAssetRegistry('org.miluxas.chatnet2.Chat');
await memberRegistry.update(ex.chat);
}

测试/逻辑.js

it('test chat', async () => {
// Use the identity for Solivan.
await useIdentity(solivanCardName);
await createNewChat('32556','first solivan group chat','PUBLIC_GROUP');
// Get the asset. and check if Ferzin added to chat
const assetRegistry = await businessNetworkConnection.getAssetRegistry('org.miluxas.chatnet2.Chat');
const asset1 = await assetRegistry.get('32556');
// Submit add other user to chat transaction
const transaction33 = factory.newTransaction(namespace, 'TestOnChat');
transaction33.chat = factory.newRelationship(namespace, 'Chat', '32556');
await businessNetworkConnection.submitTransaction(transaction33);
//console.log(asset1.type);
asset1.title.should.equal('fdfdfdf');
});

我在test/logic.js中发现了我的错误。我在提交TestOnChat transaction之前设置了asset1,并在提交交易后进行了检查。

最新更新