Skip to content

Commit

Permalink
feat: expose the entire runSolidityTests config
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Oct 23, 2024
1 parent 2f8b6d9 commit e62a664
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 7 deletions.
11 changes: 11 additions & 0 deletions v-next/example-project/contracts/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ contract CounterTest {
require(counter.x() == 0, "Initial value should be 0");
}

function testFailInitialValue() public view {
require(counter.x() == 1, "Initial value should be 1");
}

function testFuzzInc(uint8 x) public {
for (uint8 i = 0; i < x; i++) {
counter.inc();
}
require(counter.x() == x, "Value after calling inc x times should be x");
}

function testFailFuzzInc(uint8 x) public {
for (uint8 i = 0; i < x; i++) {
counter.inc();
}
require(counter.x() == x + 1, "Value after calling inc x times should be x + 1");
}

function invariant() public {
assert(true);
}
Expand Down
3 changes: 3 additions & 0 deletions v-next/example-project/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ const config: HardhatUserConfig = {
version: "0.8.1",
},
},
test: {
testFail: true,
}
},
test: {
version: "0.8.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RunOptions, TestEvent } from "./types.js";
import type { NewTaskActionFunction } from "../../../types/tasks.js";
import type { SolidityTestRunnerConfigArgs } from "@ignored/edr";

import { finished } from "node:stream/promises";

Expand All @@ -23,18 +24,19 @@ const runSolidityTests: NewTaskActionFunction = async (_taskArguments, hre) => {
)
).filter((artifact) => artifact !== undefined);

const config = {
projectRoot: hre.config.paths.root,
};

let includesFailures = false;
let includesErrors = false;

const profileName = hre.globalOptions.buildProfile;
const profile = hre.config.solidity.profiles[profileName];
const testOptions = profile.test;

const options: RunOptions = { timeout: testOptions.timeout };
const config: SolidityTestRunnerConfigArgs = {
projectRoot: hre.config.paths.root,
...testOptions,
};

const options: RunOptions = testOptions;

const runStream = run(artifacts, testSuiteIds, config, options);

Expand Down
62 changes: 62 additions & 0 deletions v-next/hardhat/src/internal/builtin-plugins/solidity/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type {
SolidityUserConfig,
} from "../../../types/config.js";
import type { HardhatUserConfigValidationError } from "../../../types/hooks.js";
import type { RunOptions } from "../solidity-test/types.js";

import { isObject } from "@ignored/hardhat-vnext-utils/lang";
import { resolveFromRoot } from "@ignored/hardhat-vnext-utils/path";
import {
conditionalUnionType,
incompatibleFieldType,
unionType,
validateUserConfigZodType,
} from "@ignored/hardhat-vnext-zod-utils";
import { z } from "zod";
Expand All @@ -35,7 +37,67 @@ const solcUserConfigType = z.object({
});

const solidityTestUserConfigType = z.object({
// RunOptions
timeout: z.number().optional(),
// Omit<SolidityTestRunnerConfigArgs, "projectRoot">
fsPermissions: z.array(z.object({
access: z.enum(["ReadWrite", "Read", "Write"]),
path: z.string(),
})).optional(),
trace: z.boolean().optional(),
testFail: z.boolean().optional(),
labels: z.array(z.object({
address: z.instanceof(Buffer),
label: z.string(),
})).optional(),
isolate: z.boolean().optional(),
ffi: z.boolean().optional(),
sender: z.instanceof(Buffer).optional(),
txOrigin: z.instanceof(Buffer).optional(),
initialBalance: z.bigint().optional(),
blockBaseFeePerGas: z.bigint().optional(),
blockCoinbase: z.instanceof(Buffer).optional(),
blockTimestamp: z.bigint().optional(),
blockDifficulty: z.bigint().optional(),
blockGasLimit: z.bigint().optional(),
disableBlockGasLimit: z.boolean().optional(),
memoryLimit: z.bigint().optional(),
ethRpcUrl: z.string().optional(),
forkBlockNumber: z.number().optional(),
rpcEndpoints: z.record(z.string()).optional(),
rpcCachePath: z.string().optional(),
rpcStorageCaching: z.object({
chains: unionType([
z.array(z.string()),
z.enum(["All", "None"]),
], ""),
endpoints: unionType([
z.string(),
z.enum(["All", "Remote"]),
], ""),
}).optional(),
promptTimeout: z.number().optional(),
fuzz: z.object({
failurePersistDir: z.string().optional(),
failurePersistFile: z.string().optional(),
runs: z.number().optional(),
maxTestRejects: z.number().optional(),
seed: z.string().optional(),
dictionaryWeight: z.number().optional(),
includeStorage: z.boolean().optional(),
includePushBytes: z.boolean().optional(),
}).optional(),
invariant: z.object({
failurePersistDir: z.string().optional(),
runs: z.number().optional(),
depth: z.number().optional(),
failOnRevert: z.boolean().optional(),
callOverride: z.boolean().optional(),
dictionaryWeight: z.number().optional(),
includeStorage: z.boolean().optional(),
includePushBytes: z.boolean().optional(),
shrinkRunLimit: z.number().optional(),
}).optional(),
});

const singleVersionSolcUserConfigType = solcUserConfigType.extend({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ declare module "../../../types/config.js" {
settings?: any;
}

export type SolidityTestUserConfig = RunOptions;
export type SolidityTestUserConfig = RunOptions &
Omit<SolidityTestRunnerConfigArgs, "projectRoot">;

export interface SingleVersionSolcUserConfig extends SolcUserConfig {
test?: SolidityTestUserConfig;
Expand Down Expand Up @@ -55,7 +56,8 @@ declare module "../../../types/config.js" {
settings: any;
}

export type SolidityTestConfig = RunOptions;
export type SolidityTestConfig = RunOptions &
Omit<SolidityTestRunnerConfigArgs, "projectRoot">;

export interface SolidityBuildProfileConfig {
compilers: SolcConfig[];
Expand Down Expand Up @@ -85,6 +87,7 @@ declare module "../../../types/config.js" {
import "../../../types/hre.js";
import type { SolidityBuildSystem } from "../../../types/solidity/build-system.js";
import type { RunOptions } from "../solidity-test/types.js";
import type { SolidityTestRunnerConfigArgs } from "@ignored/edr";

declare module "../../../types/hre.js" {
export interface HardhatRuntimeEnvironment {
Expand Down

0 comments on commit e62a664

Please sign in to comment.