Skip to content

Commit

Permalink
[ADP-3288] Extract unit tests and lib into a separate cabal package (#…
Browse files Browse the repository at this point in the history
…4457)

Part of the cabal decomposition epic that will bring a correct HLS
experience when working with "leaf" code (latency-benchmark i.e.) .
Without this work HLS reports false positive of overlapping instances

For some reasons the unit tests are monolithic and testing multiple
libraries. Further work has to be done to separate them and bring them
back next to the lib they test.

While fixing the nix code, I noticed the previous PR on breaking out
integration tests in a separate cabal package missed the nix fix.

- [x] Extract unit tests in a separate cabal package
- [x] Fix nix setup for integration tests
- [x] Update docs on how to run tests via nix develop and just
- [x] Move test data relative to the api bench to the `benchmarks`
package

ADP-3288
  • Loading branch information
paolino authored Feb 20, 2024
2 parents 144be75 + 32f07fd commit 362fdca
Show file tree
Hide file tree
Showing 306 changed files with 352 additions and 278 deletions.
3 changes: 2 additions & 1 deletion .buildkite/bench-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ echo "--- Build"
nix --version

nix build .#ci.benchmarks.api -o bench-api
bench="./bench-api/bin/api lib/wallet/test/data/api-bench"
bench="./bench-api/bin/api lib/benchmarks/data/api-bench"


echo "--- Run benchmark"

Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cabal.project.freeze linguist-generated=true
# - they clog up the GitHub PR review page.
# Also set the "binary" merge mode for Git,
# because textual merging of auto-generated JSON rarely works well.
lib/wallet/test/data/Cardano/Wallet/**/*.json linguist-generated=true merge=binary
lib/unit/test/data/Cardano/Wallet/**/*.json linguist-generated=true merge=binary

# Include documentation in code stats
*.md linguist-detectable
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ packages:
lib/temporary-extra/
lib/test-utils/
lib/text-class/
lib/unit/
lib/wai-middleware-logging/
lib/wallet-benchmarks/
lib/wallet/
Expand Down
41 changes: 27 additions & 14 deletions docs/site/src/contributor/how/testing.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
# Testing

## Pre-requisites for a fast development cycle

Enter a valid shell with:
```
nix develop
```
before running the tests. This will bring into scope all the necessary tools and dependencies.


## Unit Tests

```
$ cabal test cardano-wallet:unit
just unit-tests-cabal
```

Alternatively, one can run tests of a particular module by running:
### matching the test title

```
$ cabal test cardano-wallet:unit --test-options "--match MyModule"
just unit-test-cabal-match "something matching the title"
```

## Integration Tests

#### Pre-requisites

