Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example foundry package #1287

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Example foundry package #1287

wants to merge 25 commits into from

Conversation

wojciech-turek
Copy link
Member

Description

This PR introduces base Foundry package setup.
Documentation for Foundry: https://book.getfoundry.sh/

Setup

Navigate to the example-foundry package directory and run following commands:

Download foundry on your machine:

curl -L https://foundry.paradigm.xyz | bash

Setup foundry:

foundryup

You should now be able to successfully run:

forge --version

Testing

Build contracts:

forge build

Run tests:

forge test

Deploy to local test network:

Run local network

anvil

Deploy contracts:

forge script script/Counter.s.sol:CounterScript --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Note: Above PK is derived from test junk mnemonic account 0.

@wojciech-turek wojciech-turek requested a review from a team as a code owner November 6, 2023 10:10
@atkinsonholly
Copy link
Contributor

Some comments / next steps:

  • Is it necessary to push [all of] lib? I would like us to avoid having sub-modules for this repo (I know we need a workaround for this somehow)
  • As a next step, it would be great to expand the example to mirror the example-hardhat package for Lock.sol including the various kinds of tests
  • It would be great to add fuzzing tests / fuzzing setup in a separate test file
  • Is there a way to set the out dir as "artifacts" such that we can import our Foundry contracts in packages/deploy?

@atkinsonholly
Copy link
Contributor

We should ideally be able to run all tests etc for all packages at root level in the monorepo, so we may need to review our CI

Comment on lines 1 to 34
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this file ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, since we run those from the root we don't need it here.

Comment on lines 1 to 27
[profile.default]
src = "src"
out = "artifacts"
libs = ["lib"]
remappings = [
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
]

# OPTIMIZER SETTINGS
optimizer = true
optimizer_runs = 200

# RPC SETTINGS

[rpc_endpoints]
default = "http://localhost:8545"
mumbai = "https://rpc-mumbai.maticvigil.com/"

# ETHERSCAN SETTINGS

[etherscan]
mumbai = { key = "YOUR_API_KEY_HERE" }

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file contains secrets maybe is better to rename it to foundry.toml.example and add foundry.toml to git ignore file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can import env secrets into foundry.toml there is no need to create .example.
I will update it slightly so its shown how to do it.

Copy link
Contributor

@adjisb adjisb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If git submodules is the foundry way of doing things 👎 maybe we must install forge-std as a submodule (the files inside lib/forge-std can be removed from this PR)?
  • If we decide to base everything on hardhat maybe we must consider https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-foundry to use the npm scripts (using npm implies using nodejs anyway)
  • We may need an explanation on the rust toolchain foundry uses and how to install it, use it, etc ?

@wojciech-turek
Copy link
Member Author

@adjisb

  • The forge indeed uses the sub-modules and forge-std is not available as npm package. We could package it up ourselves and import it but we would then be burdened of maintaining that package.

  • I am not sure if we necessarily want to mix foundry and hardhat, in the past foundry was missing some features like ability to spin up a local node so people installed hardhat for that, now foundry can be used completely separately.

  • There is a readme added to the package, please let me know if you think it should be changed/updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants