test: add Ethereum Mainnet fork test
feat: add "ALCHEMY_API_KEY" env var feat: add "ethereum" ci: delete now-stale "version" param in foundry-toolchain refactor: delete "ETH_RPC_URL" env var test: delete console log in "testFuzz_Example" test: use "assertGt" instead of "assertTrue" for "x > 0" comparison
This commit is contained in:
parent
b9342870e7
commit
0efda5eabb
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue