Skip to content

Commit cfa3a53

Browse files
committed
Solidity layout helper for anvil_setStorageAt
1 parent a20de4d commit cfa3a53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+27561
-0
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ jobs:
7878
restore-keys: |
7979
go-modules-${{ matrix.test.path }}-${{ runner.os }}-test
8080
go-modules-${{ matrix.test.path }}-${{ runner.os }}
81+
- name: Install Foundry
82+
uses: foundry-rs/foundry-toolchain@v1
83+
with:
84+
version: stable
8185
- uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2.0.0
8286
with:
8387
github-token: ${{ secrets.GITHUB_TOKEN }}

framework/.changeset/v0.7.8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Solidity storage layout helper for anvil_setStorageAt + tests + guide

framework/evm_storage/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Solidity Smart Contracts Storage Layout Utilities
2+
3+
This code is used in e2e tests where we need to modify production contracts with `Anvil`'s `anvil_setStorageAt`.
4+
5+
See a simple example where we override an array [struct](layout_api_test.go)
6+
7+
Run it with
8+
```
9+
./setup.sh
10+
go test -v -run TestLayoutAPI
11+
./teardown.sh
12+
```
13+
Figure out proper encoding for your `encodeFunc` and use in your e2e tests.
14+
15+
See more [tests](layout_test.go) as examples.
16+
17+
## Useful Debug Commands
18+
19+
```
20+
anvil &
21+
forge script script/Deploy.s.sol:Deploy --rpc-url http://127.0.0.1:8545 --broadcast
22+
23+
forge script script/Counter.s.sol --rpc-url http://localhost:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast
24+
25+
cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3 0x1 --rpc-url http://localhost:8545
26+
27+
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
28+
"number()(uint256)" \
29+
--rpc-url http://localhost:8545
30+
31+
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
32+
"values(uint256)(uint256)" 0 \
33+
--rpc-url http://localhost:8545
34+
35+
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
36+
"scores(address)(uint256)" 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
37+
--rpc-url http://localhost:8545
38+
39+
cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
40+
"increment()" \
41+
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
42+
--rpc-url http://localhost:8545
43+
44+
cast --to-uint256 200 | cast --to-bytes32
45+
46+
cast rpc anvil_setStorageAt \
47+
0x5FbDB2315678afecb367f032d93F642f64180aa3 \
48+
0x0 \
49+
0x000000000000000000000000000000000000000000000000000000000000002c
50+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
env:
6+
FOUNDRY_PROFILE: ci
7+
8+
jobs:
9+
check:
10+
strategy:
11+
fail-fast: true
12+
13+
name: Foundry project
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Install Foundry
21+
uses: foundry-rs/foundry-toolchain@v1
22+
with:
23+
version: nightly
24+
25+
- name: Run Forge build
26+
run: |
27+
forge --version
28+
forge build --sizes
29+
id: build
30+
31+
- name: Run Forge tests
32+
run: |
33+
forge test -vvv
34+
id: test
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Commands
2+
3+
```
4+
anvil &
5+
forge script script/Deploy.s.sol:Deploy --rpc-url http://127.0.0.1:8545 --broadcast
6+
7+
forge script script/Counter.s.sol --rpc-url http://localhost:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast
8+
9+
cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3 0x1 --rpc-url http://localhost:8545
10+
11+
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
12+
"number()(uint256)" \
13+
--rpc-url http://localhost:8545
14+
15+
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
16+
"values(uint256)(uint256)" 0 \
17+
--rpc-url http://localhost:8545
18+
19+
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
20+
"scores(address)(uint256)" 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
21+
--rpc-url http://localhost:8545
22+
23+
cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
24+
"increment()" \
25+
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
26+
--rpc-url http://localhost:8545
27+
28+
cast --to-uint256 200 | cast --to-bytes32
29+
30+
cast rpc anvil_setStorageAt \
31+
0x5FbDB2315678afecb367f032d93F642f64180aa3 \
32+
0x0 \
33+
0x000000000000000000000000000000000000000000000000000000000000002c
34+
35+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
extra_output = ["storageLayout"]
6+
7+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/Vm.sol linguist-generated
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Foundry
17+
uses: foundry-rs/foundry-toolchain@v1
18+
with:
19+
version: nightly
20+
21+
- name: Print forge version
22+
run: forge --version
23+
24+
# Backwards compatibility checks:
25+
# - the oldest and newest version of each supported minor version
26+
# - versions with specific issues
27+
- name: Check compatibility with latest
28+
if: always()
29+
run: |
30+
output=$(forge build --skip test)
31+
if echo "$output" | grep -q "Warning"; then
32+
echo "$output"
33+
exit 1
34+
fi
35+
36+
- name: Check compatibility with 0.8.0
37+
if: always()
38+
run: |
39+
output=$(forge build --skip test --use solc:0.8.0)
40+
if echo "$output" | grep -q "Warning"; then
41+
echo "$output"
42+
exit 1
43+
fi
44+
45+
- name: Check compatibility with 0.7.6
46+
if: always()
47+
run: |
48+
output=$(forge build --skip test --use solc:0.7.6)
49+
if echo "$output" | grep -q "Warning"; then
50+
echo "$output"
51+
exit 1
52+
fi
53+
54+
- name: Check compatibility with 0.7.0
55+
if: always()
56+
run: |
57+
output=$(forge build --skip test --use solc:0.7.0)
58+
if echo "$output" | grep -q "Warning"; then
59+
echo "$output"
60+
exit 1
61+
fi
62+
63+
- name: Check compatibility with 0.6.12
64+
if: always()
65+
run: |
66+
output=$(forge build --skip test --use solc:0.6.12)
67+
if echo "$output" | grep -q "Warning"; then
68+
echo "$output"
69+
exit 1
70+
fi
71+
72+
- name: Check compatibility with 0.6.2
73+
if: always()
74+
run: |
75+
output=$(forge build --skip test --use solc:0.6.2)
76+
if echo "$output" | grep -q "Warning"; then
77+
echo "$output"
78+
exit 1
79+
fi
80+
81+
# via-ir compilation time checks.
82+
- name: Measure compilation time of Test with 0.8.17 --via-ir
83+
if: always()
84+
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir
85+
86+
- name: Measure compilation time of TestBase with 0.8.17 --via-ir
87+
if: always()
88+
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir
89+
90+
- name: Measure compilation time of Script with 0.8.17 --via-ir
91+
if: always()
92+
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir
93+
94+
- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
95+
if: always()
96+
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir
97+
98+
test:
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/checkout@v4
102+
103+
- name: Install Foundry
104+
uses: foundry-rs/foundry-toolchain@v1
105+
with:
106+
version: nightly
107+
108+
- name: Print forge version
109+
run: forge --version
110+
111+
- name: Run tests
112+
run: forge test -vvv
113+
114+
fmt:
115+
runs-on: ubuntu-latest
116+
steps:
117+
- uses: actions/checkout@v4
118+
119+
- name: Install Foundry
120+
uses: foundry-rs/foundry-toolchain@v1
121+
with:
122+
version: nightly
123+
124+
- name: Print forge version
125+
run: forge --version
126+
127+
- name: Check formatting
128+
run: forge fmt --check
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Sync Release Branch
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
sync-release-branch:
10+
runs-on: ubuntu-latest
11+
if: startsWith(github.event.release.tag_name, 'v1')
12+
steps:
13+
- name: Check out the repo
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
ref: v1
18+
19+
# The email is derived from the bots user id,
20+
# found here: https://api.github.com/users/github-actions%5Bbot%5D
21+
- name: Configure Git
22+
run: |
23+
git config user.name github-actions[bot]
24+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
25+
26+
- name: Sync Release Branch
27+
run: |
28+
git fetch --tags
29+
git checkout v1
30+
git reset --hard ${GITHUB_REF}
31+
git push --force

0 commit comments

Comments
 (0)