withChain([config])
Test runners: Examples use Vitest test and expect. scenario(...) returns an async function you can pass to any runner with a similar test callback (for example Jest or Node node:test).
Why it is useful
Use withChain() when you want fast, local integration tests without relying on any external RPC providers.
Example
index.ts
import { test, expect } from "vitest";
import { parseEther } from "viem";
import { scenario, withChain, withFundedWallet } from "@st8craft/core";
test(
"funded wallet on local chain",
scenario(
withChain(),
withFundedWallet({ balance: parseEther("1") }),
async ({ publicClient, walletClient }) => {
expect(
await publicClient.getBalance({ address: walletClient.account!.address }),
).toBe(
parseEther("1"),
);
},
),
);Options
| Option | Type | Required? | Meaning (units/semantics) | Used for / affects |
|---|---|---|---|---|
chainId | number | No | Anvil --chain-id override. | Client chain identity (affects viem chain.id) and runtime chain id. |
key | string | No | Stable correlation id forwarded to the runtime layer. | Correlates runtime config across restarts (advanced). |
Adds to context
runtimeruntimeMode("chain")chainpublicClientwalletClienttestClient
Context requirements
None; this fixture is the base runtime step.
Lifecycle
Managed lifecycle, the fixture starts and stops Anvil for the scenario.
Notes and caveats
This is the simplest fixture for local work, but it does not pin to any remote state.
