From 38c6eb863fb19c38755d447637d9de534696b88e Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Fri, 29 Sep 2023 15:36:15 -0300 Subject: [PATCH] Files cleanup --- packages/hardhat-viem/src/internal/tasks.ts | 23 +------- .../contracts/A.sol/{A.ts => A.d.ts} | 7 +-- .../contracts/A.sol/{B.ts => B.d.ts} | 0 .../A.sol/{file.d.ts => artifacts.d.ts} | 0 .../snapshots/contracts/A.sol/index.ts | 7 --- .../contracts/C.sol/{B.ts => B.d.ts} | 5 +- .../contracts/C.sol/{C.ts => C.d.ts} | 0 .../C.sol/{file.d.ts => artifacts.d.ts} | 0 .../snapshots/contracts/C.sol/index.ts | 7 --- packages/hardhat-viem/test/integration.ts | 58 +++++++------------ .../hardhat-viem/test/update-snapshots.ts | 14 ++--- 11 files changed, 35 insertions(+), 86 deletions(-) rename packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/{A.ts => A.d.ts} (91%) rename packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/{B.ts => B.d.ts} (100%) rename packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/{file.d.ts => artifacts.d.ts} (100%) delete mode 100644 packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/index.ts rename packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/{B.ts => B.d.ts} (93%) rename packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/{C.ts => C.d.ts} (100%) rename packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/{file.d.ts => artifacts.d.ts} (100%) delete mode 100644 packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/index.ts diff --git a/packages/hardhat-viem/src/internal/tasks.ts b/packages/hardhat-viem/src/internal/tasks.ts index bd51135105..ac164df7d2 100644 --- a/packages/hardhat-viem/src/internal/tasks.ts +++ b/packages/hardhat-viem/src/internal/tasks.ts @@ -91,14 +91,11 @@ subtask(TASK_COMPILE_SOLIDITY_EMIT_ARTIFACTS).setAction( const fp: Array> = []; for (const { contractName, declaration } of contractTypeData) { - fp.push(writeFile(join(srcDir, `${contractName}.ts`), declaration)); + fp.push(writeFile(join(srcDir, `${contractName}.d.ts`), declaration)); } - const indexTs = generateIndexFile(contractTypeData); - fp.push(writeFile(join(srcDir, "index.ts"), indexTs)); - const dTs = generateDTsFile(contractTypeData); - fp.push(writeFile(join(srcDir, "file.d.ts"), dTs)); + fp.push(writeFile(join(srcDir, "artifacts.d.ts"), dTs)); try { await Promise.all(fp); @@ -225,22 +222,6 @@ declare module "@nomicfoundation/hardhat-viem/types" { `; } -function generateIndexFile( - contractTypeData: Array<{ - contractName: string; - fqn: string; - typeName: string; - declaration: string; - }> -) { - return `${AUTOGENERATED_FILE_PREFACE} - -${contractTypeData - .map((ctd) => `export * from "./${ctd.contractName}";`) - .join("\n")} -`; -} - function generateDTsFile( contractTypeData: Array<{ contractName: string; diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/A.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/A.d.ts similarity index 91% rename from packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/A.ts rename to packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/A.d.ts index 0b6c76f937..1ec49e4013 100644 --- a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/A.ts +++ b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/A.d.ts @@ -3,9 +3,8 @@ // tslint:disable // eslint-disable -import type { AbiParameterToPrimitiveType } from "abitype"; import type { Address } from "viem"; -import type { GetContractReturnType } from "@nomicfoundation/hardhat-viem/types"; +import type { AbiParameterToPrimitiveType, GetContractReturnType } from "@nomicfoundation/hardhat-viem/types"; import "@nomicfoundation/hardhat-viem/types"; export interface A$Type { @@ -60,12 +59,12 @@ export interface A$Type { declare module "@nomicfoundation/hardhat-viem/types" { export function deployContract( contractName: "A", - constructorArgs: [AbiParameterToPrimitiveType<{"internalType":"address","name":"_owner","type":"address"}>], + constructorArgs: [AbiParameterToPrimitiveType<{"name":"_owner","type":"address"}>], config?: DeployContractConfig ): Promise>; export function deployContract( contractName: "contracts/A.sol:A", - constructorArgs: [AbiParameterToPrimitiveType<{"internalType":"address","name":"_owner","type":"address"}>], + constructorArgs: [AbiParameterToPrimitiveType<{"name":"_owner","type":"address"}>], config?: DeployContractConfig ): Promise>; diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/B.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/B.d.ts similarity index 100% rename from packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/B.ts rename to packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/B.d.ts diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/file.d.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/artifacts.d.ts similarity index 100% rename from packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/file.d.ts rename to packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/artifacts.d.ts diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/index.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/index.ts deleted file mode 100644 index cbd4977aa5..0000000000 --- a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/A.sol/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// This file was autogenerated by hardhat-viem, do not edit it. -// prettier-ignore -// tslint:disable -// eslint-disable - -export * from "./A"; -export * from "./B"; diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/B.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/B.d.ts similarity index 93% rename from packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/B.ts rename to packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/B.d.ts index 9a1e9c7c72..611c2f6d85 100644 --- a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/B.ts +++ b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/B.d.ts @@ -3,9 +3,8 @@ // tslint:disable // eslint-disable -import type { AbiParameterToPrimitiveType } from "abitype"; import type { Address } from "viem"; -import type { GetContractReturnType } from "@nomicfoundation/hardhat-viem/types"; +import type { AbiParameterToPrimitiveType, GetContractReturnType } from "@nomicfoundation/hardhat-viem/types"; import "@nomicfoundation/hardhat-viem/types"; export interface B$Type { @@ -52,7 +51,7 @@ export interface B$Type { declare module "@nomicfoundation/hardhat-viem/types" { export function deployContract( contractName: "contracts/C.sol:B", - constructorArgs: [AbiParameterToPrimitiveType<{"internalType":"uint256","name":"_b","type":"uint256"}>, AbiParameterToPrimitiveType<{"internalType":"string","name":"_s","type":"string"}>], + constructorArgs: [AbiParameterToPrimitiveType<{"name":"_b","type":"uint256"}>, AbiParameterToPrimitiveType<{"name":"_s","type":"string"}>], config?: DeployContractConfig ): Promise>; diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/C.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/C.d.ts similarity index 100% rename from packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/C.ts rename to packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/C.d.ts diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/file.d.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/artifacts.d.ts similarity index 100% rename from packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/file.d.ts rename to packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/artifacts.d.ts diff --git a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/index.ts b/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/index.ts deleted file mode 100644 index c452a1eddf..0000000000 --- a/packages/hardhat-viem/test/fixture-projects/type-generation/snapshots/contracts/C.sol/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// This file was autogenerated by hardhat-viem, do not edit it. -// prettier-ignore -// tslint:disable -// eslint-disable - -export * from "./B"; -export * from "./C"; diff --git a/packages/hardhat-viem/test/integration.ts b/packages/hardhat-viem/test/integration.ts index c16b81fd3b..f8ff1454c5 100644 --- a/packages/hardhat-viem/test/integration.ts +++ b/packages/hardhat-viem/test/integration.ts @@ -321,117 +321,103 @@ describe("Integration tests", function () { await assertSnapshotMatch(snapshotPath, generatedFilePath); }); - it("should generate contracts/A.sol/A.ts", async function () { - const snapshotPath = path.join("snapshots", "contracts", "A.sol", "A.ts"); - const generatedFilePath = path.join( - "artifacts", + it("should generate contracts/A.sol/A.d.ts", async function () { + const snapshotPath = path.join( + "snapshots", "contracts", "A.sol", - "A.ts" + "A.d.ts" ); - - await assertSnapshotMatch(snapshotPath, generatedFilePath); - }); - - it("should generate contracts/A.sol/B.ts", async function () { - const snapshotPath = path.join("snapshots", "contracts", "A.sol", "B.ts"); const generatedFilePath = path.join( "artifacts", "contracts", "A.sol", - "B.ts" + "A.d.ts" ); await assertSnapshotMatch(snapshotPath, generatedFilePath); }); - it("should generate contracts/A.sol/file.d.ts", async function () { + it("should generate contracts/A.sol/B.d.ts", async function () { const snapshotPath = path.join( "snapshots", "contracts", "A.sol", - "file.d.ts" + "B.d.ts" ); const generatedFilePath = path.join( "artifacts", "contracts", "A.sol", - "file.d.ts" + "B.d.ts" ); await assertSnapshotMatch(snapshotPath, generatedFilePath); }); - it("should generate contracts/A.sol/index.ts", async function () { + it("should generate contracts/A.sol/artifacts.d.ts", async function () { const snapshotPath = path.join( "snapshots", "contracts", "A.sol", - "index.ts" + "artifacts.d.ts" ); const generatedFilePath = path.join( "artifacts", "contracts", "A.sol", - "index.ts" + "artifacts.d.ts" ); await assertSnapshotMatch(snapshotPath, generatedFilePath); }); - it("should generate contracts/C.sol/B.ts", async function () { - const snapshotPath = path.join("snapshots", "contracts", "C.sol", "B.ts"); - const generatedFilePath = path.join( - "artifacts", + it("should generate contracts/C.sol/B.d.ts", async function () { + const snapshotPath = path.join( + "snapshots", "contracts", "C.sol", - "B.ts" + "B.d.ts" ); - - await assertSnapshotMatch(snapshotPath, generatedFilePath); - }); - - it("should generate contracts/C.sol/C.ts", async function () { - const snapshotPath = path.join("snapshots", "contracts", "C.sol", "C.ts"); const generatedFilePath = path.join( "artifacts", "contracts", "C.sol", - "C.ts" + "B.d.ts" ); await assertSnapshotMatch(snapshotPath, generatedFilePath); }); - it("should generate contracts/C.sol/file.d.ts", async function () { + it("should generate contracts/C.sol/C.d.ts", async function () { const snapshotPath = path.join( "snapshots", "contracts", "C.sol", - "file.d.ts" + "C.d.ts" ); const generatedFilePath = path.join( "artifacts", "contracts", "C.sol", - "file.d.ts" + "C.d.ts" ); await assertSnapshotMatch(snapshotPath, generatedFilePath); }); - it("should generate contracts/C.sol/index.ts", async function () { + it("should generate contracts/C.sol/artifacts.d.ts", async function () { const snapshotPath = path.join( "snapshots", "contracts", "C.sol", - "index.ts" + "artifacts.d.ts" ); const generatedFilePath = path.join( "artifacts", "contracts", "C.sol", - "index.ts" + "artifacts.d.ts" ); await assertSnapshotMatch(snapshotPath, generatedFilePath); diff --git a/packages/hardhat-viem/test/update-snapshots.ts b/packages/hardhat-viem/test/update-snapshots.ts index 662cc1c3dc..03540b8a57 100644 --- a/packages/hardhat-viem/test/update-snapshots.ts +++ b/packages/hardhat-viem/test/update-snapshots.ts @@ -6,14 +6,12 @@ import { resetHardhatContext } from "hardhat/plugins-testing"; const snapshotPartialPaths = [ "artifacts.d.ts", - path.join("contracts", "A.sol", "A.ts"), - path.join("contracts", "A.sol", "B.ts"), - path.join("contracts", "A.sol", "file.d.ts"), - path.join("contracts", "A.sol", "index.ts"), - path.join("contracts", "C.sol", "B.ts"), - path.join("contracts", "C.sol", "C.ts"), - path.join("contracts", "C.sol", "file.d.ts"), - path.join("contracts", "C.sol", "index.ts"), + path.join("contracts", "A.sol", "A.d.ts"), + path.join("contracts", "A.sol", "B.d.ts"), + path.join("contracts", "A.sol", "artifacts.d.ts"), + path.join("contracts", "C.sol", "B.d.ts"), + path.join("contracts", "C.sol", "C.d.ts"), + path.join("contracts", "C.sol", "artifacts.d.ts"), ]; const originalCwd = process.cwd();