0

I'm trying to test functions of a library with Truffle. But they don't seem to be available.

The library is named Commons and I include it as I would include a contract:

var Commons = artifacts.require("./Commons.sol");

But if I do

let foo = Commons.new();
let returnValue = foo.getBalancePeriod(5);

I get:

TypeError: foo.getBalancePeriod is not a function

If I instead do

let returnValue = Commons.getBalancePeriod(5);

I just get:

TypeError: Commons.getBalancePeriod is not a function

I made sure that the function name is exactly as it was defined in the library but the function just doesn't seem to exist.

1

Try this and let us know the result:

var Commons = artifacts.require("./Commons.sol");

contract("Commons", function(accounts) {
    it('should revert the transaction of getBalancePeriod if conditions are not met', function() {
        return Commons.deployed()
        .then(function (instance) {
            return instance.getBalancePeriod(5);
        });
    });
});

| improve this answer | |
  • Thank you very much! Works like a charm. – UTF-8 Jan 27 at 16:59
  • Well, the functions need to be async because I need to await the result. But then it works like a charm. (Without it, it at least doesn't crash anymore but only returns a promise.) – UTF-8 Jan 27 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.