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.