我正在使用 cucumber 在 hyperledger composer 上运行一些单元测试。我不断收到这个TypeError: Cannot read property 'getClassDeclaration' of null
资产代码是
asset Clicks identified by id {
o String id
o String ipAddress
o String publisherId
o String advertiserId
o String CreatedAt
}
交易代码是
transaction Clicks_Add
{
o Clicks clicks
}
.JS 文件中的事务代码
/**
* transaction
* @param {org.adverce.Clicks_Add} Clicks_Add
* @transaction
* This transaction is used to add new users to an already created Advertiser.
*/
function Clicks_Add(newClick) {
var factory = getFactory();
var NS='org.adverce';
var clicks = factory.newResource(NS,'Clicks',newClick.clicks.id);
clicks.ipAddress = newClick.clicks.ipAddress;
clicks.publisherId = newClick.clicks.publisherId;
clicks.advertiserId = newClick.clicks.advertiserId;
clicks.CreatedAt = newClick.clicks.CreatedAt;
return getAssetRegistry('org.adverce.Clicks')
.then(function(newclicks){
newclicks.addAll([clicks]);
})
}
现在我写的黄瓜测试就是这个。
Feature: Want to test the Clicks transactions
Scenario: Clicks Transaction send value to Clicks Assets
Given I have deployed my network
When I submit the following transaction of type org.adverce.Clicks_Add
| id | ipAddress | publisherId | advertiserId | CreatedAt |
| 01 | 192.168.1.1 | 12 | 22 | 27/1/2017 |
Then I should have the following Assets
"""
[
{"$class":"org.adverce.Clicks", "id":"01", "ipAddress":"192.168.1.1", "publisherId":"23", "advertiserId":"22", "CreatedAt":"27,1,2017"}
]
"""
为这些测试编写的方法是
'use strict';
module.exports = function () {
this.Given('I have deployed my network', function () {
// Write code here that turns the phrase above into concrete actions
});
this.When(/^I submit the following transactions? of type ([.\w]+)\.(\w+)$/, function (namespace, name, table) {
return this.composer.submitTransactions(namespace, name, table);
});
this.Then(/^I should have the following Assets?$/, function (docString) {
return this.composer.testAssets(null, null, docString);
});
};
我也会在这里分享错误截图。