Ref - https://book.getfoundry.sh/reference/forge-std/console-log?highlight=console#console-logging
To log statements, you can use Console from the forge std library
import {console} from "forge-std/Test.sol";
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
console.log(currentAllowance);
console.log(owner);
console.log(spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
It has functions like
console.logInt(int i)
console.logUint(uint i)
console.logString(string memory s)
console.logBool(bool b)
console.logAddress(address a)
hoax
is a combination of pranking followd by deal
vm.hoax(address, value);
address
: The address from which the transaction will be sent (it overrides the default sender for the transaction).value
: The amount of ETH to set on that address<aside> 💡
The effect of vm.hoax
only applies to the current (upcoming) transaction and does not carry over to subsequent transactions. After the transaction completes, the context reverts to the original msg.sender
.
</aside>
deal
is used to set a specific balance for an address in your test environment. It is useful for testing scenarios where you need to ensure that a particular address has a certain amount of ETH or tokens, or when simulating an account having specific balances before interacting with contracts.
function test_DealExample() public {
address account = address(0x123);
uint256 balance = 10 ether;
// Set the balance of `account` to `10 ether`
vm.deal(account, balance);
// Assert that the balance is set correctly
assertEq(address(account).balance, balance);
}
prank
vs startPrank
vs stopPrank
vm.prank(address)
is a shorthand function that allows you to impersonate an address for just one transaction.
vm.startPrank(address)
will start it for all upcoming txns
vm.stopPrank()
will stop the prank for all following txns