I have a contract called AccessControl, in which the owner of the contract is set when it is deployed.
I want to test that the method on it setCEO
updates correctly, but in order to do this the request must come from the owner of the contract.
contract AccessControl {
address public ceoAddress;
modifier onlyCEO() {
require(msg.sender == ceoAddress);
_;
}
function setCEO(address _newCEO) external onlyCEO {
require(_newCEO != address(0));
ceoAddress = _newCEO;
}
}
When I console.log in the tests the current ceoAddress like so:
const paymentPipe = await PaymentPipe.deployed();
console.log(await paymentPipe.ceoAddress());
I see that the address is 0x0000000000000000000000000000000000000000.
When I try to call setCEO in my tests from that account like so:
await paymentPipe.setCEO(bob, {from: contractAddress});
Truffle complains:
Error: sender account not recognized
If I try with any other account in the truffle test suite (i.e. accounts[x]) I get:
Error: VM Exception while processing transaction: revert
Implying that the method did not pass the require statement because the calling address was not the one set as CEO.
What address are contracts deployed from in the truffle test suite? And why, if I can see an address in my contract as 0x0000000000000000000000000000000000000000 can I not use this address to call functions?
ceoAddress
asmsg.sender
?