0

我正在使用 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);
        }); 

};

我也会在这里分享错误截图。

运行测试后终端输出错误

4

1 回答 1

0

我认为它失败的主要原因是因为您没有定义如何正确部署网络 - 如您所知,Composer 无论如何都会为您设置这个,如果您查看 Composer 示例网络示例(例如 basic-sample-network ) https://github.com/hyperledger/composer-sample-networks/blob/master/packages/basic-sample-network/features/support/index.js

作为参考,'basic-sample-network'中的示例黄瓜测试(包括添加资产)在这里-> https://github.com/hyperledger/composer/blob/master/packages/composer-cucumber-steps/test/composer .js#L73

最后提交交易的示例(另一个示例网络)在这里-> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/fund-clearing-network/features/1.SubmitTransferRequests.feature

于 2018-08-13T15:18:13.437 回答