From 145cb6f7c963e7b7e0ea362723b83db51609dc62 Mon Sep 17 00:00:00 2001 From: r4bbit <445106+0x-r4bbit@users.noreply.github.com> Date: Tue, 8 Aug 2023 13:35:14 +0200 Subject: [PATCH] chore: first template adjustments This is an initial take on adjusting the foundry-template to the Vac's smart contract unit's needs. In a nutshell what this does is: 1. Update README to not refer to upstream repo where not necessary 2. Removes PRBergTest library from dependencies 3. Removes `FUNDING.qml` 4. Adjust CI actions There are more things to be done and decided on in follow-up commits. --- .gas-snapshot | 1 + .github/FUNDING.yml | 2 -- .github/PULL_REQUEST_TEMPLATE.md | 12 +++++++++ .github/scripts/rename.sh | 8 +++--- .gitmodules | 8 ++---- README.md | 33 ++++++++++++++---------- lib/forge-std | 2 +- lib/prb-test | 1 - package.json | 8 +++--- remappings.txt | 1 - script/Deploy.s.sol | 2 -- test/Foo.t.sol | 43 +++----------------------------- 12 files changed, 46 insertions(+), 75 deletions(-) create mode 100644 .gas-snapshot delete mode 100644 .github/FUNDING.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 160000 lib/prb-test diff --git a/.gas-snapshot b/.gas-snapshot new file mode 100644 index 0000000..73b8bfc --- /dev/null +++ b/.gas-snapshot @@ -0,0 +1 @@ +FooTest:test_Example() (gas: 8662) \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index b9a2f48..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,2 +0,0 @@ -custom: "https://gitcoin.co/grants/1657/PaulRBerg-open-source-engineering" -github: "PaulRBerg" diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3fb4fd3 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +## Description + +Describe the changes made in your pull request here. + +## Checklist + +Ensure you completed **all of the steps** below before submitting your pull request: + +- [ ] Added natspec comments? +- [ ] Ran `forge snapshot`? +- [ ] Ran `yarn lint`? +- [ ] Ran `forge test`? diff --git a/.github/scripts/rename.sh b/.github/scripts/rename.sh index 62e37dd..d70129b 100755 --- a/.github/scripts/rename.sh +++ b/.github/scripts/rename.sh @@ -31,8 +31,6 @@ sedi () { sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" } -# Rename instances of "PaulRBerg/foundry-template" to the new repo name in README.md for badges only -sedi "/gitpod/ s|PaulRBerg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md" -sedi "/gitpod-badge/ s|PaulRBerg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md" -sedi "/gha/ s|PaulRBerg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md" -sedi "/gha-badge/ s|PaulRBerg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md" +# Rename instances of "vacp2p/foundry-template" to the new repo name in README.md for badges only +sedi "/gha/ s|vacp2p/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md" +sedi "/gha-badge/ s|vacp2p/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md" diff --git a/.gitmodules b/.gitmodules index 92e4318..53e2060 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,8 +1,4 @@ [submodule "lib/forge-std"] branch = "v1" - path = "lib/forge-std" - url = "https://github.com/foundry-rs/forge-std" -[submodule "lib/prb-test"] - branch = "release-v0" - path = "lib/prb-test" - url = "https://github.com/PaulRBerg/prb-test" + path = lib/forge-std + url = https://github.com/foundry-rs/forge-std diff --git a/README.md b/README.md index c998015..64d6d21 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# Foundry Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license] +# Foundry Template [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license] -[gitpod]: https://gitpod.io/#https://github.com/PaulRBerg/foundry-template -[gitpod-badge]: https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-FFB45B?logo=gitpod -[gha]: https://github.com/PaulRBerg/foundry-template/actions -[gha-badge]: https://github.com/PaulRBerg/foundry-template/actions/workflows/ci.yml/badge.svg +[gha]: https://github.com/vacp2p/foundry-template/actions +[gha-badge]: https://github.com/vacp2p/foundry-template/actions/workflows/ci.yml/badge.svg [foundry]: https://getfoundry.sh/ [foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg [license]: https://opensource.org/licenses/MIT @@ -11,18 +9,20 @@ A Foundry-based template for developing Solidity smart contracts, with sensible defaults. +This is a fork of [PaulRBerg's template](https://github.com/PaulRBerg/foundry-template) and adjusted to Vac's smart +contracts unit's needs. See [Upstream differences](#upstream-differences) to learn more about how this template differs +from Paul's. + ## What's Inside - [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart contracts - [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing -- [PRBTest](https://github.com/PaulRBerg/prb-test): modern collection of testing assertions and logging utilities -- [Prettier](https://github.com/prettier/prettier): code formatter for non-Solidity files - [Solhint Community](https://github.com/solhint-community/solhint-community): linter for Solidity code ## Getting Started -Click the [`Use this template`](https://github.com/PaulRBerg/foundry-template/generate) button at the top of the page to +Click the [`Use this template`](https://github.com/vacp2p/foundry-template/generate) button at the top of the page to create a new repository with this repo as the initial state. Or, if you prefer to install the template manually: @@ -30,7 +30,7 @@ Or, if you prefer to install the template manually: ```sh $ mkdir my-project $ cd my-project -$ forge init --template PaulRBerg/foundry-template +$ forge init --template vacp2p/foundry-template $ pnpm install # install Solhint, Prettier, and other Node.js deps ``` @@ -46,6 +46,15 @@ For example, if you're interested in exploring Foundry in more detail, you shoul [Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the [Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial. +### Upstream differences + +As mentioned above, this template is a fork with adjustments specific to the needs of Vac's smart contract service unit. +These differences are: + +- Removal of [PRBTest](https://github.com/PaulRBerg/prb-test) In an attempt to keep dependence on third-party code low, + we've decided to remove this library as a standard dependency of every project within Vac. If we do see a need for it, + we might bring it back in the future. + ### Sensible Defaults This template comes with a set of sensible default configurations for you to use. These defaults can be found in the @@ -78,10 +87,8 @@ You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci. ## Writing Tests -To write a new test contract, you start by importing [PRBTest](https://github.com/PaulRBerg/prb-test) and inherit from -it in your test contract. PRBTest comes with a pre-instantiated [cheatcodes](https://book.getfoundry.sh/cheatcodes/) -environment accessible via the `vm` property. If you would like to view the logs in the terminal output you can add the -`-vvv` flag and use [console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog). +If you would like to view the logs in the terminal output you can add the `-vvv` flag and use +[console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog). This template comes with an example test contract [Foo.t.sol](./test/Foo.t.sol) diff --git a/lib/forge-std b/lib/forge-std index e8a047e..74cfb77 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit e8a047e3f40f13fa37af6fe14e6e06283d9a060e +Subproject commit 74cfb77e308dd188d2f58864aaf44963ae6b88b1 diff --git a/lib/prb-test b/lib/prb-test deleted file mode 160000 index 1e9ead2..0000000 --- a/lib/prb-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1e9ead2f7bfaedda3038081c16484b0d7d0b2712 diff --git a/package.json b/package.json index 80a6006..3bbf1f3 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "@prb/foundry-template", - "description": "Foundry-based template for developing Solidity smart contracts", + "name": "@vacp2p/foundry-template", + "description": "Foundry-based template for developing Solidity smart contracts used by Vac", "version": "1.0.0", "author": { - "name": "Paul Razvan Berg", - "url": "https://github.com/PaulRBerg" + "name": "0x-r4bbit", + "url": "https://github.com/vacp2p" }, "devDependencies": { "prettier": "^3.0.0", diff --git a/remappings.txt b/remappings.txt index 853e434..feaba2d 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,2 +1 @@ -@prb/test/=lib/prb-test/src/ forge-std/=lib/forge-std/src/ diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index d01bb45..b6e65ef 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -2,10 +2,8 @@ pragma solidity >=0.8.19 <=0.9.0; import { Foo } from "../src/Foo.sol"; - import { BaseScript } from "./Base.s.sol"; -/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting contract Deploy is BaseScript { function run() public broadcast returns (Foo foo) { foo = new Foo(); diff --git a/test/Foo.t.sol b/test/Foo.t.sol index 736b7d8..5b2bb0f 100644 --- a/test/Foo.t.sol +++ b/test/Foo.t.sol @@ -1,57 +1,20 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.19 <0.9.0; -import { PRBTest } from "@prb/test/PRBTest.sol"; -import { console2 } from "forge-std/console2.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; +import { Test, console } from "forge-std/Test.sol"; import { Foo } from "../src/Foo.sol"; -interface IERC20 { - function balanceOf(address account) external view returns (uint256); -} - -/// @dev If this is your first time with Forge, read this tutorial in the Foundry Book: -/// https://book.getfoundry.sh/forge/writing-tests -contract FooTest is PRBTest, StdCheats { +contract FooTest is Test { Foo internal foo; - /// @dev A function invoked before each test case is run. function setUp() public virtual { - // Instantiate the contract-under-test. foo = new Foo(); } - /// @dev Basic test. Run it with `forge test -vvv` to see the console log. function test_Example() external { - console2.log("Hello World"); + console.log("Hello World"); uint256 x = 42; assertEq(foo.id(x), x, "value mismatch"); } - - /// @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. - /// See https://twitter.com/PaulRBerg/status/1622558791685242880 - function testFuzz_Example(uint256 x) external { - vm.assume(x != 0); // or x = bound(x, 1, 100) - assertEq(foo.id(x), x, "value mismatch"); - } - - /// @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. - function testFork_Example() external { - // Silently pass this test if there is no API key. - string memory alchemyApiKey = vm.envOr("API_KEY_ALCHEMY", string("")); - if (bytes(alchemyApiKey).length == 0) { - return; - } - - // Otherwise, run the test against the mainnet fork. - 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); - } }