-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathjustfile
More file actions
1213 lines (1026 loc) · 34.5 KB
/
Copy pathjustfile
File metadata and controls
1213 lines (1026 loc) · 34.5 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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
set positional-arguments
alias b := build
alias c := check
alias t := test
default:
@just --list
# Enter a Nix development shell without copying ignored files from JJ workspaces.
develop shell="stable":
#!/usr/bin/env bash
set -euo pipefail
shell_name={{quote(shell)}}
case "$shell_name" in
""|*[!a-zA-Z0-9._-]*)
echo "Error: invalid development shell name: $shell_name" >&2
exit 2
;;
esac
flake_ref=".#${shell_name}"
if command -v jj >/dev/null 2>&1 && jj root >/dev/null 2>&1; then
revision=$(jj log -r @ --no-graph -T commit_id)
if git_dir=$(jj git root 2>/dev/null); then
case "$git_dir" in
*/.git)
git_source=${git_dir%/.git}
;;
*)
git_source=$git_dir
;;
esac
flake_ref="git+file://${git_source}?rev=${revision}#${shell_name}"
else
echo "Warning: JJ repository is not Git-backed; using the workspace path." >&2
fi
fi
exec nix develop "$flake_ref" -c "${SHELL:-bash}"
# Create a new SQL migration file
new-migration target name:
#!/usr/bin/env bash
set -euo pipefail
if [ "{{target}}" != "mint" ] && [ "{{target}}" != "wallet" ]; then
echo "Error: target must be either 'mint' or 'wallet'"
exit 1
fi
timestamp=$(date +%Y%m%d%H%M%S)
migration_path="./crates/cdk-sql-common/src/{{target}}/migrations/${timestamp}_{{name}}.sql"
# Create the file
mkdir -p "$(dirname "$migration_path")"
touch "$migration_path"
echo "Created new migration: $migration_path"
final-check: lint clippy test
quick-check: lint clippy test-units
# run `cargo build` on everything
build *ARGS="--workspace --all-targets":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo build {{ARGS}}
# Build a statically-linked binary by profile name (requires nix)
# Profiles: cdk-mintd-static, cdk-mintd-ldk-static, cdk-cli-static
build-static profile:
#!/usr/bin/env bash
set -euo pipefail
nix build .#{{profile}}
mkdir -p ./static-bin
cp -f ./result/bin/* ./static-bin/
echo "Static binaries in ./static-bin/:"
ls -la ./static-bin/
# Build all statically-linked binaries and generate checksums (requires nix)
build-static-all: (build-static "cdk-mintd-static") (build-static "cdk-mintd-ldk-static") (build-static "cdk-cli-static")
#!/usr/bin/env bash
set -euo pipefail
cd ./static-bin
sha256sum -- *-x86_64 > SHA256SUMS
echo "Checksums:"
cat SHA256SUMS
# Build the CI cache warmup targets locally.
ci-cache-build:
#!/usr/bin/env bash
set -euo pipefail
cd "{{justfile_directory()}}"
nix build -L --no-link \
'path:.#deps' \
'path:.#deps-msrv' \
'path:.#checks.x86_64-linux.workspace-clippy-all-targets' \
'path:.#dart-bindings' \
'path:.#kotlin-bindings' \
'path:.#go-bindings'
# Push the locally built CI cache warmup targets to Cachix.
ci-cache-push:
#!/usr/bin/env bash
set -euo pipefail
cd "{{justfile_directory()}}"
nix build --json --no-link \
'path:.#deps' \
'path:.#deps-msrv' \
'path:.#checks.x86_64-linux.workspace-clippy-all-targets' \
'path:.#dart-bindings' \
'path:.#kotlin-bindings' \
'path:.#go-bindings' \
| jq -r '.[].outputs | to_entries[].value' \
| cachix push cashudevkit
# Build and push CI cache warmup targets as they complete.
ci-cache-watch:
#!/usr/bin/env bash
set -euo pipefail
cd "{{justfile_directory()}}"
cachix watch-exec cashudevkit -- just ci-cache-build
# run `cargo check` on everything
check *ARGS="--workspace --all-targets":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo check {{ARGS}}
# run code formatters
format:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo fmt --all
nixpkgs-fmt $(echo **.nix)
# run doc tests
test:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
# Unit/lib tests always run from source (not included in the nextest archive)
cargo test --lib --workspace --exclude cdk-postgres
# Run pure integration tests
if [ -n "${CDK_ITEST_ARCHIVE:-}" ] && [ -f "$CDK_ITEST_ARCHIVE" ]; then
# Run the mint integration test from the pre-built nextest archive
cargo nextest run --archive-file "$CDK_ITEST_ARCHIVE" --workspace-remap . -E "binary(/^mint$/)"
else
# Run pure integration tests
cargo test -p cdk-integration-tests --test mint
fi
test-units:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo test --lib --workspace --exclude cdk-postgres --exclude cdk-integration-tests
# run doc tests
cargo test --doc
coverage:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
# Clean up previous coverage data
cargo llvm-cov clean --workspace
# Start PostgreSQL for cdk-postgres tests
echo "Starting PostgreSQL for coverage..."
start-postgres
# Run unit tests with coverage (all workspace crates including cdk-postgres)
echo "Running unit tests coverage..."
cargo llvm-cov --no-report --lib --workspace --exclude cdk-integration-tests
# Run pure integration tests with coverage (memory backend)
echo "Running pure integration tests coverage (memory)..."
CDK_TEST_DB_TYPE=memory cargo llvm-cov --no-report -p cdk-integration-tests --test integration_tests_pure
# Run pure integration tests with coverage (sqlite backend)
echo "Running pure integration tests coverage (sqlite)..."
CDK_TEST_DB_TYPE=sqlite cargo llvm-cov --no-report -p cdk-integration-tests --test integration_tests_pure
# Run NWC e2e tests with coverage (requires nostr-rs-relay on PATH)
echo "Running NWC e2e tests coverage (memory)..."
CDK_TEST_DB_TYPE=memory cargo llvm-cov --no-report -p cdk-integration-tests --test nwc_e2e
# Generate report
echo "Generating coverage report..."
cargo llvm-cov report --lcov --output-path lcov.info
test-pure db="memory":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
if [ -n "${CDK_ITEST_ARCHIVE:-}" ] && [ -f "$CDK_ITEST_ARCHIVE" ]; then
# Run pure integration tests from nextest archive
CDK_TEST_DB_TYPE={{db}} cargo nextest run --archive-file "$CDK_ITEST_ARCHIVE" --workspace-remap . -E "binary(~integration_tests_pure)" -j 1
CDK_TEST_DB_TYPE={{db}} cargo nextest run --archive-file "$CDK_ITEST_ARCHIVE" --workspace-remap . -E "binary(~test_swap_flow)" -j 1
CDK_TEST_DB_TYPE={{db}} cargo nextest run --archive-file "$CDK_ITEST_ARCHIVE" --workspace-remap . -E "binary(~wallet_saga)" -j 1
CDK_TEST_DB_TYPE={{db}} cargo nextest run --archive-file "$CDK_ITEST_ARCHIVE" --workspace-remap . -E "binary(~nwc_e2e)" -j 1
else
# Run pure integration tests (cargo test will only build what's needed for the test)
CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test integration_tests_pure -- --test-threads 1
# Run swap flow tests (detailed testing of swap operation)
CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test test_swap_flow -- --test-threads 1
# Run wallet saga tests
CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test wallet_saga -- --test-threads 1
# Run NWC (NIP-47) e2e tests (requires nostr-rs-relay on PATH; skipped locally if absent)
CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test nwc_e2e -- --test-threads 1
fi
# Run Redis cache clippy and unit tests against both single-node and cluster Redis.
# Starts a single-node Redis (port 6379) and a 3-node cluster (ports 7001-7003)
# using Nix-managed scripts, mirrors both code paths in cdk-axum cache.
test-redis:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
# Start both Redis topologies and stop them on exit
trap 'stop-redis-single; stop-redis-cluster' EXIT
start-redis-single
start-redis-cluster
# Lint once (compile-time only, topology is irrelevant for clippy)
CDK_MINTD_CACHE_BACKEND=redis \
CDK_MINTD_CACHE_REDIS_USE_CLUSTER=false \
CDK_MINTD_CACHE_REDIS_URL=redis://127.0.0.1:6379 \
cargo clippy -p cdk-axum --features redis -- -D warnings
# Run the full lib test suite once with both endpoint vars present.
# Each test constructs its own topology explicitly so a single invocation
# exercises both the single-node and cluster paths.
CDK_MINTD_CACHE_BACKEND=redis \
CDK_MINTD_CACHE_REDIS_URL=redis://127.0.0.1:6379 \
CDK_MINTD_CACHE_REDIS_CLUSTER_NODES=redis://127.0.0.1:7001,redis://127.0.0.1:7002,redis://127.0.0.1:7003 \
cargo test -p cdk-axum --features redis,integration-tests --lib
# Mutation Testing Commands
# Run mutation tests on a specific crate
# Usage: just mutants <crate-name>
# Example: just mutants cashu
mutants CRATE:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutation tests on crate: {{CRATE}}"
cargo mutants --package {{CRATE}} -vV
# Run mutation tests on the cashu crate
mutants-cashu:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutation tests on cashu crate..."
cargo mutants --package cashu -vV
# Run mutation tests on NUT-27 with wallet+nostr features enabled
mutants-cashu-nut27-nostr:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutation tests on cashu NUT-27 with Nostr features..."
cargo mutants --package cashu --no-config --file crates/cashu/src/nuts/nut27.rs --features wallet,nostr -vV
# Run mutation tests on the cdk crate
mutants-cdk:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutation tests on cdk crate..."
cargo mutants --package cdk -vV
# Run mutation tests on entire workspace (WARNING: very slow)
mutants-all:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutation tests on entire workspace..."
echo "WARNING: This may take a very long time!"
cargo mutants -vV
# Quick mutation test for current work (alias for mutants-diff)
mutants-quick:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutations on changed files since HEAD..."
cargo mutants --in-diff HEAD -vV
# Fuzzing Commands
# Run fuzzing on a specific target
# Usage: just fuzz <target> [duration] [jobs]
# Example: just fuzz fuzz_token
# Example: just fuzz fuzz_token 60
# Example: just fuzz fuzz_token 60 4 (run for 60s on 4 cores)
fuzz TARGET DURATION="0" JOBS="1":
#!/usr/bin/env bash
set -euo pipefail
echo "Running fuzzer on target: {{TARGET}} (jobs: {{JOBS}})"
cd fuzz
# Create corpus directory if it doesn't exist
mkdir -p "corpus/{{TARGET}}"
# Use seeds directory if it exists
SEEDS_DIR=""
if [ -d "seeds/{{TARGET}}" ]; then
SEEDS_DIR="seeds/{{TARGET}}"
fi
FORK_FLAG=""
if [ "{{JOBS}}" != "1" ]; then
FORK_FLAG="-fork={{JOBS}}"
fi
if [ "{{DURATION}}" = "0" ]; then
cargo fuzz run {{TARGET}} corpus/{{TARGET}} $SEEDS_DIR -- $FORK_FLAG
else
cargo fuzz run {{TARGET}} corpus/{{TARGET}} $SEEDS_DIR -- -max_total_time={{DURATION}} $FORK_FLAG
fi
# List available fuzz targets
fuzz-list:
#!/usr/bin/env bash
set -euo pipefail
echo "Available fuzz targets:"
cd fuzz
cargo fuzz list
# Run all fuzz targets for a short duration (useful for CI)
# Usage: just fuzz-ci [duration] [jobs]
# Example: just fuzz-ci 30 4 (run each target for 30s on 4 cores)
fuzz-ci DURATION="30" JOBS="1":
#!/usr/bin/env bash
set -euo pipefail
echo "Running all fuzz targets for {{DURATION}} seconds each (jobs: {{JOBS}})..."
cd fuzz
FORK_FLAG=""
if [ "{{JOBS}}" != "1" ]; then
FORK_FLAG="-fork={{JOBS}}"
fi
for target in $(cargo fuzz list); do
echo "Fuzzing $target..."
mkdir -p "corpus/$target"
SEEDS_DIR=""
if [ -d "seeds/$target" ]; then
SEEDS_DIR="seeds/$target"
fi
cargo fuzz run "$target" "corpus/$target" $SEEDS_DIR -- -max_total_time={{DURATION}} $FORK_FLAG
done
echo "All fuzz targets completed!"
# Run mutation tests only on changed code since HEAD
mutants-diff:
#!/usr/bin/env bash
set -euo pipefail
echo "Running mutation tests on changed code..."
cargo mutants --in-diff HEAD -vV
# Run mutation tests and save output to log file
# Usage: just mutants-log <crate-name> <log-suffix>
# Example: just mutants-log cashu baseline
mutants-log CRATE SUFFIX:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
LOG_FILE="mutants-{{CRATE}}-{{SUFFIX}}.log"
echo "Running mutation tests on {{CRATE}}, saving to $LOG_FILE..."
cargo mutants --package {{CRATE}} -vV 2>&1 | tee "$LOG_FILE"
echo "Results saved to $LOG_FILE"
# Mutation test with baseline comparison
# Usage: just mutants-check <crate-name>
# Example: just mutants-check cashu
mutants-check CRATE:
#!/usr/bin/env bash
set -euo pipefail
BASELINE="mutants-{{CRATE}}-baseline.log"
if [ ! -f "$BASELINE" ]; then
echo "ERROR: No baseline found at $BASELINE"
echo "Run: just mutants-log {{CRATE}} baseline"
exit 1
fi
cargo mutants --package {{CRATE}} -vV | tee mutants-{{CRATE}}-current.log
# Compare results
echo "=== Baseline vs Current ==="
diff <(grep "^CAUGHT\|^MISSED" "$BASELINE" | wc -l) \
<(grep "^CAUGHT\|^MISSED" mutants-{{CRATE}}-current.log | wc -l) || true
test-nutshell:
#!/usr/bin/env bash
set -euo pipefail
# Function to cleanup docker containers
cleanup() {
echo "Cleaning up docker containers..."
docker stop nutshell 2>/dev/null || true
docker rm nutshell 2>/dev/null || true
unset CDK_ITESTS_DIR
}
# Trap to ensure cleanup happens on exit (success or failure)
trap cleanup EXIT
# Clean up any leftover containers from previous runs
docker stop nutshell 2>/dev/null || true
docker rm nutshell 2>/dev/null || true
docker run -d --network=host --name nutshell -e MINT_LIGHTNING_BACKEND=FakeWallet -e MINT_LISTEN_HOST=0.0.0.0 -e MINT_LISTEN_PORT=3338 -e MINT_PRIVATE_KEY=TEST_PRIVATE_KEY -e MINT_INPUT_FEE_PPK=100 cashubtc/nutshell:latest poetry run mint
export CDK_ITESTS_DIR=$(mktemp -d)
# Wait for the Nutshell service to be ready
echo "Waiting for Nutshell to start..."
max_attempts=30
attempt=0
while ! curl -s http://127.0.0.1:3338/v1/info > /dev/null; do
attempt=$((attempt+1))
if [ $attempt -ge $max_attempts ]; then
echo "Nutshell failed to start after $max_attempts attempts"
echo "=== Docker container status ==="
docker ps -a --filter name=nutshell
echo "=== Docker logs ==="
docker logs nutshell 2>&1 || true
exit 1
fi
echo "Waiting for Nutshell to start (attempt $attempt/$max_attempts)..."
# Show container status every 10 attempts
if [ $((attempt % 10)) -eq 0 ]; then
echo "=== Container status check ==="
docker ps -a --filter name=nutshell
fi
sleep 1
done
echo "Nutshell is ready!"
# Set environment variables and run tests
export CDK_TEST_MINT_URL=http://127.0.0.1:3338
export LN_BACKEND=FAKEWALLET
# Track test results
test_exit_code=0
# Run first test and capture exit code
# Serialize tests (--test-threads=1) to avoid concurrent writes against
# Nutshell's SQLite backend, which can cause transient lock-acquisition
# failures under parallel load.
echo "Running happy_path_mint_wallet test..."
if ! cargo test -p cdk-integration-tests --test happy_path_mint_wallet -- --test-threads=1; then
echo "ERROR: happy_path_mint_wallet test failed"
test_exit_code=1
fi
# Run second test and capture exit code
echo "Running test_fees test..."
if ! cargo test -p cdk-integration-tests --test test_fees -- --test-threads=1; then
echo "ERROR: test_fees test failed"
test_exit_code=1
fi
unset CDK_TEST_MINT_URL
unset LN_BACKEND
# Exit with error code if any test failed
if [ $test_exit_code -ne 0 ]; then
echo "One or more tests failed"
exit $test_exit_code
fi
echo "All tests passed successfully"
# run `cargo clippy` on everything
clippy *ARGS="--workspace --all-targets":
cargo clippy {{ARGS}} -- -D warnings
# run `cargo clippy --fix` on everything
clippy-fix *ARGS="--workspace --all-targets":
cargo clippy {{ARGS}} --fix
typos:
typos
# fix all typos
[no-exit-message]
typos-fix:
just typos -w
# run all linting checks (format check, typos, nix format)
lint:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
echo "Checking Rust formatting..."
cargo fmt --all -- --check
echo "Checking Nix formatting..."
nixpkgs-fmt --check $(echo **.nix)
echo "Checking for typos..."
typos
echo "All checks passed!"
update-msrv-lock:
#!/usr/bin/env bash
set -euo pipefail
nix develop --ignore-environment .#msrv --command bash -c '
cp Cargo.lock Cargo.lock.msrv
echo "Copied Cargo.lock to Cargo.lock.msrv (MSRV 1.85.0)"
'
nix develop --ignore-environment .#stable --command bash -c '
cargo update
echo "Updated Cargo.lock (stable)"
'
itest db suite="all":
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/itests.sh "{{db}}" "{{suite}}"
itest-ln db:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/itests.sh "{{db}}" ln
itest-onchain db:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/itests.sh "{{db}}" onchain
fake-mint-itest db:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/fake_itests.sh "{{db}}"
bash ./misc/fake_itests.sh "{{db}}" external_signatory
itest-payment-processor ln:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/mintd_payment_processor.sh "{{ln}}"
fake-auth-mint-itest db openid_discovery:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/fake_auth_itests.sh "{{db}}" "{{openid_discovery}}"
nutshell-wallet-itest:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/nutshell_wallet_itest.sh
# Start interactive regtest environment (Bitcoin + 4 LN nodes + 2 CDK mints)
regtest db="sqlite" host="127.0.0.1":
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/interactive_regtest_mprocs.sh {{db}} "{{host}}"
# Lightning Network Commands (require regtest environment to be running)
# Get CLN node 1 info
ln-cln1 *ARGS:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh ln-cln1 "$@"
# Get CLN node 2 info
ln-cln2 *ARGS:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh ln-cln2 "$@"
# Get LND node 1 info
ln-lnd1 *ARGS:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh ln-lnd1 "$@"
# Get LND node 2 info
ln-lnd2 *ARGS:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh ln-lnd2 "$@"
# Bitcoin regtest commands
btc *ARGS:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh btc "$@"
# Mine blocks in regtest
btc-mine blocks="10":
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh btc-mine {{blocks}}
# Show mint information
mint-info:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh mint-info
# Run integration tests against regtest environment
mint-test:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh mint-test
# Restart mints after recompiling (useful for development)
restart-mints:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh restart-mints
# Show regtest environment status
regtest-status:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh show-status
# Show regtest environment logs
regtest-logs:
#!/usr/bin/env bash
set -euo pipefail
bash ./misc/regtest_helper.sh show-logs
run-examples:
cargo r --example p2pk
cargo r --example mint-token
cargo r --example melt-token
cargo r --example proof_selection
cargo r --example wallet
check-wasm *ARGS="--target wasm32-unknown-unknown":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
buildargs=(
"-p cdk"
"-p cdk --no-default-features"
"-p cdk --no-default-features --features wallet"
"-p cdk --no-default-features --features mint"
)
for arg in "${buildargs[@]}"; do
echo "Checking '$arg'"
cargo check $arg {{ARGS}}
echo
done
release m="":
#!/usr/bin/env bash
set -euo pipefail
# Extract version from the cdk-ffi crate
VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "cdk-ffi") | .version')
if ! git ls-remote --exit-code --tags origin "refs/tags/v$VERSION" > /dev/null; then
echo "Tag v$VERSION does not exist on origin. Push the release tag before publishing crates."
exit 1
fi
args=(
"-p cashu"
"-p cdk-prometheus"
"-p cdk-http-client"
"-p cdk-common"
"-p cdk-npubcash"
"-p cdk-sql-common"
"-p cdk-sqlite"
"-p cdk-postgres"
"-p cdk-redb"
"-p cdk-signatory"
"-p cdk-fake-wallet"
"-p cdk"
"-p cdk-supabase"
"-p cdk-ffi"
"-p cdk-axum"
"-p cdk-mint-rpc"
"-p cdk-bdk"
"-p cdk-cln"
"-p cdk-lnd"
"-p cdk-lnbits"
"-p cdk-ldk-node"
"-p cdk-payment-processor"
"-p cdk-cli"
"-p cdk-mintd"
)
for arg in "${args[@]}";
do
echo "Publishing '$arg'"
cargo publish $arg {{m}}
echo
done
# Trigger all FFI binding releases (Dart, Kotlin, Swift, Go)
echo "📦 Triggering all FFI binding releases for version $VERSION..."
just ffi-release-all $VERSION
check-docs:
#!/usr/bin/env bash
set -euo pipefail
args=(
"-p cashu"
"-p cdk-common"
"-p cdk-http-client"
"-p cdk-npubcash"
"-p cdk-sql-common"
"-p cdk-sqlite"
"-p cdk-postgres"
"-p cdk-redb"
"-p cdk-signatory"
"-p cdk-fake-wallet"
"-p cdk"
"-p cdk-ffi"
"-p cdk-axum"
"-p cdk-mint-rpc"
"-p cdk-cln"
"-p cdk-lnd"
"-p cdk-lnbits"
"-p cdk-ldk-node"
"-p cdk-prometheus"
"-p cdk-payment-processor"
"-p cdk-cli"
"-p cdk-mintd"
)
for arg in "${args[@]}"; do
echo "Checking '$arg' docs"
cargo doc $arg --all-features
echo
done
# Build docs for all crates and error on warnings
docs-strict:
#!/usr/bin/env bash
set -euo pipefail
args=(
"-p cashu"
"-p cdk-common"
"-p cdk-http-client"
"-p cdk-npubcash"
"-p cdk-sql-common"
"-p cdk-sqlite"
"-p cdk-postgres"
"-p cdk-redb"
"-p cdk-signatory"
"-p cdk-fake-wallet"
"-p cdk"
"-p cdk-ffi"
"-p cdk-axum"
"-p cdk-mint-rpc"
"-p cdk-cln"
"-p cdk-lnd"
"-p cdk-lnbits"
"-p cdk-ldk-node"
"-p cdk-prometheus"
"-p cdk-payment-processor"
"-p cdk-cli"
"-p cdk-mintd"
)
for arg in "${args[@]}"; do
echo "Building docs for $arg with strict warnings"
RUSTDOCFLAGS="-D warnings" cargo doc $arg --all-features --no-deps
echo
done
# =============================================================================
# FFI Commands - CDK Foreign Function Interface bindings
# =============================================================================
# Helper function to get library extension based on platform
_ffi-lib-ext:
#!/usr/bin/env bash
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "dylib"
else
echo "so"
fi
# Build the FFI library
ffi-build *ARGS="--release":
#!/usr/bin/env bash
set -euo pipefail
if [[ "{{ARGS}}" == *"--debug"* ]]; then
cargo build --package cdk-ffi
else
cargo build {{ARGS}} --package cdk-ffi
fi
# Check the FFI crate
ffi-check:
cargo check --package cdk-ffi --all-targets
# Generate bindings for a specific language
ffi-generate LANGUAGE *ARGS="--release":
#!/usr/bin/env bash
set -euo pipefail
LANG="{{LANGUAGE}}"
# Validate language
case "$LANG" in
python|swift|kotlin)
;;
*)
echo "❌ Unsupported language: $LANG"
echo "Supported languages: python, swift, kotlin"
exit 1
;;
esac
# Set emoji and build type
case "$LANG" in
python) EMOJI="🐍" ;;
swift) EMOJI="🍎" ;;
kotlin) EMOJI="🎯" ;;
esac
# Determine build type and library path
if [[ "{{ARGS}}" == *"--release"* ]] || [[ "{{ARGS}}" == "" ]]; then
BUILD_TYPE="release"
else
BUILD_TYPE="debug"
fi
just ffi-build {{ARGS}}
LIB_EXT=$(just _ffi-lib-ext)
echo "$EMOJI Generating $LANG bindings..."
mkdir -p target/bindings/$LANG
cargo run -p cdk-ffi --bin uniffi-bindgen generate \
--library target/$BUILD_TYPE/libcdk_ffi.$LIB_EXT \
--language $LANG \
--out-dir target/bindings/$LANG \
--no-format
echo "✅ $LANG bindings generated in target/bindings/$LANG/"
# Generate Python bindings (shorthand)
ffi-generate-python *ARGS="--release":
just ffi-generate python {{ARGS}}
# Generate Swift bindings and set up SPM package for testing
ffi-generate-swift *ARGS="--release":
#!/usr/bin/env bash
set -euo pipefail
just ffi-generate swift {{ARGS}}
ROOT="{{justfile_directory()}}"
# Determine build type
if [[ "{{ARGS}}" == *"--release"* ]] || [[ "{{ARGS}}" == "" ]]; then
BUILD_TYPE="release"
else
BUILD_TYPE="debug"
fi
# Set up SPM-compatible directory structure for testing.
# Derive the FFI module name from the generated header so the on-disk
# directory matches the target path written into Package.swift below
# (the header name follows uniffi.toml's module_name, e.g. CashuDevKitFFI).
BINDINGS_DIR="$ROOT/target/bindings/swift"
SWIFT_SRC="$ROOT/Sources/Cdk"
HEADER_NAME=$(basename "$BINDINGS_DIR/"*FFI.h)
MODULE_NAME="${HEADER_NAME%.h}"
FFI_MODULE="$ROOT/Sources/${MODULE_NAME}"
mkdir -p "$SWIFT_SRC" "$FFI_MODULE"
# Copy generated Swift sources
cp "$BINDINGS_DIR/"*.swift "$SWIFT_SRC/"
# Copy generated FFI header and create modulemap.
# The modulemap generated by uniffi uses 'link' directives; replace with one
# that lets SPM link the dylib via Package.swift linkerSettings instead.
cp "$BINDINGS_DIR/"*FFI.h "$FFI_MODULE/"
printf 'module %s {\n header "%s"\n export *\n}\n' \
"${MODULE_NAME}" "${HEADER_NAME}" > "$FFI_MODULE/module.modulemap"
LIB_DIR="$ROOT/target/$BUILD_TYPE"
# Generate Package.swift for local testing
{
echo '// swift-tools-version: 5.9'
echo '// Auto-generated for local testing — do not commit'
echo 'import PackageDescription'
echo ''
echo 'let package = Package('
echo ' name: "cdk-swift",'
echo ' platforms: [.macOS(.v13)],'
echo ' products: ['
echo ' .library(name: "Cdk", targets: ["Cdk"]),'
echo ' ],'
echo ' targets: ['
echo ' .systemLibrary('
echo " name: \"${MODULE_NAME}\","
echo " path: \"Sources/${MODULE_NAME}\""
echo ' ),'
echo ' .target('
echo ' name: "Cdk",'
echo " dependencies: [\"${MODULE_NAME}\"],"
echo ' path: "Sources/Cdk",'
echo ' linkerSettings: ['
echo " .unsafeFlags([\"-L${LIB_DIR}\", \"-lcdk_ffi\"]),"
echo ' ]'
echo ' ),'
echo ' .testTarget('
echo ' name: "CdkTests",'
echo ' dependencies: ["Cdk"],'
echo ' path: "bindings/swift/Tests"'
echo ' ),'
echo ' ]'
echo ')'
} > "$ROOT/Package.swift"
echo "📦 SPM package ready for testing"
# Generate Kotlin bindings (shorthand)
ffi-generate-kotlin *ARGS="--release":
just ffi-generate kotlin {{ARGS}}
# Generate bindings for all supported languages
ffi-generate-all *ARGS="--release":
@echo "🔧 Generating UniFFI bindings for all languages..."
just ffi-generate python {{ARGS}}
just ffi-generate swift {{ARGS}}
just ffi-generate kotlin {{ARGS}}
@echo "✅ All bindings generated successfully!"
# Run Python FFI tests
ffi-test: ffi-generate-python
#!/usr/bin/env bash
set -euo pipefail
echo "🧪 Running Python FFI tests..."
python3 crates/cdk-ffi/tests/test_transactions.py
python3 crates/cdk-ffi/tests/test_kvstore.py
echo "✅ Tests completed!"
# Build debug version and generate Python bindings quickly (for development)
ffi-dev-python:
#!/usr/bin/env bash
set -euo pipefail
# Generate Python bindings first
just ffi-generate python --debug
# Copy library to Python bindings directory
LIB_EXT=$(just _ffi-lib-ext)
echo "📦 Copying library to Python bindings directory..."
cp target/debug/libcdk_ffi.$LIB_EXT target/bindings/python/
# Launch Python REPL with CDK FFI loaded
cd target/bindings/python
echo "🐍 Launching Python REPL with CDK FFI library loaded..."
echo "💡 The 'cdk_ffi' module is pre-imported and ready to use!"
python3 -i -c "from cdk_ffi import *; print('✅ CDK FFI library loaded successfully!');"
# Test language bindings with a simple import
ffi-test-bindings LANGUAGE: (ffi-generate LANGUAGE "--debug")
#!/usr/bin/env bash
set -euo pipefail
LANG="{{LANGUAGE}}"
LIB_EXT=$(just _ffi-lib-ext)
echo "📦 Copying library to $LANG bindings directory..."