-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJustfile
205 lines (153 loc) · 6.31 KB
/
Justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
set dotenv-load
import "fork.just"
chain := env_var_or_default("CHAIN", "mainnet")
deploy_script_name := if chain == "mainnet" {
"DeployMainnet"
} else if chain == "holesky" {
"DeployHolesky"
} else {
error("Unsupported chain " + chain)
}
deploy_implementations_script_name := if chain == "mainnet" {
"DeployImplementationsMainnet"
} else if chain == "holesky" {
"DeployImplementationsHolesky"
} else {
error("Unsupported chain " + chain)
}
deploy_config_path := if chain == "mainnet" {
"artifacts/mainnet/deploy-mainnet.json"
} else if chain == "holesky" {
"artifacts/holesky/deploy-holesky.json"
} else {
error("Unsupported chain " + chain)
}
deploy_script_path := "script" / deploy_script_name + ".s.sol:" + deploy_script_name
deploy_impls_script_path := "script" / deploy_implementations_script_name + ".s.sol:" + deploy_implementations_script_name
anvil_host := env_var_or_default("ANVIL_IP_ADDR", "127.0.0.1")
anvil_port := "8545"
anvil_rpc_url := "http://" + anvil_host + ":" + anvil_port
default: clean deps build test-all
build *args:
forge build --force {{args}}
clean:
forge clean
rm -rf cache broadcast out node_modules
deps:
yarn workspaces focus --all --production
deps-dev:
yarn workspaces focus --all && npx husky install
lint-solhint:
yarn lint:solhint
lint-fix:
yarn lint:fix
lint:
yarn lint:check
test-all:
just test-unit &
just test-local
test-unit *args:
forge test --no-match-path 'test/fork/*' -vvv {{args}}
test-integration *args:
forge test --match-path 'test/fork/integration/*' -vvv {{args}}
test-deployment *args:
forge test --match-path 'test/fork/*' --no-match-path='test/fork/voting/*' -vvv {{args}}
test-post-voting *args:
forge test --match-path 'test/fork/*' --no-match-path='test/fork/deployment/*' -vvv {{args}}
test-invariant *args:
forge test --match-path 'test/fork/invariant/*' -vvv {{args}}
gas-report:
#!/usr/bin/env python
import subprocess
import re
command = "just test-unit --nmt 'testFuzz.+' --gas-report"
output = subprocess.check_output(command, shell=True, text=True)
lines = output.split('\n')
filename = 'GAS.md'
to_print = False
skip_next = False
with open(filename, 'w') as fh:
for line in lines:
if skip_next:
skip_next = False
continue
if line.startswith('|'):
to_print = True
if line.startswith('| Deployment Cost'):
to_print = False
skip_next = True
if re.match(r"Ran \d+ test suites", line):
break
if to_print:
fh.write(line + '\n')
print(f"Done. Gas report saved to {filename}")
coverage *args:
FOUNDRY_PROFILE=coverage forge coverage --no-match-path 'test/fork/*' {{args}}
# Run coverage and save the report in LCOV file.
coverage-lcov *args:
FOUNDRY_PROFILE=coverage forge coverage --no-match-path 'test/fork/*' --report lcov {{args}}
diffyscan-contracts *args:
yarn generate:diffyscan {{args}}
make-fork *args:
@if pgrep -x "anvil" > /dev/null; \
then just _warn "anvil process is already running in the background. Make sure it's connected to the right network and in the right state."; \
else anvil -f ${RPC_URL} --host {{anvil_host}} --port {{anvil_port}} --config-out localhost.json {{args}}; \
fi
kill-fork:
@-pkill anvil && just _warn "anvil process is killed"
deploy *args:
forge script {{deploy_script_path}} --sig="run(string)" --rpc-url {{anvil_rpc_url}} --broadcast --slow {{args}} -- `git rev-parse HEAD`
deploy-prod *args:
just _warn "The current `tput bold`chain={{chain}}`tput sgr0` with the following rpc url: $RPC_URL"
ARTIFACTS_DIR=./artifacts/latest/ just _deploy-prod-confirm {{args}}
cp ./broadcast/{{deploy_script_name}}.s.sol/`cast chain-id --rpc-url=$RPC_URL`/run-latest.json \
./artifacts/latest/transactions.json
[confirm("You are about to broadcast deployment transactions to the network. Are you sure?")]
_deploy-prod-confirm *args:
just _deploy-prod --broadcast --verify {{args}}
deploy-prod-dry *args:
just _deploy-prod {{args}}
verify-prod *args:
just _warn "Pass --chain=your_chain manually. e.g. --chain=holesky for testnet deployment"
forge script {{deploy_script_path}} --sig="run(string)" --rpc-url ${RPC_URL} --verify {{args}} --unlocked -- `git rev-parse HEAD`
_deploy-prod *args:
forge script {{deploy_script_path}} --sig="run(string)" --force --rpc-url ${RPC_URL} {{args}} -- `git rev-parse HEAD`
_deploy-impl *args:
forge script {{deploy_impls_script_path}} --sig="deploy(string,string)" \
--rpc-url {{anvil_rpc_url}} --slow {{args}} \
-- {{deploy_config_path}} `git rev-parse HEAD`
[confirm("You are about to broadcast deployment transactions to the network. Are you sure?")]
deploy-impl-prod *args:
ARTIFACTS_DIR=./artifacts/latest/ just _deploy-impl --broadcast --verify {{args}}
deploy-impl-dry *args:
just _deploy-impl {{args}}
deploy-local:
just make-fork &
@while ! echo exit | nc {{anvil_host}} {{anvil_port}} > /dev/null; do sleep 1; done
just deploy
just _warn "anvil is kept running in the background: {{anvil_rpc_url}}"
test-upgrade *args:
just make-fork --silent &
@while ! echo exit | nc {{anvil_host}} {{anvil_port}} > /dev/null; do sleep 1; done
DEPLOYER_PRIVATE_KEY=`cat localhost.json | jq -r ".private_keys[0]"` \
just _deploy-impl --broadcast
DEPLOY_CONFIG=./artifacts/{{chain}}/deploy-{{chain}}.json \
UPGRADE_CONFIG=./artifacts/local/upgrade-{{chain}}.json \
RPC_URL={{anvil_rpc_url}} \
just vote-upgrade
DEPLOY_CONFIG=./artifacts/{{chain}}/deploy-{{chain}}.json \
UPGRADE_CONFIG=./artifacts/local/upgrade-{{chain}}.json \
RPC_URL={{anvil_rpc_url}} \
just test-post-voting {{args}}
just kill-fork
test-local *args:
just make-fork --silent &
@while ! echo exit | nc {{anvil_host}} {{anvil_port}} > /dev/null; do sleep 1; done
DEPLOYER_PRIVATE_KEY=`cat localhost.json | jq -r ".private_keys[0]"` \
just deploy --silent
DEPLOY_CONFIG=./artifacts/local/deploy-{{chain}}.json \
RPC_URL={{anvil_rpc_url}} \
just test-deployment {{args}}
just kill-fork
_warn message:
@tput setaf 3 && printf "[WARNING]" && tput sgr0 && echo " {{message}}"