diff --git a/packages/conformance/src/adapters/soldb.ts b/packages/conformance/src/adapters/soldb.ts index ecc1b96468..205b33c6f5 100644 --- a/packages/conformance/src/adapters/soldb.ts +++ b/packages/conformance/src/adapters/soldb.ts @@ -102,14 +102,19 @@ 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. function ethdebugResources(artifact: EthdebugArtifact): unknown { - if (artifact.resources) { - return artifact.resources; + const { resources, compilation } = artifact; + if (resources) { + return { compilation, ...resources }; } - if (artifact.compilation) { + if (compilation) { return Data.stamp("ethdebug/format/info/resources", { - compilation: artifact.compilation, + compilation, types: {}, pointers: {}, }); diff --git a/packages/conformance/src/runner.ts b/packages/conformance/src/runner.ts index d3d34686f0..505f756630 100644 --- a/packages/conformance/src/runner.ts +++ b/packages/conformance/src/runner.ts @@ -74,7 +74,7 @@ function sourceIds(artifact: EthdebugArtifact): Set { for (const source of artifact.compilation?.sources ?? []) { ids.add(source.id); } - for (const source of artifact.resources?.compilation.sources ?? []) { + for (const source of artifact.resources?.compilation?.sources ?? []) { ids.add(source.id); } return ids; @@ -180,7 +180,7 @@ export async function validateStaticConformance( } if ( - artifact.resources && + artifact.resources?.compilation && !Materials.isCompilation(artifact.resources.compilation) ) { issues.push( diff --git a/packages/conformance/src/types.ts b/packages/conformance/src/types.ts index eb294069ea..d2444b0e74 100644 --- a/packages/conformance/src/types.ts +++ b/packages/conformance/src/types.ts @@ -21,7 +21,7 @@ export interface EthdebugArtifact { compilation?: Materials.Compilation; resources?: { ethdebug?: Data.Stamp; - compilation: Materials.Compilation; + compilation?: Materials.Compilation; types: Record; pointers: Record; }; diff --git a/packages/conformance/test/conformance.test.ts b/packages/conformance/test/conformance.test.ts index 8eced22288..300e4c3844 100644 --- a/packages/conformance/test/conformance.test.ts +++ b/packages/conformance/test/conformance.test.ts @@ -233,8 +233,11 @@ describe("@ethdebug/conformance", () => { expect(result.exitCode).toBe(0); const json = result.json as any; expect(json.contracts[0].name).toBe("Counter"); + const written = JSON.parse( + await readFile(path.join(debugDir.debugDir, "ethdebug.json"), "utf8"), + ); expect(json.contracts[0].resources).toEqual( - withoutResourcesStamp(artifact.resources, json.contracts[0].resources), + withoutResourcesStamp(written, json.contracts[0].resources), ); expect( json.contracts[0].resources.compilation.sources[0].contents, @@ -497,6 +500,20 @@ describe("@ethdebug/conformance", () => { }); }); + it("puts a separate compilation into the resources it writes for SolDB", async () => { + const { compilation: _, ...resources } = validResources(); + const debugDir = await writeSoldbDebugDir( + validArtifact({ resources: resources as any }), + { contractName: "Counter" }, + ); + + const written = JSON.parse( + await readFile(path.join(debugDir.debugDir, "ethdebug.json"), "utf8"), + ); + + expect(written).toEqual({ ...resources, compilation: validCompilation() }); + }); + it("materializes non-empty resources into SolDB debug directories", async () => { const debugDir = await writeSoldbDebugDir( validArtifact({