0

I'm testing using foundry. Isn't it correct syntax for balanceOf ? I don'k know why but it keeps revert.

assertEq(IERC20(address(ico)).balanceOf(address(attacker)), 10 * ONE_TOKEN);

2 Answers 2

2

use the following code

console.log(IERC20(address(ico)).balanceOf(address(attacker)));
assertEq(IERC20(address(ico)).balanceOf(address(attacker)), 10 * ONE_TOKEN);

This will print out the current balance of the attacker address in the console, which can help you determine if the issue is with the balanceOf function call or the assertion itself.

1

One thing that tripped me up is that not all forge commands use the ETH_RPC_URL environment variable. Make sure the --rpc-url argument is set when you run your command, otherwise onchain calls will revert.

E.g. forge create and cast send use the environment variable, while forge test and forge script do not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.