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


  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?");


function error(uint16 errorCode, string message) constant returns (bool result) {
    result = (errorCode != 0);
    if (result)
        _report(result, message);
        _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

  • Side note: What's the point in returning something already known to you? (i.e. output errorCode != 0, when errorCode is the input). – goodvibration May 24 '18 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 May 24 '18 at 13:25

Your Answer

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

Browse other questions tagged or ask your own question.