0

I have two contracts: ElephanteumStorage and ElephanteumCore. Storage just keeps some data. Core is provided to change the data in the Storage.
As a constructor argument, ElephanteumCore receives Storage address so Core can call Storage's functions. Also, I have setted Core as an owner of the Storage.
I wrote init function in Core that must save data in storage and I tested this functionality in Remix IDE with Rinkeby and JS VM and everything was just fine. But in Truffle test I got revert error message.

contract ElephanteumCore is Ownable {

        ElephanteumStorage public eStorage;

        function ElephanteumCore(address _eStorage) public payable {
            eStorage = ElephanteumStorage(_eStorage);     
        }

        function init(bytes32 _name, bytes32 _symbol, uint _supply) public onlyOwner {
            eStorage.setTotalSupply(_supply);
            eStorage.setElephantsRemainingToAssign(_supply);
            eStorage.setName(_name);
            eStorage.setSymbol(_symbol);
        }
}




contract ElephanteumStorage is Ownable {

        bytes32 public name;
        bytes32 public symbol;

        uint public totalSupply;

        uint public elephantsRemainingToAssign;

        function setName(bytes32 _name) onlyOwner external {
            name = _name;
        }

        function setSymbol(bytes32 _symbol) onlyOwner external {
            symbol = _symbol;
        }

        function setTotalSupply(uint _totalSupply) onlyOwner external {
            totalSupply = _totalSupply;
        }

        function setElephantsRemainingToAssign(uint _elephantsRemainingToAssign) onlyOwner external {
            elephantsRemainingToAssign = _elephantsRemainingToAssign;
        } 
}

And there is my truffle test:

const elephanteumCore = artifacts.require('ElephanteumCore');
const elephanteumStorage = artifacts.require('ElephanteumStorage');


contract('ElephanteumCore', accounts => {
  let eCore, eStorage;

  before(async () => {
    eStorage = await elephanteumStorage.new();
    eCore = await elephanteumCore.new(eStorage.address);
    await eStorage.transferOwnership(eCore.address);
  })

  it('Should initialize the contract correcty', async () => {
    let name = "Elephanteum";
    let symbol = "EPH";
    let supply = 100;

    await eCore.init(name, symbol, supply);

    let rName =  await eStorage.name.call();
    let rSymbol = await eStorage.symbol.call();
    let rSupply = await eStorage.totalSupply.call();

    assert.equal(name, web3.toUtf8(rName), "name should have be initialize correctly");
    assert.equal(symbol, web3.toUtf8(rSymbol), "symbol should have be initialize correctly");
    assert.equal(supply, rSupply.toNumber(), "supply should have be initialize correctly");

  })

I tried to run test both in testrpc and rinkeby, everywhere it raise exception on line

await eCore.init(name, symbol, supply);

And I don't know why.

2 Answers 2

1

You use the function setElephantsRemainingToAssign in the init function, but I'm not seeing that function on the ElephanteumStorage contract.

1
  • I have removed some functions and variables to simplify the example. Now the example is true. As I said, I have tested the functionality in Remix. I suppose, the problem is in truffle test. Dec 30, 2017 at 9:17
-1

I have deleted "build" dir and now it works. The problem was the Truffle doesn't recompile contracts before running test by default.

Your Answer

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

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