|
1 | 1 | # Tests Directory |
2 | 2 |
|
3 | | -This folder is reserved for integration and end-to-end tests as the project grows. |
| 3 | +This folder holds **integration tests that are compiled as part of the |
| 4 | +`tipjar` package** (`contracts/tipjar`), even though the files live at the |
| 5 | +repo root rather than under `contracts/tipjar/tests/`. |
4 | 6 |
|
5 | | -Current contract unit tests live in `contracts/tipjar/src/lib.rs` and use Soroban's testing framework. |
| 7 | +## Why the files are here, not under `contracts/tipjar/tests/` |
| 8 | + |
| 9 | +`pause_tests.rs` and `partial_pause_tests.rs` share a common harness in |
| 10 | +`tests/common/mod.rs`. Cargo compiles `mod common;` fresh into each |
| 11 | +`[[test]]` binary, so a single shared `tests/common/` directory is the |
| 12 | +simplest way to avoid duplicating the harness across two packages. |
| 13 | + |
| 14 | +Because Cargo's test auto-discovery only looks in a package's *own* |
| 15 | +`tests/` directory, these root-level files are **not** auto-discovered. |
| 16 | +They are wired in explicitly via `[[test]]` entries in |
| 17 | +`contracts/tipjar/Cargo.toml`: |
| 18 | + |
| 19 | +```toml |
| 20 | +[[test]] |
| 21 | +name = "pause_tests" |
| 22 | +path = "../../tests/pause_tests.rs" |
| 23 | + |
| 24 | +[[test]] |
| 25 | +name = "partial_pause_tests" |
| 26 | +path = "../../tests/partial_pause_tests.rs" |
| 27 | +``` |
| 28 | + |
| 29 | +## How to verify the wiring |
| 30 | + |
| 31 | +These targets are real `[[test]]` targets of the `tipjar` package — they |
| 32 | +are **not** orphaned. You can confirm this directly: |
| 33 | + |
| 34 | +```bash |
| 35 | +# 1. They appear as `test` targets of the `tipjar` package in cargo metadata: |
| 36 | +cargo metadata --no-deps --format-version 1 \ |
| 37 | + | jq -r '.packages[] | select(.name=="tipjar") | .targets[] | select(.kind[0]=="test") | .name' |
| 38 | +# => pause_tests |
| 39 | +# => partial_pause_tests |
| 40 | + |
| 41 | +# 2. They enumerate their expected test functions: |
| 42 | +cargo test -p tipjar --test pause_tests --test partial_pause_tests -- --list |
| 43 | + |
| 44 | +# 3. They pass: |
| 45 | +cargo test -p tipjar --test pause_tests --test partial_pause_tests |
| 46 | +``` |
| 47 | + |
| 48 | +> Note: `cargo test -p tipjar` (the full suite) additionally compiles the |
| 49 | +> in-tree unit tests under `contracts/tipjar/src/`, which embed a v2 upgrade |
| 50 | +> fixture WASM via `soroban_sdk::contractimport!`. That fixture must be built |
| 51 | +> first — see `docs/UPGRADE_GUIDE.md` and `.github/workflows/test.yml`. |
| 52 | +> The two integration targets above do **not** depend on that fixture and can |
| 53 | +> be run independently. |
| 54 | +
|
| 55 | +## Other files in this directory |
| 56 | + |
| 57 | +The remaining `*.rs` files (`core_functionality.rs`, `edge_cases.rs`, |
| 58 | +`security_tests.rs`, etc.) are **not** wired to any package and are not |
| 59 | +compiled by `cargo test`. They are legacy/scratch integration tests kept |
| 60 | +for reference; see `tests/README.md` history and the audit notes in |
| 61 | +`docs/SECURITY.md` for the orphaned-test-tree context. |
0 commit comments