Skip to content

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

OptionTypeRequired?Meaning (units/semantics)Used for / affects
name (record key)stringYesDeployment name you choose as the key in your config object.Becomes ctx.deployments[name].
artifactContractArtifactYesContract artifact including required abi plus creation bytecode.Drives walletClient.deployContract, and (when ABI is present) produces a typed contract handle.
args`readonly unknown[]DeploymentArgsResolver`NoConstructor arguments, or a resolver (ctx) => args that can depend on earlier deployments.
afterDeploy(ctx) => PromiseNoOptional 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, or withExternalRuntime (for ctx.publicClient and ctx.testClient).
  • Requires a funded wallet on ctx.walletClient (typically provided by withFundedWallet) so walletClient.deployContract can 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.abi is required at runtime (deployment fails if missing).