├── .gas-snapshot ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── foundry.toml ├── src └── Contract.sol └── test └── Contract.t.sol /.gas-snapshot: -------------------------------------------------------------------------------- 1 | TestContract:testBar() (gas: 401) 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | 8 | env: 9 | FOUNDRY_PROFILE: ci 10 | 11 | jobs: 12 | run-ci: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Install Foundry 18 | uses: foundry-rs/foundry-toolchain@v1 19 | with: 20 | version: nightly 21 | 22 | - name: Install deps 23 | run: forge install 24 | 25 | - name: Check gas snapshots 26 | run: forge snapshot --check 27 | 28 | - name: Run tests 29 | run: forge test 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cache/ 2 | out/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/forge-std"] 2 | path = lib/forge-std 3 | url = https://github.com/foundry-rs/forge-std 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #

Forge Template

2 | 3 | **Template repository for getting started quickly with Foundry projects** 4 | 5 | ![Github Actions](https://github.com/foundry-rs/forge-template/workflows/CI/badge.svg) 6 | 7 | ## Getting Started 8 | 9 | Click "Use this template" on [GitHub](https://github.com/foundry-rs/forge-template) to create a new repository with this repo as the initial state. 10 | 11 | Or, if your repo already exists, run: 12 | ```sh 13 | forge init 14 | forge build 15 | forge test 16 | ``` 17 | 18 | ## Writing your first test 19 | 20 | All you need is to `import forge-std/Test.sol` and then inherit it from your test contract. Forge-std's Test contract comes with a pre-instatiated [cheatcodes environment](https://book.getfoundry.sh/cheatcodes/), the `vm`. It also has support for [ds-test](https://book.getfoundry.sh/reference/ds-test.html)-style logs and assertions. Finally, it supports Hardhat's [console.log](https://github.com/brockelmore/forge-std/blob/master/src/console.sol). The logging functionalities require `-vvvv`. 21 | 22 | ```solidity 23 | pragma solidity 0.8.10; 24 | 25 | import "forge-std/Test.sol"; 26 | 27 | contract ContractTest is Test { 28 | function testExample() public { 29 | vm.roll(100); 30 | console.log(1); 31 | emit log("hi"); 32 | assertTrue(true); 33 | } 34 | } 35 | ``` 36 | 37 | ## Development 38 | 39 | This project uses [Foundry](https://getfoundry.sh). See the [book](https://book.getfoundry.sh/getting-started/installation.html) for instructions on how to install and use Foundry. 40 | -------------------------------------------------------------------------------- /foundry.toml: -------------------------------------------------------------------------------- 1 | [profile.ci.fuzz] 2 | runs = 10_000 3 | -------------------------------------------------------------------------------- /src/Contract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity ^0.8.13; 3 | 4 | contract Contract { } 5 | -------------------------------------------------------------------------------- /test/Contract.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity ^0.8.13; 3 | 4 | import "forge-std/Test.sol"; 5 | 6 | import "src/Contract.sol"; 7 | 8 | contract TestContract is Test { 9 | Contract c; 10 | 11 | function setUp() public { 12 | c = new Contract(); 13 | } 14 | 15 | function testBar() public { 16 | assertEq(uint256(1), uint256(1), "ok"); 17 | } 18 | 19 | function testFoo(uint256 x) public { 20 | vm.assume(x < type(uint128).max); 21 | assertEq(x + x, x * 2); 22 | } 23 | } 24 | --------------------------------------------------------------------------------