diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a47c0a56..7f4258d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,6 @@ jobs: -p cdk-integration-tests, --bin cdk-cli, --bin cdk-mintd, - --examples ] steps: - name: Checkout @@ -96,3 +95,33 @@ jobs: run: cargo build ${{ matrix.build-args }} --target wasm32-unknown-unknown - name: Clippy run: cargo clippy ${{ matrix.build-args }} --target wasm32-unknown-unknown -- -D warnings + + run-examples: + name: Run Examples + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - version: stable + build-args: + [ + mint-token, + p2pk, + proof-selection, + wallet + ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-wasm32-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} + - name: Set default toolchain + run: rustup default ${{ matrix.rust.version }} + - name: Run + run: cargo run --example ${{ matrix.build-args }} diff --git a/crates/cdk-integration-tests/tests/mint.rs b/crates/cdk-integration-tests/tests/mint.rs index e60a78d4..bd0d7cd8 100644 --- a/crates/cdk-integration-tests/tests/mint.rs +++ b/crates/cdk-integration-tests/tests/mint.rs @@ -26,7 +26,7 @@ pub async fn test_mint_double_receive() -> Result<()> { let mnemonic = Mnemonic::generate(12)?; let wallet = Wallet::new( - &MINT_URL, + MINT_URL, CurrencyUnit::Sat, Arc::new(WalletMemoryDatabase::default()), &mnemonic.to_seed_normalized(""), @@ -51,7 +51,7 @@ pub async fn test_mint_double_receive() -> Result<()> { let mnemonic = Mnemonic::generate(12)?; let wallet_two = Wallet::new( - &MINT_URL, + MINT_URL, CurrencyUnit::Sat, Arc::new(WalletMemoryDatabase::default()), &mnemonic.to_seed_normalized(""), diff --git a/crates/cdk-integration-tests/tests/p2pk.rs b/crates/cdk-integration-tests/tests/p2pk.rs index ee9e6198..964b788d 100644 --- a/crates/cdk-integration-tests/tests/p2pk.rs +++ b/crates/cdk-integration-tests/tests/p2pk.rs @@ -22,7 +22,7 @@ pub async fn test_p2pk_swap() -> Result<()> { let mnemonic = Mnemonic::generate(12)?; let wallet = Wallet::new( - &MINT_URL, + MINT_URL, CurrencyUnit::Sat, Arc::new(WalletMemoryDatabase::default()), &mnemonic.to_seed_normalized(""), diff --git a/crates/cdk/Cargo.toml b/crates/cdk/Cargo.toml index 77696161..b399e585 100644 --- a/crates/cdk/Cargo.toml +++ b/crates/cdk/Cargo.toml @@ -70,7 +70,7 @@ name = "wallet" required-features = ["wallet"] [[example]] -name = "proof_selection" +name = "proof-selection" required-features = ["wallet"] [dev-dependencies] diff --git a/crates/cdk/examples/proof_selection.rs b/crates/cdk/examples/proof-selection.rs similarity index 100% rename from crates/cdk/examples/proof_selection.rs rename to crates/cdk/examples/proof-selection.rs diff --git a/flake.nix b/flake.nix index fc54a62b..ece16669 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ name = "cdk"; path = ./.; }; - paths = [ "crates/cashu" "crates/cashu-sdk" ]; + paths = [ "crates/*" ]; }; targetsStd = flakeboxLib.mkStdTargets { }; diff --git a/justfile b/justfile index 5203eb71..e28c3260 100644 --- a/justfile +++ b/justfile @@ -1,4 +1,5 @@ # THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION +import "./misc/justfile.custom.just" alias b := build alias c := check @@ -9,18 +10,6 @@ alias t := test default: @just --list -# Execute a partial check (MSRV is not checked) -precommit: - @bash misc/scripts/precommit.sh - -# Format the entire Rust code -fmt: - @bash misc/scripts/check-fmt.sh - -# Check if the Rust code is formatted -check-fmt: - @bash misc/scripts/check-fmt.sh check - # run `cargo build` on everything build *ARGS="--workspace --all-targets": #!/usr/bin/env bash @@ -42,7 +31,7 @@ check *ARGS="--workspace --all-targets": # run all checks recommended before opening a PR -final-check: lint clippy +final-check: lint clippy check-wasm #!/usr/bin/env bash set -euo pipefail if [ ! -f Cargo.toml ]; then diff --git a/misc/justfile.custom.just b/misc/justfile.custom.just new file mode 100644 index 00000000..d1995b1d --- /dev/null +++ b/misc/justfile.custom.just @@ -0,0 +1,56 @@ +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" + "-p cdk-js" + ) + + for arg in "${buildargs[@]}"; do + echo "Checking '$arg'" + cargo check $arg {{ARGS}} + echo + done + +run-examples: + cargo r --example p2pk + cargo r --example mint-token + cargo r --example proof_selection + cargo r --example wallet + +clippy-each: + #!/usr/bin/env bash + set -euo pipefail + buildargs=( + "-p cdk-integration-tests" + "-p cdk" + "-p cdk --no-default-features" + "-p cdk --no-default-features --features wallet" + "-p cdk --no-default-features --features mint" + "-p cdk-redb" + "-p cdk-redb --no-default-features --features wallet" + "-p cdk-redb --no-default-features --features mint" + "-p cdk-sqlite --no-default-features --features mint" + "-p cdk-sqlite --no-default-features --features wallet" + "-p cdk-cln" + "-p cdk-axum" + "-p cdk-fake-wallet" + "-p cdk-strike" + "--bin cdk-cli" + "--bin cdk-mintd" + ) + + for arg in "${buildargs[@]}"; do + echo "Checking '$arg'" + cargo check $arg + cargo clippy $arg -- -D warnings + echo + done diff --git a/misc/scripts/check-bindings.sh b/misc/scripts/check-bindings.sh deleted file mode 100755 index 0dd8a922..00000000 --- a/misc/scripts/check-bindings.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Check bindings -buildargs=( - "-p cdk-js --target wasm32-unknown-unknown" -) - -for arg in "${buildargs[@]}"; do - echo "Checking '$arg'" - - cargo build $arg - - if [[ $arg != *"--target wasm32-unknown-unknown"* ]]; - then - cargo test $arg - fi - - cargo clippy $arg -- -D warnings - - echo -done diff --git a/misc/scripts/check-crates.sh b/misc/scripts/check-crates.sh deleted file mode 100755 index 25ccfab7..00000000 --- a/misc/scripts/check-crates.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# MSRV -msrv="1.70.0" - -is_msrv=false -version="" - -# Check if "msrv" is passed as an argument -if [[ "$#" -gt 0 && "$1" == "msrv" ]]; then - is_msrv=true - version="+$msrv" -fi - -# Check if MSRV -if [ "$is_msrv" == true ]; then - # Install MSRV - rustup install $msrv - rustup component add clippy --toolchain $msrv - rustup target add wasm32-unknown-unknown --toolchain $msrv -fi - -buildargs=( - "-p cdk-integration-tests" - "-p cdk" - "-p cdk --no-default-features" - "-p cdk --no-default-features --features wallet" - "-p cdk --no-default-features --features mint" - "-p cdk-redb" - "-p cdk-redb --no-default-features --features wallet" - "-p cdk-redb --no-default-features --features mint" - "-p cdk-sqlite --no-default-features --features mint" - "-p cdk-sqlite --no-default-features --features wallet" - "-p cdk-cln" - "-p cdk-axum" - "-p cdk-fake-wallet" - "-p cdk-strike" - "--bin cdk-cli" - "--bin cdk-mintd" - "--examples" -) - -for arg in "${buildargs[@]}"; do - if [[ $version == "" ]]; then - echo "Checking '$arg' [default]" - else - echo "Checking '$arg' [$version]" - fi - cargo $version check $arg - if [[ $arg != *"--target wasm32-unknown-unknown"* ]]; then - cargo $version test $arg - fi - cargo $version clippy $arg -- -D warnings - echo -done diff --git a/misc/scripts/check-docs.sh b/misc/scripts/check-docs.sh deleted file mode 100755 index 08069633..00000000 --- a/misc/scripts/check-docs.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -buildargs=( - "-p cdk" -) - -for arg in "${buildargs[@]}"; do - echo "Checking '$arg' docs" - cargo doc $arg --all-features - echo -done diff --git a/misc/scripts/check-fmt.sh b/misc/scripts/check-fmt.sh deleted file mode 100755 index b55f977a..00000000 --- a/misc/scripts/check-fmt.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -flags="" - -# Check if "check" is passed as an argument -if [[ "$#" -gt 0 && "$1" == "check" ]]; then - flags="--check" -fi - - -# Check workspace crates -cargo fmt --all -- --config format_code_in_doc_comments=true $flags diff --git a/misc/scripts/check.sh b/misc/scripts/check.sh deleted file mode 100755 index fe34ff96..00000000 --- a/misc/scripts/check.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -exuo pipefail - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -"${DIR}/check-fmt.sh" check # Check if Rust code is formatted -"${DIR}/check-crates.sh" # Check all crates -"${DIR}/check-crates.sh" msrv # Check all crates MSRV -"${DIR}/check-bindings.sh" # Check all bindings -"${DIR}/check-docs.sh" # Check Rust docs diff --git a/misc/scripts/precommit.sh b/misc/scripts/precommit.sh deleted file mode 100755 index 5c0d9c0f..00000000 --- a/misc/scripts/precommit.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -exuo pipefail - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -typos -"${DIR}/check-fmt.sh" # Format the code -"${DIR}/check-crates.sh" # Check all crates -"${DIR}/check-bindings.sh" # Check all bindings -"${DIR}/check-docs.sh" # Check Rust docs diff --git a/misc/scripts/release.sh b/misc/scripts/release.sh deleted file mode 100644 index e9792434..00000000 --- a/misc/scripts/release.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -args=( - "-p cdk" - "-p cdk-redb" - "-p cdk-sqlite" - "-p cdk-rexie" - "-p cdk-cln" - "-p cdk-fake-wallet" - "-p cdk-strike" - "-p cdk-cli" - "-p cdk-axum" - "-p cdk-mintd" -) - -for arg in "${args[@]}"; -do - echo "Publishing '$arg'" - cargo publish "$arg" - echo -done