diff --git a/.env.example b/.env.example index 729b6a3..c0646ee 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -ETH_RPC_URL="https://goerli.infura.io/v3/INFURA_API_KEY" +ALCHEMY_API_KEY="YOUR_ALCHEMY_API_KEY" ETHERSCAN_API_KEY="YOUR_ETHERSCAN_API_KEY" INFURA_API_KEY="YOUR_INFURA_API_KEY" MNEMONIC="YOUR_MNEMONIC" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca1a80f..45a9a2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,6 @@ jobs: - name: "Install Foundry" uses: "foundry-rs/foundry-toolchain@v1" - with: - version: "nightly" - name: "Install Node.js" uses: "actions/setup-node@v3" diff --git a/foundry.toml b/foundry.toml index c0d8d6e..2b3a93a 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,6 +1,7 @@ # Full reference https://github.com/foundry-rs/foundry/tree/master/config [etherscan] +ethereum = { key = "${ETHERSCAN_API_KEY}" } goerli = { key = "${ETHERSCAN_API_KEY}" } [fmt] @@ -31,5 +32,6 @@ fuzz = { runs = 10_000 } verbosity = 4 [rpc_endpoints] +ethereum="https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" localhost="http://localhost:8545" goerli="https://goerli.infura.io/v3/${INFURA_API_KEY}" diff --git a/test/Foo.t.sol b/test/Foo.t.sol index 127a576..75acaf2 100644 --- a/test/Foo.t.sol +++ b/test/Foo.t.sol @@ -5,6 +5,10 @@ import { PRBTest } from "@prb/test/PRBTest.sol"; import { console2 } from "forge-std/console2.sol"; import { StdCheats } from "forge-std/StdCheats.sol"; +interface IERC20 { + function balanceOf(address account) external view returns (uint256); +} + /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests contract FooTest is PRBTest, StdCheats { @@ -19,10 +23,24 @@ contract FooTest is PRBTest, StdCheats { assertTrue(true); } - /// @dev Test that fuzzes an unsigned integer. Run Forge with `-vvvv` to see console logs. + /// @dev Test that fuzzes an unsigned integer. function testFuzz_Example(uint256 x) external { vm.assume(x != 0); - console2.log("x", x); - assertTrue(x > 0); + assertGt(x, 0); + } + + /// @dev Test that runs against a fork of Ethereum Mainnet. You need to set `ALCHEMY_API_KEY` in your environment + /// for this test to run - you can get an API key for free at https://alchemy.com. + function testFork_Example() external { + string memory alchemyApiKey = vm.envOr("ALCHEMY_API_KEY", string("")); + if (bytes(alchemyApiKey).length == 0) { + return; + } + vm.createSelectFork({urlOrAlias: "ethereum", blockNumber: 16_428_000}); + address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; + address holder = 0x7713974908Be4BEd47172370115e8b1219F4A5f0; + uint256 actualBalance = IERC20(usdc).balanceOf(holder); + uint256 expectedBalance = 196_307_713.810457e6; + assertEq(actualBalance, expectedBalance); } }