Install [`cardano-node`](https://docs.cardano.org/projects/cardano-node/en/latest/getting-started/install.html) and [`cardano-cli`](https://docs.cardano.org/projects/cardano-node/en/latest/getting-started/install.html); make sure to use one of the [compatible versions](https://github.com/cardano-foundation/cardano-wallet/blob/master/README.md#latest-releases).

Alternatively, use `cabal test all -j8`.
## babbage era
```
just babbage-integration-tests-cabal
```

#### Test
### matching the test title
```
just babbage-integration-tests-cabal-match "something matching the title"
```

## conway era
```
$ cabal test cardano-wallet:integration
just conway-integration-tests-cabal
```

Many tests require a cardano network with stake pools. To support
this, the integration tests run a local `cardano-node` cluster with
one Ouroboros BFT node and three Ouroboros Praos nodes for the three
stake pools.
### matching the test title
```
just conway-integration-tests-cabal-match "something matching the title"
```

#### Environment Variables
## Environment Variables

Several environment variables control debugging features of the
integration tests and test cluster.
Expand Down
47 changes: 28 additions & 19 deletions hie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ cradle:
- path: "lib/faucet/exe/Faucet.hs"
component: "faucet:exe:faucet"

- path: "lib/integration/framework"
component: "cardano-wallet-integration:lib:framework"

- path: "lib/integration/scenarios"
component: "cardano-wallet-integration:lib:scenarios"

- path: "lib/integration/./integration-tests-exe.hs"
component: "cardano-wallet-integration:exe:integration-exe"

- path: "lib/integration/./"
component: "cardano-wallet-integration:test:integration"

- path: "lib/iohk-monitoring-extra/src"
component: "lib:iohk-monitoring-extra"

Expand Down Expand Up @@ -126,6 +138,12 @@ cradle:
- path: "lib/read/test"
component: "cardano-wallet-read:test:test"

- path: "lib/secrets/src"
component: "lib:cardano-wallet-secrets"

- path: "lib/secrets/test"
component: "cardano-wallet-secrets:test:test"

- path: "lib/std-gen-seed/src"
component: "lib:std-gen-seed"

Expand All @@ -147,6 +165,15 @@ cradle:
- path: "lib/text-class/test/unit"
component: "text-class:test:unit"

- path: "lib/unit/test-common"
component: "cardano-wallet-unit:lib:test-common"

- path: "lib/unit/test/unit"
component: "cardano-wallet-unit:test:unit"

- path: "lib/unit/test/data"
component: "cardano-wallet-unit:test:unit"

- path: "lib/wai-middleware-logging/src"
component: "lib:wai-middleware-logging"

Expand All @@ -168,28 +195,10 @@ cradle:
- path: "lib/wallet/./exe/mock-token-metadata-server.hs"
component: "cardano-wallet:exe:mock-token-metadata-server"

- path: "lib/wallet/test-common"
component: "cardano-wallet:lib:test-common"

- path: "lib/wallet/test/unit"
component: "cardano-wallet:test:unit"

- path: "lib/wallet/test/data"
component: "cardano-wallet:test:unit"

- path: "lib/integration/framework"
component: "cardano-wallet-integration:lib:framework"

- path: "lib/integration/scenarios"
component: "cardano-wallet-integration:lib:scenarios"

- path: "lib/integration/exe/integration-tests-exe.hs"
component: "cardano-wallet-integration:exe:integration-exe"

- path: "lib/wallet-benchmarks/bench/memory-benchmark.hs"
component: "cardano-wallet-blackbox-benchmarks:bench:memory"

- path: "lib/wallet-benchmarks/bench/Paths_cardano_wallet_benchmarks.hs"
- path: "lib/wallet-benchmarks/bench/Paths_cardano_wallet_blackbox_benchmarks.hs"
component: "cardano-wallet-blackbox-benchmarks:bench:memory"

- path: "lib/wallet-e2e/src"
Expand Down
12 changes: 8 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ local-cluster:
-c "local-cluster" \
--cluster-configs lib/local-cluster/test/data/cluster-configs

# run unit tests
unit:
cabal run cardano-wallet:test:unit \
--test-options '--cluster-configs lib/local-cluster/test/data/cluster-configs'
# run unit tests on a match
unit-tests-cabal-match match:
LOCAL_CLUSTER_CONFIGS=../../lib/local-cluster/test/data/cluster-configs \
cabal test cardano-wallet-unit:unit -O0 -v0 \
--test-options '--match="{{match}}"'

# run unit tests
unit-tests-cabal:
just unit-tests-cabal-match ""
# run wallet-e2e suite against the preprod network
e2e-preprod:
nix run '.#cardano-wallet-e2e' -- preprod \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ pingPong_2 = PartialTx
-- | A collection of signed transaction bytestrings useful for testing.
--
-- These bytestrings can be regenerated by running the integration tests
-- with lib/wallet/test/data/signedTxs/genData.patch applied.
-- with lib/unit/test/data/signedTxs/genData.patch applied.
--
signedTxTestData :: IO [(FilePath, ByteString)]
signedTxTestData = do
Expand Down
6 changes: 4 additions & 2 deletions lib/benchmarks/cardano-wallet-benchmarks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ benchmark db
, cardano-wallet-read
, cardano-wallet-secrets
, cardano-wallet-test-utils
, cardano-wallet:{cardano-wallet, test-common}
, cardano-wallet-unit:test-common
, cardano-wallet:cardano-wallet
, containers
, contra-tracer
, criterion
Expand Down Expand Up @@ -193,7 +194,8 @@ benchmark api
, cardano-wallet-network-layer
, cardano-wallet-primitive
, cardano-wallet-read
, cardano-wallet:{cardano-wallet, test-common}
, cardano-wallet-unit:test-common
, cardano-wallet:cardano-wallet
, containers
, fmt
, iohk-monitoring
Expand Down
Loading

0 comments on commit 362fdca

Please sign in to comment.