Skip to content

Commit 594afa1

Browse files
authored
refactor: use Foundry contracts with sol! macro for rpc tests (#262)
* move contracts into test-utils * refactor existing rpc tests to use foundry contracts * build-contracts as dep for build * build-contracts as dep for test * install foundry in CI * setup foundry and build contracts for udeps CI
1 parent 37150ff commit 594afa1

File tree

20 files changed

+478
-363
lines changed

20 files changed

+478
-363
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
2626
with:
2727
cache-on-failure: true
28-
add-rust-environment-hash-key: 'false'
28+
add-rust-environment-hash-key: "false"
2929
key: stable-${{ hashFiles('Cargo.lock') }}
3030
- name: Install just
3131
uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
@@ -41,19 +41,25 @@ jobs:
4141
egress-policy: audit
4242

4343
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44+
with:
45+
submodules: recursive
4446
- uses: dtolnay/rust-toolchain@4305c38b25d97ef35a8ad1f985ccf2d2242004f2 # stable
4547
- uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
4648
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
4749
with:
4850
cache-on-failure: true
49-
add-rust-environment-hash-key: 'false'
51+
add-rust-environment-hash-key: "false"
5052
key: stable-${{ hashFiles('Cargo.lock') }}
5153
- name: Install just
5254
uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
5355
- name: Install cargo-nextest
5456
uses: taiki-e/install-action@3575e532701a5fc614b0c842e4119af4cc5fd16d # v2.62.60
5557
with:
5658
tool: cargo-nextest
59+
- name: Install Foundry
60+
uses: foundry-rs/foundry-toolchain@50d5a8956f2e319df19e6b57539d7e2acb9f8c1e # v1.5.0
61+
with:
62+
version: stable
5763
- name: Run tests
5864
run: just test
5965

@@ -73,7 +79,7 @@ jobs:
7379
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
7480
with:
7581
cache-on-failure: true
76-
add-rust-environment-hash-key: 'false'
82+
add-rust-environment-hash-key: "false"
7783
key: nightly-${{ hashFiles('Cargo.lock') }}
7884
- name: Install just
7985
uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
@@ -95,7 +101,7 @@ jobs:
95101
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
96102
with:
97103
cache-on-failure: true
98-
add-rust-environment-hash-key: 'false'
104+
add-rust-environment-hash-key: "false"
99105
key: stable-${{ hashFiles('Cargo.lock') }}
100106
- name: Install just
101107
uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
@@ -140,11 +146,15 @@ jobs:
140146
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
141147
with:
142148
cache-on-failure: true
143-
add-rust-environment-hash-key: 'false'
149+
add-rust-environment-hash-key: "false"
144150
key: nightly-${{ hashFiles('Cargo.lock') }}
145151
- uses: taiki-e/install-action@3575e532701a5fc614b0c842e4119af4cc5fd16d # v2.62.60
146-
with:
152+
with:
147153
tool: cargo-udeps
148154
- name: Install just
149155
uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
156+
- name: Install Foundry
157+
uses: foundry-rs/foundry-toolchain@50d5a8956f2e319df19e6b57539d7e2acb9f8c1e # v1.5.0
158+
with:
159+
version: stable
150160
- run: just check-udeps

.gitmodules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[submodule "contracts/lib/forge-std"]
2-
path = contracts/lib/forge-std
1+
[submodule "crates/test-utils/contracts/lib/forge-std"]
2+
path = crates/test-utils/contracts/lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4-
[submodule "contracts/lib/solmate"]
5-
path = contracts/lib/solmate
4+
[submodule "crates/test-utils/contracts/lib/solmate"]
5+
path = crates/test-utils/contracts/lib/solmate
66
url = https://github.com/transmissions11/solmate

Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ alloy-provider = { version = "1.0.41" }
107107
alloy-hardforks = "0.4.4"
108108
alloy-rpc-client = { version = "1.0.41" }
109109
alloy-serde = { version = "1.0.41" }
110+
alloy-sol-macro = { version = "1.4.1", features = ["json"] }
111+
alloy-sol-types = { version = "1.4.1" }
112+
alloy-contract = { version = "1.0.41" }
110113

111114
# op-alloy
112115
op-alloy-rpc-types = { version = "0.22.0", default-features = false }

Justfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ zepter-fix:
3939
zepter format features --fix
4040

4141
# Runs tests across workspace with all features enabled
42-
test:
42+
test: build-contracts
4343
@command -v cargo-nextest >/dev/null 2>&1 || cargo install cargo-nextest
4444
RUSTFLAGS="-D warnings" cargo nextest run --workspace --all-features
4545

@@ -80,17 +80,21 @@ build-maxperf:
8080
build-node:
8181
cargo build --bin base-reth-node
8282

83+
# Build the contracts used for tests
84+
build-contracts:
85+
cd crates/test-utils/contracts && forge build
86+
8387
# Cleans the workspace
8488
clean:
8589
cargo clean
8690

8791
# Checks if there are any unused dependencies
88-
check-udeps:
92+
check-udeps: build-contracts
8993
@command -v cargo-udeps >/dev/null 2>&1 || cargo install cargo-udeps
9094
cargo +nightly udeps --workspace --all-features --all-targets
9195

9296
# Watches tests
93-
watch-test:
97+
watch-test: build-contracts
9498
cargo watch -x test
9599

96100
# Watches checks

contracts/lib/forge-std

Lines changed: 0 additions & 1 deletion
This file was deleted.

contracts/script/Counter.s.sol

Lines changed: 0 additions & 19 deletions
This file was deleted.

contracts/src/Counter.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

contracts/test/Counter.t.sol

Lines changed: 0 additions & 24 deletions
This file was deleted.

crates/rpc/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ futures-util.workspace = true
7676
alloy-rpc-types-eth.workspace = true
7777
alloy-rpc-types-engine.workspace = true
7878
alloy-provider.workspace = true
79+
alloy-sol-macro.workspace = true
80+
alloy-sol-types.workspace = true
81+
alloy-contract.workspace = true
7982

8083
[package.metadata.cargo-udeps.ignore]
8184
normal = ["reth-optimism-cli"]

0 commit comments

Comments
 (0)