/substreams:substreams-testingfrom substreams
Expert knowledge for testing Substreams modules: unit tests with substreams::testing (map!, clock), real block fixtures via firecore, CLI integration (substreams run, --test-file), performance checks, and CI patterns.
Ships in substreams. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Expert assistant for testing Substreams modules: unit tests without WASM, real-block fixtures, CLI integration/golden checks, and CI.
Load this skill when the user wants to test, verify, benchmark, or CI a Substreams project. For authoring modules, prefer substreams-dev plus the chain skill (substreams-ethereum / substreams-solana).
| Level | Goal | Primary tools |
|---|---|---|
| Unit | Pure handler logic, edge cases | cargo test + substreams::testing::map! |
| Integration | Real blocks / multi-module behavior | Fixtures + map!, or substreams run |
| CLI / golden | Engine + WASM + network data | substreams run -o jsonl, --test-file |
| Performance | Scale / production mode | Criterion, time substreams run --production-mode |
Agent workflow (match this repo’s eval style):
cargo test (unit + pure helpers)substreams buildsubstreams run -s <start> -t +N <module> -o jsonl on a small range--test-file tests/assertions.yaml or diff against a golden JSONL--production-modeAlways pin initialBlock near the test window (see substreams-dev) so cold runs do not backfill from genesis.
substreams::testing, 0.7.4+)Experimental API — only available under #[cfg(test)]. Surface today: map! and clock. There is no official store mock / TestStore.
map! — call handlers without WASM#[substreams::handlers::map] generates a testable __impl_<name> function. map! rewrites the call to that function:
use substreams::errors::Error;
use substreams_ethereum::pb::eth::v2::Block;
#[substreams::handlers::map]
pub fn map_events(block: Block) -> Result<Events, Error> {
let events = block
.logs()
.filter(|log| is_relevant(log))
.filter_map(|log| parse_event(log).ok())
.collect();
Ok(Events { events })
}
#[cfg(test)]
mod tests {
use super::*;
use substreams::testing;
#[test]
fn empty_block_ok() {
let result = testing::map!(map_events(Block::default())).unwrap();
assert!(result.events.is_empty());
}
#[test]
fn chain_handlers() {
let block = create_test_block();
let all = testing::map!(map_events(block)).unwrap();
let filtered =
testing::map!(filter_events("transfer".to_string(), all)).unwrap();
assert!(filtered.events.iter().all(|e| e.event_type == "transfer"));
}
}
Opt out: #[substreams::handlers::map(no_testable)] (use a thin pure helper for tests instead).
Legacy: extract _map_events(block) -> Result<...> and call it from both the handler and tests when you are below 0.7.4 or use no_testable.
clock — requires a stringSignature: clock(input: impl AsRef<str>) -> Clock.
use substreams::testing::clock;
let c = clock("17000000"); // number + id from digits; ts ≈ number (seconds)
let c = clock("17000000@1680000000000"); // explicit ms-since-epoch after @
let c = clock("abc@1609459200500"); // non-numeric id → number 0
Do not call clock() with zero arguments — that does not compile.
substreams_ethereum::pb::eth::v2::Block fields include hash, number, header, transaction_traces, …
There is no timestamp_seconds or parent_hash field on Block — those live on header (timestamp_seconds() is a method).
use buffa_types::google::protobuf::Timestamp;
use substreams_ethereum::pb::eth::v2::{
Block, BlockHeader, Log, TransactionReceipt, TransactionTrace,
};
fn create_block_with_transfer() -> Block {
Block {
number: 17_000_000,
hash: hex::decode("aa".repeat(32)).unwrap(),
header: BlockHeader {
parent_hash: hex::decode("bb".repeat(32)).unwrap(),
timestamp: Timestamp {
seconds: 1_680_000_000,
nanos: 0,
..Default::default()
}
.into(),
..Default::default()
}
.into(),
transaction_traces: vec![TransactionTrace {
hash: hex::decode("cc".repeat(32)).unwrap(),
receipt: TransactionReceipt {
logs: vec![Log {
address: hex::decode("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")
.unwrap(),
topics: vec![
// Transfer(address,address,uint256)
hex::decode(
"ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
)
.unwrap(),
// from / to left-padded to 32 bytes
hex::decode(format!("{:0>64}", "742d35cc6634c0532925a3b844bc454e4438f44e")).unwrap(),
hex::decode(format!("{:0>64}", "5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")).unwrap(),
],
// amount as 32-byte big-endian hex, not a decimal string
data: hex::decode(format!("{:0>64x}", 1_000_000u64)).unwrap(),
..Default::default()
}],
..Default::default()
}
.into(),
..Default::default()
}],
..Default::default()
}
}
Solana: same map! pattern with substreams_solana block types — keep decoding rules from substreams-solana (typed instruction fields, not raw blobs).
There is no supported in-process store mock in substreams::testing. Prefer:
substreams run and/or --test-file (debug store outputs)Prefer protobuf bytes fixtures over hand-rolled JSON of full blocks.
# Single block as base64 protobuf (best for unit/integration fixtures)
firecore tools firehose-single-block-client \
mainnet.eth.streamingfast.io:443 17000000 \
-o bytes --bytes-encoding=base64 \
> src/testdata/eth_mainnet_17000000.binpb.b64
# Range as JSONL (inspection / golden drafting — not ideal to re-decode as Block)
firecore tools firehose-client mainnet -o json -- 17000000 +100
Load in Rust:
use buffa::Message;
use substreams_ethereum::pb::eth::v2::Block;
fn load_block_b64(path: &str) -> Block {
use base64::{engine::general_purpose::STANDARD, Engine as _};
let b64 = std::fs::read_to_string(path).expect("fixture missing");
let bytes = STANDARD.decode(b64.trim()).expect("base64");
Block::decode_from_slice(&bytes).expect("protobuf Block")
}
Auth: data-plane token via substreams auth / SUBSTREAMS_API_TOKEN (or Firehose env vars the CLI documents). Not Portal admin auth.
Details: references/firecore-tools.md
substreams build
substreams run -s 17000000 -t +100 map_events --network mainnet -o jsonl > /tmp/out.jsonl
test -s /tmp/out.jsonl
Wrap in Rust with std::process::Command only for optional/nightly tests (#[ignore]), so default cargo test stays offline-friendly.
Production mode: re-run the same range with --production-mode and confirm outputs match development mode (caching / parallel path).
substreams run --test-file (jq assertions)Built-in assertion runner. Spec formats: .yaml, .jsonl, .csv.
Each case: module, block, path (gojq), expect, optional op / args.
# tests/assertions.yaml
tests:
- module: map_events
block: 17000000
path: .events | length
expect: "0"
op: float
- module: map_events
block: 17000000
path: .events[0].contract
expect: "a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
- module: store_balances
block: 17000010
path: select(.key == "token:alice") | .new
expect: "1000"
substreams run substreams.yaml map_events \
-s 17000000 -t +20 \
--test-file tests/assertions.yaml \
--test-verbose
Store assertions need store outputs in the stream (debug stores / module selection as required by your CLI version). Prefer absolute block numbers that fall inside -s/-t.
cargo bench)time substreams run -s … -t +1000 … --production-modeblockFilter indexes before micro-optimizing (see substreams-dev)Full guide: references/performance-testing.md
# .github/workflows/test.yml (excerpt)
jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: rustfmt, clippy
- run: cargo test --lib
- run: cargo clippy -- -D warnings
- run: cargo fmt -- --check
- run: substreams build # after installing substreams CLI
# Optional job with secrets: SUBSTREAMS_API_TOKEN
# integration:
# run: |
# substreams run -s 17000000 -t +50 map_events --network mainnet -o jsonl
# substreams run … --test-file tests/assertions.yaml
Do not call hosted endpoints from default PR jobs without secrets and rate limits.
Do
#[ignore]--test-file for regressionsuint256, and address casing conventions you emitDon’t
Block that do not exist (timestamp_seconds, parent_hash at top level)initialBlock to protocol genesis for local 100-block checksWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
12 skills in this plugin
/substreams-bitcoinExpert knowledge for developing Bitcoin Substreams. Use when working with Bitcoin blockchain data, UTXO model, transaction parsing, address extraction, or Esplora API compatibility./substreams-convertExpert knowledge for converting existing blockchain indexing projects into Substreams. Use when migrating a subgraph (The Graph) or a Solana program/contract into a Substreams module pipeline./substreams-devCross-cutting Substreams development — manifests, module graphs (map/store/index), protobuf, performance, debugging. For Ethereum/EVM contract decoding use substreams-ethereum; for Solana programs use substreams-solana; for SQL sinks use substreams-sql./substreams-dev-legacySubstreams development on the pre-buffa stack — substreams 0.7.x and below, where protobuf is prost. Use when the project pins substreams <= 0.7, substreams-ethereum <= 0.11, substreams-solana <= 0.15, or substreams-database-change <= 4, or when Cargo.toml declares prost / prost-build. On substreams 0.8+ use substreams-dev instead; the two stacks generate incompatible types./substreams-ethereumDevelop Substreams for Ethereum and EVM contracts — ABI codegen (Abigen/build.rs), event decoding via match_and_decode, raw topic0 decoding without an ABI, eth_call / RpcBatch, and token-metadata stores. Always decode log data into typed structured protobuf objects (never raw bytes or JSON); one protobuf message type per event. Use when building EVM Substreams, decoding contract events, ERC-20/721/1155, Uniswap/DEX pools, or when the user mentions an Ethereum contract address, ABI, topic0, Solidity, or an EVM chain (Polygon, Arbitrum, Base, BSC, Optimism).
/substreams-hosted-sinkUse when the user wants StreamingFast to host and run a Substreams sink — deploy a .spkg to managed infrastructure (PostgreSQL or ClickHouse only) via the Portal API HostedService. HARD RULE: before any first-time hosted Deploy (or any "ready to deploy?" prompt), stop and offer a substreams run output-quality check as its own turn. For that check, give the user a ready-to-paste substreams run command only (stdout/jsonl) — never substreams sink postgres / any sink binary, never a local ClickHouse/Postgres sync. Building the module is not enough. SF hosts only the sink runner; the user supplies the database. Self-managed sinks: substreams-sink-deploy-local; modules: substreams-sql / substreams-dev.
npx claudepluginhub streamingfast/substreams-skills --plugin substreams-dev