Created a simple HelloEthereum.sol contract:

pragma solidity ^0.4.17;

contract HelloEth {

    string message;

    function HelloEth() public{
         message = "Hello Ethereum!";

    function getmessage() public returns (string) {
        return message;

Wanted to test it so I made a test.sol file in the same directory as the HelloEth.sol. The test file is:

pragma solidity ^0.4.17;

import "truffle/Assert.sol";

import "truffle/DeployedAddresses.sol";

contract TestHelloEth {

    function testGetMessage() public{
        HelloEth obj = new HelloEth();
        string expected = "Hello Ethereum!";
        Assert.equal(obj.getmessage(),expected,"str is right");

ON COMPILING by typing truffle test test_hello_eth.sol I get the error: Identifier Undeclared or Not Unique (reported on the line HelloEth obj = new HelloEth();)

Any help will be appreciated. THANKS!

  • I'm unfamiliar with truffle, so perhaps it does some magic I don't understand, but don't you need to import your HelloEth contract? – user19510 Jan 10 '18 at 21:41

You need to import HelloEth where you import another contracts. You are creating an instance here, but Solidity doesn't know what that HelloEth means until you import the contract.

Also, in the future, try use Mocha.js so you don't have to spend gas and it will be faster. You will use the same truffle and code in asynchronous way.

| improve this answer | |

Test.sol needs the contract name to be test not TestHelloEth. You need to import "./HelloEth.sol" so you can create that object. Your second file doesn't have the source code for HelloEth without import

| improve this answer | |
  • faced a another problem of "member equal is not available in type(library assert) outside of storage". Is the best fix to replace string with bytes32? – Rahul Kothari Jan 11 '18 at 9:00
  • yes, i rarely use string as bytes32 is a fixed size type – Karan Kurbur Jan 11 '18 at 19:04

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.