Skip to content

Commit

Permalink
Files cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
schaable authored and fvictorio committed Oct 9, 2023
1 parent 09a0590 commit 38c6eb8
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 86 deletions.
23 changes: 2 additions & 21 deletions packages/hardhat-viem/src/internal/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ subtask(TASK_COMPILE_SOLIDITY_EMIT_ARTIFACTS).setAction(

const fp: Array<Promise<void>> = [];
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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<GetContractReturnType<A$Type["abi"]>>;
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<GetContractReturnType<A$Type["abi"]>>;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<GetContractReturnType<B$Type["abi"]>>;

Expand Down

This file was deleted.

58 changes: 22 additions & 36 deletions packages/hardhat-viem/test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions packages/hardhat-viem/test/update-snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 38c6eb8

Please sign in to comment.