/** * NEAR Sandbox - Local testing environment * * Simple, explicit API for running a local NEAR node for testing. */ interface PlatformInfo { system: string; arch: string; } /** * Default code hash for accounts without deployed contract code. * This is a base58-encoded sha256 hash of an empty byte array. */ export declare const EMPTY_CODE_HASH = "11111111111111111111111111111111"; /** * State record from sandbox state dump. * Used for patching state and creating snapshots. */ export interface StateRecord { Account?: { account_id: string; account: { amount: string; locked: string; code_hash: string; storage_usage: number; version?: string; }; }; AccessKey?: { account_id: string; public_key: string; access_key: { nonce: number; permission: "FullAccess" | { FunctionCall: { allowance: string | null; receiver_id: string; method_names: string[]; }; }; }; }; Contract?: { account_id: string; code: string; }; Data?: { account_id: string; data_key: string; value: string; }; } /** * State snapshot for restoring sandbox state between tests. */ export interface StateSnapshot { records: StateRecord[]; timestamp: number; } export interface SandboxOptions { version?: string; /** * Path to a local near-sandbox binary. If provided, skips downloading. * Falls back to NEAR_SANDBOX_BIN_PATH environment variable if not set. */ binaryPath?: string; /** * Whether to spawn the sandbox process as detached. * Default: true * Set to false in test environments to prevent the process from being killed by test runners. */ detached?: boolean; } /** * NEAR Sandbox instance * * Manages a local NEAR node for testing. Automatically cleans up on stop(). * * @example * ```typescript * const sandbox = await Sandbox.start(); * const near = new Near({ network: sandbox }); * // ... run tests * await sandbox.stop(); * ``` */ export declare class Sandbox { readonly rpcUrl: string; readonly networkId: string; readonly rootAccount: { id: string; secretKey: string; }; private process; private homeDir; private binaryPath; private detached; private originalGenesisPath; private constructor(); /** * Start a new sandbox instance * * Downloads the sandbox binary if needed, initializes a temporary directory, * and starts the sandbox process. * * @param options - Optional configuration * @returns Promise resolving to a running Sandbox instance */ static start(options?: SandboxOptions): Promise; /** * Stop the sandbox and clean up * * Kills the sandbox process and removes temporary files. */ stop(): Promise; /** * Patch the state of accounts and contracts in the sandbox. * * Allows direct modification of blockchain state including account balances, * access keys, contract code, and contract storage. * * Note: The patched state is applied during the next block's processing. * This method waits for that block to be produced before returning to * ensure subsequent reads see the updated state. * * @param records - Array of state records to patch * * @example * ```typescript * await sandbox.patchState([{ * Account: { * account_id: "alice.test.near", * account: { * amount: "1000000000000000000000000000", * locked: "0", * code_hash: EMPTY_CODE_HASH, * storage_usage: 100, * } * } * }]) * ``` */ patchState(records: StateRecord[]): Promise; /** * Fast-forward the blockchain by a number of blocks. * * Advances the sandbox by producing empty blocks, useful for testing * time-dependent contract logic without waiting for real blocks. * * @param numBlocks - Number of blocks to advance (must be positive) * * @example * ```typescript * await sandbox.fastForward(100) * ``` */ fastForward(numBlocks: number): Promise; /** * Dump the current state of the sandbox to a snapshot. * * Runs the sandbox binary's `view-state dump-state` command which reads * state from RocksDB in read-only mode. The snapshot includes all accounts, * access keys, contracts, and contract data. * * @returns The state snapshot * * @example * ```typescript * const snapshot = await sandbox.dumpState() * // ... modify state ... * await sandbox.restoreState(snapshot) * ``` */ dumpState(): Promise; /** * Restore the sandbox state from a previously saved snapshot. * * Patches the blockchain state to match the snapshot. Useful for * running multiple tests against the same initial state. * * @param snapshot - The state snapshot from `dumpState()` */ restoreState(snapshot: StateSnapshot): Promise; /** * Save a state snapshot to a file. * * @returns Path to the saved snapshot file */ saveSnapshot(): Promise; /** * Load a state snapshot from a file. * * @param snapshotPath - Path to the snapshot file * @returns The loaded state snapshot */ loadSnapshot(snapshotPath: string): Promise; /** * Restart the sandbox, optionally with modified genesis state. * * Stops the process, optionally appends snapshot records to genesis, * clears the data directory, and restarts. Block height resets to 0. * * @param snapshot - Optional state snapshot to include in genesis */ restart(snapshot?: StateSnapshot): Promise; /** * Wait for the next block to be produced. * Used internally to ensure state changes are committed to RocksDB. */ private waitForNextBlock; private getBlockHeight; } /** * Get platform identifier for downloading correct binary. * Exported for testing only. * @internal */ export declare function getPlatformId(system?: string, arch?: string): PlatformInfo; export {}; //# sourceMappingURL=sandbox.d.ts.map