Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/anvil-extra-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": minor
---

add `--anvil-arg` option to `cartesi run` to pass extra arguments to anvil
8 changes: 8 additions & 0 deletions apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ export const createRunCommand = () => {
"deploy application with PRT consensus",
).default(false),
)
.option(
"--anvil-arg <arg>",
"extra argument passed verbatim to anvil, can be repeated (e.g. --anvil-arg=--slots-in-an-epoch=1)",
(value, prev: string[]) => prev.concat([value]),
[] as string[],
)
.addOption(
new Option(
"--block-time <number>",
Expand Down Expand Up @@ -394,6 +400,7 @@ export const createRunCommand = () => {
.option("-v, --verbose", "verbose output", false)
.action(async (options, program) => {
const {
anvilArg: anvilArgs,
prt,
blockTime,
cpus,
Expand Down Expand Up @@ -456,6 +463,7 @@ export const createRunCommand = () => {

// run compose environment (detached)
const { cmd, config } = await startEnvironment({
anvilArgs,
blockTime,
cpus,
defaultBlock,
Expand Down
7 changes: 6 additions & 1 deletion apps/cli/src/compose/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ type ServiceOptions = {
imageTag?: string;
blockTime?: number;
forkConfig?: ForkConfig;
extraArgs?: string[];
};

// Anvil service
const service = (options?: ServiceOptions): Service => {
const blockTime = options?.blockTime ?? 2;
const imageTag = options?.imageTag ?? "latest";
const forkConfig = options?.forkConfig;
const extraArgs = options?.extraArgs ?? [];

// command for fork and command for load-state local (non-fork)
const command = forkConfig
const baseCommand = forkConfig
? [
"anvil",
"--chain-id",
Expand All @@ -30,6 +32,9 @@ const service = (options?: ServiceOptions): Service => {
]
: ["devnet", "--block-time", blockTime.toString()];

// extra arguments passed verbatim to anvil
const command = [...baseCommand, ...extraArgs];

// in case of forked network service is ready only when it responds with target block number
const test = forkConfig?.blockNumber
? ["CMD", "eth_isready", forkConfig.blockNumber?.toString()]
Expand Down
3 changes: 3 additions & 0 deletions apps/cli/src/exec/rollups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ const serviceMonitorTask = (options: {
};

export const startEnvironment = async (options: {
anvilArgs?: string[];
blockTime: number;
cpus?: number;
defaultBlock: "latest" | "safe" | "pending" | "finalized";
Expand Down Expand Up @@ -343,6 +344,7 @@ export const startEnvironment = async (options: {
services,
verbose,
} = options;
const anvilArgs = options.anvilArgs ?? [];

// setup the environment variable used in docker compose
const env: NodeJS.ProcessEnv = {
Expand All @@ -360,6 +362,7 @@ export const startEnvironment = async (options: {
const files = [
anvil({
blockTime,
extraArgs: anvilArgs,
forkConfig,
imageTag: runtimeVersion,
}),
Expand Down
4 changes: 4 additions & 0 deletions apps/cli/tests/integration/builder/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
describe,
expect,
it,
setDefaultTimeout,
} from "bun:test";
import fs from "fs-extra";
import path from "node:path";
Expand All @@ -14,6 +15,9 @@ import type { DockerDriveConfig } from "../../../src/config.js";
import { setupIntegrationTests, TEST_SDK } from "../config.js";
import { cleanupTempDir, createTempDir } from "./tmpdirTest.js";

// building pulls the base image on a cold docker cache, which can exceed the default 5s timeout
setDefaultTimeout(60000);

beforeAll(
async () => {
tmp.setGracefulCleanup();
Expand Down
51 changes: 51 additions & 0 deletions apps/cli/tests/unit/compose/anvil.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { describe, expect, it } from "bun:test";
import anvil from "../../../src/compose/anvil.js";

describe("compose anvil", () => {
it("should run devnet with block time by default", () => {
const { services } = anvil();
expect(services?.anvil?.command).toEqual([
"devnet",
"--block-time",
"2",
]);
});

it("should append extra args to devnet command", () => {
const { services } = anvil({
blockTime: 5,
extraArgs: ["--slots-in-an-epoch=1", "--gas-limit", "60000000"],
});
expect(services?.anvil?.command).toEqual([
"devnet",
"--block-time",
"5",
"--slots-in-an-epoch=1",
"--gas-limit",
"60000000",
]);
});

it("should append extra args to fork command", () => {
const { services } = anvil({
forkConfig: {
url: "http://localhost:8545",
blockNumber: 10n,
chainId: 1,
},
extraArgs: ["--slots-in-an-epoch=1"],
});
expect(services?.anvil?.command).toEqual([
"anvil",
"--chain-id",
"31337",
"--block-time",
"2",
"--fork-url",
"http://localhost:8545",
"--fork-block-number",
"10",
"--slots-in-an-epoch=1",
]);
});
});
Loading