Skip to main content
@subsquid/pipes/testing provides utilities for testing pipes end-to-end without hitting a real portal:
  • mockPortal(responses) / finalizedMockPortal(responses): spin up a local HTTP server that plays back scripted portal responses. Both resolve to { url, close() }; pass url as the stream’s portal.
  • readAll(stream): drain a stream into a flat array of data items.
@subsquid/pipes/testing/evm adds typed EVM helpers on top:
  • encodeEvent({ abi, eventName, address, args }): encode an event log from a viem-style ABI. args are fully typed from the ABI.
  • mockBlock({ transactions }): build a portal block; metadata (number, hash, timestamp) is auto-generated with an incrementing block counter.
  • resetMockBlockCounter(): reset the auto-incrementing block numbers between tests.
  • mockEvmPortalStream({ blocks, finalized? }): shorthand that wraps blocks in a mock portal serving one 200 response.

Example (Vitest)

Custom .pipe() transforms are tested the same way: chain them onto the stream and assert on the collected output. Full runnable example: 14.writing-testing.example.ts.

Mock response types

mockPortal accepts an array of scripted responses, played back in order:
The 409 variant lets you test fork handling deterministically, and 500/503 let you exercise retry behavior.