I have a contract where some functions can be called only by the owner of the contract and I want to test it with a solidity test in truffle. The contract looks like this:
contract owned {
address public owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
owner = newOwner;
}
}
contract MyContract is owned{
function doSomething() onlyOwner public {
// do something ..
}
}
I have setup truffle to connect to a Ganache blockchain that has only one address A. I have also verified that the address saved in owner matches the only address A. The problem is that when I try to test any of the functions that can be run only by an owner my test fails and I get the error Error: Returned error: VM Exception while processing transaction: revert
. In my test I call the functions like this myContract.doSomething(params..);
. Why does the transaction fail even if I have only one address in my blockchain? How can I solve this?