mirror of
https://github.com/vacp2p/foundry-template.git
synced 2026-01-06 22:03:57 -05:00
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.
This commit is contained in:
1
.gas-snapshot
Normal file
1
.gas-snapshot
Normal file
@@ -0,0 +1 @@
|
||||
FooTest:test_Example() (gas: 8662)
|
||||
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +0,0 @@
|
||||
custom: "https://gitcoin.co/grants/1657/PaulRBerg-open-source-engineering"
|
||||
github: "PaulRBerg"
|
||||
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -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`?
|
||||
8
.github/scripts/rename.sh
vendored
8
.github/scripts/rename.sh
vendored
@@ -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"
|
||||
|
||||
8
.gitmodules
vendored
8
.gitmodules
vendored
@@ -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
|
||||
|
||||
33
README.md
33
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)
|
||||
|
||||
|
||||
2
lib/forge-std
vendored
2
lib/forge-std
vendored
Submodule lib/forge-std updated: e8a047e3f4...74cfb77e30
1
lib/prb-test
vendored
1
lib/prb-test
vendored
Submodule lib/prb-test deleted from 1e9ead2f7b
@@ -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",
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
@prb/test/=lib/prb-test/src/
|
||||
forge-std/=lib/forge-std/src/
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user