forge init
├── lib
│ └── forge-std
...
├── script
│ └── Counter.s.sol
├── src
│ └── Counter.sol
└── test
│ └── Counter.t.sol
├── foundry.toml
├── README.md
forge test
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
contract ForkTest is Test {
function setUp() public {
vm.createFork(MAINNET_RPC_URL);
}
function test_PrintBalanceCETH {
address cETH = 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5;
uint256 balanceOnCETH = cETH.balance;
console.log("Balance on cETH: ", balanceOnCETH);
}
vm.createFork("MAINNET_RPC_URL")
MAINNET_RPC_URL=https://eth.llamarpc.com
function test_PrintBalanceCETH {
address cETH = 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5;
uint256 balanceOnCETH = cETH.balance;
console.log("Balance on cETH: ", balanceOnCETH);
}
forge test
forge test -vv
forge test --contracts src/test/NAME_OF_THE_FILE.t.sol -vv
forge test --match-path src/test/NAME_OF_THE_FILE.t.sol -vv
function setUp() public {
cheats.createSelectFork("mainnet", 16_574_048);
vm.label(address(DAI), "DAI");
vm.label(address(swapGuard), "SwapGuard");
vm.label(address(GPv2Settlement), "GPv2Settlement");
}
vm.createSelectFork()
and
vm.createFork()
vm.label(address(DAI), "DAI");
...
cheats.startPrank(HundredFinanceExploiter);
hWBTC.transfer(address(this), 1_503_167_295);
cheats.stopPrank();
...