diff --git a/packages/conformance/src/adapters/soldb.ts b/packages/conformance/src/adapters/soldb.ts index 205b33c6f5..f83d37f76a 100644 --- a/packages/conformance/src/adapters/soldb.ts +++ b/packages/conformance/src/adapters/soldb.ts @@ -102,10 +102,12 @@ function contractName(artifact: EthdebugArtifact, fallback?: string): string { ); } -// SolDB reads source contents only from the `compilation` of the resources -// file in its debug directory. A compiler can emit the compilation on its -// own instead (solc does since argotorg/solidity#17179), so put it in the -// resources here. +// Shim for an expected failure (#416): SolDB reads source contents only from +// the `compilation` of the resources file in its debug directory. A compiler +// can emit the compilation on its own instead (solc does since +// argotorg/solidity#17179), so put it in the resources here. A tripwire in +// the conformance test fails once SolDB reads the separate compilation; then +// write the resources as they are. function ethdebugResources(artifact: EthdebugArtifact): unknown { const { resources, compilation } = artifact; if (resources) { diff --git a/packages/conformance/test/conformance.test.ts b/packages/conformance/test/conformance.test.ts index 300e4c3844..50e8e19a7a 100644 --- a/packages/conformance/test/conformance.test.ts +++ b/packages/conformance/test/conformance.test.ts @@ -1,6 +1,6 @@ import { spawnSync } from "node:child_process"; import { accessSync, constants } from "node:fs"; -import { readFile } from "node:fs/promises"; +import { readFile, rm, writeFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -245,6 +245,59 @@ describe("@ethdebug/conformance", () => { }, ); + // Expected failure (#416): SolDB reads sources only from the compilation + // inside its resources file, and writeSoldbDebugDir shims this by merging + // the separate compilation in. This test gives SolDB the directory as + // solc's `--ethdebug` output writes it: `ethdebug_resources.json` without + // a compilation and `ethdebug_compilation.json` next to it. SolDB now + // rejects that resources file, so it reports no sources. The check fails + // once SolDB reports the sources from this directory; then remove the + // shim in ethdebugResources and this test. + it.skipIf(!soldb || !solc)( + "[soldb] does not yet read a compilation separate from resources", + async () => { + const artifact = await compileEthdebug({ + kind: "solc", + solcPath: solc!, + sourcePath: path.join(root, "test/fixtures/solc/Counter.sol"), + }); + const { compilation: _, ...resources } = artifact.resources ?? {}; + const compilation = + artifact.compilation ?? artifact.resources?.compilation; + expect(compilation).toBeDefined(); + + const debugDir = await writeSoldbDebugDir(artifact, { + contractName: "Counter", + }); + const dir = debugDir.debugDir; + await rm(path.join(dir, "ethdebug.json")); + await writeFile( + path.join(dir, "ethdebug_resources.json"), + JSON.stringify(resources), + ); + await writeFile( + path.join(dir, "ethdebug_compilation.json"), + JSON.stringify(compilation), + ); + + const result = await runSoldb({ + executable: soldb!, + args: ["info", "resources", "--ethdebug-dir", debugDir.spec, "--json"], + }); + const sources = + result.exitCode === 0 + ? JSON.parse(result.stdout).contracts[0].resources.compilation + ?.sources + : undefined; + + expect( + sources, + "SolDB now reads the separate compilation; " + + "remove the shim in ethdebugResources (#416)", + ).toBeUndefined(); + }, + ); + it.skipIf(!soldb || !solc)( "[soldb] checks multi-source solc ETHDebug resources through the SolDB consumer backend", async () => {