7

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

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".

1

I faced a similar issue. My codes can be found here Identifier not found or Not Unique testing contract truffle

I am not sure if this is the best way to fix it, but I replaced "string" with bytes32 everywhere. Apparently it's a solidity issue.

1

You can give assert a hint about the type to use:

Assert.equal(uint(1), uint(1), "Uh oh");

This works fine with uint. I had trouble with uint8, and others had trouble with bytes. See this post for more details.

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.