Selaa lähdekoodia

feat: unit test on features (#1467)

tsk 2 viikkoa sitten
vanhempi
säilyke
5081d9ef08
4 muutettua tiedostoa jossa 55 lisäystä ja 47 poistoa
  1. 13 12
      .github/workflows/ci.yml
  2. 2 0
      crates/cdk-mintd/src/config.rs
  3. 3 4
      crates/cdk-mintd/src/lib.rs
  4. 37 31
      flake.nix

+ 13 - 12
.github/workflows/ci.yml

@@ -83,9 +83,9 @@ jobs:
           BINARY_NAME="${BINARY_NAME#example-}"
           ./result/bin/$BINARY_NAME
 
-  # Discover clippy checks from flake - single source of truth
+  # Discover clippy + test checks from flake - single source of truth
   discover-checks:
-    name: "Discover clippy checks"
+    name: "Discover checks"
     runs-on: self-hosted
     timeout-minutes: 5
     outputs:
@@ -93,7 +93,7 @@ jobs:
     steps:
       - name: checkout
         uses: actions/checkout@v4
-      - name: Get clippy check names
+      - name: Get check names
         id: checks
         run: |
           # Get all check names except pre-commit-check, example-*, msrv-*, wasm-*, doc-tests, strict-docs, ffi-tests
@@ -102,9 +102,10 @@ jobs:
           echo "checks=$checks" >> $GITHUB_OUTPUT
           echo "Found checks: $checks"
 
-  # Dynamic clippy matrix - uses cached deps from Cachix
-  clippy:
-    name: "Clippy: ${{ matrix.check }}"
+  # Dynamic clippy + test matrix - uses cached deps from Cachix
+  # Each check runs both clippy and unit tests for that crate/feature combination
+  clippy-and-test:
+    name: "Check: ${{ matrix.check }}"
     runs-on: self-hosted
     timeout-minutes: 30
     needs: [pre-commit-checks, discover-checks]
@@ -121,12 +122,12 @@ jobs:
           authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
           useDaemon: false
         continue-on-error: true
-      - name: Run clippy check
+      - name: Run clippy and tests
         run: nix build -L .#checks.x86_64-linux.${{ matrix.check }}
 
-  # Run tests using nix develop (tests need to execute, not just build)
-  tests:
-    name: "Tests"
+  # Tests that require a running PostgreSQL instance
+  postgres-tests:
+    name: "PostgreSQL Tests"
     runs-on: self-hosted
     timeout-minutes: 30
     needs: pre-commit-checks
@@ -139,8 +140,8 @@ jobs:
           authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
           useDaemon: false
         continue-on-error: true
-      - name: Run workspace tests
-        run: nix develop -i -L .#stable --command bash -c "start-postgres && cargo test --workspace --exclude cdk-integration-tests"
+      - name: Run clippy and tests for cdk-postgres
+        run: nix develop -i -L .#stable --command bash -c "start-postgres && cargo clippy -p cdk-postgres -- -D warnings && cargo test -p cdk-postgres"
 
   regtest-itest:
     name: "Integration regtest tests"

+ 2 - 0
crates/cdk-mintd/src/config.rs

@@ -373,10 +373,12 @@ impl Default for FakeWallet {
 
 // Helper functions to provide default values
 // Common fee defaults for all backends
+#[cfg(any(feature = "cln", feature = "lnbits", feature = "lnd"))]
 fn default_fee_percent() -> f32 {
     0.02
 }
 
+#[cfg(any(feature = "cln", feature = "lnbits", feature = "lnd"))]
 fn default_reserve_fee_min() -> Amount {
     2.into()
 }

+ 3 - 4
crates/cdk-mintd/src/lib.rs

@@ -30,8 +30,7 @@ use cdk::nuts::nut19::{CachedEndpoint, Method as NUT19Method, Path as NUT19Path}
     feature = "cln",
     feature = "lnbits",
     feature = "lnd",
-    feature = "ldk-node",
-    feature = "fakewallet"
+    feature = "ldk-node"
 ))]
 use cdk::nuts::CurrencyUnit;
 #[cfg(feature = "auth")]
