0

I am using cucumber to run some unit tests on hyperledger composer.I am constantly getting this TypeError: Cannot read property 'getClassDeclaration' of null

ASSET CODE IS

asset Clicks identified by id {
  o String id
  o String ipAddress
  o String publisherId
  o String advertiserId
  o String CreatedAt
}

TRANSACTION CODE IS

transaction Clicks_Add 
{
  o Clicks clicks
}

CODE FOR THE TRANSACTION IN .JS FILE

/**
 * 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]);
    })
}

NOW THE CUCUMBER TEST THAT I WROTE IS THIS.

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"}
        ]
        """

THE METHODS WRITTEN FOR THESE TESTS ARE

'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);
        }); 

};

I will share the error screenshot here as well.

Error output in terminal after running the test

deenario
  • 11
  • 4

1 Answers1

0

I think the main reason its failing is because you've not defined how to deploy the network correctly - as you know, Composer sets this for you anyway, if you take a look at the Composer sample networks example (eg basic-sample-network) https://github.com/hyperledger/composer-sample-networks/blob/master/packages/basic-sample-network/features/support/index.js

For reference the sample Cucumber test (incl add asset) in 'basic-sample-network' is here -> https://github.com/hyperledger/composer/blob/master/packages/composer-cucumber-steps/test/composer.js#L73 and

finally examples of submit transactions (another sample network) is here -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/fund-clearing-network/features/1.SubmitTransferRequests.feature

Paul O'Mahony
  • 6,740
  • 1
  • 10
  • 15