Conversation
📝 WalkthroughWalkthroughThis PR adds comprehensive integration tests for the Atlas server's HTTP API endpoints, introduces testcontainers-based PostgreSQL test fixtures, exports internal modules (head, api, faucet) as public, and establishes a shared test environment infrastructure with dev-dependencies. Changes
Sequence Diagram(s)sequenceDiagram
actor Test
participant LazyLock as LazyLock<TestEnv>
participant Testcontainers as Testcontainers
participant Container as Postgres Container
participant SQLx as SQLx
participant Pool as PgPool
Test->>LazyLock: Initialize TestEnv (once)
LazyLock->>Testcontainers: Start container
Testcontainers->>Container: Spawn Postgres instance
Container-->>Testcontainers: Host/Port info
Testcontainers-->>LazyLock: Container handle
LazyLock->>SQLx: Create connection pool
SQLx->>Container: Connect to Postgres
Container-->>SQLx: Connection established
LazyLock->>SQLx: Run migrations
SQLx->>Container: Execute migration scripts
Container-->>SQLx: Migrations complete
SQLx-->>LazyLock: Pool ready
LazyLock-->>Test: Return shared TestEnv
Test->>Pool: pool() - access PgPool
Pool-->>Test: PgPool reference
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
21 integration tests covering blocks, transactions, search, status, addresses, ERC-20 tokens, and NFT collections. Tests use testcontainers to spin up a real PostgreSQL instance with migrations applied, and hit the actual Axum router via tower::ServiceExt::oneshot — no mocking. All tests share a single persistent runtime and connection pool to avoid the tokio-per-test-runtime problem, and are isolated by block number ranges to prevent data collisions when running in parallel.
e1e5b53 to
85a1ee8
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/crates/atlas-server/tests/integration/nfts.rs (1)
130-138: Consider extending the ordering assertion to all three tokens.The ordering check only verifies
id0 < id1but notid1 < id2. For consistency withtransactions.rs(which checks all three indices), consider:♻️ Extend ordering verification
let id0 = parse_token_id(&data[0]["token_id"]); let id1 = parse_token_id(&data[1]["token_id"]); - assert!(id0 < id1); + let id2 = parse_token_id(&data[2]["token_id"]); + assert!(id0 < id1 && id1 < id2); }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/crates/atlas-server/tests/integration/nfts.rs` around lines 130 - 138, The test currently parses token_id for the first two items using the closure parse_token_id and asserts id0 < id1 but never checks the third token; parse the third token into id2 (e.g., let id2 = parse_token_id(&data[2]["token_id"])) and add an assertion to verify ordering across all three tokens (e.g., assert!(id1 < id2) or combine into assert!(id0 < id1 && id1 < id2)) so the test enforces full ascending order for the data array.backend/crates/atlas-server/tests/integration/common.rs (1)
59-81: Consider documenting the empty HeadTracker limitation.
HeadTracker::empty(10)initializes withlatest=None. This is fine for the current tests since they avoid endpoints that depend on real-time head state (SSE,/api/height). Adding a brief comment would help future contributors understand why certain endpoints are excluded from integration testing.📝 Optional documentation improvement
pub fn test_router() -> Router { let pool = pool().clone(); + // HeadTracker::empty means latest() returns None. This is fine for DB-backed + // endpoints but SSE/height endpoints won't work correctly in integration tests. let head_tracker = Arc::new(HeadTracker::empty(10)); let (tx, _) = broadcast::channel(1);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/crates/atlas-server/tests/integration/common.rs` around lines 59 - 81, Add a short inline comment in the test setup (inside test_router) documenting that HeadTracker::empty(10) initializes with latest=None and therefore the test router deliberately excludes endpoints depending on real-time head state (SSE, /api/height), so future contributors understand why those endpoints are not covered by these integration tests; place the comment near the HeadTracker::empty(10) line and mention HeadTracker, test_router, and build_router for context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/crates/atlas-server/tests/integration/common.rs`:
- Around line 59-81: Add a short inline comment in the test setup (inside
test_router) documenting that HeadTracker::empty(10) initializes with
latest=None and therefore the test router deliberately excludes endpoints
depending on real-time head state (SSE, /api/height), so future contributors
understand why those endpoints are not covered by these integration tests; place
the comment near the HeadTracker::empty(10) line and mention HeadTracker,
test_router, and build_router for context.
In `@backend/crates/atlas-server/tests/integration/nfts.rs`:
- Around line 130-138: The test currently parses token_id for the first two
items using the closure parse_token_id and asserts id0 < id1 but never checks
the third token; parse the third token into id2 (e.g., let id2 =
parse_token_id(&data[2]["token_id"])) and add an assertion to verify ordering
across all three tokens (e.g., assert!(id1 < id2) or combine into assert!(id0 <
id1 && id1 < id2)) so the test enforces full ascending order for the data array.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 73da0d79-0059-4b64-9e16-87dd1a509dd5
📒 Files selected for processing (13)
backend/Cargo.tomlbackend/crates/atlas-server/Cargo.tomlbackend/crates/atlas-server/src/head.rsbackend/crates/atlas-server/src/lib.rsbackend/crates/atlas-server/tests/integration/addresses.rsbackend/crates/atlas-server/tests/integration/blocks.rsbackend/crates/atlas-server/tests/integration/common.rsbackend/crates/atlas-server/tests/integration/main.rsbackend/crates/atlas-server/tests/integration/nfts.rsbackend/crates/atlas-server/tests/integration/search.rsbackend/crates/atlas-server/tests/integration/status.rsbackend/crates/atlas-server/tests/integration/tokens.rsbackend/crates/atlas-server/tests/integration/transactions.rs
Summary
testcontainers-rsto spin up a real PostgreSQL instance with migrations applied — no mocking, no external setup required (Docker must be running)tower::ServiceExt::oneshotand assert on real HTTP responses + JSON bodiesWhat's NOT tested (and why)
get_*endpoints — trigger on-demand RPC calls for metadataRunning
Other changes
src/lib.rsadded to exposeapi,faucet,headmodules to the integration test binaryhead.rs:pub(crate)→pubonHeadTrackerand its methods (required for external test access)Summary by CodeRabbit
Tests
Chores