@@ -24,6 +24,7 @@ Use unit tests for regular development and only run integration tests when:
2424Unit tests are inlined with source code.
2525
2626** Prerequisites:**
27+
27281 . PostgreSQL running on localhost:5432 (with initialised ` graph-test ` database)
28292 . IPFS running on localhost:5001
29303 . PNPM
@@ -33,6 +34,7 @@ Unit tests are inlined with source code.
3334The environment dependencies and environment setup are operated by the human.
3435
3536** Running Unit Tests:**
37+
3638``` bash
3739# Run unit tests
3840just test-unit
@@ -47,13 +49,15 @@ When filtering for specific tests, ensure the intended test name(s) appear in th
4749### Runner Tests (Integration Tests)
4850
4951** Prerequisites:**
52+
50531 . PostgreSQL running on localhost:5432 (with initialised ` graph-test ` database)
51542 . IPFS running on localhost:5001
52553 . PNPM
53564 . Foundry (for smart contract compilation)
54575 . Environment variable ` THEGRAPH_STORE_POSTGRES_DIESEL_URL ` set to ` postgresql://graph:graph@127.0.0.1:5432/graph-test `
5558
5659** Running Runner Tests:**
60+
5761``` bash
5862# Run runner tests.
5963just test-runner
@@ -66,13 +70,15 @@ just test-runner block_handlers
6670When filtering for specific tests, ensure the intended test name(s) appear in the output.
6771
6872** Important Notes:**
73+
6974- Runner tests take moderate time (10-20 seconds)
7075- Tests automatically reset the database between runs
71- - Some tests can pass without IPFS, but tests involving file data sources or substreams require it
76+ - Some tests can pass without IPFS, but tests involving file data sources require it
7277
7378### Integration Tests
7479
7580** Prerequisites:**
81+
76821 . PostgreSQL running on localhost:3011 (with initialised ` graph-node ` database)
77832 . IPFS running on localhost:3001
78843 . Anvil running on localhost:3021
@@ -83,6 +89,7 @@ When filtering for specific tests, ensure the intended test name(s) appear in th
8389The environment dependencies and environment setup are operated by the human.
8490
8591** Running Integration Tests:**
92+
8693``` bash
8794# REQUIRED: Build graph-node binary before running integration tests
8895just build
@@ -95,30 +102,34 @@ TEST_CASE=grafted just test-integration
95102```
96103
97104** ⚠️ Test Verification Requirements:**
105+
98106- ** ALWAYS verify tests actually ran** - Check the output for "test result: ok. X passed" where X > 0
99107- ** If output shows "0 passed" or "0 tests run"** , the TEST_CASE variable or filter was wrong - fix and re-run
100108- ** Never trust exit code 0 alone** - Cargo can exit successfully even when no tests matched your filter
101109
102110** Important Notes:**
111+
103112- Integration tests take significant time (several minutes)
104113- Tests automatically reset the database between runs
105114- Logs are written to ` tests/integration-tests/graph-node.log `
106115
107116### Code Quality
117+
108118``` bash
109119# 🚨 MANDATORY: Format all code IMMEDIATELY after any .rs file edit
110120just format
111121
112122# 🚨 MANDATORY: Check code for warnings and errors - MUST have zero warnings
113- just check
123+ just lint
114124
115125# 🚨 MANDATORY: Check in release mode to catch linking/optimization issues that cargo check misses
116126just check --release
117127```
118128
119129🚨 ** CRITICAL REQUIREMENTS for ANY implementation** :
130+
120131- ** 🚨 MANDATORY** : ` cargo fmt --all ` MUST be run before any commit
121- - ** 🚨 MANDATORY** : ` cargo check ` MUST show zero warnings before any commit
132+ - ** 🚨 MANDATORY** : ` just lint ` MUST show zero warnings before any commit
122133- ** 🚨 MANDATORY** : ` cargo check --release ` MUST complete successfully before any commit
123134- ** 🚨 MANDATORY** : The unit test suite MUST pass before any commit
124135
@@ -127,6 +138,7 @@ Forgetting any of these means you failed to follow instructions. Before any comm
127138## High-Level Architecture
128139
129140### Core Components
141+
130142- ** ` graph/ ` ** : Core abstractions, traits, and shared types
131143- ** ` node/ ` ** : Main executable and CLI (graphman)
132144- ** ` chain/ ` ** : Blockchain-specific adapters (ethereum, near, substreams)
@@ -136,6 +148,7 @@ Forgetting any of these means you failed to follow instructions. Before any comm
136148- ** ` server/ ` ** : HTTP/WebSocket APIs
137149
138150### Data Flow
151+
139152```
140153Blockchain → Chain Adapter → Block Stream → Trigger Processing → Runtime → Store → GraphQL API
141154```
@@ -148,13 +161,15 @@ Blockchain → Chain Adapter → Block Stream → Trigger Processing → Runtime
1481616 . ** GraphQL** processes queries and returns results
149162
150163### Key Abstractions
164+
151165- ** ` Blockchain ` ** trait: Core blockchain interface
152166- ** ` Store ` ** trait: Storage abstraction with read/write variants
153167- ** ` RuntimeHost ` ** : WASM execution environment
154168- ** ` TriggerData ` ** : Standardized blockchain events
155169- ** ` EventConsumer ` /` EventProducer ` ** : Component communication
156170
157171### Architecture Patterns
172+
158173- ** Event-driven** : Components communicate through async streams and channels
159174- ** Trait-based** : Extensive use of traits for abstraction and modularity
160175- ** Async/await** : Tokio-based async runtime throughout
@@ -164,35 +179,42 @@ Blockchain → Chain Adapter → Block Stream → Trigger Processing → Runtime
164179## Development Guidelines
165180
166181### Commit Convention
182+
167183Use format: ` {crate-name}: {description} `
184+
168185- Single crate: ` store: Support 'Or' filters `
169186- Multiple crates: ` core, graphql: Add event source to store `
170187- All crates: ` all: {description} `
171188
172189### Git Workflow
190+
173191- Rebase on master (don't merge master into feature branch)
174192- Keep commits logical and atomic
175193- Squash commits to clean up history before merging
176194
177195## Crate Structure
178196
179197### Core Crates
198+
180199- ** ` graph ` ** : Shared types, traits, and utilities
181200- ** ` node ` ** : Main binary and component wiring
182201- ** ` core ` ** : Business logic and subgraph management
183202
184203### Blockchain Integration
204+
185205- ** ` chain/ethereum ` ** : Ethereum chain support
186206- ** ` chain/near ` ** : NEAR protocol support
187207- ** ` chain/substreams ` ** : Substreams data source support
188208
189209### Infrastructure
210+
190211- ** ` store/postgres ` ** : PostgreSQL storage implementation
191212- ** ` runtime/wasm ` ** : WebAssembly runtime and host functions
192213- ** ` graphql ` ** : Query processing and execution
193214- ** ` server/ ` ** : HTTP/WebSocket servers
194215
195216### Key Dependencies
217+
196218- ** ` diesel ` ** : PostgreSQL ORM
197219- ** ` tokio ` ** : Async runtime
198220- ** ` tonic ` ** : gRPC framework
@@ -208,6 +230,7 @@ The repository includes a process-compose-flake setup that provides native, decl
208230Currently, the human is required to operate the service dependencies as illustrated below.
209231
210232** Unit Tests:**
233+
211234``` bash
212235# Human: Start PostgreSQL + IPFS for unit tests in a separate terminal
213236# PostgreSQL: localhost:5432, IPFS: localhost:5001
@@ -218,6 +241,7 @@ just test-unit
218241```
219242
220243** Runner Tests:**
244+
221245``` bash
222246# Human: Start PostgreSQL + IPFS for runner tests in a separate terminal
223247# PostgreSQL: localhost:5432, IPFS: localhost:5001
@@ -228,6 +252,7 @@ just test-runner
228252```
229253
230254** Integration Tests:**
255+
231256``` bash
232257# Human: Start all services for integration tests in a separate terminal
233258# PostgreSQL: localhost:3011, IPFS: localhost:3001, Anvil: localhost:3021
@@ -243,18 +268,20 @@ just test-integration
243268** Services Configuration:**
244269The services are configured to use the test suite default ports for unit- and integration tests respectively.
245270
246- | Service | Unit Tests Port | Integration Tests Port | Database/Config |
247- | ---------| ----------------- | ------------------------| -----------------|
248- | PostgreSQL | 5432 | 3011 | ` graph-test ` / ` graph-node ` |
249- | IPFS | 5001 | 3001 | Data in ` ./.data/unit ` or ` ./.data/integration ` |
250- | Anvil (Ethereum) | - | 3021 | Deterministic test chain |
271+ | Service | Unit Tests Port | Integration Tests Port | Database/Config |
272+ | ---------------- | --------------- | ---------------------- | ----------------------------------------------- |
273+ | PostgreSQL | 5432 | 3011 | ` graph-test ` / ` graph-node ` |
274+ | IPFS | 5001 | 3001 | Data in ` ./.data/unit ` or ` ./.data/integration ` |
275+ | Anvil (Ethereum) | - | 3021 | Deterministic test chain |
251276
252277** Service Configuration:**
253278The setup combines built-in services-flake services with custom multiService modules:
254279
255280** Built-in Services:**
281+
256282- ** PostgreSQL** : Uses services-flake's postgres service with a helper function (` mkPostgresConfig ` ) that provides graph-specific defaults including required extensions.
257283
258284** Custom Services** (located in ` ./nix ` ):
285+
259286- ` ipfs.nix ` : IPFS (kubo) with automatic initialization and configurable ports
260287- ` anvil.nix ` : Ethereum test chain with deterministic configuration
0 commit comments