# Testing

## Contract Tests (Foundry)
Run inside `onchain/`:
```bash
forge build      # compile contracts
forge test       # run unit + fork tests
forge snapshot   # gas snapshot
```

## Fuzzing
Scripts under `onchain/analysis/` generate replayable scenarios:
```bash
./analysis/run-fuzzing.sh [optimizer] debugCSV
```

## Integration Testing
After the stack boots via `dev.sh`:
- Anvil logs: check for revert errors
- Ponder GraphQL: `http://localhost:8081/api/graphql`
- txnBot health: `http://localhost:8081/api/txn/status`

## E2E Tests (Playwright)
Full-stack tests in `tests/e2e/` verify complete user journeys (mint ETH → swap KRK → stake).

```bash
npm run test:e2e   # from repo root
```

- Tests use a mocked wallet provider with Anvil accounts.
- In CI, the Woodpecker `e2e.yml` pipeline runs these against pre-built service images.
- See [docs/ci-pipeline.md](ci-pipeline.md) for CI-specific E2E details.

## Version Validation System
The stack enforces version compatibility across contracts, indexer, and frontend:

- **Contract VERSION**: `Kraiken.sol` exposes a `VERSION` constant (currently v2) that must be incremented for breaking changes to TAX_RATES, events, or core data structures.
- **Ponder Validation**: On startup, Ponder reads the contract VERSION and validates against `COMPATIBLE_CONTRACT_VERSIONS` in `kraiken-lib/src/version.ts`. Fails hard (exit 1) on mismatch to prevent indexing wrong data.
- **Frontend Check**: Web-app validates `KRAIKEN_LIB_VERSION` at runtime (currently placeholder; future: query Ponder GraphQL for full 3-way validation).
- **CI Enforcement**: Woodpecker `release.yml` pipeline validates that contract VERSION matches `COMPATIBLE_CONTRACT_VERSIONS` before release.
- See `VERSION_VALIDATION.md` (repo root) for complete architecture, workflows, and troubleshooting.
