withDeployments({ ... })
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 withDeployments() when constructor arguments and deployment-time behavior matter, and you want deployment results (addresses and optional typed contract handles) available by name.
Example
index.ts
import { test, expect } from "vitest";
import { scenario, withChain, withFundedWallet, withDeployments } from "@st8craft/core";
import { isAddress } from "viem";
import { answerArtifact } from "./config.js";
test(
"deployment record is present in ctx.deployments",
scenario(
withChain(),
withFundedWallet({ balance: 1n }),
withDeployments({
answer: {
artifact: answerArtifact,
args: [],
},
}),
async ({ deployments }) => {
expect(isAddress(deployments?.answer?.address)).toBe(true);
},
),
);Options
| Option | Type | Required? | Meaning (units/semantics) | Used for / affects |
|---|---|---|---|---|
name (record key) | string | Yes | Deployment name you choose as the key in your config object. | Becomes ctx.deployments[name]. |
artifact | ContractArtifact | Yes | Contract artifact including required abi plus creation bytecode. | Drives walletClient.deployContract, and (when ABI is present) produces a typed contract handle. |
args | `readonly unknown[] | DeploymentArgsResolver` | No | Constructor arguments, or a resolver (ctx) => args that can depend on earlier deployments. |
afterDeploy | (ctx) => Promise | No | Optional async hook called after the receipt is mined and merged into deployments. | Allows extra node-only setup after deployment. |
Adds to context
deployments(map of deployment name → deployment record)
Context requirements
- Requires runtime + clients from
withChain,withFork, orwithExternalRuntime(forctx.publicClientandctx.testClient). - Requires a funded wallet on
ctx.walletClient(typically provided bywithFundedWallet) sowalletClient.deployContractcan send the transaction.
Lifecycle
Managed middleware that deploys contracts in key order, then forwards to next.
Notes and caveats
- Deployment ordering is the key order in your config object.
artifact.abiis required at runtime (deployment fails if missing).
