Template repository for getting started quickly with Foundry projects
- Base forge-template from Foundry team
Utilities.sol
from FrankieIsLost forge-template
- Added FrankieIsLost
Utilities.sol
- Extended FrankieIsLost
Utilities.sol
to create tests users and setup them viaUtilities.createUsers
- Auto labeling created test users
- Created
BaseTest.sol
contract - preconfigured
solhint
andprettier
Click "Use this template" on GitHub to create a new repository with this repo as the initial state.
Or, if your repo already exists, run:
forge init
forge build
forge test
All you need is to import "./utils/BaseTest.sol";
that will inherit from and then inherit it from your test contract. Forge-std's Test contract comes with a pre-instatiated cheatcodes environment, the vm
. It also has support for ds-test-style logs and assertions. Finally, it supports Hardhat's console.log. The logging functionalities require -vvvv
.
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
import './utils/BaseTest.sol';
contract TestContract is BaseTest {
constructor() {
// Created (during `setUp()`) users will be available in `users` state variable
// Setup test to create 2 test user with 100 ether in balance each
// preSetUp(2);
// Setup test to create 2 test user with 1 ether in balance each
// preSetUp(2, 1 ether);
// Setup test to create 2 test user with 1 ether in balance each and label them accordingly
string[] memory userLabels = new string[](2);
userLabels[0] = 'Alice';
userLabels[1] = 'Bob';
preSetUp(2, 100 ether, userLabels);
}
function setUp() public override {
// Call the BaseTest setUp() function that will also create testsing accounts
super.setUp();
}
function testSetUp() public {
assertEq(users.length, 2);
assertEq(users[0].balance, 100 ether);
}
function testBar() public {
assertEq(uint256(1), uint256(1), 'ok');
}
function testFoo(uint256 x) public {
vm.assume(x < type(uint128).max);
assertEq(x + x, x * 2);
}
}
This project uses Foundry. See the book for instructions on how to install and use Foundry.