Hyperledger交易本应被拒绝,但转到了默认规则



我正在尝试为我的链代码运行测试,这就是我得到的。

return useIdentity(aliceIdentity)
.then(() => {
// Submit the transaction.
const transaction = factory.newTransaction('com.james.demo', 'UpdateAppointment');
transaction.asset = factory.newRelationship('com.james.demo', 'Appointment', '2', '11/2/2017', '08:19','new','3');
transaction.newValue = '50';
return businessNetworkConnection.submitTransaction(transaction);
})
.should.be.rejectedWith(/does not have .* access to resource/);

我得到这个:

AssertionError: expected promise to be rejected with an error matching /does not have .* access to resource/ but it was fulfilled with undefined

这就是我的代码:

/**
* Sample transaction processor function.
* @param {com.james.demo.UpdateAppointment} tx The sample transaction instance.
* @transaction
*/
function UpdateAppointment(tx, patient, doctor, origAppointment) {
// Save the old value of the asset.
var oldValue = tx.asset.value;
// Update the asset with the new value.
tx.asset.value = tx.newValue;
// Get the asset registry for the asset.
return getAssetRegistry('com.james.demo.Appointment')
.then(function (assetRegistry) {
// Update the asset in the asset registry.
return assetRegistry.update(tx.asset);
})
.then(function () {
console.log(JSON.stringify(tx));
});
}

这就是规则:

rule DoctorHasFullAccessToTheirAssets {
description: "Allow all participants full access to their assets"
participant(p): "com.james.demo.Doctor"
operation: ALL
resource(r): "com.james.demo.Appointment"
condition: (r.doctor.getIdentifier() === p.getIdentifier())
action: ALLOW
}

这是预约

asset Appointment identified by appointmentId {
o String appointmentId
o String appointmentDate optional
o String appointmentTime optional
o String status optional
--> Doctor doctor optional
--> Patient owner optional
o String value optional
}

医生:

participant Doctor identified by npiId {
o String npiId
o String firstName
o String lastName
}

UpdateAppointment中,我有一个console.log命令没有被执行,它出现了。所以我认为我的功能实际上并没有被执行。

在我的UpdateAppointment中有多个参数,这不正确吗?

如何通过此测试?

我在你的帖子中没有看到你的建模交易,即com.james.demo.UpdateAppointment。但是您只需要传递UpdateAppointment事务实例,因此:

function UpdateAppointment(tx) { 
...
}

然后通过交易定义中的关系参考您的患者、医生(参与者)和预约(例如资产列表)。

查看此示例网络逻辑https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/lib/logic.js以及如何在交易中建模关系(即,对您来说可能是类似的事情:预约关系:患者(被任命者和参与者)、医生(预约参与者)、原始预约(患者可以将预约作为列表进行一对多关系?)。不管怎样,你更了解你的用例。重点是,当事务逻辑被执行时,您的事务实例可以通过事务处理器功能了解参与者是谁以及资产实例是什么-请参阅此处的更多信息https://hyperledger.github.io/composer/reference/js_scripts.html

希望这能有所帮助。。

最新更新