justfile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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-sqlite/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. ./misc/fake_itests.sh "{{db}}" external_signatory
  69. ./misc/fake_itests.sh "{{db}}"
  70. test-nutshell:
  71. #!/usr/bin/env bash
  72. 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
  73. # Wait for the Nutshell service to be ready
  74. echo "Waiting for Nutshell to start..."
  75. max_attempts=30
  76. attempt=0
  77. while ! curl -s http://127.0.0.1:3338/v1/info > /dev/null; do
  78. attempt=$((attempt+1))
  79. if [ $attempt -ge $max_attempts ]; then
  80. echo "Nutshell failed to start after $max_attempts attempts"
  81. docker stop nutshell
  82. docker rm nutshell
  83. exit 1
  84. fi
  85. echo "Waiting for Nutshell to start (attempt $attempt/$max_attempts)..."
  86. sleep 1
  87. done
  88. echo "Nutshell is ready!"
  89. export CDK_TEST_MINT_URL=http://127.0.0.1:3338
  90. export LN_BACKEND=FAKEWALLET
  91. cargo test -p cdk-integration-tests --test happy_path_mint_wallet
  92. cargo test -p cdk-integration-tests --test test_fees
  93. unset CDK_TEST_MINT_URL
  94. unset LN_BACKEND
  95. docker stop nutshell
  96. docker rm nutshell
  97. # run `cargo clippy` on everything
  98. clippy *ARGS="--locked --offline --workspace --all-targets":
  99. cargo clippy {{ARGS}}
  100. # run `cargo clippy --fix` on everything
  101. clippy-fix *ARGS="--locked --offline --workspace --all-targets":
  102. cargo clippy {{ARGS}} --fix
  103. typos:
  104. typos
  105. # fix all typos
  106. [no-exit-message]
  107. typos-fix:
  108. just typos -w
  109. itest db:
  110. #!/usr/bin/env bash
  111. ./misc/itests.sh "{{db}}"
  112. fake-mint-itest db:
  113. #!/usr/bin/env bash
  114. ./misc/fake_itests.sh "{{db}}" external_signatory
  115. ./misc/fake_itests.sh "{{db}}"
  116. itest-payment-processor ln:
  117. #!/usr/bin/env bash
  118. ./misc/mintd_payment_processor.sh "{{ln}}"
  119. fake-auth-mint-itest db openid_discovery:
  120. #!/usr/bin/env bash
  121. ./misc/fake_auth_itests.sh "{{db}}" "{{openid_discovery}}"
  122. nutshell-wallet-itest:
  123. #!/usr/bin/env bash
  124. ./misc/nutshell_wallet_itest.sh
  125. # Start interactive regtest environment (Bitcoin + 4 LN nodes + 2 CDK mints)
  126. regtest db="sqlite":
  127. #!/usr/bin/env bash
  128. ./misc/interactive_regtest.sh {{db}}
  129. # Start regtest with direct process management via mprocs (lets you start/stop mints)
  130. regtest-mprocs db="sqlite":
  131. #!/usr/bin/env bash
  132. ./misc/interactive_regtest_mprocs.sh {{db}}
  133. # Lightning Network Commands (require regtest environment to be running)
  134. # Get CLN node 1 info
  135. ln-cln1 *ARGS:
  136. #!/usr/bin/env bash
  137. ./misc/regtest_helper.sh ln-cln1 {{ARGS}}
  138. # Get CLN node 2 info
  139. ln-cln2 *ARGS:
  140. #!/usr/bin/env bash
  141. ./misc/regtest_helper.sh ln-cln2 {{ARGS}}
  142. # Get LND node 1 info
  143. ln-lnd1 *ARGS:
  144. #!/usr/bin/env bash
  145. ./misc/regtest_helper.sh ln-lnd1 {{ARGS}}
  146. # Get LND node 2 info
  147. ln-lnd2 *ARGS:
  148. #!/usr/bin/env bash
  149. ./misc/regtest_helper.sh ln-lnd2 {{ARGS}}
  150. # Bitcoin regtest commands
  151. btc *ARGS:
  152. #!/usr/bin/env bash
  153. ./misc/regtest_helper.sh btc {{ARGS}}
  154. # Mine blocks in regtest
  155. btc-mine blocks="10":
  156. #!/usr/bin/env bash
  157. ./misc/regtest_helper.sh btc-mine {{blocks}}
  158. # Show mint information
  159. mint-info:
  160. #!/usr/bin/env bash
  161. ./misc/regtest_helper.sh mint-info
  162. # Run integration tests against regtest environment
  163. mint-test:
  164. #!/usr/bin/env bash
  165. ./misc/regtest_helper.sh mint-test
  166. # Restart mints after recompiling (useful for development)
  167. restart-mints:
  168. #!/usr/bin/env bash
  169. ./misc/regtest_helper.sh restart-mints
  170. # Show regtest environment status
  171. regtest-status:
  172. #!/usr/bin/env bash
  173. ./misc/regtest_helper.sh show-status
  174. # Show regtest environment logs
  175. regtest-logs:
  176. #!/usr/bin/env bash
  177. ./misc/regtest_helper.sh show-logs
  178. run-examples:
  179. cargo r --example p2pk
  180. cargo r --example mint-token
  181. cargo r --example melt-token
  182. cargo r --example proof_selection
  183. cargo r --example wallet
  184. check-wasm *ARGS="--target wasm32-unknown-unknown":
  185. #!/usr/bin/env bash
  186. set -euo pipefail
  187. if [ ! -f Cargo.toml ]; then
  188. cd {{invocation_directory()}}
  189. fi
  190. buildargs=(
  191. "-p cdk"
  192. "-p cdk --no-default-features"
  193. "-p cdk --no-default-features --features wallet"
  194. "-p cdk --no-default-features --features mint"
  195. )
  196. for arg in "${buildargs[@]}"; do
  197. echo "Checking '$arg'"
  198. cargo check $arg {{ARGS}}
  199. echo
  200. done
  201. release m="":
  202. #!/usr/bin/env bash
  203. set -euo pipefail
  204. args=(
  205. "-p cashu"
  206. "-p cdk-common"
  207. "-p cdk-sqlite"
  208. "-p cdk-redb"
  209. "-p cdk-signatory"
  210. "-p cdk"
  211. "-p cdk-rexie"
  212. "-p cdk-axum"
  213. "-p cdk-mint-rpc"
  214. "-p cdk-cln"
  215. "-p cdk-lnd"
  216. "-p cdk-lnbits"
  217. "-p cdk-fake-wallet"
  218. "-p cdk-payment-processor"
  219. "-p cdk-cli"
  220. "-p cdk-mintd"
  221. )
  222. for arg in "${args[@]}";
  223. do
  224. echo "Publishing '$arg'"
  225. cargo publish $arg {{m}}
  226. echo
  227. done
  228. check-docs:
  229. #!/usr/bin/env bash
  230. set -euo pipefail
  231. args=(
  232. "-p cashu"
  233. "-p cdk-common"
  234. "-p cdk"
  235. "-p cdk-redb"
  236. "-p cdk-sqlite"
  237. "-p cdk-axum"
  238. "-p cdk-rexie"
  239. "-p cdk-cln"
  240. "-p cdk-lnd"
  241. "-p cdk-lnbits"
  242. "-p cdk-fake-wallet"
  243. "-p cdk-mint-rpc"
  244. "-p cdk-signatory"
  245. "-p cdk-cli"
  246. "-p cdk-mintd"
  247. )
  248. for arg in "${args[@]}"; do
  249. echo "Checking '$arg' docs"
  250. cargo doc $arg --all-features
  251. echo
  252. done
  253. # Build docs for all crates and error on warnings
  254. docs-strict:
  255. #!/usr/bin/env bash
  256. set -euo pipefail
  257. args=(
  258. "-p cashu"
  259. "-p cdk-common"
  260. "-p cdk"
  261. "-p cdk-redb"
  262. "-p cdk-sqlite"
  263. "-p cdk-axum"
  264. "-p cdk-rexie"
  265. "-p cdk-cln"
  266. "-p cdk-lnd"
  267. "-p cdk-lnbits"
  268. "-p cdk-fake-wallet"
  269. "-p cdk-mint-rpc"
  270. "-p cdk-payment-processor"
  271. "-p cdk-cli"
  272. "-p cdk-mintd"
  273. )
  274. for arg in "${args[@]}"; do
  275. echo "Building docs for $arg with strict warnings"
  276. RUSTDOCFLAGS="-D warnings" cargo doc $arg --all-features --no-deps
  277. echo
  278. done