2022-07-16 11:36:29 +00:00
|
|
|
// SPDX-License-Identifier: UNLICENSED
|
2023-02-25 13:52:34 +00:00
|
|
|
pragma solidity >=0.8.19 <0.9.0;
|
2022-07-16 11:36:29 +00:00
|
|
|
|
|
|
|
import { PRBTest } from "@prb/test/PRBTest.sol";
|
2023-01-07 09:50:02 +00:00
|
|
|
import { console2 } from "forge-std/console2.sol";
|
2022-10-31 16:34:49 +00:00
|
|
|
import { StdCheats } from "forge-std/StdCheats.sol";
|
2022-07-16 11:36:29 +00:00
|
|
|
|
2023-05-23 18:45:52 +00:00
|
|
|
import { Foo } from "../src/Foo.sol";
|
|
|
|
|
2023-01-17 17:49:14 +00:00
|
|
|
interface IERC20 {
|
|
|
|
function balanceOf(address account) external view returns (uint256);
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:45:52 +00:00
|
|
|
/// @dev If this is your first time with Forge, read this tutorial in the Foundry Book:
|
2022-07-16 11:36:29 +00:00
|
|
|
/// https://book.getfoundry.sh/forge/writing-tests
|
2022-11-18 19:50:45 +00:00
|
|
|
contract FooTest is PRBTest, StdCheats {
|
2023-05-23 18:45:52 +00:00
|
|
|
// Instantiate the contract-under-test
|
|
|
|
Foo internal foo = new Foo();
|
|
|
|
|
2023-04-18 11:14:53 +00:00
|
|
|
/// @dev An optional function invoked before each test case is run.
|
2023-04-01 06:46:18 +00:00
|
|
|
function setUp() public virtual {
|
2022-07-16 11:36:29 +00:00
|
|
|
// solhint-disable-previous-line no-empty-blocks
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:45:52 +00:00
|
|
|
/// @dev Basic test. Run it with `forge test -vvv` to see the console log.
|
2023-01-07 09:47:59 +00:00
|
|
|
function test_Example() external {
|
2022-10-29 13:37:43 +00:00
|
|
|
console2.log("Hello World");
|
2023-05-23 18:45:52 +00:00
|
|
|
uint256 x = 42;
|
|
|
|
assertEq(foo.id(x), x, "value mismatch");
|
2022-07-16 11:36:29 +00:00
|
|
|
}
|
2023-01-07 09:47:59 +00:00
|
|
|
|
2023-05-23 18:45:52 +00:00
|
|
|
/// @dev Fuzz test that provides random values for an unsigned integer, but which rejects zero as an input.
|
|
|
|
/// If you need more sophisticated input validation, you should use the `bound` utility instead.
|
2023-04-18 11:14:53 +00:00
|
|
|
/// See https://twitter.com/PaulRBerg/status/1622558791685242880
|
2023-01-07 09:47:59 +00:00
|
|
|
function testFuzz_Example(uint256 x) external {
|
2023-04-18 11:14:53 +00:00
|
|
|
vm.assume(x != 0); // or x = bound(x, 1, 100)
|
2023-05-23 18:45:52 +00:00
|
|
|
assertEq(foo.id(x), x, "value mismatch");
|
2023-01-17 17:49:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 11:14:53 +00:00
|
|
|
/// @dev Fork test that runs against an Ethereum Mainnet fork. For this to work, you need to set `API_KEY_ALCHEMY`
|
|
|
|
/// in your environment You can get an API key for free at https://alchemy.com.
|
2023-01-17 17:49:14 +00:00
|
|
|
function testFork_Example() external {
|
2023-04-18 11:14:53 +00:00
|
|
|
// Silently pass this test if there is no API key.
|
2023-03-01 12:15:16 +00:00
|
|
|
string memory alchemyApiKey = vm.envOr("API_KEY_ALCHEMY", string(""));
|
2023-01-17 17:49:14 +00:00
|
|
|
if (bytes(alchemyApiKey).length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-17 17:58:43 +00:00
|
|
|
|
2023-04-18 11:14:53 +00:00
|
|
|
// Otherwise, run the test against the mainnet fork.
|
2023-03-17 17:41:43 +00:00
|
|
|
vm.createSelectFork({ urlOrAlias: "mainnet", blockNumber: 16_428_000 });
|
2023-01-17 17:49:14 +00:00
|
|
|
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
|
|
|
|
address holder = 0x7713974908Be4BEd47172370115e8b1219F4A5f0;
|
|
|
|
uint256 actualBalance = IERC20(usdc).balanceOf(holder);
|
|
|
|
uint256 expectedBalance = 196_307_713.810457e6;
|
|
|
|
assertEq(actualBalance, expectedBalance);
|
2023-01-07 09:47:59 +00:00
|
|
|
}
|
2022-07-16 11:36:29 +00:00
|
|
|
}
|