justfile 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. alias b := build
  2. alias c := check
  3. alias t := test
  4. default:
  5. @just --list
  6. # Create a new SQL migration file
  7. new-migration target name:
  8. #!/usr/bin/env bash
  9. if [ "{{target}}" != "mint" ] && [ "{{target}}" != "wallet" ]; then
  10. echo "Error: target must be either 'mint' or 'wallet'"
  11. exit 1
  12. fi
  13. timestamp=$(date +%Y%m%d%H%M%S)
  14. migration_path="./crates/cdk-sql-common/src/{{target}}/migrations/${timestamp}_{{name}}.sql"
  15. # Create the file
  16. mkdir -p "$(dirname "$migration_path")"
  17. touch "$migration_path"
  18. echo "Created new migration: $migration_path"
  19. final-check: typos format clippy test
  20. # run `cargo build` on everything
  21. build *ARGS="--workspace --all-targets":
  22. #!/usr/bin/env bash
  23. set -euo pipefail
  24. if [ ! -f Cargo.toml ]; then
  25. cd {{invocation_directory()}}
  26. fi
  27. cargo build {{ARGS}}
  28. # run `cargo check` on everything
  29. check *ARGS="--workspace --all-targets":
  30. #!/usr/bin/env bash
  31. set -euo pipefail
  32. if [ ! -f Cargo.toml ]; then
  33. cd {{invocation_directory()}}
  34. fi
  35. cargo check {{ARGS}}
  36. # run code formatters
  37. format:
  38. #!/usr/bin/env bash
  39. set -euo pipefail
  40. if [ ! -f Cargo.toml ]; then
  41. cd {{invocation_directory()}}
  42. fi
  43. cargo fmt --all
  44. nixpkgs-fmt $(echo **.nix)
  45. # run doc tests
  46. test: build
  47. #!/usr/bin/env bash
  48. set -euo pipefail
  49. if [ ! -f Cargo.toml ]; then
  50. cd {{invocation_directory()}}
  51. fi
  52. cargo test --lib
  53. # Run pure integration tests
  54. cargo test -p cdk-integration-tests --test mint
  55. # run doc tests
  56. test-pure db="memory": build
  57. #!/usr/bin/env bash
  58. set -euo pipefail
  59. if [ ! -f Cargo.toml ]; then
  60. cd {{invocation_directory()}}
  61. fi
  62. # Run pure integration tests
  63. CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test integration_tests_pure -- --test-threads 1
  64. test-all db="memory":
  65. #!/usr/bin/env bash
  66. just test {{db}}
  67. ./misc/itests.sh "{{db}}"
  68. status=$?
  69. if [ $status -ne 0 ]; then
  70. echo "Failed test with status {$status}"
  71. exit $status
  72. fi
  73. ./misc/fake_itests.sh "{{db}}" external_signatory
  74. status=$?
  75. if [ $status -ne 0 ]; then
  76. echo "Failed test with status {$status}"
  77. exit $status
  78. fi
  79. ./misc/fake_itests.sh "{{db}}"
  80. exit $?
  81. test-nutshell:
  82. #!/usr/bin/env bash
  83. set -euo pipefail
  84. # Function to cleanup docker containers
  85. cleanup() {
  86. echo "Cleaning up docker containers..."
  87. docker stop nutshell 2>/dev/null || true
  88. docker rm nutshell 2>/dev/null || true
  89. unset CDK_ITESTS_DIR
  90. }
  91. # Trap to ensure cleanup happens on exit (success or failure)
  92. trap cleanup EXIT
  93. docker run -d -p 3338:3338 --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
  94. export CDK_ITESTS_DIR=$(mktemp -d)
  95. # Wait for the Nutshell service to be ready
  96. echo "Waiting for Nutshell to start..."
  97. max_attempts=30
  98. attempt=0
  99. while ! curl -s http://127.0.0.1:3338/v1/info > /dev/null; do
  100. attempt=$((attempt+1))
  101. if [ $attempt -ge $max_attempts ]; then
  102. echo "Nutshell failed to start after $max_attempts attempts"
  103. exit 1
  104. fi
  105. echo "Waiting for Nutshell to start (attempt $attempt/$max_attempts)..."
  106. sleep 1
  107. done
  108. echo "Nutshell is ready!"
  109. export CDK_TEST_MINT_URL=http://127.0.0.1:3338
  110. export LN_BACKEND=FAKEWALLET
  111. # Track test results
  112. test_exit_code=0
  113. # Run first test and capture exit code
  114. echo "Running happy_path_mint_wallet test..."
  115. if ! cargo test -p cdk-integration-tests --test happy_path_mint_wallet; then
  116. echo "ERROR: happy_path_mint_wallet test failed"
  117. test_exit_code=1
  118. fi
  119. # Run second test and capture exit code
  120. echo "Running test_fees test..."
  121. if ! cargo test -p cdk-integration-tests --test test_fees; then
  122. echo "ERROR: test_fees test failed"
  123. test_exit_code=1
  124. fi
  125. unset CDK_TEST_MINT_URL
  126. unset LN_BACKEND
  127. # Exit with error code if any test failed
  128. if [ $test_exit_code -ne 0 ]; then
  129. echo "One or more tests failed"
  130. exit $test_exit_code
  131. fi
  132. echo "All tests passed successfully"
  133. # run `cargo clippy` on everything
  134. clippy *ARGS="--locked --offline --workspace --all-targets":
  135. cargo clippy {{ARGS}}
  136. # run `cargo clippy --fix` on everything
  137. clippy-fix *ARGS="--locked --offline --workspace --all-targets":
  138. cargo clippy {{ARGS}} --fix
  139. typos:
  140. typos
  141. # fix all typos
  142. [no-exit-message]
  143. typos-fix:
  144. just typos -w
  145. # Goose AI Recipe Commands
  146. # Update changelog from staged changes using Goose AI
  147. goose-git-msg:
  148. #!/usr/bin/env bash
  149. goose run --recipe ./misc/recipes/git-commit-message.yaml --interactive
  150. # Create git message from staged changes using Goose AI
  151. goose-changelog-staged:
  152. #!/usr/bin/env bash
  153. goose run --recipe ./misc/recipes/changelog-update.yaml --interactive
  154. # Update changelog from recent commits using Goose AI
  155. # Usage: just goose-changelog-commits [number_of_commits]
  156. goose-changelog-commits *COMMITS="5":
  157. #!/usr/bin/env bash
  158. COMMITS={{COMMITS}} goose run --recipe ./misc/recipes/changelog-from-commits.yaml --interactive
  159. itest db:
  160. #!/usr/bin/env bash
  161. ./misc/itests.sh "{{db}}"
  162. exit $?
  163. fake-mint-itest db:
  164. #!/usr/bin/env bash
  165. ./misc/fake_itests.sh "{{db}}" external_signatory
  166. status=$?
  167. if [ $status -ne 0 ]; then
  168. echo "Failed test with status {$status}"
  169. exit $status
  170. fi
  171. ./misc/fake_itests.sh "{{db}}"
  172. exit $?
  173. itest-payment-processor ln:
  174. #!/usr/bin/env bash
  175. ./misc/mintd_payment_processor.sh "{{ln}}"
  176. fake-auth-mint-itest db openid_discovery:
  177. #!/usr/bin/env bash
  178. ./misc/fake_auth_itests.sh "{{db}}" "{{openid_discovery}}"
  179. nutshell-wallet-itest:
  180. #!/usr/bin/env bash
  181. ./misc/nutshell_wallet_itest.sh
  182. # Start interactive regtest environment (Bitcoin + 4 LN nodes + 2 CDK mints)
  183. regtest db="sqlite":
  184. #!/usr/bin/env bash
  185. ./misc/interactive_regtest_mprocs.sh {{db}}
  186. # Lightning Network Commands (require regtest environment to be running)
  187. # Get CLN node 1 info
  188. ln-cln1 *ARGS:
  189. #!/usr/bin/env bash
  190. ./misc/regtest_helper.sh ln-cln1 {{ARGS}}
  191. # Get CLN node 2 info
  192. ln-cln2 *ARGS:
  193. #!/usr/bin/env bash
  194. ./misc/regtest_helper.sh ln-cln2 {{ARGS}}
  195. # Get LND node 1 info
  196. ln-lnd1 *ARGS:
  197. #!/usr/bin/env bash
  198. ./misc/regtest_helper.sh ln-lnd1 {{ARGS}}
  199. # Get LND node 2 info
  200. ln-lnd2 *ARGS:
  201. #!/usr/bin/env bash
  202. ./misc/regtest_helper.sh ln-lnd2 {{ARGS}}
  203. # Bitcoin regtest commands
  204. btc *ARGS:
  205. #!/usr/bin/env bash
  206. ./misc/regtest_helper.sh btc {{ARGS}}
  207. # Mine blocks in regtest
  208. btc-mine blocks="10":
  209. #!/usr/bin/env bash
  210. ./misc/regtest_helper.sh btc-mine {{blocks}}
  211. # Show mint information
  212. mint-info:
  213. #!/usr/bin/env bash
  214. ./misc/regtest_helper.sh mint-info
  215. # Run integration tests against regtest environment
  216. mint-test:
  217. #!/usr/bin/env bash
  218. ./misc/regtest_helper.sh mint-test
  219. # Restart mints after recompiling (useful for development)
  220. restart-mints:
  221. #!/usr/bin/env bash
  222. ./misc/regtest_helper.sh restart-mints
  223. # Show regtest environment status
  224. regtest-status:
  225. #!/usr/bin/env bash
  226. ./misc/regtest_helper.sh show-status
  227. # Show regtest environment logs
  228. regtest-logs:
  229. #!/usr/bin/env bash
  230. ./misc/regtest_helper.sh show-logs
  231. run-examples:
  232. cargo r --example p2pk
  233. cargo r --example mint-token
  234. cargo r --example melt-token
  235. cargo r --example proof_selection
  236. cargo r --example wallet
  237. check-wasm *ARGS="--target wasm32-unknown-unknown":
  238. #!/usr/bin/env bash
  239. set -euo pipefail
  240. if [ ! -f Cargo.toml ]; then
  241. cd {{invocation_directory()}}
  242. fi
  243. buildargs=(
  244. "-p cdk"
  245. "-p cdk --no-default-features"
  246. "-p cdk --no-default-features --features wallet"
  247. "-p cdk --no-default-features --features mint"
  248. )
  249. for arg in "${buildargs[@]}"; do
  250. echo "Checking '$arg'"
  251. cargo check $arg {{ARGS}}
  252. echo
  253. done
  254. release m="":
  255. #!/usr/bin/env bash
  256. set -euo pipefail
  257. args=(
  258. "-p cashu"
  259. "-p cdk-common"
  260. "-p cdk-sqlite"
  261. "-p cdk-redb"
  262. "-p cdk-signatory"
  263. "-p cdk"
  264. "-p cdk-axum"
  265. "-p cdk-mint-rpc"
  266. "-p cdk-cln"
  267. "-p cdk-lnd"
  268. "-p cdk-lnbits"
  269. "-p cdk-fake-wallet"
  270. "-p cdk-payment-processor"
  271. "-p cdk-cli"
  272. "-p cdk-mintd"
  273. )
  274. for arg in "${args[@]}";
  275. do
  276. echo "Publishing '$arg'"
  277. cargo publish $arg {{m}}
  278. echo
  279. done
  280. check-docs:
  281. #!/usr/bin/env bash
  282. set -euo pipefail
  283. args=(
  284. "-p cashu"
  285. "-p cdk-common"
  286. "-p cdk"
  287. "-p cdk-redb"
  288. "-p cdk-sqlite"
  289. "-p cdk-axum"
  290. "-p cdk-cln"
  291. "-p cdk-lnd"
  292. "-p cdk-lnbits"
  293. "-p cdk-fake-wallet"
  294. "-p cdk-mint-rpc"
  295. "-p cdk-signatory"
  296. "-p cdk-cli"
  297. "-p cdk-mintd"
  298. )
  299. for arg in "${args[@]}"; do
  300. echo "Checking '$arg' docs"
  301. cargo doc $arg --all-features
  302. echo
  303. done
  304. # Build docs for all crates and error on warnings
  305. docs-strict:
  306. #!/usr/bin/env bash
  307. set -euo pipefail
  308. args=(
  309. "-p cashu"
  310. "-p cdk-common"
  311. "-p cdk"
  312. "-p cdk-redb"
  313. "-p cdk-sqlite"
  314. "-p cdk-axum"
  315. "-p cdk-cln"
  316. "-p cdk-lnd"
  317. "-p cdk-lnbits"
  318. "-p cdk-fake-wallet"
  319. "-p cdk-mint-rpc"
  320. "-p cdk-payment-processor"
  321. "-p cdk-cli"
  322. "-p cdk-mintd"
  323. )
  324. for arg in "${args[@]}"; do
  325. echo "Building docs for $arg with strict warnings"
  326. RUSTDOCFLAGS="-D warnings" cargo doc $arg --all-features --no-deps
  327. echo
  328. done