Skip to content

Conversation

@lempira
Copy link
Contributor

@lempira lempira commented Nov 13, 2025

This PR migrates the algod client test suite from snapshot-based testing to runtime Zod schema validation, improving test reliability and type safety. The changes replace snapshot comparisons with strict schema validation that catches type mismatches and ensures API responses conform to their documented structure.

The migration introduces a modelMetadataToZodSchema utility that converts model metadata into Zod schemas, with support for circular references through lazy evaluation. All 22 test files now use expectTypeOf for compile-time checks alongside Zod's runtime validation. For endpoints without mock server support, tests use dummy data with vi.spyOn mocking to validate schema correctness while maintaining proper type handling for BigInt and Uint8Array values.

The api calls are being sent to either localnet or a mock server that replays recorded HAR files for particular endpoints.

Technical note: The Zod utility handles recursive models (like SimulationTransactionExecTrace) using a cache and lazy schema resolution to prevent stack overflow. Some composite types like SuggestedParams require manual schema definitions since they don't have their own ModelMetadata.

neilcampbell and others added 11 commits November 14, 2025 22:22
  - Update get_health test to use external snapshots
  - Add get_v_2_status test
  - Add get_ready test
  - Add get_genesis test
  - Add get_versions test
  - Update get_v_2_accounts_address test to use external snapshots
  - Add get_v_2_accounts_address_applications_application_id test
  - Add get_v_2_accounts_address_assets_asset_id test
  - Add get_v_2_accounts_address_transactions_pending test
  - Add test constants to config.ts
  - Add get_v_2_transactions_params test
  - Add get_v_2_transactions_pending test
  - Add get_v_2_applications_application_id test
  - Add get_v_2_ledger_supply test
  - Add get_v_2_ledger_sync test
  - Add get_v_2_status_wait_for_block_after_round test
  - Add get_v_2_blocks_round test
  - Add get_v_2_blocks_round_hash test
  - Add get_v_2_blocks_round_lightheader_proof test
  - Add get_v_2_blocks_round_txids test
  - Add get_v_2_deltas_round test
  - Add TEST_ROUND constant to config.ts
- Add localnetConfig for connecting to localnet algod (port 4001)
- Implement POST/GET devmode blocks offset tests with verification
- Implement POST/DELETE sync round tests (skipped - requires follower mode)
- Skip catchup test (API not implemented)
- Update snapshots for existing tests
- Replace snapshot-based testing with runtime Zod schema validation
- Add zod-utils.ts with lazy evaluation support for recursive models
- Update 22 test files to use expectTypeOf and Zod validation pattern
- Handle circular references in SimulationTransactionExecTrace
- Create manual schema for SuggestedParams composite type
- Skip tests with schema mismatches (genesis, ledger sync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants