foundry-template/test/Foo.t.sol

50 lines
1.9 KiB
Solidity
Raw Normal View History

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
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
}
2022-07-16 11:36:29 +00:00
/// @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 {
/// @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
}
/// @dev Simple test. Run Forge with `-vvvv` to see console logs.
function test_Example() external {
console2.log("Hello World");
2022-07-16 11:36:29 +00:00
assertTrue(true);
}
/// @dev Test that fuzzes an unsigned integer.
function testFuzz_Example(uint256 x) external {
vm.assume(x != 0);
assertGt(x, 0);
}
/// @dev Test that runs against a fork of Ethereum Mainnet. You need to set `API_KEY_ALCHEMY` 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("API_KEY_ALCHEMY", string(""));
// Silently pass this test if the user didn't define the API key.
if (bytes(alchemyApiKey).length == 0) {
return;
}
// Run the test normally, otherwise.
2023-03-17 17:41:43 +00:00
vm.createSelectFork({ urlOrAlias: "mainnet", 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);
}
2022-07-16 11:36:29 +00:00
}