diff --git a/.gas-snapshot b/.gas-snapshot new file mode 100644 index 0000000..7b7b9ec --- /dev/null +++ b/.gas-snapshot @@ -0,0 +1 @@ +TestContract:testBar() (gas: 401) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fbe7307 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI +on: + push: + branches: + - master + pull_request: + +env: + FOUNDRY_PROFILE: ci + +jobs: + run-ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Install deps + run: forge install + + - name: Check gas snapshots + run: forge snapshot --check + + - name: Run tests + run: forge test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8a1d07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cache/ +out/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7fea7ee --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/forge-std"] + path = lib/forge-std + url = git@github.com:foundry-rs/forge-std.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..efac030 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +#

Forge Template

+ +**Template repository for getting started quickly with Foundry projects** + +![Github Actions](https://github.com/foundry-rs/forge-template/workflows/CI/badge.svg) + +## Getting Started + +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. + +Or, if your repo already exists, run: +```sh +forge init +forge build +forge test +``` + +## Writing your first test + +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`. + +```solidity +pragma solidity 0.8.10; + +import "forge-std/Test.sol"; + +contract ContractTest is Test { + function testExample() public { + vm.roll(100); + console.log(1); + emit log("hi"); + assertTrue(true); + } +} +``` + +## Development + +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. diff --git a/foundry.toml b/foundry.toml new file mode 100644 index 0000000..93d2364 --- /dev/null +++ b/foundry.toml @@ -0,0 +1,2 @@ +[profile.ci.fuzz] +runs = 10_000 diff --git a/lib/forge-std b/lib/forge-std new file mode 160000 index 0000000..f73c73d --- /dev/null +++ b/lib/forge-std @@ -0,0 +1 @@ +Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 diff --git a/src/Contract.sol b/src/Contract.sol new file mode 100644 index 0000000..45cf848 --- /dev/null +++ b/src/Contract.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.13; + +contract Contract { } diff --git a/test/Contract.t.sol b/test/Contract.t.sol new file mode 100644 index 0000000..d7d6076 --- /dev/null +++ b/test/Contract.t.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; + +import "src/Contract.sol"; + +contract TestContract is Test { + Contract c; + + function setUp() public { + c = new Contract(); + } + + 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); + } +}