You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,11 @@ We really appreciate and value contributions to OpenZeppelin Contracts for Compa
23
23
*[Pull Requests](#pull-requests)
24
24
*[Opening an Issue](#opening-an-issue)
25
25
26
+
[Running Tests](#running-tests)
27
+
28
+
*[Unit Tests](#unit-tests)
29
+
*[Live Tests](#live-tests)
30
+
26
31
[Styleguides](#styleguides)
27
32
28
33
*[Git Commit Messages](#git-commit-messages)
@@ -152,6 +157,76 @@ A maintainer will re-run the status check for you. If we conclude that the failu
152
157
153
158
While the prerequisites above must be satisfied prior to having your pull request reviewed, the reviewer(s) may ask you to complete additional design work, tests, or other changes before your pull request can be ultimately accepted.
154
159
160
+
## Running Tests
161
+
162
+
Run all commands from the repository root. Enable Corepack once (`corepack enable`) so `yarn` resolves to the version pinned in `package.json`.
163
+
164
+
### Unit Tests
165
+
166
+
Unit tests run against an in-process mock backend (no network, ZK proving skipped):
167
+
168
+
```bash
169
+
yarn test
170
+
```
171
+
172
+
### Live Tests
173
+
174
+
Live tests run against a local Midnight network (node, indexer, and proof server) defined in [`local-env.yml`](./local-env.yml). They require [Docker](https://docs.docker.com/get-docker/) and a completed `yarn install`.
175
+
176
+
One command runs everything — it compiles, resets the stack, runs a quick harness smoke, then each live-ready category sequentially on a freshly reset node:
177
+
178
+
```bash
179
+
yarn test:live
180
+
```
181
+
182
+
Currently `multisig` is the only live-ready category; the others still assume dry-only semantics and are skipped (listed in the run banner). Each category joins the run — with its own `test:live:<category>` script — as its specs are refactored for the live backend.
183
+
184
+
If any files fail, a second round re-runs just those files on a fresh node with one worker, to separate a real failure from an environment flake:
Scope the same mechanism to one category, or to a subset within it. The first
190
+
argument names the category; any further argument is a filename substring
191
+
(vitest matches it), so pass a spec name to run every file whose name matches it
192
+
on the live backend — the fast loop while iterating on one feature, instead of
193
+
waiting for the whole category. The match is a substring, not an exact file, so
194
+
a name that prefixes others runs all of them:
195
+
196
+
```bash
197
+
yarn test:live multisig # the whole category
198
+
yarn test:live multisig ShieldedTreasury # any file matching "ShieldedTreasury"
199
+
```
200
+
201
+
The two-round flake check still applies to a scoped run, so a green result
202
+
means the same thing it does for the full suite.
203
+
204
+
Stop the network when done: `yarn env:down`. (No manual `env:up` is needed — the runner resets the stack itself.)
205
+
206
+
> **Note:** The live tests all run against one shared node, so state left by an earlier run can make a later one fail. Two rules keep them reliable, both enforced by a guard that fails fast, before any wallet build:
207
+
>
208
+
> 1.**Start from a fresh node.** State left by a previous run makes shielded spends fail with node `Custom error: 103`. The guard aborts if it finds any shielded coin event beyond genesis. The `test:live*` runner resets for you; reset manually with `yarn env:up`.
209
+
> 2.**One live run at a time.** A pid-stamped lock (`contracts/logs/.live-run.lock`) makes a second concurrent run abort.
|`MIDNIGHT_LIVE_MAX_SCAN_BLOCKS`| 3600 | Above this indexer head, the guard asks you to `env:up` rather than scan. |
219
+
220
+
`unit-live` runs up to 3 workers in parallel, so their output interleaves. It is tagged per worker: a `▶ live worker N/3 ready` banner when a worker's wallets are funded, a `[wN] ❯ <file>` line as each spec file starts, and a `[wN] ✓ <test> (<ms>) [done/total]` line per test — showing the worker, the result, and overall progress through the run. Each worker also writes a detailed log to `logs/live-harness-wN.log`.
221
+
222
+
> **Tip:** to save the run to a colored, readable log, force color and pipe to `tee`. Piping (stdout is no longer a TTY) makes vitest print one clean line per result instead of an animated spinner, and `FORCE_COLOR=1` keeps the color. Write it to a `.ansi` file:
223
+
>
224
+
> ```bash
225
+
> FORCE_COLOR=1 yarn test:live multisig 2>&1| tee logs/live-multisig.ansi
226
+
>```
227
+
>
228
+
> The file stores ANSI color codes, so render them rather than reading them raw. In VS Code, an ANSI extension such as [`iliazeus.vscode-ansi`](https://marketplace.visualstudio.com/items?itemName=iliazeus.vscode-ansi) renders a `.ansi` file via **"ANSI Text: Open Preview"**. In a terminal, use `less -R logs/live-multisig.ansi`. On Linux, prefix `systemd-inhibit --why="live tests"`for a long run.
0 commit comments