-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path.justfile
More file actions
404 lines (346 loc) · 12.4 KB
/
.justfile
File metadata and controls
404 lines (346 loc) · 12.4 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# Variables
git_tag := `git describe --tags --abbrev=0 2>/dev/null || echo "no-tag"`
timestamp := `date +%s`
build_path := "target"
functional_tests_dir := "functional-tests"
functional_tests_datadir := "_dd"
docker_dir := "docker"
docker_datadir := "data"
profile := env("PROFILE", "dev")
cargo_install_extra_flags := env("CARGO_INSTALL_EXTRA_FLAGS", "")
features := env("FEATURES", "")
docker_image_name := env("DOCKER_IMAGE_NAME", "")
unit_test_args := "--locked --workspace --profile ci --retries 2 --status-level fail --no-capture"
cov_file := "lcov.info"
# Default recipe - show available commands
default:
@just --list
# Build the workspace into the `target` directory
[group('build')]
build:
cargo build --workspace --features "{{features}}" --profile "{{profile}}" --lib --bins --examples --tests --benches
# Run unit tests
[group('test')]
test-unit: ensure-cargo-nextest
ZKVM_MOCK=1 cargo nextest run {{unit_test_args}}
# Run unit tests with coverage
[group('test')]
cov-unit: ensure-cargo-llvm-cov ensure-cargo-nextest
rm -f {{cov_file}}
cargo llvm-cov nextest --lcov --output-path {{cov_file}} {{unit_test_args}}
# Generate an HTML coverage report and open it in the browser
[group('test')]
cov-report-html: ensure-cargo-llvm-cov ensure-cargo-nextest
cargo llvm-cov --open nextest {{unit_test_args}}
# Runs `nextest` under `cargo-mutants`. Caution: This can take *really* long to run
[group('test')]
mutants-test: ensure-cargo-mutants
cargo mutants --workspace -j2
# Check for security advisories on any dependencies
[group('test')]
sec: ensure-cargo-audit
cargo audit
# cargo clean
[group('build')]
clean-cargo:
cargo clean 2>/dev/null || true
# Remove docker data files inside /docker/data
[group('docker')]
clean-docker-data:
rm -rf {{docker_dir}}/{{docker_datadir}} 2>/dev/null || true
# Builds the base image used to build the binaries
[group('docker')]
build-base:
docker build -f docker/base.Dockerfile . -t bridge-base:latest
# Builds the runtime image used as the final container
[group('docker')]
build-rt:
docker build -f docker/rt.Dockerfile . -t bridge-rt:latest
# Builds all images in the compose.yml
[group('docker')]
build-compose:
docker compose down
docker compose build
just start-fdb
docker compose up -d
# Clean docker volumes
[group('docker')]
clean:
rm -rf docker/vol/*/data
# Start FoundationDB container, wait for health, and initialize
[group('docker')]
start-fdb:
docker compose up -d foundationdb
just init-fdb
docker compose up -d --wait foundationdb
# Initialize FoundationDB (idempotent - safe to run multiple times)
[group('docker')]
init-fdb:
#!/usr/bin/env bash
if docker compose exec -T foundationdb fdbcli --no-status --exec "status minimal" 2>/dev/null | grep -q "The database is available"; then
echo "FoundationDB already configured, skipping..."
else
docker compose exec -T foundationdb fdbcli --exec "configure new single ssd"
echo -e "\n\033[36m======== FDB_INITIALIZED ========\033[0m\n"
fi
# Cleans data and rebuilds all containers
[group('docker')]
clean-docker: build-base build-rt clean build-compose
@echo "\n\033[36m======== DOCKER_BUILD_COMPLETE ========\033[0m\n"
# Rebuilds and starts containers without cleaning data
[group('docker')]
docker: build-base build-rt build-compose
@echo "\n\033[36m======== DOCKER_BUILD_COMPLETE_WITH_DATA ========\033[0m\n"
# Generate TLS for secret service 1
[group('docker')]
gen-s2-tls-1:
./docker/gen_s2_tls.sh docker/vol/strata-bridge-1 docker/vol/secret-service-1
# Generate TLS for secret service 2
[group('docker')]
gen-s2-tls-2:
./docker/gen_s2_tls.sh docker/vol/strata-bridge-2 docker/vol/secret-service-2
# Generate TLS for secret service 3
[group('docker')]
gen-s2-tls-3:
./docker/gen_s2_tls.sh docker/vol/strata-bridge-3 docker/vol/secret-service-3
# (Re)generates the TLS CAs, certs and keys for S2's and the bridge nodes to connect
[group('docker')]
gen-s2-tls: gen-s2-tls-1 gen-s2-tls-2 gen-s2-tls-3
@echo "\n\033[36m======== TLS FILES GENERATION COMPLETE ========\033[0m\n"
# Check formatting issues but do not fix automatically
[group('code-quality')]
fmt-check-ws:
cargo fmt --check
# Format source code in the workspace
[group('code-quality')]
fmt-ws:
cargo fmt --all
# Check formatting of python files inside `test` directory
[group('code-quality')]
fmt-check-func-tests: ensure-uv activate-uv
cd {{functional_tests_dir}} && uv run ruff format --check
# Apply formatting of python files inside `test` directory
[group('code-quality')]
fmt-func-tests: ensure-uv activate-uv
cd {{functional_tests_dir}} && uv run ruff format
# Lints the functional tests and applies fixes where possible
[group('code-quality')]
lint-fix-func-tests: ensure-uv activate-uv
cd {{functional_tests_dir}} && uv run ruff check --fix
# Lints the functional tests
[group('code-quality')]
lint-check-func-tests: ensure-uv activate-uv
cd {{functional_tests_dir}} && uv run ruff check && uv run ty check
# Check if cargo-audit is installed
[group('prerequisites')]
ensure-cargo-audit:
#!/usr/bin/env bash
if ! command -v cargo-audit &> /dev/null;
then
echo "cargo-audit not found. Please install it by running the command 'cargo install cargo-audit'"
exit 1
fi
# Check if cargo-llvm-cov is installed
[group('prerequisites')]
ensure-cargo-llvm-cov:
#!/usr/bin/env bash
if ! command -v cargo-llvm-cov &> /dev/null;
then
echo "cargo-llvm-cov not found. Please install it by running the command 'cargo install cargo-llvm-cov --locked'"
exit 1
fi
# Check if cargo-mutants is installed
[group('prerequisites')]
ensure-cargo-mutants:
#!/usr/bin/env bash
if ! command -v cargo-mutants &> /dev/null;
then
echo "cargo-mutants not found. Please install it by running the command 'cargo install cargo-mutants'"
exit 1
fi
# Check if cargo-nextest is installed
[group('prerequisites')]
ensure-cargo-nextest:
#!/usr/bin/env bash
if ! command -v cargo-nextest &> /dev/null;
then
echo "cargo-nextest not found. Please install it by running the command 'cargo install cargo-nextest --locked'"
exit 1
fi
# Check if taplo is installed
[group('prerequisites')]
ensure-taplo:
#!/usr/bin/env bash
if ! command -v taplo &> /dev/null; then
echo "taplo not found. Please install it by following the instructions from: https://taplo.tamasfe.dev/cli/installation/binary.html"
exit 1
fi
# Check if uv is installed
[group('prerequisites')]
ensure-uv:
#!/usr/bin/env bash
if ! command -v uv &> /dev/null;
then
echo "uv not found. Please install it by following the instructions from: https://docs.astral.sh/uv/"
exit 1
fi
# Runs `taplo` to check that TOML files are properly formatted
[group('code-quality')]
fmt-check-toml: ensure-taplo
taplo fmt --check
# Runs `taplo` to format TOML files
[group('code-quality')]
fmt-toml: ensure-taplo
taplo fmt
# Checks for lint issues in the workspace
[group('code-quality')]
lint-check-ws:
cargo clippy \
--workspace \
--lib \
--examples \
--tests \
--benches \
--all-features \
--no-deps \
-- -D warnings
# Lints the workspace and applies fixes where possible
[group('code-quality')]
lint-fix-ws:
cargo clippy \
--workspace \
--lib \
--examples \
--tests \
--benches \
--all-features \
--fix \
--no-deps \
-- -D warnings
# Check if codespell is installed
[group('prerequisites')]
ensure-codespell:
#!/usr/bin/env bash
if ! command -v codespell &> /dev/null; then
echo "codespell not found. Please install it by running the command 'pip install codespell' or refer to the following link for more information: https://github.com/codespell-project/codespell"
exit 1
fi
# Runs `codespell` to check for spelling errors
[group('code-quality')]
lint-check-codespell: ensure-codespell
codespell
# Runs orphan check for Jira-linked TODO/FIXME comments
[group('code-quality')]
orphan-check-jira:
python3 scripts/orphan_check.py --format jira-link --slugs TODO FIXME
# Runs orphan check for assignee-tagged NOTE/HACK/PERF comments
[group('code-quality')]
orphan-check-assignees:
python3 scripts/orphan_check.py --format assignee --slugs NOTE HACK PERF --allow-rust-docstrings NOTE
# Runs all orphan checks for comment formatting
[group('code-quality')]
orphan-check: orphan-check-jira orphan-check-assignees
# Runs `codespell` to fix spelling errors if possible
[group('code-quality')]
lint-fix-codespell: ensure-codespell
codespell -w
# Lints TOML files
[group('code-quality')]
lint-check-toml: ensure-taplo
taplo lint
# Runs all lints and checks for issues without trying to fix them
[group('code-quality')]
lint: fmt-check-ws fmt-check-toml lint-check-ws lint-check-codespell orphan-check
@echo "\n\033[36m======== OK: Lints and Formatting ========\033[0m\n"
# Runs all lints and applies fixes where possible
[group('code-quality')]
lint-fix: fmt-toml fmt-ws lint-fix-ws lint-fix-codespell
@echo "\n\033[36m======== OK: Lints and Formatting Fixes ========\033[0m\n"
# Runs `cargo docs` to generate the Rust documents in the `target/doc` directory
[group('code-quality')]
rustdocs:
RUSTDOCFLAGS="\
--show-type-layout \
--enable-index-page -Z unstable-options \
-A rustdoc::private-doc-tests \
-D warnings" \
cargo doc \
--workspace \
--no-deps
# Runs doctests on the workspace
[group('code-quality')]
test-doc:
cargo test --doc --workspace
# Runs all tests in the workspace including unit and docs tests
[group('code-quality')]
test: test-unit test-doc
# Runs lints (without fixing), audit, docs, and tests (run this before creating a PR)
[group('code-quality')]
pr: lint rustdocs test-doc test-unit
@echo "\n\033[36m======== CHECKS_COMPLETE ========\033[0m\n"
@test -z "`git status --porcelain`" || echo "WARNING: You have uncommitted changes"
@echo "All good to create a PR!"
# Broadcast a mock checkpoint
[group('bridge')]
checkpoint genesis-l1-height="101" num-withdrawals="1" ol-start-slot="0" ol-end-slot="1" epoch="1" assignee-node-idx="0":
RUST_LOG=info \
cargo r \
--bin dev-cli \
-- \
create-and-publish-mock-checkpoint \
--btc-url http://localhost:18443/wallet/default \
--btc-user user \
--btc-pass password \
--epoch {{ epoch }} \
--ol-start-slot {{ ol-start-slot }} \
--ol-end-slot {{ ol-end-slot }} \
--num-withdrawals {{ num-withdrawals }} \
--genesis-l1-height {{ genesis-l1-height }} \
--assignee-node-idx {{ assignee-node-idx }}
# Run bridge-in
[group('bridge')]
bridge-in:
RUST_LOG=info \
cargo r \
--bin dev-cli \
-- \
bridge-in \
--btc-url http://localhost:18443/wallet/default \
--btc-user user \
--btc-pass password \
--params bin/dev-cli/params.toml \
--ee-address 70997970C51812dc3A010C7d01b50e0d17dc79C8 # from anvil #2
# Contest a claim transaction by signing and broadcasting a challenge via the game graph
[group('bridge')]
contest deposit-idx="0" operator-idx="0" contester-node-idx="1" seed="" bridge-node-url="http://localhost:4781":
RUST_LOG=info \
cargo r \
--bin dev-cli \
-- \
contest \
--deposit-idx {{ deposit-idx }} \
--operator-idx {{ operator-idx }} \
--bridge-node-url {{ bridge-node-url }} \
--contester-node-idx {{ contester-node-idx }} \
--seed {{ seed }} \
--params bin/dev-cli/params.toml \
--btc-url http://localhost:18443/wallet/default \
--btc-user user \
--btc-pass password
# Derive operator keys from a seed for functional tests
[group('bridge')]
derive-keys seed:
cargo r --bin dev-cli -- derive-keys {{seed}}
# Activate uv environment for integration tests
[group('functional-tests')]
activate-uv: ensure-uv
cd {{functional_tests_dir}} && uv venv --clear
@if [ -n "${FISH_VERSION:-}" ]; then source {{functional_tests_dir}}/.venv/bin/activate.fish; else source {{functional_tests_dir}}/.venv/bin/activate; fi
# Remove the data directory used by functional tests
[group('functional-tests')]
clean-dd:
rm -rf {{functional_tests_dir}}/{{functional_tests_datadir}} 2>/dev/null || true
# Runs functional tests
[group('functional-tests')]
test-functional: ensure-uv activate-uv clean-dd
cd {{functional_tests_dir}} && ./run_test.sh