1

Trying to test my Solidity contract for errors using Truffle test.

TestSafeMath.sol

  function test_add_10_and_max_should_return_err() {
    uint256 max = 2**256 - 1;
    Assert.error(SafeMathExt.add(10, max), "Addition of 10 and max should return error?");
  }

Assert.sol

function error(uint16 errorCode, string message) constant returns (bool result) {
    result = (errorCode != 0);
    if (result)
        _report(result, message);
    else
        _report(result, _appendTagged(_tag(uint(errorCode), "Tested"), message));
}

Error Message:

TestSafeMathExt.sol:24:5: TypeError: Member "error" not found or not visible after argument-dependent lookup in type(library Assert)
Assert.error(SafeMathExt.sub(0, 10), "Subscraction of 0 and 10 should return error?");
^----------^

Note: Other tests are working as expected

2
  • Side note: What's the point in returning something already known to you? (i.e. output errorCode != 0, when errorCode is the input). Commented May 24, 2018 at 6:26
  • Just to have a way for automated testing that the error actually occurs. At the same time I preferably would like to know the exact error that is thrown. I wanna make sure I am catching the overflow.
    – Senju
    Commented May 24, 2018 at 13:25

1 Answer 1

1

In my experience, the error:

TypeError: Member "error" not found or not visible after argument-dependent lookup in type(library Assert)

is saying that its looking through the Assert library and there's not a function named "equal" with a type signature matching what you're trying to pass.

In this case it looks like the Assert.equal function you're trying to use is expecting a uint16 and string to be passed to the function. I'd suspect that SafeMathExt.add(10, max) in your example isn't returning uint16.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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