From 62c521bf5dfd0290ca53a494037855fe2d0c6431 Mon Sep 17 00:00:00 2001 From: alejoamiras Date: Thu, 26 Nov 2026 21:09:10 +0000 Subject: [PATCH 01/61] test(network-smoke): add a scripted Aztec node that prunes and regrows its chain `startScriptedNode` serves a fixed script of chain states through the SDK's own JSON-RPC server and `AztecNodeApiSchema`, under both the `aztec` and `node` namespaces, as a real node registers them. It implements what the listeners call; any other method answers "Method not found", as a real node does for an unknown one. A separate control port reads the script and steps it. The script grows blocks 1-10, proves and finalizes 1-6, then prunes 7-10 and grows 7'-12' on 6. Blocks come from the SDK's classes: each header links to its parent's archive and commits to its body. The replacing chain carries a recorded contract deployment again, one height lower than the dead chain did. The unit test walks every state through `createAztecNodeClient`. The Vitest config runs the test harness from source: CI's unit job builds only the shared packages. Co-Authored-By: Claude Opus 5.5 --- services/network-smoke/package.json | 3 + services/network-smoke/src/script-control.ts | 52 ++++ services/network-smoke/src/scripted-chain.ts | 189 +++++++++++++ .../network-smoke/src/scripted-node.test.ts | 131 +++++++++ services/network-smoke/src/scripted-node.ts | 252 ++++++++++++++++++ services/network-smoke/tsconfig.json | 2 +- services/network-smoke/vitest.config.ts | 15 ++ yarn.lock | 3 + 8 files changed, 646 insertions(+), 1 deletion(-) create mode 100644 services/network-smoke/src/script-control.ts create mode 100644 services/network-smoke/src/scripted-chain.ts create mode 100644 services/network-smoke/src/scripted-node.test.ts create mode 100644 services/network-smoke/src/scripted-node.ts create mode 100644 services/network-smoke/vitest.config.ts diff --git a/services/network-smoke/package.json b/services/network-smoke/package.json index b8c801ac..c0f9110b 100644 --- a/services/network-smoke/package.json +++ b/services/network-smoke/package.json @@ -19,7 +19,10 @@ "@aztec-foundation/l1-artifacts": "6.0.0", "@aztec-labs/accounts": "6.0.0", "@aztec-labs/aztec.js": "6.0.0", + "@aztec-labs/foundation": "6.0.0", + "@aztec-labs/stdlib": "6.0.0", "@aztec-labs/wallets": "6.0.0", + "@chicmoz-pkg/message-registry": "workspace:^", "@chicmoz-pkg/types": "workspace:^", "@chicmoz/test-harness": "workspace:^", "viem": "2.20.0", diff --git a/services/network-smoke/src/script-control.ts b/services/network-smoke/src/script-control.ts new file mode 100644 index 00000000..fc3c74bf --- /dev/null +++ b/services/network-smoke/src/script-control.ts @@ -0,0 +1,52 @@ +import { z } from "zod"; + +const blockIdSchema = z.object({ height: z.number().int(), hash: z.string() }); + +/** What the explorer must end up serving, as the scripted node built it. */ +export const scriptFactsSchema = z.object({ + states: z.array(z.string()), + /** Index of the first state that serves the replacing chain. */ + pruneAt: z.number().int(), + /** Blocks 7–10 as the node served them before the prune. */ + dead: z.array(blockIdSchema), + /** Blocks 1–12′ of the last state. */ + final: z.array(blockIdSchema), + /** In a dead block and again in the replacing chain; it deploys `contractAddress`. */ + movedTx: z.object({ + hash: z.string(), + deadHeight: z.number().int(), + finalHeight: z.number().int(), + }), + contractAddress: z.string(), +}); + +export type ScriptFacts = z.infer; +export type BlockId = z.infer; + +export const scriptStatusSchema = scriptFactsSchema.extend({ + current: z.number().int(), + /** `getChainTips` and `getBlockNumber` calls served so far: the listener's polls. */ + tipReads: z.number().int(), +}); + +export type ScriptStatus = z.infer; + +const stepSchema = z.object({ current: z.number().int(), label: z.string() }); + +/** The scripted node's control port: read the script, move to the next state. */ +export const scriptControl = (controlUrl: string) => { + const call = async (path: string, method: "GET" | "POST") => { + const res = await fetch(new URL(path, controlUrl), { + method, + signal: AbortSignal.timeout(5_000), + }); + if (!res.ok) { + throw new Error(`${method} ${path}: ${res.status} ${await res.text()}`); + } + return (await res.json()) as unknown; + }; + return { + status: async () => scriptStatusSchema.parse(await call("/script", "GET")), + step: async () => stepSchema.parse(await call("/script/step", "POST")), + }; +}; diff --git a/services/network-smoke/src/scripted-chain.ts b/services/network-smoke/src/scripted-chain.ts new file mode 100644 index 00000000..05531133 --- /dev/null +++ b/services/network-smoke/src/scripted-chain.ts @@ -0,0 +1,189 @@ +import { + BlockNumber, + CheckpointNumber, + IndexWithinCheckpoint, + SlotNumber, + TreeLeafIndex, +} from "@aztec-labs/foundation/branded-types"; +import { Fr } from "@aztec-labs/foundation/curves/bn254"; +import { Body, L2Block } from "@aztec-labs/stdlib/block"; +import { CheckpointHeader } from "@aztec-labs/stdlib/rollup"; +import { AppendOnlyTreeSnapshot } from "@aztec-labs/stdlib/trees"; +import { BlockHeader, type TxEffect } from "@aztec-labs/stdlib/tx"; +import { loadFixture } from "@chicmoz/test-harness"; +import { type BlockId, type ScriptFacts } from "./script-control.js"; + +export type ScriptedBlock = { + block: L2Block; + hash: string; + /** Each block is its own checkpoint, as on the local network. */ + checkpointHash: string; +}; + +/** What the node serves at one step: `chain[h]` is the block at height `h`; the last one is the proposed tip. */ +export type NodeState = { + label: string; + chain: readonly ScriptedBlock[]; + checkpointed: number; + proven: number; + finalized: number; +}; + +export type Script = { states: NodeState[]; facts: ScriptFacts }; + +/** The node info a local network served; the blocks carry its chain id and rollup version. */ +export const recordedNodeInfo = () => + loadFixture("local-network", "node-info", "node-info").data.result; + +const recordedBlock = (name: string) => + loadFixture("local-network", "l2-block", name).data; + +/** The only tx of a recorded local-network block, as the node served it. */ +const recordedTx = (name: string): TxEffect => { + const { hex } = recordedBlock(name); + const [tx] = L2Block.fromBuffer(Buffer.from(hex, "hex")).body.txEffects; + return tx; +}; + +type ChainConstants = { chainId: Fr; version: Fr; genesisTime: bigint }; + +const SLOT_SECONDS = 72n; + +const makeBlock = async ( + parent: ScriptedBlock | undefined, + height: number, + slot: number, + txs: TxEffect[], + { chainId, version, genesisTime }: ChainConstants, +): Promise => { + const body = new Body(txs); + const header = BlockHeader.random({ + lastArchive: parent?.block.archive ?? AppendOnlyTreeSnapshot.empty(), + txEffectsTreeRoot: await body.computeTxEffectsTreeRoot(), + chainId, + version, + blockNumber: BlockNumber(height), + slotNumber: SlotNumber(slot), + timestamp: genesisTime + BigInt(slot) * SLOT_SECONDS, + }); + // Only the links matter downstream: a child's hash covers its lastArchive, + // and nothing recomputes a root from the archive tree, so a random root, as + // L2Block.random draws, is enough. + const archive = new AppendOnlyTreeSnapshot( + Fr.random(), + TreeLeafIndex(height + 1), + ); + const block = new L2Block( + archive, + header, + body, + CheckpointNumber(height), + IndexWithinCheckpoint(0), + ); + const { globalVariables } = header; + const checkpoint = CheckpointHeader.random({ + lastArchiveRoot: header.lastArchive.root, + slotNumber: globalVariables.slotNumber, + timestamp: globalVariables.timestamp, + coinbase: globalVariables.coinbase, + feeRecipient: globalVariables.feeRecipient, + gasFees: globalVariables.gasFees, + totalManaUsed: header.totalManaUsed, + }); + return { + block, + hash: (await block.hash()).toString(), + checkpointHash: checkpoint.hash().toString(), + }; +}; + +const idOf = ({ block, hash }: ScriptedBlock): BlockId => ({ + height: block.number, + hash, +}); + +/** + * Blocks 1–10 grow one per step and 1–6 become proven and finalized; then + * the node prunes 7–10 and grows 7′–12′ on 6. The tips move as the local + * network's did across an epoch prune: the shorter chain is never served + * (the replacing block is already there), the checkpointed tip reaches 7′ one + * step later, and the proven and finalized tips stay at the prune target. + */ +export const buildScript = async (): Promise