@@ -881,7 +880,7 @@ async fn build_mint(
 async fn start_services_with_shutdown(
     mint: Arc<cdk::mint::Mint>,
     settings: &config::Settings,
-    work_dir: &Path,
+    _work_dir: &Path,
     mint_builder_info: cdk::nuts::MintInfo,
     shutdown_signal: impl std::future::Future<Output = ()> + Send + 'static,
     routers: Vec<Router>,
@@ -907,7 +906,7 @@ async fn start_services_with_shutdown(
                 let port = rpc_settings.port.unwrap_or(8086);
                 let mut mint_rpc = cdk_mint_rpc::MintRPCServer::new(&addr, port, mint.clone())?;
 
-                let tls_dir = rpc_settings.tls_dir_path.unwrap_or(work_dir.join("tls"));
+                let tls_dir = rpc_settings.tls_dir_path.unwrap_or(_work_dir.join("tls"));
 
                 let tls_dir = if tls_dir.exists() {
                     Some(tls_dir)

+ 37 - 31
flake.nix

@@ -170,11 +170,16 @@
           cargoExtraArgs = "--workspace";
         });
 
-        # Helper function to create clippy checks
-        mkClippy = name: cargoArgs: craneLib.cargoClippy (commonCraneArgs // {
-          pname = "cdk-clippy-${name}";
+        # Helper function to create combined clippy + test checks
+        # Runs both in a single derivation to share build artifacts
+        mkClippyAndTest = name: cargoArgs: craneLib.mkCargoDerivation (commonCraneArgs // {
+          pname = "cdk-check-${name}";
           cargoArtifacts = workspaceDeps;
-          cargoClippyExtraArgs = "${cargoArgs} -- -D warnings";
+          buildPhaseCargoCommand = ''
+            cargo clippy ${cargoArgs} -- -D warnings
+            cargo test ${cargoArgs}
+          '';
+          installPhaseCommand = "mkdir -p $out";
         });
 
         # Helper function to create example checks (compile only, no network access in sandbox)
@@ -292,9 +297,10 @@
         ];
 
         # ========================================
-        # Clippy check definitions - single source of truth
+        # Clippy + test check definitions - single source of truth
+        # These run both clippy and unit tests in a single derivation
         # ========================================
-        clippyChecks = {
+        clippyAndTestChecks = {
           # Core crate: cashu
           "cashu" = "-p cashu";
           "cashu-no-default" = "-p cashu --no-default-features";
@@ -347,31 +353,31 @@
           "cdk-ffi" = "-p cdk-ffi";
 
           # Binaries: cdk-cli
-          "bin-cdk-cli" = "--bin cdk-cli";
-          "bin-cdk-cli-sqlcipher" = "--bin cdk-cli --features sqlcipher";
-          "bin-cdk-cli-redb" = "--bin cdk-cli --features redb";
+          "cdk-cli" = "-p cdk-cli";
+          "cdk-cli-sqlcipher" = "-p cdk-cli --features sqlcipher";
+          "cdk-cli-redb" = "-p cdk-cli --features redb";
 
           # Binaries: cdk-mintd
-          "bin-cdk-mintd" = "--bin cdk-mintd";
-          "bin-cdk-mintd-redis" = "--bin cdk-mintd --features redis";
-          "bin-cdk-mintd-sqlcipher" = "--bin cdk-mintd --features sqlcipher";
-          "bin-cdk-mintd-lnd-sqlite" = "--bin cdk-mintd --no-default-features --features lnd,sqlite";
-          "bin-cdk-mintd-cln-postgres" = "--bin cdk-mintd --no-default-features --features cln,postgres";
-          "bin-cdk-mintd-lnbits-sqlite" = "--bin cdk-mintd --no-default-features --features lnbits,sqlite";
-          "bin-cdk-mintd-fakewallet-sqlite" = "--bin cdk-mintd --no-default-features --features fakewallet,sqlite";
-          "bin-cdk-mintd-grpc-processor-sqlite" = "--bin cdk-mintd --no-default-features --features grpc-processor,sqlite";
-          "bin-cdk-mintd-management-rpc-lnd-sqlite" = "--bin cdk-mintd --no-default-features --features management-rpc,lnd,sqlite";
-          "bin-cdk-mintd-cln-sqlite" = "--bin cdk-mintd --no-default-features --features cln,sqlite";
-          "bin-cdk-mintd-lnd-postgres" = "--bin cdk-mintd --no-default-features --features lnd,postgres";
-          "bin-cdk-mintd-lnbits-postgres" = "--bin cdk-mintd --no-default-features --features lnbits,postgres";
-          "bin-cdk-mintd-fakewallet-postgres" = "--bin cdk-mintd --no-default-features --features fakewallet,postgres";
-          "bin-cdk-mintd-grpc-processor-postgres" = "--bin cdk-mintd --no-default-features --features grpc-processor,postgres";
-          "bin-cdk-mintd-management-rpc-cln-postgres" = "--bin cdk-mintd --no-default-features --features management-rpc,cln,postgres";
-          "bin-cdk-mintd-auth-sqlite-fakewallet" = "--bin cdk-mintd --no-default-features --features auth,sqlite,fakewallet";
-          "bin-cdk-mintd-auth-postgres-lnd" = "--bin cdk-mintd --no-default-features --features auth,postgres,lnd";
-
-          # Binaries: cdk-mint-cli
-          "bin-cdk-mint-cli" = "--bin cdk-mint-cli";
+          "cdk-mintd" = "-p cdk-mintd";
+          "cdk-mintd-redis" = "-p cdk-mintd --features redis";
+          "cdk-mintd-sqlcipher" = "-p cdk-mintd --features sqlcipher";
+          "cdk-mintd-lnd-sqlite" = "-p cdk-mintd --no-default-features --features lnd,sqlite";
+          "cdk-mintd-cln-postgres" = "-p cdk-mintd --no-default-features --features cln,postgres";
+          "cdk-mintd-lnbits-sqlite" = "-p cdk-mintd --no-default-features --features lnbits,sqlite";
+          "cdk-mintd-fakewallet-sqlite" = "-p cdk-mintd --no-default-features --features fakewallet,sqlite";
+          "cdk-mintd-grpc-processor-sqlite" = "-p cdk-mintd --no-default-features --features grpc-processor,sqlite";
+          "cdk-mintd-management-rpc-lnd-sqlite" = "-p cdk-mintd --no-default-features --features management-rpc,lnd,sqlite";
+          "cdk-mintd-cln-sqlite" = "-p cdk-mintd --no-default-features --features cln,sqlite";
+          "cdk-mintd-lnd-postgres" = "-p cdk-mintd --no-default-features --features lnd,postgres";
+          "cdk-mintd-lnbits-postgres" = "-p cdk-mintd --no-default-features --features lnbits,postgres";
+          "cdk-mintd-fakewallet-postgres" = "-p cdk-mintd --no-default-features --features fakewallet,postgres";
+          "cdk-mintd-grpc-processor-postgres" = "-p cdk-mintd --no-default-features --features grpc-processor,postgres";
+          "cdk-mintd-management-rpc-cln-postgres" = "-p cdk-mintd --no-default-features --features management-rpc,cln,postgres";
+          "cdk-mintd-auth-sqlite-fakewallet" = "-p cdk-mintd --no-default-features --features auth,sqlite,fakewallet";
+          "cdk-mintd-auth-postgres-lnd" = "-p cdk-mintd --no-default-features --features auth,postgres,lnd";
+
+          # Binaries: cdk-mint-cli (binary name, package is cdk-mint-rpc)
+          "cdk-mint-cli" = "-p cdk-mint-rpc";
         };
 
         # ========================================
@@ -537,8 +543,8 @@
         # Example packages (binaries that can be run outside sandbox with network access)
         // (builtins.listToAttrs (map (name: { name = "example-${name}"; value = mkExamplePackage name; }) exampleChecks));
         checks =
-          # Generate clippy checks from clippyChecks attrset
-          (builtins.mapAttrs (name: args: mkClippy name args) clippyChecks)
+          # Generate clippy + test checks from clippyAndTestChecks attrset
+          (builtins.mapAttrs (name: args: mkClippyAndTest name args) clippyAndTestChecks)
           # Generate MSRV build checks (prefixed with msrv-)
           // (builtins.listToAttrs (map (name: { name = "msrv-${name}"; value = mkMsrvBuild name msrvChecks.${name}; }) (builtins.attrNames msrvChecks)))
           # Generate WASM build checks (prefixed with wasm-)