I am creating a ERC20 token solidity contract and when writing tests I encountered a problem.
Here is a function I use to test the token cap with.
function testTokenCap() public {
uint256 mintValueCap = mintValue + token.cap();
vm.expectRevert();
vm.prank(OWNER);
token.mint(USER, mintValueCap);
}
This function works fine but the weird thing is that if write the function like this:
function testTokenCap() public {
vm.expectRevert();
vm.prank(OWNER);
token.mint(USER, mintValue + token.cap());
}
Then vm.prank(OWNER)
sends the test contract's address and not the owner's one which causes my function to revert because I have an onlyOwner
modifier:
modifier onlyOwner {
require(msg.sender == i_owner, "Only owner can use this function");
_;
}
I am guessing that vm.prank(OWNER)
executes mintValue + token.cap()
as the msg.sender
to do the calculation and the test contract is left to execute token.mint()
contract so it passes it's address. I am just starting with solidity and blockchain technology and I would like to know if I am thinking correctly.