I'm used to Java mocks, where I could access and modify private values. As we are on our local machine and own ethereum node, we may do the same.
My problem is I want to modify a required address. Only my Oracle is authorized to call a function, and I would like my test to do it so.
contract CodeFanSites {
address private constant _Oracle = 0xf17f52151EbEF6C7334FAD080c5704D77216b732;
function addSite(address payable user, string memory domain) external {
require(msg.sender == _Oracle);
// ....
}
}
And my tests, using truffle :
contract("CodeFanSites", (accounts) => {
let [nik, oracle] = accounts;
it("should be able to add a new domain site", async () => {
const contract = await CodeFanSites.new();
console.log({balance: sites, accounts, nik});
// I need before here to modify the _Oracle private address in the contract
const result = await contract.addSite(oracle, "site.com");
// ....
})
How can I change the _Oracle
private address in the contract before calling the addSite()
function in the test ?
Note that _Oracle
don't have to be constant, it may just be private. I don't want anybody to be able to change this value, except while testing.