Truffle – Compile Error with Trivial Assertion in Test

soliditytestingtruffle

Before I did anything serious I just wanted to check the toolchain is working. I wrote a test like this:

pragma solidity ^0.4.2;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/MyContract.sol";

contract TestMyContract {
  function testOneEqualsOne() {
    Assert.equal(1, 1, "The world as we know it has ended!");
  }
}

But it produces an error:

TestMyContract.sol:10:5: : Member "equal" not unique after argument-dependent lookup in type(library Assert)
    Assert.equal(1, 1, "The world as we know it has ended!");
    ^----------^

What's going on?

The sample test, which are created via truffle init all work perfectly:

uint expected = 10000;
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");

And even with the arguments reversed:

Assert.equal(expected, meta.getBalance(tx.origin), "Owner should have 10000 MetaCoin initially");

Best Answer

I ran into the same problem.

This is obviously a typing problem.

uint256 i = 1;
Assert.equal(i, 1, "The world as we know it has ended!");

is working.

So, when one argument is uint256 (which it is not when using the "1" literal), the correct function signature can be found and the test is run. Remember, Solidity is kind of a "type hinted JS".

Related Topic