# Testing

> How tests are organized in v2-monorepo and how to add your own.

How tests are organized in v2-monorepo and how to add your own.

## Unit tests (SDK)

```bash
cd packages/sdk
pnpm test                    # runs vitest, no chain interaction
pnpm typecheck               # tsc --noEmit
```

Located in `packages/sdk/test/unit/`. Cover individual services (PoseidonHashService, NoteComputationService) and schemas. [CryptoService](/sdk/crypto-services) tests live in `packages/sdk/test/services/`.

## Integration tests (SDK)

```bash
cd apps/sample
cp tests/integration/.env.example tests/integration/.env
# Fill in real Sepolia values
pnpm test:integration
```

End-to-end against the real Sepolia testnet. Slow but high-confidence: the test suite makes [deposits](/operations/deposit), runs [transfers](/operations/transfer), and exits the pool.

## Contracts (forge)

```bash
cd packages/contracts
forge test                   # full suite
forge test --match-test Transact -vvv   # one test, verbose trace
```

Located in `packages/contracts/test/`. Forks Sepolia state, exercises end-to-end transact flows including verifier contract calls.

## Circuits (circomkit)

```bash
cd packages/circuits
pnpm test                    # runs circomkit's proving tests
```

Builds witnesses, runs the prover, verifies proofs. Useful for changes that modify circuit signal layout.

## Adding a new test that covers a real flow

1.  Pick the layer the change lives at (SDK unit / integration / contracts / circuits).
2.  Read an existing test in that layer as a template.
3.  For integration tests, expect long run times: forks, real RPC, and real proofs.
4.  For new contract behaviors, add both a unit-style test (single revert path) and an integration test (full E2E flow).

## CI

GitHub Actions runs several workflows. SDK unit tests and typecheck, contract tests, circuit tests, and the [relayer](/operations/relaying) CI run automatically on push and pull request. Contract integration tests run in CI as well, against mainnet and Sepolia forks using RPC secrets, and the relayer has its own end-to-end workflow on pull request. The SDK and sample end-to-end integration suite is the exception: it runs only on manual `workflow_dispatch` and needs configured secrets (an RPC endpoint, a funded key, and the postman-role key), so it is not part of the automatic PR gate.
