Overview
Dokrypt includes a built-in test runner that discovers and executes tests across multiple languages and frameworks. It supports:- Automatic discovery — Finds test files by convention
- Parallel execution — Run tests concurrently
- Gas reporting — Track gas usage per function
- Coverage analysis — Measure code coverage
- Snapshot isolation — Each test gets a clean chain state
- Built-in validation — Health checks for your chain environment
Test Discovery
Dokrypt automatically finds test files based on these patterns:| Language | File Patterns | Runner |
|---|---|---|
| Solidity | *.t.sol, *.test.sol, *_test.sol | forge test |
| JavaScript | *.test.js | node or npx hardhat test |
| TypeScript | *.test.ts | npx hardhat test |
test/, tests/, contracts/test/
Quick Start
Configuration
Configure test settings indokrypt.yaml:
Snapshot Isolation
When--snapshot is enabled (or snapshot_isolation: true in config), each test:
- Takes a snapshot before running
- Executes the test
- Reverts to the snapshot after the test completes
Gas Reporting
Enable gas tracking to see how much gas each contract function uses:Built-in Validation Suite
If no test files are discovered, Dokrypt runs its built-in validation suite to check chain health:| Test | What It Checks |
|---|---|
chain_is_running | Basic RPC connectivity |
accounts_available | At least one account exists |
chain_id_valid | Chain ID is non-zero |
mining_works | Blocks can be mined |
snapshot_restore | Snapshot/revert works correctly |
Test Reports
Test results are persisted to~/.dokrypt/reports/<project>/latest.json. View the last report:
Assertion Helpers (Go SDK)
If building custom test suites using Dokrypt’s Go packages, thetestrunner package provides assertion helpers:
| Function | Description |
|---|---|
AssertTxSuccess(t, tx) | Assert transaction succeeded |
AssertTxReverted(t, tx) | Assert transaction reverted |
AssertTxRevertedWith(t, tx, reason) | Assert specific revert reason |
AssertGasBelow(t, tx, maxGas) | Assert gas usage is below threshold |
AssertEvent(t, tx, eventName, args) | Assert event was emitted |
AssertEventCount(t, tx, name, count) | Assert number of events emitted |
AssertNoEvent(t, tx, eventName) | Assert event was not emitted |
AssertBalance(t, actual, expected) | Assert balance (string comparison) |
AssertETHBalance(t, actual, expected) | Assert balance (*big.Int) |
AssertJSONEqual(t, actual, expected) | Assert JSON equality |
Fixtures
TheFixture type provides snapshot-based isolation for individual tests: