Skip to content

Commit

Permalink
Merge pull request #6332 from NomicFoundation/test-suites
Browse files Browse the repository at this point in the history
fix: correctly identify test suites
  • Loading branch information
galargh authored Feb 18, 2025
2 parents 29becc9 + 81cae17 commit 60426f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { RunOptions } from "./runner.js";
import type { Abi } from "../../../types/artifacts.js";
import type { SolidityTestConfig } from "../../../types/config.js";
import type {
SolidityTestRunnerConfigArgs,
Expand All @@ -7,6 +8,7 @@ import type {
PathPermission,
StorageCachingConfig,
AddressLabel,
Artifact,
} from "@ignored/edr";

import { hexStringToBytes } from "@ignored/hardhat-vnext-utils/hex";
Expand Down Expand Up @@ -98,3 +100,13 @@ export function solidityTestConfigToSolidityTestRunnerConfigArgs(
rpcStorageCaching,
};
}

export function isTestSuiteArtifact(artifact: Artifact): boolean {
const abi: Abi = JSON.parse(artifact.contract.abi);
return abi.some(({ type, name }) => {
if (type === "function" && typeof name === "string") {
return name.startsWith("test") || name.startsWith("invariant");
}
return false;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "../solidity/build-results.js";

import {
isTestSuiteArtifact,
solidityTestConfigToRunOptions,
solidityTestConfigToSolidityTestRunnerConfigArgs,
} from "./helpers.js";
Expand Down Expand Up @@ -86,7 +87,9 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (

const buildInfos = await getBuildInfos(results, hre.artifacts);
const artifacts = await getArtifacts(results);
const testSuiteIds = artifacts.map((artifact) => artifact.id);
const testSuiteIds = artifacts
.filter(isTestSuiteArtifact)
.map((artifact) => artifact.id);

console.log("Running Solidity tests");
console.log();
Expand Down

0 comments on commit 60426f8

Please sign in to comment.