I am making upgradeable erc20 smart contract using chugsplash as upgrader and foundry as framework. It's name is FractionToken.sol and has it test contract FractionToken.t.sol.
It went well(The contract deployed successfully and the test ran successfully) before I implement the chugsplash to the contract.
FYI: I am new both to smart contract and using chugsplash
when implementing the chugsplash to FractionToken.sol and did some corrections to how the contract(FractionToken.sol) constructor defined, eventually It's deployed using chugsplash successfully in localhost using anvil.
But, the problem now is in Testing, on of the problem is, functions that were defined in FractionToken.sol that has onlyOwner modifier, now reverts with error ([FAIL. Reason: Ownable: caller is not the owner]). So I tried to debug, in FractionToken.t.sol,
in FrractionToken.t.sol:
contract FractionTokenTest is Test {
FractionToken fractionToken;
function setUp() public virtual {
// Create a ChugSplash instance
ChugSplash chugsplash = new ChugSplash();
// Define the path from the project root to your ChugSplash file.
string memory chugsplashFilePath = "./chugsplash/hello-chugsplash.json";
// Deploy all contracts in your ChugSplash file
chugsplash.deploy(chugsplashFilePath, true);
// You *must* refresh EVM state after calling `chugsplash.deploy`.
chugsplash.refresh();
fractionToken = FractionToken(
payable(
chugsplash.getAddress(chugsplashFilePath, "<MY SC REFERENCE NAME>")
)
);
}
}
And on of the tests, I consolelog:
console2.logAddress(address(fractionToken));
// returns 0x7Fdfb1eF01b5B4bC59F5D7FF2530f2dC4E1889E6
console2.logAddress(fractionToken.getOwner());
//returns 0x0000000000000000000000007fdfb1ef01b5b4bc59f5d7ff2530f2dc4e1889e6
Why they return basically the same address only that the other has "0x000000000000000000000000" as prefix and this made the test reverted with error as mentioned above.