Skip to main content
Graph Node has a comprehensive test suite covering unit tests, runner tests (integration-style tests), and full integration tests. This guide explains how to run each type of test and when to use them.
Use unit tests for regular development. Only run integration tests when explicitly needed or when making changes to integration/end-to-end functionality.

Test Types Overview

Graph Node uses three types of tests:
  1. Unit Tests: Fast, focused tests inlined with source code
  2. Runner Tests: Medium-speed integration-style tests for subgraph execution
  3. Integration Tests: Full end-to-end tests with real services

Unit Tests

Unit tests are inlined with the source code and test individual functions and modules in isolation.

Prerequisites

1

Start PostgreSQL

PostgreSQL must be running on localhost:5432 with an initialized graph-test database.Using Process Compose (recommended):
Or manually:
2

Start IPFS

IPFS must be running on localhost:5001.
3

Install Additional Tools

Install PNPM and Foundry:
4

Set Environment Variable

Running Unit Tests

Test Verification Requirement: When filtering for specific tests, ensure the intended test name(s) appear in the output. Cargo can exit successfully even when no tests matched your filter.

Unit Test Best Practices

  • Write unit tests for all new functions and modules
  • Keep tests focused on a single behavior
  • Use descriptive test names that explain what is being tested
  • Mock external dependencies when possible
  • Tests should be fast (< 1 second each)

Runner Tests

Runner tests are integration-style tests that test subgraph execution with real services but in a controlled environment.

Prerequisites

Runner tests use the same prerequisites as unit tests:
  1. PostgreSQL running on localhost:5432 (with initialized graph-test database)
  2. IPFS running on localhost:5001
  3. PNPM installed
  4. Foundry installed
  5. Environment variable THEGRAPH_STORE_POSTGRES_DIESEL_URL set
Runner tests use the same Nix services stack as unit tests:

Running Runner Tests

Runner Test Characteristics

  • Take moderate time (10-20 seconds)
  • Automatically reset the database between runs
  • Some tests can pass without IPFS, but tests involving file data sources require it
  • Test real subgraph execution with compiled WASM
Test Verification Requirement: When filtering for specific tests, ensure the intended test name(s) appear in the output.

Integration Tests

Only run integration tests when explicitly needed:
  • Making changes to integration/end-to-end functionality
  • Debugging issues requiring full system testing
  • Preparing releases or major changes
Integration tests take several minutes to complete.
Integration tests run Graph Node with real blockchain nodes and test the complete indexing pipeline.

Prerequisites

1

Start PostgreSQL

PostgreSQL must be running on localhost:3011 with an initialized graph-node database.Using Process Compose (recommended):
2

Start IPFS

IPFS must be running on localhost:3001.Included in Process Compose setup above.
3

Start Anvil

Anvil (Ethereum test chain) must be running on localhost:3021.Included in Process Compose setup above.
4

Install Tools

Install PNPM and Foundry as described in the unit tests section.

Running Integration Tests

Integration Test Verification

Critical Verification Requirements:
  • ALWAYS verify tests actually ran: Check the output for “test result: ok. X passed” where X > 0
  • If output shows “0 passed” or “0 tests run”: The TEST_CASE variable or filter was wrong - fix and re-run
  • Never trust exit code 0 alone: Cargo can exit successfully even when no tests matched your filter

Integration Test Logs

Logs are written to tests/integration-tests/graph-node.log for debugging:

Service Configuration

Port Mapping

Process Compose Services

The repository includes Process Compose configurations for managing test services:

Code Quality Checks

Mandatory before ANY commit:
  • cargo fmt --all MUST be run
  • just lint MUST show zero warnings
  • cargo check --release MUST complete successfully
  • Unit test suite MUST pass

Running Quality Checks

1

Format Code

2

Lint Code

This must show zero warnings before committing.
3

Check Release Build

This catches issues that cargo check alone might miss.
4

Run Tests

Development Workflow

Continuous Testing During Development

Use cargo-watch to automatically run checks during development:
This will continuously:
  1. Format all source files
  2. Check for compilation errors
  3. Run tests
  4. Generate documentation

Test-Driven Development

1

Write Test First

Write a failing test that describes the desired behavior:
2

Run Test to Verify Failure

3

Implement Feature

Write the minimum code needed to make the test pass.
4

Run Test to Verify Success

5

Run All Quality Checks

Testing Specific Components

Testing Store Changes

Testing Chain Adapters

Testing GraphQL

Debugging Tests

View Test Output

Run Tests in Serial

Debug with RUST_LOG

Common Test Issues

Database Connection Errors

If you see database connection errors, ensure:
  • PostgreSQL is running on the correct port
  • The database exists and has the required extensions
  • The THEGRAPH_STORE_POSTGRES_DIESEL_URL environment variable is set correctly

IPFS Connection Errors

If you see IPFS errors:
  • Ensure IPFS daemon is running: ipfs daemon
  • Check IPFS is accessible: curl http://localhost:5001/api/v0/version

Test Timeout Issues

Best Practices

1

Write Tests First

Use test-driven development: write tests before implementation.
2

Keep Tests Fast

Unit tests should be fast. Move slow tests to runner or integration tests.
3

Test Edge Cases

Test boundary conditions, error cases, and unusual inputs.
4

Use Descriptive Names

Test names should clearly describe what is being tested.
5

Clean Up Resources

Ensure tests clean up after themselves (database, files, etc.).
6

Verify Test Coverage

Use cargo tarpaulin or similar tools to check test coverage.

Resources