diff --git a/.changeset/chatty-toys-hunt.md b/.changeset/chatty-toys-hunt.md new file mode 100644 index 000000000..db2e39a74 --- /dev/null +++ b/.changeset/chatty-toys-hunt.md @@ -0,0 +1,12 @@ +--- +'@typechain/hardhat': major +'@typechain/ethers-v5': major +'@typechain/web3-v1': major +'typechain': major +--- + +Directory tree in generated types now reflects the directory tree in the inputs. +Also, only the main contract type is reexported from each file. + +This change solves a number of name clashing problems. +All generated code can still be imported after updating the import path. diff --git a/README.md b/README.md index 382b61a5f..7e21c2975 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,10 @@ Use `ethers-v5` target to generate wrappers for [ethers.js](https://github.com/e work great with Hardhat, use [Hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat). If you're using Ethers.js v4, you can find legacy `@typechain/ethers-v4` target on -[npm](https://www.npmjs.com/package/@typechain/ethers-v4) and commit . +[npm](https://www.npmjs.com/package/@typechain/ethers-v4) and commit +[`db551b5`](https://github.com/dethcrypto/TypeChain/tree/db551b5c5f70e86f3ca342551e9e0369d099cfa2). -### Truffle v4 / v5 +### Truffle v5 Truffle target is great when you use truffle contracts already. Check out [truffle-typechain-example](https://github.com/ethereum-ts/truffle-typechain-example) for more details. It require diff --git a/contracts/v0.8.9/nested/a/NestedLibrary.json b/contracts/v0.8.9/nested/a/NestedLibrary.json new file mode 100644 index 000000000..62e20b2d3 --- /dev/null +++ b/contracts/v0.8.9/nested/a/NestedLibrary.json @@ -0,0 +1,9 @@ +[ + { + "inputs": [], + "name": "getValue", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "pure", + "type": "function" + } +] diff --git a/contracts/v0.8.9/nested/b/NestedLibrary.json b/contracts/v0.8.9/nested/b/NestedLibrary.json new file mode 100644 index 000000000..670e91fe2 --- /dev/null +++ b/contracts/v0.8.9/nested/b/NestedLibrary.json @@ -0,0 +1,9 @@ +[ + { + "inputs": [], + "name": "getValue", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + } +] diff --git a/examples/ethers-v5/src/index.ts b/examples/ethers-v5/src/index.ts index ced03285d..39be25f9e 100644 --- a/examples/ethers-v5/src/index.ts +++ b/examples/ethers-v5/src/index.ts @@ -1,4 +1,5 @@ -import { utils, ethers } from 'ethers' +import { ethers, utils } from 'ethers' + import { Dai__factory } from '../types/ethers-contracts/factories/Dai__factory' const RPC_HOST = 'https://mainnet.infura.io/v3/6d6c70e65c77429482df5b64a4d0c943' diff --git a/examples/hardhat-truffe-v5/test/counter.ts b/examples/hardhat-truffe-v5/test/counter.ts index 89cce145a..7e3f13bfd 100644 --- a/examples/hardhat-truffe-v5/test/counter.ts +++ b/examples/hardhat-truffe-v5/test/counter.ts @@ -1,8 +1,7 @@ -import { artifacts, contract } from 'hardhat' +import BN from 'bn.js' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' - -import BN from 'bn.js' +import { artifacts, contract } from 'hardhat' // chai.use(solidity); chai.use(chaiAsPromised).should() @@ -31,7 +30,7 @@ contract('Counter', (accounts: string[]) => { describe('count up', async () => { it('should count up', async () => { await counter.countUp() - let count = await counter.getCount() + const count = await counter.getCount() expect(count.eq(new BN(1))) }) }) diff --git a/examples/hardhat/Counter.ts b/examples/hardhat/Counter.ts new file mode 100644 index 000000000..cc8259200 --- /dev/null +++ b/examples/hardhat/Counter.ts @@ -0,0 +1,111 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + BaseContract, + BigNumber, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers' +import { FunctionFragment, Result, EventFragment } from '@ethersproject/abi' +import { Listener, Provider } from '@ethersproject/providers' +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from '../common' + +export interface CounterInterface extends utils.Interface { + contractName: 'Counter' + functions: { + 'countDown()': FunctionFragment + 'countUp()': FunctionFragment + 'getCount()': FunctionFragment + } + + encodeFunctionData(functionFragment: 'countDown', values?: undefined): string + encodeFunctionData(functionFragment: 'countUp', values?: undefined): string + encodeFunctionData(functionFragment: 'getCount', values?: undefined): string + + decodeFunctionResult(functionFragment: 'countDown', data: BytesLike): Result + decodeFunctionResult(functionFragment: 'countUp', data: BytesLike): Result + decodeFunctionResult(functionFragment: 'getCount', data: BytesLike): Result + + events: { + 'CountedTo(uint256)': EventFragment + } + + getEvent(nameOrSignatureOrTopic: 'CountedTo'): EventFragment +} + +export type CountedToEvent = TypedEvent<[BigNumber], { number: BigNumber }> + +export type CountedToEventFilter = TypedEventFilter + +export interface Counter extends BaseContract { + contractName: 'Counter' + connect(signerOrProvider: Signer | Provider | string): this + attach(addressOrName: string): this + deployed(): Promise + + interface: CounterInterface + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise> + + listeners(eventFilter?: TypedEventFilter): Array> + listeners(eventName?: string): Array + removeAllListeners(eventFilter: TypedEventFilter): this + removeAllListeners(eventName?: string): this + off: OnEvent + on: OnEvent + once: OnEvent + removeListener: OnEvent + + functions: { + countDown(overrides?: Overrides & { from?: string | Promise }): Promise + + countUp(overrides?: Overrides & { from?: string | Promise }): Promise + + getCount(overrides?: CallOverrides): Promise<[BigNumber]> + } + + countDown(overrides?: Overrides & { from?: string | Promise }): Promise + + countUp(overrides?: Overrides & { from?: string | Promise }): Promise + + getCount(overrides?: CallOverrides): Promise + + callStatic: { + countDown(overrides?: CallOverrides): Promise + + countUp(overrides?: CallOverrides): Promise + + getCount(overrides?: CallOverrides): Promise + } + + filters: { + 'CountedTo(uint256)'(number?: null): CountedToEventFilter + CountedTo(number?: null): CountedToEventFilter + } + + estimateGas: { + countDown(overrides?: Overrides & { from?: string | Promise }): Promise + + countUp(overrides?: Overrides & { from?: string | Promise }): Promise + + getCount(overrides?: CallOverrides): Promise + } + + populateTransaction: { + countDown(overrides?: Overrides & { from?: string | Promise }): Promise + + countUp(overrides?: Overrides & { from?: string | Promise }): Promise + + getCount(overrides?: CallOverrides): Promise + } +} diff --git a/examples/web3-v1/src/index.ts b/examples/web3-v1/src/index.ts index 5e1661137..b169cbdc1 100644 --- a/examples/web3-v1/src/index.ts +++ b/examples/web3-v1/src/index.ts @@ -1,5 +1,6 @@ import Web3 from 'web3' -import { Dai } from '../types/web3-v1-contracts/dai' + +import { Dai } from '../types/web3-v1-contracts/Dai' const abi = require('../abi/dai.json') diff --git a/packages/hardhat-test/typechain-types/factories/index.ts b/packages/hardhat-test/typechain-types/factories/index.ts new file mode 100644 index 000000000..1d5e59c84 --- /dev/null +++ b/packages/hardhat-test/typechain-types/factories/index.ts @@ -0,0 +1,6 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { Counter__factory } from "./Counter__factory"; +export { Demo__factory } from "./Demo__factory"; +export { StructsInConstructor__factory } from "./StructsInConstructor__factory"; diff --git a/packages/hardhat-test/typechain-types/index.ts b/packages/hardhat-test/typechain-types/index.ts index daf689d32..66e9bbebb 100644 --- a/packages/hardhat-test/typechain-types/index.ts +++ b/packages/hardhat-test/typechain-types/index.ts @@ -4,7 +4,7 @@ export type { Counter } from "./Counter"; export type { Demo } from "./Demo"; export type { StructsInConstructor } from "./StructsInConstructor"; - +export * as factories from "./factories"; export { Counter__factory } from "./factories/Counter__factory"; export { Demo__factory } from "./factories/Demo__factory"; export { StructsInConstructor__factory } from "./factories/StructsInConstructor__factory"; diff --git a/packages/hardhat/test/__snapshots__/project.test.snap b/packages/hardhat/test/__snapshots__/project.test.snap index 4c21a93f1..00f5f2af4 100644 --- a/packages/hardhat/test/__snapshots__/project.test.snap +++ b/packages/hardhat/test/__snapshots__/project.test.snap @@ -4,14 +4,16 @@ exports[`Typechain x Hardhat when recompiling generates typings only for changed "/* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ +import type * as lib from \\"./lib\\"; +export type { lib }; export type { EdgeCases } from \\"./EdgeCases\\"; -export type { SafeMath } from \\"./SafeMath\\"; export type { TestContract } from \\"./TestContract\\"; export type { TestContract1 } from \\"./TestContract1\\"; export type { TestContract2 } from \\"./TestContract2\\"; - +export * as factories from \\"./factories\\"; export { EdgeCases__factory } from \\"./factories/EdgeCases__factory\\"; -export { SafeMath__factory } from \\"./factories/SafeMath__factory\\"; +export type { SafeMath } from \\"./lib/SafeMath\\"; +export { SafeMath__factory } from \\"./factories/lib/SafeMath__factory\\"; export { TestContract__factory } from \\"./factories/TestContract__factory\\"; export { TestContract1__factory } from \\"./factories/TestContract1__factory\\"; export { TestContract2__factory } from \\"./factories/TestContract2__factory\\"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/EdgeCases.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/EdgeCases.ts similarity index 98% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/EdgeCases.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/EdgeCases.ts index 5f5dacf21..17ba28299 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/EdgeCases.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/EdgeCases.ts @@ -9,7 +9,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../../common"; export interface EdgeCasesInterface extends utils.Interface { contractName: "EdgeCases"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/TestContract.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/TestContract.ts similarity index 98% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/TestContract.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/TestContract.ts index 6d94ac0fd..0cf00788a 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/TestContract.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/TestContract.ts @@ -9,7 +9,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../../common"; export interface TestContractInterface extends utils.Interface { contractName: "TestContract"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/TestContract1.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/TestContract1.ts similarity index 98% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/TestContract1.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/TestContract1.ts index eecadb857..67827fcd2 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/TestContract1.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/TestContract1.ts @@ -9,7 +9,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../../common"; export interface TestContract1Interface extends utils.Interface { contractName: "TestContract1"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/index.ts new file mode 100644 index 000000000..c81e83281 --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/index.ts @@ -0,0 +1,8 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type * as lib from "./lib"; +export type { lib }; +export type { EdgeCases } from "./EdgeCases"; +export type { TestContract } from "./TestContract"; +export type { TestContract1 } from "./TestContract1"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/SafeMath.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/lib/SafeMath.ts similarity index 99% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/SafeMath.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/lib/SafeMath.ts index 0be950ef4..d36f773cc 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/SafeMath.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/lib/SafeMath.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../../../common"; export interface SafeMathInterface extends utils.Interface { contractName: "SafeMath"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/lib/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/lib/index.ts new file mode 100644 index 000000000..cb397bdeb --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/lib/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { SafeMath } from "./SafeMath"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/index.ts new file mode 100644 index 000000000..a11e4ca29 --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type * as contracts from "./contracts"; +export type { contracts }; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/ERC20.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/externalArtifacts/ERC20.ts similarity index 99% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/ERC20.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/externalArtifacts/ERC20.ts index 18a70932a..fec9b58c8 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/ERC20.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/externalArtifacts/ERC20.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface ERC20Interface extends utils.Interface { contractName: "ERC20"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/externalArtifacts/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/externalArtifacts/index.ts new file mode 100644 index 000000000..063d2fbc4 --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/externalArtifacts/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { ERC20 } from "./ERC20"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/EdgeCases__factory.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/EdgeCases__factory.ts similarity index 97% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/EdgeCases__factory.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/EdgeCases__factory.ts index 787fd70e9..b404d3dee 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/EdgeCases__factory.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/EdgeCases__factory.ts @@ -11,7 +11,10 @@ import { Overrides, } from "ethers"; import type { Provider, TransactionRequest } from "@ethersproject/providers"; -import type { EdgeCases, EdgeCasesInterface } from "../EdgeCases"; +import type { + EdgeCases, + EdgeCasesInterface, +} from "../../../artifacts/contracts/EdgeCases"; const _abi = [ { diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/TestContract1__factory.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/TestContract1__factory.ts similarity index 96% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/TestContract1__factory.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/TestContract1__factory.ts index 9391493f9..81025d995 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/TestContract1__factory.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/TestContract1__factory.ts @@ -10,7 +10,10 @@ import { Overrides, } from "ethers"; import type { Provider, TransactionRequest } from "@ethersproject/providers"; -import type { TestContract1, TestContract1Interface } from "../TestContract1"; +import type { + TestContract1, + TestContract1Interface, +} from "../../../artifacts/contracts/TestContract1"; const _abi = [ { diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/TestContract__factory.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/TestContract__factory.ts similarity index 97% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/TestContract__factory.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/TestContract__factory.ts index 0bde16c3f..05fc4e7c8 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/TestContract__factory.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/TestContract__factory.ts @@ -10,7 +10,10 @@ import { Overrides, } from "ethers"; import type { Provider, TransactionRequest } from "@ethersproject/providers"; -import type { TestContract, TestContractInterface } from "../TestContract"; +import type { + TestContract, + TestContractInterface, +} from "../../../artifacts/contracts/TestContract"; const _abi = [ { diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/index.ts new file mode 100644 index 000000000..fc1517da7 --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/index.ts @@ -0,0 +1,7 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export * as lib from "./lib"; +export { EdgeCases__factory } from "./EdgeCases__factory"; +export { TestContract__factory } from "./TestContract__factory"; +export { TestContract1__factory } from "./TestContract1__factory"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/SafeMath__factory.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/lib/SafeMath__factory.ts similarity index 97% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/SafeMath__factory.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/lib/SafeMath__factory.ts index ce138fc40..02c63ef7d 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/SafeMath__factory.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/lib/SafeMath__factory.ts @@ -3,7 +3,10 @@ /* eslint-disable */ import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers"; import type { Provider, TransactionRequest } from "@ethersproject/providers"; -import type { SafeMath, SafeMathInterface } from "../SafeMath"; +import type { + SafeMath, + SafeMathInterface, +} from "../../../../artifacts/contracts/lib/SafeMath"; const _abi = [ { diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/lib/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/lib/index.ts new file mode 100644 index 000000000..ca18d664f --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/contracts/lib/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { SafeMath__factory } from "./SafeMath__factory"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/index.ts new file mode 100644 index 000000000..6397da096 --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/artifacts/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export * as contracts from "./contracts"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/ERC20__factory.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/externalArtifacts/ERC20__factory.ts similarity index 99% rename from packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/ERC20__factory.ts rename to packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/externalArtifacts/ERC20__factory.ts index 768d5027f..559fc4a34 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/ERC20__factory.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/externalArtifacts/ERC20__factory.ts @@ -3,7 +3,7 @@ /* eslint-disable */ import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers"; import type { Provider, TransactionRequest } from "@ethersproject/providers"; -import type { ERC20, ERC20Interface } from "../ERC20"; +import type { ERC20, ERC20Interface } from "../../externalArtifacts/ERC20"; const _abi = [ { diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/externalArtifacts/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/externalArtifacts/index.ts new file mode 100644 index 000000000..4a39ead9a --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/externalArtifacts/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { ERC20__factory } from "./ERC20__factory"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/index.ts new file mode 100644 index 000000000..35aa9033f --- /dev/null +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/factories/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export * as artifacts from "./artifacts"; +export * as externalArtifacts from "./externalArtifacts"; diff --git a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/index.ts b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/index.ts index c0efcc001..f86865461 100644 --- a/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/index.ts +++ b/packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/index.ts @@ -1,14 +1,18 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ -export type { EdgeCases } from "./EdgeCases"; -export type { SafeMath } from "./SafeMath"; -export type { TestContract } from "./TestContract"; -export type { TestContract1 } from "./TestContract1"; -export type { ERC20 } from "./ERC20"; - -export { EdgeCases__factory } from "./factories/EdgeCases__factory"; -export { SafeMath__factory } from "./factories/SafeMath__factory"; -export { TestContract__factory } from "./factories/TestContract__factory"; -export { TestContract1__factory } from "./factories/TestContract1__factory"; -export { ERC20__factory } from "./factories/ERC20__factory"; +import type * as artifacts from "./artifacts"; +export type { artifacts }; +import type * as externalArtifacts from "./externalArtifacts"; +export type { externalArtifacts }; +export * as factories from "./factories"; +export type { EdgeCases } from "./artifacts/contracts/EdgeCases"; +export { EdgeCases__factory } from "./factories/artifacts/contracts/EdgeCases__factory"; +export type { SafeMath } from "./artifacts/contracts/lib/SafeMath"; +export { SafeMath__factory } from "./factories/artifacts/contracts/lib/SafeMath__factory"; +export type { TestContract } from "./artifacts/contracts/TestContract"; +export { TestContract__factory } from "./factories/artifacts/contracts/TestContract__factory"; +export type { TestContract1 } from "./artifacts/contracts/TestContract1"; +export { TestContract1__factory } from "./factories/artifacts/contracts/TestContract1__factory"; +export type { ERC20 } from "./externalArtifacts/ERC20"; +export { ERC20__factory } from "./factories/externalArtifacts/ERC20__factory"; diff --git a/packages/hardhat/test/project.test.ts b/packages/hardhat/test/project.test.ts index 579db0138..48c25d853 100644 --- a/packages/hardhat/test/project.test.ts +++ b/packages/hardhat/test/project.test.ts @@ -78,7 +78,7 @@ describe('Typechain x Hardhat', function () { expect(exists).toEqual(false) await this.hre.run('compile') - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 11 typings!']) + expect(consoleLogMock).toHaveBeenCalledWith([expect.stringMatching(/Successfully generated \d\d\d? typings!/)]) // copy one more file and recompile project copyFileSync(TestContract2OriginPath, TestContract2DestinationPath) @@ -86,7 +86,7 @@ describe('Typechain x Hardhat', function () { expect(existsSync(this.hre.config.typechain.outDir)).toEqual(true) expect(readFileSync(typechainIndexFilePath, 'utf-8')).toMatchSnapshot() - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 5 typings!']) // 4 b/c commons.ts, hardhat.d.ts, index.ts, TestContract2 and TestContract2Factory + expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 8 typings!']) }) it('does nothing when there are no changes to recompile', async function () { @@ -94,7 +94,7 @@ describe('Typechain x Hardhat', function () { expect(exists).toEqual(false) await this.hre.run('compile') - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 11 typings!']) + expect(consoleLogMock).toHaveBeenCalledWith([expect.stringMatching(/Successfully generated \d\d\d? typings!/)]) await this.hre.run('compile') @@ -107,12 +107,12 @@ describe('Typechain x Hardhat', function () { expect(exists).toEqual(false) await this.hre.run('compile') - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 11 typings!']) + expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 14 typings!']) await this.hre.run('typechain') expect(existsSync(this.hre.config.typechain.outDir)).toEqual(true) - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 11 typings!']) + expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 14 typings!']) }) it('generates typing for external artifacts', async function () { @@ -122,10 +122,10 @@ describe('Typechain x Hardhat', function () { this.hre.config.typechain.externalArtifacts = ['externalArtifacts/*.json'] await this.hre.run('compile') - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 5 typings for external artifacts!']) + expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 14 typings for external artifacts!']) await this.hre.run('compile') - expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 5 typings for external artifacts!']) + expect(consoleLogMock).toHaveBeenCalledWith(['Successfully generated 14 typings for external artifacts!']) }) }) }) diff --git a/packages/target-ethers-v5-test/test/DataTypesInput.test.ts b/packages/target-ethers-v5-test/test/DataTypesInput.test.ts index d46add399..8a498cd45 100644 --- a/packages/target-ethers-v5-test/test/DataTypesInput.test.ts +++ b/packages/target-ethers-v5-test/test/DataTypesInput.test.ts @@ -6,7 +6,7 @@ import { BigNumber, ethers } from 'ethers' import type { AssertTrue, IsExact } from 'test-utils' import { q18, typedAssert } from 'test-utils' -import type { DataTypesInput } from '../types/DataTypesInput' +import type { DataTypesInput } from '../types/v0.6.4/DataTypesInput' import { createNewBlockchain, deployContract } from './common' type Struct1Struct = DataTypesInput.Struct1Struct @@ -287,4 +287,4 @@ describe('DataTypesInput', () => { // @ts-expect-error contract.functions.not_existing(1) }) -}) +}).timeout(15_000) diff --git a/packages/target-ethers-v5-test/test/Events.test.ts b/packages/target-ethers-v5-test/test/Events.test.ts index cae390be0..0a3d6b529 100644 --- a/packages/target-ethers-v5-test/test/Events.test.ts +++ b/packages/target-ethers-v5-test/test/Events.test.ts @@ -2,7 +2,7 @@ import { BigNumber, ethers } from 'ethers' import { AssertTrue, IsExact, typedAssert } from 'test-utils' import type { TypedEventFilter } from '../types/common' -import type { Event1Event, Event1EventFilter, Event3_bool_uint256_Event, Events } from '../types/Events' +import type { Event1Event, Event1EventFilter, Event3_bool_uint256_Event, Events } from '../types/v0.6.4/Events' import { createNewBlockchain, deployContract } from './common' describe('Events', () => { diff --git a/packages/target-ethers-v5-test/test/Issue552Reproduction.test.ts b/packages/target-ethers-v5-test/test/Issue552Reproduction.test.ts index 9063de131..bac19da11 100644 --- a/packages/target-ethers-v5-test/test/Issue552Reproduction.test.ts +++ b/packages/target-ethers-v5-test/test/Issue552Reproduction.test.ts @@ -1,18 +1,18 @@ import type { AssertTrue, IsExact } from 'test-utils' -import type { Issue552Observer, Issue552Reproduction } from '../types/Issue552Reproduction' +import type { Issue552_Observer, Issue552_Reproduction } from '../types/v0.8.9/Issue552_Reproduction' import { createNewBlockchain, deployContract } from './common' describe('Issue552Reproduction', () => { it('does not emit overly long tuples', () => { type _ = [ AssertTrue< - IsExact + IsExact >, AssertTrue< IsExact< - Issue552Reproduction.ObservationParamsStructOutput['observations'], - Issue552Observer.ObservationStructOutput[] + Issue552_Reproduction.ObservationParamsStructOutput['observations'], + Issue552_Observer.ObservationStructOutput[] > >, ] @@ -22,7 +22,7 @@ describe('Issue552Reproduction', () => { const { signer, ganache } = await createNewBlockchain() try { - const contract = await deployContract(signer, 'Issue552_Reproduction') + const contract = await deployContract(signer, 'Issue552_Reproduction') await contract.input([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) } finally { diff --git a/packages/target-ethers-v5-test/test/Overload.test.ts b/packages/target-ethers-v5-test/test/Overload.test.ts index f84df8192..b1325097a 100644 --- a/packages/target-ethers-v5-test/test/Overload.test.ts +++ b/packages/target-ethers-v5-test/test/Overload.test.ts @@ -2,7 +2,7 @@ import { expect } from 'earljs' import { BigNumber } from 'ethers' import { typedAssert } from 'test-utils' -import type { Overloads } from '../types/Overloads' +import type { Overloads } from '../types/v0.6.4/Overloads' import { createNewBlockchain, deployContract } from './common' describe('Overloads', () => { diff --git a/packages/target-ethers-v5-test/types/factories/index.ts b/packages/target-ethers-v5-test/types/factories/index.ts new file mode 100644 index 000000000..49c819f1e --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export * as v064 from "./v0.6.4"; +export * as v089 from "./v0.8.9"; diff --git a/packages/target-ethers-v5-test/types/factories/B__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/B__factory.ts similarity index 94% rename from packages/target-ethers-v5-test/types/factories/B__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/B__factory.ts index fdaf19d1a..2e94a3ad9 100644 --- a/packages/target-ethers-v5-test/types/factories/B__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/B__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { B, BInterface } from "../B"; +import type { B, BInterface } from "../../v0.6.4/B"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/DataTypesInput__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesInput__factory.ts similarity index 99% rename from packages/target-ethers-v5-test/types/factories/DataTypesInput__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesInput__factory.ts index 9b7530985..c64e610b8 100644 --- a/packages/target-ethers-v5-test/types/factories/DataTypesInput__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesInput__factory.ts @@ -7,7 +7,7 @@ import type { Provider } from "@ethersproject/providers"; import type { DataTypesInput, DataTypesInputInterface, -} from "../DataTypesInput"; +} from "../../v0.6.4/DataTypesInput"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/DataTypesPure__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesPure__factory.ts similarity index 97% rename from packages/target-ethers-v5-test/types/factories/DataTypesPure__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesPure__factory.ts index 63f5eaa41..df564aa68 100644 --- a/packages/target-ethers-v5-test/types/factories/DataTypesPure__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesPure__factory.ts @@ -4,7 +4,10 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { DataTypesPure, DataTypesPureInterface } from "../DataTypesPure"; +import type { + DataTypesPure, + DataTypesPureInterface, +} from "../../v0.6.4/DataTypesPure"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/DataTypesView__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesView__factory.ts similarity index 97% rename from packages/target-ethers-v5-test/types/factories/DataTypesView__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesView__factory.ts index 28e20928d..58efde74e 100644 --- a/packages/target-ethers-v5-test/types/factories/DataTypesView__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/DataTypesView__factory.ts @@ -4,7 +4,10 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { DataTypesView, DataTypesViewInterface } from "../DataTypesView"; +import type { + DataTypesView, + DataTypesViewInterface, +} from "../../v0.6.4/DataTypesView"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Events__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/Events__factory.ts similarity index 98% rename from packages/target-ethers-v5-test/types/factories/Events__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/Events__factory.ts index 6c2e9c718..73bb5bc18 100644 --- a/packages/target-ethers-v5-test/types/factories/Events__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/Events__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { Events, EventsInterface } from "../Events"; +import type { Events, EventsInterface } from "../../v0.6.4/Events"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Issue428Reproduction__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/Issue428_Reproduction__factory.ts similarity index 65% rename from packages/target-ethers-v5-test/types/factories/Issue428Reproduction__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/Issue428_Reproduction__factory.ts index 6011c7f7e..b8a1c1bf3 100644 --- a/packages/target-ethers-v5-test/types/factories/Issue428Reproduction__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/Issue428_Reproduction__factory.ts @@ -5,9 +5,9 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; import type { - Issue428Reproduction, - Issue428ReproductionInterface, -} from "../Issue428Reproduction"; + Issue428_Reproduction, + Issue428_ReproductionInterface, +} from "../../v0.6.4/Issue428_Reproduction"; const _abi = [ { @@ -25,19 +25,19 @@ const _abi = [ }, ]; -export class Issue428Reproduction__factory { +export class Issue428_Reproduction__factory { static readonly abi = _abi; - static createInterface(): Issue428ReproductionInterface { - return new utils.Interface(_abi) as Issue428ReproductionInterface; + static createInterface(): Issue428_ReproductionInterface { + return new utils.Interface(_abi) as Issue428_ReproductionInterface; } static connect( address: string, signerOrProvider: Signer | Provider - ): Issue428Reproduction { + ): Issue428_Reproduction { return new Contract( address, _abi, signerOrProvider - ) as Issue428Reproduction; + ) as Issue428_Reproduction; } } diff --git a/packages/target-ethers-v5-test/types/factories/LibraryConsumer__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/LibraryConsumer__factory.ts similarity index 96% rename from packages/target-ethers-v5-test/types/factories/LibraryConsumer__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/LibraryConsumer__factory.ts index 52e0115bd..0f1c82701 100644 --- a/packages/target-ethers-v5-test/types/factories/LibraryConsumer__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/LibraryConsumer__factory.ts @@ -7,7 +7,7 @@ import type { Provider } from "@ethersproject/providers"; import type { LibraryConsumer, LibraryConsumerInterface, -} from "../LibraryConsumer"; +} from "../../v0.6.4/LibraryConsumer"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Library__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/Library__factory.ts similarity index 92% rename from packages/target-ethers-v5-test/types/factories/Library__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/Library__factory.ts index 34ad5bca3..18fe323bd 100644 --- a/packages/target-ethers-v5-test/types/factories/Library__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/Library__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { Library, LibraryInterface } from "../Library"; +import type { Library, LibraryInterface } from "../../v0.6.4/Library"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/NameMangling__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/NameMangling__factory.ts similarity index 91% rename from packages/target-ethers-v5-test/types/factories/NameMangling__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/NameMangling__factory.ts index a9b3407a2..cbaa301f2 100644 --- a/packages/target-ethers-v5-test/types/factories/NameMangling__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/NameMangling__factory.ts @@ -4,7 +4,10 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { NameMangling, NameManglingInterface } from "../NameMangling"; +import type { + NameMangling, + NameManglingInterface, +} from "../../v0.6.4/NameMangling"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Overloads__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/Overloads__factory.ts similarity index 94% rename from packages/target-ethers-v5-test/types/factories/Overloads__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/Overloads__factory.ts index 5715095c9..6df345b52 100644 --- a/packages/target-ethers-v5-test/types/factories/Overloads__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/Overloads__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { Overloads, OverloadsInterface } from "../Overloads"; +import type { Overloads, OverloadsInterface } from "../../v0.6.4/Overloads"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/PayableFactory__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/PayableFactory__factory.ts similarity index 95% rename from packages/target-ethers-v5-test/types/factories/PayableFactory__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/PayableFactory__factory.ts index 22abce57f..9ff8bfe69 100644 --- a/packages/target-ethers-v5-test/types/factories/PayableFactory__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/PayableFactory__factory.ts @@ -7,7 +7,7 @@ import type { Provider } from "@ethersproject/providers"; import type { PayableFactory, PayableFactoryInterface, -} from "../PayableFactory"; +} from "../../v0.6.4/PayableFactory"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Payable__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/Payable__factory.ts similarity index 91% rename from packages/target-ethers-v5-test/types/factories/Payable__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.6.4/Payable__factory.ts index 8f8c49f03..4b70034e1 100644 --- a/packages/target-ethers-v5-test/types/factories/Payable__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/Payable__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { Payable, PayableInterface } from "../Payable"; +import type { Payable, PayableInterface } from "../../v0.6.4/Payable"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/v0.6.4/index.ts b/packages/target-ethers-v5-test/types/factories/v0.6.4/index.ts new file mode 100644 index 000000000..be919451c --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.6.4/index.ts @@ -0,0 +1,15 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { B__factory } from "./B__factory"; +export { DataTypesInput__factory } from "./DataTypesInput__factory"; +export { DataTypesPure__factory } from "./DataTypesPure__factory"; +export { DataTypesView__factory } from "./DataTypesView__factory"; +export { Events__factory } from "./Events__factory"; +export { Issue428_Reproduction__factory } from "./Issue428_Reproduction__factory"; +export { Library__factory } from "./Library__factory"; +export { LibraryConsumer__factory } from "./LibraryConsumer__factory"; +export { NameMangling__factory } from "./NameMangling__factory"; +export { Overloads__factory } from "./Overloads__factory"; +export { Payable__factory } from "./Payable__factory"; +export { PayableFactory__factory } from "./PayableFactory__factory"; diff --git a/packages/target-ethers-v5-test/types/factories/ERC721Enumerable__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/ERC721Enumerable__factory.ts similarity index 99% rename from packages/target-ethers-v5-test/types/factories/ERC721Enumerable__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/ERC721Enumerable__factory.ts index 9803aab77..aa92619f6 100644 --- a/packages/target-ethers-v5-test/types/factories/ERC721Enumerable__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/ERC721Enumerable__factory.ts @@ -7,7 +7,7 @@ import type { Provider } from "@ethersproject/providers"; import type { ERC721Enumerable, ERC721EnumerableInterface, -} from "../ERC721Enumerable"; +} from "../../v0.8.9/ERC721Enumerable"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/ERC721__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/ERC721__factory.ts similarity index 98% rename from packages/target-ethers-v5-test/types/factories/ERC721__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/ERC721__factory.ts index 1c26d0eb1..7ffcc3382 100644 --- a/packages/target-ethers-v5-test/types/factories/ERC721__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/ERC721__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { ERC721, ERC721Interface } from "../ERC721"; +import type { ERC721, ERC721Interface } from "../../v0.8.9/ERC721"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/IERC721Enumerable__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721Enumerable__factory.ts similarity index 99% rename from packages/target-ethers-v5-test/types/factories/IERC721Enumerable__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721Enumerable__factory.ts index b9e1bb3aa..5f5a4e0b7 100644 --- a/packages/target-ethers-v5-test/types/factories/IERC721Enumerable__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721Enumerable__factory.ts @@ -7,7 +7,7 @@ import type { Provider } from "@ethersproject/providers"; import type { IERC721Enumerable, IERC721EnumerableInterface, -} from "../IERC721Enumerable"; +} from "../../v0.8.9/IERC721Enumerable"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/IERC721Receiver__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721Receiver__factory.ts similarity index 97% rename from packages/target-ethers-v5-test/types/factories/IERC721Receiver__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721Receiver__factory.ts index 80dc29888..a298a333e 100644 --- a/packages/target-ethers-v5-test/types/factories/IERC721Receiver__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721Receiver__factory.ts @@ -7,7 +7,7 @@ import type { Provider } from "@ethersproject/providers"; import type { IERC721Receiver, IERC721ReceiverInterface, -} from "../IERC721Receiver"; +} from "../../v0.8.9/IERC721Receiver"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/IERC721__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721__factory.ts similarity index 98% rename from packages/target-ethers-v5-test/types/factories/IERC721__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721__factory.ts index ec3c86b7b..745387656 100644 --- a/packages/target-ethers-v5-test/types/factories/IERC721__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/IERC721__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { IERC721, IERC721Interface } from "../IERC721"; +import type { IERC721, IERC721Interface } from "../../v0.8.9/IERC721"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Issue552Reproduction__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/Issue552_Reproduction__factory.ts similarity index 85% rename from packages/target-ethers-v5-test/types/factories/Issue552Reproduction__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/Issue552_Reproduction__factory.ts index 198874ed2..99e971583 100644 --- a/packages/target-ethers-v5-test/types/factories/Issue552Reproduction__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/Issue552_Reproduction__factory.ts @@ -5,9 +5,9 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; import type { - Issue552Reproduction, - Issue552ReproductionInterface, -} from "../Issue552Reproduction"; + Issue552_Reproduction, + Issue552_ReproductionInterface, +} from "../../v0.8.9/Issue552_Reproduction"; const _abi = [ { @@ -86,19 +86,19 @@ const _abi = [ }, ]; -export class Issue552Reproduction__factory { +export class Issue552_Reproduction__factory { static readonly abi = _abi; - static createInterface(): Issue552ReproductionInterface { - return new utils.Interface(_abi) as Issue552ReproductionInterface; + static createInterface(): Issue552_ReproductionInterface { + return new utils.Interface(_abi) as Issue552_ReproductionInterface; } static connect( address: string, signerOrProvider: Signer | Provider - ): Issue552Reproduction { + ): Issue552_Reproduction { return new Contract( address, _abi, signerOrProvider - ) as Issue552Reproduction; + ) as Issue552_Reproduction; } } diff --git a/packages/target-ethers-v5-test/types/factories/KingOfTheHill__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/KingOfTheHill__factory.ts similarity index 95% rename from packages/target-ethers-v5-test/types/factories/KingOfTheHill__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/KingOfTheHill__factory.ts index f0d39abfa..2a907d4ae 100644 --- a/packages/target-ethers-v5-test/types/factories/KingOfTheHill__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/KingOfTheHill__factory.ts @@ -4,7 +4,10 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { KingOfTheHill, KingOfTheHillInterface } from "../KingOfTheHill"; +import type { + KingOfTheHill, + KingOfTheHillInterface, +} from "../../v0.8.9/KingOfTheHill"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Rarity__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/Rarity__factory.ts similarity index 99% rename from packages/target-ethers-v5-test/types/factories/Rarity__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/Rarity__factory.ts index 063a121b1..560ed060c 100644 --- a/packages/target-ethers-v5-test/types/factories/Rarity__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/Rarity__factory.ts @@ -4,7 +4,7 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { Rarity, RarityInterface } from "../Rarity"; +import type { Rarity, RarityInterface } from "../../v0.8.9/Rarity"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/Withdrawable__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/Withdrawable__factory.ts similarity index 88% rename from packages/target-ethers-v5-test/types/factories/Withdrawable__factory.ts rename to packages/target-ethers-v5-test/types/factories/v0.8.9/Withdrawable__factory.ts index 4c657db08..1e2ff00f3 100644 --- a/packages/target-ethers-v5-test/types/factories/Withdrawable__factory.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/Withdrawable__factory.ts @@ -4,7 +4,10 @@ import { Contract, Signer, utils } from "ethers"; import type { Provider } from "@ethersproject/providers"; -import type { Withdrawable, WithdrawableInterface } from "../Withdrawable"; +import type { + Withdrawable, + WithdrawableInterface, +} from "../../v0.8.9/Withdrawable"; const _abi = [ { diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts new file mode 100644 index 000000000..f97aa5824 --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts @@ -0,0 +1,13 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export * as nested from "./nested"; +export { ERC721__factory } from "./ERC721__factory"; +export { ERC721Enumerable__factory } from "./ERC721Enumerable__factory"; +export { IERC721__factory } from "./IERC721__factory"; +export { IERC721Enumerable__factory } from "./IERC721Enumerable__factory"; +export { IERC721Receiver__factory } from "./IERC721Receiver__factory"; +export { Issue552_Reproduction__factory } from "./Issue552_Reproduction__factory"; +export { KingOfTheHill__factory } from "./KingOfTheHill__factory"; +export { Rarity__factory } from "./Rarity__factory"; +export { Withdrawable__factory } from "./Withdrawable__factory"; diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/a/NestedLibrary__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/a/NestedLibrary__factory.ts new file mode 100644 index 000000000..d6be41f10 --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/a/NestedLibrary__factory.ts @@ -0,0 +1,39 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import type { Provider } from "@ethersproject/providers"; +import type { + NestedLibrary, + NestedLibraryInterface, +} from "../../../../v0.8.9/nested/a/NestedLibrary"; + +const _abi = [ + { + inputs: [], + name: "getValue", + outputs: [ + { + internalType: "uint32", + name: "", + type: "uint32", + }, + ], + stateMutability: "pure", + type: "function", + }, +]; + +export class NestedLibrary__factory { + static readonly abi = _abi; + static createInterface(): NestedLibraryInterface { + return new utils.Interface(_abi) as NestedLibraryInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): NestedLibrary { + return new Contract(address, _abi, signerOrProvider) as NestedLibrary; + } +} diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/a/index.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/a/index.ts new file mode 100644 index 000000000..73e4f06e8 --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/a/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { NestedLibrary__factory } from "./NestedLibrary__factory"; diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/b/NestedLibrary__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/b/NestedLibrary__factory.ts new file mode 100644 index 000000000..42024752e --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/b/NestedLibrary__factory.ts @@ -0,0 +1,39 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import type { Provider } from "@ethersproject/providers"; +import type { + NestedLibrary, + NestedLibraryInterface, +} from "../../../../v0.8.9/nested/b/NestedLibrary"; + +const _abi = [ + { + inputs: [], + name: "getValue", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "pure", + type: "function", + }, +]; + +export class NestedLibrary__factory { + static readonly abi = _abi; + static createInterface(): NestedLibraryInterface { + return new utils.Interface(_abi) as NestedLibraryInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): NestedLibrary { + return new Contract(address, _abi, signerOrProvider) as NestedLibrary; + } +} diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/b/index.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/b/index.ts new file mode 100644 index 000000000..73e4f06e8 --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/b/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { NestedLibrary__factory } from "./NestedLibrary__factory"; diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/index.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/index.ts new file mode 100644 index 000000000..87fbeeb9a --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/nested/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export * as a from "./a"; +export * as b from "./b"; diff --git a/packages/target-ethers-v5-test/types/index.ts b/packages/target-ethers-v5-test/types/index.ts index b4c8de61c..9c2d65939 100644 --- a/packages/target-ethers-v5-test/types/index.ts +++ b/packages/target-ethers-v5-test/types/index.ts @@ -1,46 +1,52 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ -export type { B } from "./B"; -export type { DataTypesInput } from "./DataTypesInput"; -export type { DataTypesPure } from "./DataTypesPure"; -export type { DataTypesView } from "./DataTypesView"; -export type { Events } from "./Events"; -export type { Issue428Reproduction } from "./Issue428Reproduction"; -export type { Library } from "./Library"; -export type { LibraryConsumer } from "./LibraryConsumer"; -export type { NameMangling } from "./NameMangling"; -export type { Overloads } from "./Overloads"; -export type { Payable } from "./Payable"; -export type { PayableFactory } from "./PayableFactory"; -export type { ERC721 } from "./ERC721"; -export type { ERC721Enumerable } from "./ERC721Enumerable"; -export type { IERC721 } from "./IERC721"; -export type { IERC721Enumerable } from "./IERC721Enumerable"; -export type { IERC721Receiver } from "./IERC721Receiver"; -export type { Issue552Reproduction } from "./Issue552Reproduction"; -export type { KingOfTheHill } from "./KingOfTheHill"; -export type { Rarity } from "./Rarity"; -export type { Withdrawable } from "./Withdrawable"; - -export { B__factory } from "./factories/B__factory"; -export { DataTypesInput__factory } from "./factories/DataTypesInput__factory"; -export { DataTypesPure__factory } from "./factories/DataTypesPure__factory"; -export { DataTypesView__factory } from "./factories/DataTypesView__factory"; -export { Events__factory } from "./factories/Events__factory"; -export { Issue428Reproduction__factory } from "./factories/Issue428Reproduction__factory"; -export { Library__factory } from "./factories/Library__factory"; -export { LibraryConsumer__factory } from "./factories/LibraryConsumer__factory"; -export { NameMangling__factory } from "./factories/NameMangling__factory"; -export { Overloads__factory } from "./factories/Overloads__factory"; -export { Payable__factory } from "./factories/Payable__factory"; -export { PayableFactory__factory } from "./factories/PayableFactory__factory"; -export { ERC721__factory } from "./factories/ERC721__factory"; -export { ERC721Enumerable__factory } from "./factories/ERC721Enumerable__factory"; -export { IERC721__factory } from "./factories/IERC721__factory"; -export { IERC721Enumerable__factory } from "./factories/IERC721Enumerable__factory"; -export { IERC721Receiver__factory } from "./factories/IERC721Receiver__factory"; -export { Issue552Reproduction__factory } from "./factories/Issue552Reproduction__factory"; -export { KingOfTheHill__factory } from "./factories/KingOfTheHill__factory"; -export { Rarity__factory } from "./factories/Rarity__factory"; -export { Withdrawable__factory } from "./factories/Withdrawable__factory"; +import type * as v064 from "./v0.6.4"; +export type { v064 }; +import type * as v089 from "./v0.8.9"; +export type { v089 }; +export * as factories from "./factories"; +export type { B } from "./v0.6.4/B"; +export { B__factory } from "./factories/v0.6.4/B__factory"; +export type { DataTypesInput } from "./v0.6.4/DataTypesInput"; +export { DataTypesInput__factory } from "./factories/v0.6.4/DataTypesInput__factory"; +export type { DataTypesPure } from "./v0.6.4/DataTypesPure"; +export { DataTypesPure__factory } from "./factories/v0.6.4/DataTypesPure__factory"; +export type { DataTypesView } from "./v0.6.4/DataTypesView"; +export { DataTypesView__factory } from "./factories/v0.6.4/DataTypesView__factory"; +export type { Events } from "./v0.6.4/Events"; +export { Events__factory } from "./factories/v0.6.4/Events__factory"; +export type { Issue428_Reproduction } from "./v0.6.4/Issue428_Reproduction"; +export { Issue428_Reproduction__factory } from "./factories/v0.6.4/Issue428_Reproduction__factory"; +export type { Library } from "./v0.6.4/Library"; +export { Library__factory } from "./factories/v0.6.4/Library__factory"; +export type { LibraryConsumer } from "./v0.6.4/LibraryConsumer"; +export { LibraryConsumer__factory } from "./factories/v0.6.4/LibraryConsumer__factory"; +export type { NameMangling } from "./v0.6.4/NameMangling"; +export { NameMangling__factory } from "./factories/v0.6.4/NameMangling__factory"; +export type { Overloads } from "./v0.6.4/Overloads"; +export { Overloads__factory } from "./factories/v0.6.4/Overloads__factory"; +export type { Payable } from "./v0.6.4/Payable"; +export { Payable__factory } from "./factories/v0.6.4/Payable__factory"; +export type { PayableFactory } from "./v0.6.4/PayableFactory"; +export { PayableFactory__factory } from "./factories/v0.6.4/PayableFactory__factory"; +export type { ERC721 } from "./v0.8.9/ERC721"; +export { ERC721__factory } from "./factories/v0.8.9/ERC721__factory"; +export type { ERC721Enumerable } from "./v0.8.9/ERC721Enumerable"; +export { ERC721Enumerable__factory } from "./factories/v0.8.9/ERC721Enumerable__factory"; +export type { IERC721 } from "./v0.8.9/IERC721"; +export { IERC721__factory } from "./factories/v0.8.9/IERC721__factory"; +export type { IERC721Enumerable } from "./v0.8.9/IERC721Enumerable"; +export { IERC721Enumerable__factory } from "./factories/v0.8.9/IERC721Enumerable__factory"; +export type { IERC721Receiver } from "./v0.8.9/IERC721Receiver"; +export { IERC721Receiver__factory } from "./factories/v0.8.9/IERC721Receiver__factory"; +export type { Issue552_Reproduction } from "./v0.8.9/Issue552_Reproduction"; +export { Issue552_Reproduction__factory } from "./factories/v0.8.9/Issue552_Reproduction__factory"; +export type { KingOfTheHill } from "./v0.8.9/KingOfTheHill"; +export { KingOfTheHill__factory } from "./factories/v0.8.9/KingOfTheHill__factory"; +export type { NestedLibrary } from "./v0.8.9/nested/a/NestedLibrary"; +export { NestedLibrary__factory } from "./factories/v0.8.9/nested/a/NestedLibrary__factory"; +export type { Rarity } from "./v0.8.9/Rarity"; +export { Rarity__factory } from "./factories/v0.8.9/Rarity__factory"; +export type { Withdrawable } from "./v0.8.9/Withdrawable"; +export { Withdrawable__factory } from "./factories/v0.8.9/Withdrawable__factory"; diff --git a/packages/target-ethers-v5-test/types/B.ts b/packages/target-ethers-v5-test/types/v0.6.4/B.ts similarity index 99% rename from packages/target-ethers-v5-test/types/B.ts rename to packages/target-ethers-v5-test/types/v0.6.4/B.ts index 0d8cb19d6..0a060bd5d 100644 --- a/packages/target-ethers-v5-test/types/B.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/B.ts @@ -9,7 +9,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface BInterface extends utils.Interface { contractName: "B"; diff --git a/packages/target-ethers-v5-test/types/DataTypesInput.ts b/packages/target-ethers-v5-test/types/v0.6.4/DataTypesInput.ts similarity index 99% rename from packages/target-ethers-v5-test/types/DataTypesInput.ts rename to packages/target-ethers-v5-test/types/v0.6.4/DataTypesInput.ts index 08102a7dc..e36ab1664 100644 --- a/packages/target-ethers-v5-test/types/DataTypesInput.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/DataTypesInput.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export declare namespace StructsLib1 { export type InfoStruct = { a: BigNumberish; b: BigNumberish }; diff --git a/packages/target-ethers-v5-test/types/DataTypesPure.ts b/packages/target-ethers-v5-test/types/v0.6.4/DataTypesPure.ts similarity index 99% rename from packages/target-ethers-v5-test/types/DataTypesPure.ts rename to packages/target-ethers-v5-test/types/v0.6.4/DataTypesPure.ts index 41013f8bb..5621ae716 100644 --- a/packages/target-ethers-v5-test/types/DataTypesPure.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/DataTypesPure.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export declare namespace DataTypesPure { export type Struct1Struct = { diff --git a/packages/target-ethers-v5-test/types/DataTypesView.ts b/packages/target-ethers-v5-test/types/v0.6.4/DataTypesView.ts similarity index 99% rename from packages/target-ethers-v5-test/types/DataTypesView.ts rename to packages/target-ethers-v5-test/types/v0.6.4/DataTypesView.ts index 158f96f3b..88f7a952b 100644 --- a/packages/target-ethers-v5-test/types/DataTypesView.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/DataTypesView.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export declare namespace DataTypesView { export type Struct1Struct = { diff --git a/packages/target-ethers-v5-test/types/Events.ts b/packages/target-ethers-v5-test/types/v0.6.4/Events.ts similarity index 99% rename from packages/target-ethers-v5-test/types/Events.ts rename to packages/target-ethers-v5-test/types/v0.6.4/Events.ts index c93de9d5b..2d3f6435c 100644 --- a/packages/target-ethers-v5-test/types/Events.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/Events.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export declare namespace Events { export type EventDataStruct = { index: BigNumberish; name: string }; diff --git a/packages/target-ethers-v5-test/types/Issue428Reproduction.ts b/packages/target-ethers-v5-test/types/v0.6.4/Issue428_Reproduction.ts similarity index 85% rename from packages/target-ethers-v5-test/types/Issue428Reproduction.ts rename to packages/target-ethers-v5-test/types/v0.6.4/Issue428_Reproduction.ts index 841e82618..76e6731f2 100644 --- a/packages/target-ethers-v5-test/types/Issue428Reproduction.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/Issue428_Reproduction.ts @@ -9,10 +9,10 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; -export interface Issue428ReproductionInterface extends utils.Interface { - contractName: "Issue428Reproduction"; +export interface Issue428_ReproductionInterface extends utils.Interface { + contractName: "Issue428_Reproduction"; functions: {}; @@ -27,13 +27,13 @@ export type CommittedEvent = TypedEvent<[string[]], { whitelist: string[] }>; export type CommittedEventFilter = TypedEventFilter; -export interface Issue428Reproduction extends BaseContract { - contractName: "Issue428Reproduction"; +export interface Issue428_Reproduction extends BaseContract { + contractName: "Issue428_Reproduction"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; - interface: Issue428ReproductionInterface; + interface: Issue428_ReproductionInterface; queryFilter( event: TypedEventFilter, diff --git a/packages/target-ethers-v5-test/types/Library.ts b/packages/target-ethers-v5-test/types/v0.6.4/Library.ts similarity index 99% rename from packages/target-ethers-v5-test/types/Library.ts rename to packages/target-ethers-v5-test/types/v0.6.4/Library.ts index e029538a9..ecf0c19b7 100644 --- a/packages/target-ethers-v5-test/types/Library.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/Library.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface LibraryInterface extends utils.Interface { contractName: "Library"; diff --git a/packages/target-ethers-v5-test/types/LibraryConsumer.ts b/packages/target-ethers-v5-test/types/v0.6.4/LibraryConsumer.ts similarity index 99% rename from packages/target-ethers-v5-test/types/LibraryConsumer.ts rename to packages/target-ethers-v5-test/types/v0.6.4/LibraryConsumer.ts index 821b2657d..1c2558974 100644 --- a/packages/target-ethers-v5-test/types/LibraryConsumer.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/LibraryConsumer.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface LibraryConsumerInterface extends utils.Interface { contractName: "LibraryConsumer"; diff --git a/packages/target-ethers-v5-test/types/NameMangling.ts b/packages/target-ethers-v5-test/types/v0.6.4/NameMangling.ts similarity index 99% rename from packages/target-ethers-v5-test/types/NameMangling.ts rename to packages/target-ethers-v5-test/types/v0.6.4/NameMangling.ts index 223e3591a..975be796c 100644 --- a/packages/target-ethers-v5-test/types/NameMangling.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/NameMangling.ts @@ -17,7 +17,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface NameManglingInterface extends utils.Interface { contractName: "NameMangling"; diff --git a/packages/target-ethers-v5-test/types/Overloads.ts b/packages/target-ethers-v5-test/types/v0.6.4/Overloads.ts similarity index 99% rename from packages/target-ethers-v5-test/types/Overloads.ts rename to packages/target-ethers-v5-test/types/v0.6.4/Overloads.ts index 93fae3166..59125ce58 100644 --- a/packages/target-ethers-v5-test/types/Overloads.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/Overloads.ts @@ -18,7 +18,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface OverloadsInterface extends utils.Interface { contractName: "Overloads"; diff --git a/packages/target-ethers-v5-test/types/Payable.ts b/packages/target-ethers-v5-test/types/v0.6.4/Payable.ts similarity index 99% rename from packages/target-ethers-v5-test/types/Payable.ts rename to packages/target-ethers-v5-test/types/v0.6.4/Payable.ts index 47e8745f1..678d79d19 100644 --- a/packages/target-ethers-v5-test/types/Payable.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/Payable.ts @@ -20,7 +20,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface PayableInterface extends utils.Interface { contractName: "Payable"; diff --git a/packages/target-ethers-v5-test/types/PayableFactory.ts b/packages/target-ethers-v5-test/types/v0.6.4/PayableFactory.ts similarity index 99% rename from packages/target-ethers-v5-test/types/PayableFactory.ts rename to packages/target-ethers-v5-test/types/v0.6.4/PayableFactory.ts index a02e859e6..4d1739fcc 100644 --- a/packages/target-ethers-v5-test/types/PayableFactory.ts +++ b/packages/target-ethers-v5-test/types/v0.6.4/PayableFactory.ts @@ -19,7 +19,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface PayableFactoryInterface extends utils.Interface { contractName: "PayableFactory"; diff --git a/packages/target-ethers-v5-test/types/v0.6.4/index.ts b/packages/target-ethers-v5-test/types/v0.6.4/index.ts new file mode 100644 index 000000000..0adb695c2 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.6.4/index.ts @@ -0,0 +1,15 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { B } from "./B"; +export type { DataTypesInput } from "./DataTypesInput"; +export type { DataTypesPure } from "./DataTypesPure"; +export type { DataTypesView } from "./DataTypesView"; +export type { Events } from "./Events"; +export type { Issue428_Reproduction } from "./Issue428_Reproduction"; +export type { Library } from "./Library"; +export type { LibraryConsumer } from "./LibraryConsumer"; +export type { NameMangling } from "./NameMangling"; +export type { Overloads } from "./Overloads"; +export type { Payable } from "./Payable"; +export type { PayableFactory } from "./PayableFactory"; diff --git a/packages/target-ethers-v5-test/types/ERC721.ts b/packages/target-ethers-v5-test/types/v0.8.9/ERC721.ts similarity index 99% rename from packages/target-ethers-v5-test/types/ERC721.ts rename to packages/target-ethers-v5-test/types/v0.8.9/ERC721.ts index ebf7253ce..316a1dd79 100644 --- a/packages/target-ethers-v5-test/types/ERC721.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/ERC721.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface ERC721Interface extends utils.Interface { contractName: "ERC721"; diff --git a/packages/target-ethers-v5-test/types/ERC721Enumerable.ts b/packages/target-ethers-v5-test/types/v0.8.9/ERC721Enumerable.ts similarity index 99% rename from packages/target-ethers-v5-test/types/ERC721Enumerable.ts rename to packages/target-ethers-v5-test/types/v0.8.9/ERC721Enumerable.ts index 83ea2ce29..1f74bcf6d 100644 --- a/packages/target-ethers-v5-test/types/ERC721Enumerable.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/ERC721Enumerable.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface ERC721EnumerableInterface extends utils.Interface { contractName: "ERC721Enumerable"; diff --git a/packages/target-ethers-v5-test/types/IERC721.ts b/packages/target-ethers-v5-test/types/v0.8.9/IERC721.ts similarity index 99% rename from packages/target-ethers-v5-test/types/IERC721.ts rename to packages/target-ethers-v5-test/types/v0.8.9/IERC721.ts index 025a7ac5e..73fb7870d 100644 --- a/packages/target-ethers-v5-test/types/IERC721.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/IERC721.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface IERC721Interface extends utils.Interface { contractName: "IERC721"; diff --git a/packages/target-ethers-v5-test/types/IERC721Enumerable.ts b/packages/target-ethers-v5-test/types/v0.8.9/IERC721Enumerable.ts similarity index 99% rename from packages/target-ethers-v5-test/types/IERC721Enumerable.ts rename to packages/target-ethers-v5-test/types/v0.8.9/IERC721Enumerable.ts index 9ce5b2fa0..aa47f60d1 100644 --- a/packages/target-ethers-v5-test/types/IERC721Enumerable.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/IERC721Enumerable.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface IERC721EnumerableInterface extends utils.Interface { contractName: "IERC721Enumerable"; diff --git a/packages/target-ethers-v5-test/types/IERC721Receiver.ts b/packages/target-ethers-v5-test/types/v0.8.9/IERC721Receiver.ts similarity index 99% rename from packages/target-ethers-v5-test/types/IERC721Receiver.ts rename to packages/target-ethers-v5-test/types/v0.8.9/IERC721Receiver.ts index db7e789ce..455dbf011 100644 --- a/packages/target-ethers-v5-test/types/IERC721Receiver.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/IERC721Receiver.ts @@ -20,7 +20,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface IERC721ReceiverInterface extends utils.Interface { contractName: "IERC721Receiver"; diff --git a/packages/target-ethers-v5-test/types/Issue552Reproduction.ts b/packages/target-ethers-v5-test/types/v0.8.9/Issue552_Reproduction.ts similarity index 84% rename from packages/target-ethers-v5-test/types/Issue552Reproduction.ts rename to packages/target-ethers-v5-test/types/v0.8.9/Issue552_Reproduction.ts index 0a97d3b3b..939306926 100644 --- a/packages/target-ethers-v5-test/types/Issue552Reproduction.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/Issue552_Reproduction.ts @@ -20,9 +20,9 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; -export declare namespace Issue552Observer { +export declare namespace Issue552_Observer { export type ObservationStruct = { val: BigNumberish; blockTimestamp: BigNumberish; @@ -34,23 +34,23 @@ export declare namespace Issue552Observer { }; } -export declare namespace Issue552Reproduction { +export declare namespace Issue552_Reproduction { export type ObservationParamsStruct = { - observations: Issue552Observer.ObservationStruct[]; + observations: Issue552_Observer.ObservationStruct[]; index: BigNumberish; }; export type ObservationParamsStructOutput = [ - Issue552Observer.ObservationStructOutput[], + Issue552_Observer.ObservationStructOutput[], number ] & { - observations: Issue552Observer.ObservationStructOutput[]; + observations: Issue552_Observer.ObservationStructOutput[]; index: number; }; } -export interface Issue552ReproductionInterface extends utils.Interface { - contractName: "Issue552Reproduction"; +export interface Issue552_ReproductionInterface extends utils.Interface { + contractName: "Issue552_Reproduction"; functions: { "bars(uint256)": FunctionFragment; @@ -82,13 +82,13 @@ export interface Issue552ReproductionInterface extends utils.Interface { ): Result; } -export interface Issue552Reproduction extends BaseContract { - contractName: "Issue552Reproduction"; +export interface Issue552_Reproduction extends BaseContract { + contractName: "Issue552_Reproduction"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; - interface: Issue552ReproductionInterface; + interface: Issue552_ReproductionInterface; queryFilter( event: TypedEventFilter, @@ -114,8 +114,8 @@ export interface Issue552Reproduction extends BaseContract { arg0: BigNumberish, overrides?: CallOverrides ): Promise< - [Issue552Reproduction.ObservationParamsStructOutput] & { - fooObservations: Issue552Reproduction.ObservationParamsStructOutput; + [Issue552_Reproduction.ObservationParamsStructOutput] & { + fooObservations: Issue552_Reproduction.ObservationParamsStructOutput; } >; @@ -131,7 +131,7 @@ export interface Issue552Reproduction extends BaseContract { bars( arg0: BigNumberish, overrides?: CallOverrides - ): Promise; + ): Promise; input(values: BigNumberish[], overrides?: CallOverrides): Promise; @@ -145,7 +145,7 @@ export interface Issue552Reproduction extends BaseContract { bars( arg0: BigNumberish, overrides?: CallOverrides - ): Promise; + ): Promise; input(values: BigNumberish[], overrides?: CallOverrides): Promise; diff --git a/packages/target-ethers-v5-test/types/KingOfTheHill.ts b/packages/target-ethers-v5-test/types/v0.8.9/KingOfTheHill.ts similarity index 99% rename from packages/target-ethers-v5-test/types/KingOfTheHill.ts rename to packages/target-ethers-v5-test/types/v0.8.9/KingOfTheHill.ts index d347edf63..b3cf6c644 100644 --- a/packages/target-ethers-v5-test/types/KingOfTheHill.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/KingOfTheHill.ts @@ -25,7 +25,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export declare namespace KingOfTheHill { export type BidStruct = { bidder: string; value: BigNumberish }; diff --git a/packages/target-ethers-v5-test/types/Rarity.ts b/packages/target-ethers-v5-test/types/v0.8.9/Rarity.ts similarity index 99% rename from packages/target-ethers-v5-test/types/Rarity.ts rename to packages/target-ethers-v5-test/types/v0.8.9/Rarity.ts index 3dbeedc43..aede99a1c 100644 --- a/packages/target-ethers-v5-test/types/Rarity.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/Rarity.ts @@ -24,7 +24,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface RarityInterface extends utils.Interface { contractName: "Rarity"; diff --git a/packages/target-ethers-v5-test/types/Withdrawable.ts b/packages/target-ethers-v5-test/types/v0.8.9/Withdrawable.ts similarity index 99% rename from packages/target-ethers-v5-test/types/Withdrawable.ts rename to packages/target-ethers-v5-test/types/v0.8.9/Withdrawable.ts index 6af7fa7cb..108735274 100644 --- a/packages/target-ethers-v5-test/types/Withdrawable.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/Withdrawable.ts @@ -19,7 +19,7 @@ import type { TypedEvent, TypedListener, OnEvent, -} from "./common"; +} from "../common"; export interface WithdrawableInterface extends utils.Interface { contractName: "Withdrawable"; diff --git a/packages/target-ethers-v5-test/types/v0.8.9/index.ts b/packages/target-ethers-v5-test/types/v0.8.9/index.ts new file mode 100644 index 000000000..a36ab4d20 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/index.ts @@ -0,0 +1,14 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type * as nested from "./nested"; +export type { nested }; +export type { ERC721 } from "./ERC721"; +export type { ERC721Enumerable } from "./ERC721Enumerable"; +export type { IERC721 } from "./IERC721"; +export type { IERC721Enumerable } from "./IERC721Enumerable"; +export type { IERC721Receiver } from "./IERC721Receiver"; +export type { Issue552_Reproduction } from "./Issue552_Reproduction"; +export type { KingOfTheHill } from "./KingOfTheHill"; +export type { Rarity } from "./Rarity"; +export type { Withdrawable } from "./Withdrawable"; diff --git a/packages/target-ethers-v5-test/types/v0.8.9/nested/a/NestedLibrary.ts b/packages/target-ethers-v5-test/types/v0.8.9/nested/a/NestedLibrary.ts new file mode 100644 index 000000000..7bc6e4548 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/nested/a/NestedLibrary.ts @@ -0,0 +1,84 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BytesLike, + CallOverrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import type { FunctionFragment, Result } from "@ethersproject/abi"; +import type { Listener, Provider } from "@ethersproject/providers"; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from "../../../common"; + +export interface NestedLibraryInterface extends utils.Interface { + contractName: "NestedLibrary"; + + functions: { + "getValue()": FunctionFragment; + }; + + events: {}; + + getFunction(nameOrSignatureOrTopic: "getValue"): FunctionFragment; + + encodeFunctionData(functionFragment: "getValue", values?: undefined): string; + + decodeFunctionResult(functionFragment: "getValue", data: BytesLike): Result; +} + +export interface NestedLibrary extends BaseContract { + contractName: "NestedLibrary"; + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: NestedLibraryInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + getValue(overrides?: CallOverrides): Promise<[number]>; + }; + + getValue(overrides?: CallOverrides): Promise; + + callStatic: { + getValue(overrides?: CallOverrides): Promise; + }; + + filters: {}; + + estimateGas: { + getValue(overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + getValue(overrides?: CallOverrides): Promise; + }; +} diff --git a/packages/target-ethers-v5-test/types/v0.8.9/nested/a/index.ts b/packages/target-ethers-v5-test/types/v0.8.9/nested/a/index.ts new file mode 100644 index 000000000..db3202d75 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/nested/a/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { NestedLibrary } from "./NestedLibrary"; diff --git a/packages/target-ethers-v5-test/types/v0.8.9/nested/b/NestedLibrary.ts b/packages/target-ethers-v5-test/types/v0.8.9/nested/b/NestedLibrary.ts new file mode 100644 index 000000000..c742f8048 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/nested/b/NestedLibrary.ts @@ -0,0 +1,84 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BytesLike, + CallOverrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import type { FunctionFragment, Result } from "@ethersproject/abi"; +import type { Listener, Provider } from "@ethersproject/providers"; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from "../../../common"; + +export interface NestedLibraryInterface extends utils.Interface { + contractName: "NestedLibrary"; + + functions: { + "getValue()": FunctionFragment; + }; + + events: {}; + + getFunction(nameOrSignatureOrTopic: "getValue"): FunctionFragment; + + encodeFunctionData(functionFragment: "getValue", values?: undefined): string; + + decodeFunctionResult(functionFragment: "getValue", data: BytesLike): Result; +} + +export interface NestedLibrary extends BaseContract { + contractName: "NestedLibrary"; + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: NestedLibraryInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + getValue(overrides?: CallOverrides): Promise<[BigNumber]>; + }; + + getValue(overrides?: CallOverrides): Promise; + + callStatic: { + getValue(overrides?: CallOverrides): Promise; + }; + + filters: {}; + + estimateGas: { + getValue(overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + getValue(overrides?: CallOverrides): Promise; + }; +} diff --git a/packages/target-ethers-v5-test/types/v0.8.9/nested/b/index.ts b/packages/target-ethers-v5-test/types/v0.8.9/nested/b/index.ts new file mode 100644 index 000000000..db3202d75 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/nested/b/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { NestedLibrary } from "./NestedLibrary"; diff --git a/packages/target-ethers-v5-test/types/v0.8.9/nested/index.ts b/packages/target-ethers-v5-test/types/v0.8.9/nested/index.ts new file mode 100644 index 000000000..cca41f2e7 --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/nested/index.ts @@ -0,0 +1,7 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type * as a from "./a"; +export type { a }; +import type * as b from "./b"; +export type { b }; diff --git a/packages/target-ethers-v5/src/codegen/hardhat.ts b/packages/target-ethers-v5/src/codegen/hardhat.ts index f85bbb980..cb04c5667 100644 --- a/packages/target-ethers-v5/src/codegen/hardhat.ts +++ b/packages/target-ethers-v5/src/codegen/hardhat.ts @@ -1,10 +1,11 @@ import { FACTORY_POSTFIX } from '../common' +// @todo hardhat helper needs to import _all_ generated contract files except of duplicates export function generateHardhatHelper(contracts: string[]): string { return ` import { ethers } from 'ethers' -import { FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomiclabs/hardhat-ethers/types"; +import { FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomiclabs/hardhat-ethers/types"; import * as Contracts from "." diff --git a/packages/target-ethers-v5/src/codegen/index.ts b/packages/target-ethers-v5/src/codegen/index.ts index 829915962..dc184f626 100644 --- a/packages/target-ethers-v5/src/codegen/index.ts +++ b/packages/target-ethers-v5/src/codegen/index.ts @@ -115,6 +115,10 @@ export function codegenContractTypings(contract: Contract, codegenConfig: Codege }; }` + const commonPath = contract.path.length + ? `${new Array(contract.path.length).fill('..').join('/')}/common` + : './common' + const imports = createImportsForUsedIdentifiers( { @@ -137,7 +141,7 @@ export function codegenContractTypings(contract: Contract, codegenConfig: Codege source, ) + '\n' + - createImportTypeDeclaration(EVENT_IMPORTS, './common') + createImportTypeDeclaration(EVENT_IMPORTS, commonPath) return imports + source } @@ -234,11 +238,17 @@ function codegenCommonContractFactory(contract: Contract, abi: any): { header: s imports.add(structName.namespace || structName.identifier + STRUCT_INPUT_POSTFIX) } }) + + const contractTypesImportPath = [...Array(contract.path.length + 1).fill('..'), ...contract.path, contract.name].join( + '/', + ) + const header = ` - import type { ${[...imports.values()].join(', ')} } from "../${contract.name}"; + import type { ${[...imports.values()].join(', ')} } from "${contractTypesImportPath}"; const _abi = ${JSON.stringify(abi, null, 2)}; `.trim() + const body = ` static readonly abi = _abi; static createInterface(): ${contract.name}Interface { @@ -248,6 +258,7 @@ function codegenCommonContractFactory(contract: Contract, abi: any): { header: s return new Contract(address, _abi, signerOrProvider) as ${contract.name}; } `.trim() + return { header, body } } diff --git a/packages/target-ethers-v5/src/index.ts b/packages/target-ethers-v5/src/index.ts index f3e30c2de..071f612f9 100644 --- a/packages/target-ethers-v5/src/index.ts +++ b/packages/target-ethers-v5/src/index.ts @@ -1,12 +1,14 @@ import { readFileSync } from 'fs' -import { compact, uniqBy } from 'lodash' -import { basename, join, resolve } from 'path' +import { compact, partition, uniqBy } from 'lodash' +import { join, relative, resolve } from 'path' import { Dictionary } from 'ts-essentials' import { BytecodeWithLinkReferences, CodegenConfig, Config, Contract, + createBarrelFiles, + detectInputsRoot, extractAbi, extractBytecode, extractDocumentation, @@ -14,7 +16,10 @@ import { getFileExtension, getFilename, normalizeName, + normalizeSlashes, parse, + parseContractPath, + shortenFullJsonFilePath, TypeChainTarget, } from 'typechain' @@ -31,15 +36,10 @@ const DEFAULT_OUT_PATH = './types/ethers-contracts/' export default class Ethers extends TypeChainTarget { name = 'Ethers' - private readonly allContracts: string[] + private readonly inputsRoot: string + private readonly allFiles: string[] private readonly outDirAbs: string - private readonly contractCache: Dictionary< - | { - abi: any - contract: Contract - } - | undefined - > = {} + private readonly contractsWithoutBytecode: Dictionary<{ abi: any; contract: Contract } | undefined> = {} private readonly bytecodeCache: Dictionary = {} constructor(config: Config) { @@ -47,9 +47,12 @@ export default class Ethers extends TypeChainTarget { const { cwd, outDir, allFiles } = config + this.inputsRoot = detectInputsRoot(allFiles) + this.allFiles = allFiles + .map(shortenFullJsonFilePath) + .map((x) => relative(this.inputsRoot, x)) + .map(normalizeSlashes) this.outDirAbs = resolve(cwd, outDir || DEFAULT_OUT_PATH) - - this.allContracts = allFiles.map((fp) => normalizeName(getFilename(fp))) } transformFile(file: FileDescription): FileDescription[] | void { @@ -67,24 +70,22 @@ export default class Ethers extends TypeChainTarget { } transformBinFile(file: FileDescription): FileDescription[] | void { - const name = getFilename(file.path) const bytecode = extractBytecode(file.contents) if (!bytecode) { return } - if (this.contractCache[name]) { - const { contract, abi } = this.contractCache[name]! - delete this.contractCache[name] + if (this.contractsWithoutBytecode[file.path]) { + const { contract, abi } = this.contractsWithoutBytecode[file.path]! + delete this.contractsWithoutBytecode[file.path] return [this.genContractFactoryFile(contract, abi, bytecode)] } else { - this.bytecodeCache[name] = bytecode + this.bytecodeCache[file.path] = bytecode } } transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void { - const name = getFilename(file.path) const abi = extractAbi(file.contents) if (abi.length === 0) { @@ -93,8 +94,11 @@ export default class Ethers extends TypeChainTarget { const documentation = extractDocumentation(file.contents) - const contract = parse(abi, name, documentation) - const bytecode = extractBytecode(file.contents) || this.bytecodeCache[name] + const path = relative(this.inputsRoot, shortenFullJsonFilePath(file.path)) + + const contract = parse(abi, path, documentation) + + const bytecode = extractBytecode(file.contents) || this.bytecodeCache[file.path] if (bytecode) { return [ @@ -102,21 +106,21 @@ export default class Ethers extends TypeChainTarget { this.genContractFactoryFile(contract, abi, bytecode), ] } else { - this.contractCache[name] = { abi, contract } + this.contractsWithoutBytecode[file.path] = { abi, contract } return [this.genContractTypingsFile(contract, this.cfg.flags)] } } genContractTypingsFile(contract: Contract, codegenConfig: CodegenConfig): FileDescription { return { - path: join(this.outDirAbs, `${contract.name}.ts`), + path: join(this.outDirAbs, ...contract.path, `${contract.name}.ts`), contents: codegenContractTypings(contract, codegenConfig), } } genContractFactoryFile(contract: Contract, abi: any, bytecode?: BytecodeWithLinkReferences) { return { - path: join(this.outDirAbs, 'factories', `${contract.name}${FACTORY_POSTFIX}.ts`), + path: join(this.outDirAbs, 'factories', ...contract.path, `${contract.name}${FACTORY_POSTFIX}.ts`), contents: codegenContractFactory(contract, abi, bytecode), } } @@ -124,54 +128,70 @@ export default class Ethers extends TypeChainTarget { override afterRun(): FileDescription[] { // For each contract that doesn't have bytecode (it's either abstract, or only ABI was provided) // generate a simplified factory, that allows to interact with deployed contract instances. - const abstractFactoryFiles = Object.keys(this.contractCache).map((contractName) => { - const { contract, abi } = this.contractCache[contractName]! + const abstractFactoryFiles = Object.keys(this.contractsWithoutBytecode).map((contractName) => { + const { contract, abi } = this.contractsWithoutBytecode[contractName]! return { - path: join(this.outDirAbs, 'factories', `${contract.name}${FACTORY_POSTFIX}.ts`), + path: join(this.outDirAbs, 'factories', ...contract.path, `${contract.name}${FACTORY_POSTFIX}.ts`), contents: codegenAbstractContractFactory(contract, abi), } }) + const common = { + path: join(this.outDirAbs, 'common.ts'), + contents: readFileSync(join(__dirname, '../static/common.ts'), 'utf-8'), + } + + const allContracts = this.allFiles.map((path) => normalizeName(getFilename(path))) const hardhatHelper = this.cfg.flags.environment === 'hardhat' - ? { path: join(this.outDirAbs, 'hardhat.d.ts'), contents: generateHardhatHelper(this.allContracts) } + ? { path: join(this.outDirAbs, 'hardhat.d.ts'), contents: generateHardhatHelper(allContracts) } : undefined - const allFiles = compact([ - ...abstractFactoryFiles, - { - path: join(this.outDirAbs, 'common.ts'), - contents: readFileSync(join(__dirname, '../static/common.ts'), 'utf-8'), - }, - { - path: join(this.outDirAbs, 'index.ts'), - contents: this.genReExports(), - }, - hardhatHelper, - ]) - return allFiles - } - - private genReExports(): string { - const codegen: string[] = [] - - const allContractsNoDuplicates = uniqBy(this.allContracts, (c) => basename(c)) + const typesBarrels = createBarrelFiles(this.allFiles, { typeOnly: true }) + const factoriesBarrels = createBarrelFiles( + this.allFiles.map((s) => `factories/${s}`), + { typeOnly: false, postfix: FACTORY_POSTFIX }, + ) - for (const fileName of allContractsNoDuplicates) { - const desiredSymbol = fileName + const allBarrels = typesBarrels.concat(factoriesBarrels) + const [rootIndexes, otherBarrels] = partition(allBarrels, (fd) => fd.path === 'index.ts') - codegen.push(`export type { ${desiredSymbol} } from './${desiredSymbol}'`) + const rootIndex = { + path: join(this.outDirAbs, 'index.ts'), + contents: createRootIndexContent(rootIndexes, this.allFiles), } - codegen.push('\n') - - // then generate reexports for TypeChain generated factories - for (const fileName of allContractsNoDuplicates) { - const desiredSymbol = fileName + '__factory' - - codegen.push(`export { ${desiredSymbol} } from './factories/${desiredSymbol}'`) - } + const allFiles = compact([ + common, + hardhatHelper, + rootIndex, + ...abstractFactoryFiles, + ...otherBarrels.map((fd) => ({ + path: join(this.outDirAbs, fd.path), + contents: fd.contents, + })), + ]) - return codegen.join('\n') + return allFiles } } + +// root index.ts reexports also from deeper paths +function createRootIndexContent(rootIndexes: FileDescription[], paths: string[]) { + const contracts: { path: string[]; name: string }[] = paths.map(parseContractPath) + const rootReexports = uniqBy(Object.values(contracts), (c) => c.name).flatMap((c) => { + const path = c.path.length === 0 ? c.name : `${c.path.join('/')}/${c.name}` + return [ + `export type { ${c.name} } from './${path}';`, + `export { ${c.name}${FACTORY_POSTFIX} } from './factories/${path}${FACTORY_POSTFIX}';`, + ] + }) + + const rootIndexContent = new Set([ + ...rootIndexes[0].contents.split('\n'), + ...rootIndexes[1].contents.split('\n'), + ...rootReexports, + ]) + + return [...rootIndexContent].join('\n') +} diff --git a/packages/target-ethers-v5/test/generation.test.ts b/packages/target-ethers-v5/test/generation.test.ts index 233bd63de..02afc9e9f 100644 --- a/packages/target-ethers-v5/test/generation.test.ts +++ b/packages/target-ethers-v5/test/generation.test.ts @@ -12,6 +12,7 @@ describe('Ethers generation edge cases', () => { events: {}, structs: {}, constructor: [{ name: 'constructor', inputs: [], outputs: [], stateMutability: 'nonpayable' }], + path: [], } it('should generate simple factory when no bytecode available', () => { diff --git a/packages/target-web3-v1-test/test/DataTypesInput.test.ts b/packages/target-web3-v1-test/test/DataTypesInput.test.ts index c509fe51f..ee1fce6e4 100644 --- a/packages/target-web3-v1-test/test/DataTypesInput.test.ts +++ b/packages/target-web3-v1-test/test/DataTypesInput.test.ts @@ -2,7 +2,7 @@ import BN from 'bn.js' import { q18, typedAssert } from 'test-utils' import type Web3 from 'web3' -import type { DataTypesInput } from '../types/DataTypesInput' +import type { DataTypesInput } from '../types/v0.6.4/DataTypesInput' import { createNewBlockchain, deployContract } from './common' describe('DataTypesInput', () => { diff --git a/packages/target-web3-v1-test/test/DataTypesPure.test.ts b/packages/target-web3-v1-test/test/DataTypesPure.test.ts index e286b3cc7..b82da0a62 100644 --- a/packages/target-web3-v1-test/test/DataTypesPure.test.ts +++ b/packages/target-web3-v1-test/test/DataTypesPure.test.ts @@ -1,6 +1,6 @@ import { q18, typedAssert } from 'test-utils' -import type { DataTypesPure } from '../types/DataTypesPure' +import type { DataTypesPure } from '../types/v0.6.4/DataTypesPure' import { createNewBlockchain, deployContract } from './common' describe('DataTypesPure', () => { diff --git a/packages/target-web3-v1-test/test/DataTypesView.test.ts b/packages/target-web3-v1-test/test/DataTypesView.test.ts index cda5ac7f9..a1dc2b1dc 100644 --- a/packages/target-web3-v1-test/test/DataTypesView.test.ts +++ b/packages/target-web3-v1-test/test/DataTypesView.test.ts @@ -1,6 +1,6 @@ import { q18, typedAssert } from 'test-utils' -import type { DataTypesView } from '../types/DataTypesView' +import type { DataTypesView } from '../types/v0.6.4/DataTypesView' import { createNewBlockchain, deployContract } from './common' describe('DataTypesView', () => { diff --git a/packages/target-web3-v1-test/test/Events.test.ts b/packages/target-web3-v1-test/test/Events.test.ts index 15c2984d3..98c285663 100644 --- a/packages/target-web3-v1-test/test/Events.test.ts +++ b/packages/target-web3-v1-test/test/Events.test.ts @@ -1,7 +1,7 @@ import BigNumber from 'bn.js' import { asyncWithDoneCase, typedAssert } from 'test-utils' -import type { Events } from '../types/Events' +import type { Events } from '../types/v0.6.4/Events' import { createNewBlockchain, deployContract, GAS_LIMIT_STANDARD } from './common' // Docs: https://web3js.readthedocs.io/en/v1.2.6/web3-eth-contract.html#events diff --git a/packages/target-web3-v1-test/test/Overload.test.ts b/packages/target-web3-v1-test/test/Overload.test.ts index f380ea83c..271000d4a 100644 --- a/packages/target-web3-v1-test/test/Overload.test.ts +++ b/packages/target-web3-v1-test/test/Overload.test.ts @@ -1,7 +1,7 @@ import { typedAssert } from 'test-utils' import type Web3 from 'web3' -import type { Overloads } from '../types/Overloads' +import type { Overloads } from '../types/v0.6.4/Overloads' import { createNewBlockchain, deployContract } from './common' describe('Overloads', () => { diff --git a/packages/target-web3-v1-test/test/Payable.test.ts b/packages/target-web3-v1-test/test/Payable.test.ts index 866ca1a9e..5800b2310 100644 --- a/packages/target-web3-v1-test/test/Payable.test.ts +++ b/packages/target-web3-v1-test/test/Payable.test.ts @@ -1,7 +1,7 @@ import { typeCase, typedAssert } from 'test-utils' import type Web3 from 'web3' -import type { Payable } from '../types/Payable' +import type { Payable } from '../types/v0.6.4/Payable' import { createNewBlockchain, deployContract } from './common' describe('Payable', () => { diff --git a/packages/target-web3-v1-test/types/KingOfTheHill.d.ts b/packages/target-web3-v1-test/types/KingOfTheHill.d.ts deleted file mode 100644 index ce2251174..000000000 --- a/packages/target-web3-v1-test/types/KingOfTheHill.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* tslint:disable */ -/* eslint-disable */ - -import BN from "bn.js"; -import { ContractOptions } from "web3-eth-contract"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { - Callback, - PayableTransactionObject, - NonPayableTransactionObject, - BlockType, - ContractEventLog, - BaseContract, -} from "./types"; - -interface EventOptions { - filter?: object; - fromBlock?: BlockType; - topics?: string[]; -} - -export type HighestBidIncreased = ContractEventLog<{ - bid: [string, string]; - 0: [string, string]; -}>; - -export interface KingOfTheHill extends BaseContract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ): KingOfTheHill; - clone(): KingOfTheHill; - methods: { - bid(): PayableTransactionObject; - - highestBid(): NonPayableTransactionObject<{ - bidder: string; - value: string; - 0: string; - 1: string; - }>; - - withdraw(): NonPayableTransactionObject; - }; - events: { - HighestBidIncreased(cb?: Callback): EventEmitter; - HighestBidIncreased( - options?: EventOptions, - cb?: Callback - ): EventEmitter; - - allEvents(options?: EventOptions, cb?: Callback): EventEmitter; - }; - - once(event: "HighestBidIncreased", cb: Callback): void; - once( - event: "HighestBidIncreased", - options: EventOptions, - cb: Callback - ): void; -} diff --git a/packages/target-web3-v1-test/types/Withdrawable.d.ts b/packages/target-web3-v1-test/types/Withdrawable.d.ts deleted file mode 100644 index 5e53add01..000000000 --- a/packages/target-web3-v1-test/types/Withdrawable.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* tslint:disable */ -/* eslint-disable */ - -import BN from "bn.js"; -import { ContractOptions } from "web3-eth-contract"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { - Callback, - PayableTransactionObject, - NonPayableTransactionObject, - BlockType, - ContractEventLog, - BaseContract, -} from "./types"; - -interface EventOptions { - filter?: object; - fromBlock?: BlockType; - topics?: string[]; -} - -export interface Withdrawable extends BaseContract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ): Withdrawable; - clone(): Withdrawable; - methods: { - withdraw(): NonPayableTransactionObject; - }; - events: { - allEvents(options?: EventOptions, cb?: Callback): EventEmitter; - }; -} diff --git a/packages/target-web3-v1-test/types/B.ts b/packages/target-web3-v1-test/types/v0.6.4/B.ts similarity index 98% rename from packages/target-web3-v1-test/types/B.ts rename to packages/target-web3-v1-test/types/v0.6.4/B.ts index 577a63124..cad3eadf0 100644 --- a/packages/target-web3-v1-test/types/B.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/B.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/DataTypesInput.ts b/packages/target-web3-v1-test/types/v0.6.4/DataTypesInput.ts similarity index 99% rename from packages/target-web3-v1-test/types/DataTypesInput.ts rename to packages/target-web3-v1-test/types/v0.6.4/DataTypesInput.ts index 663028397..81d68c9e8 100644 --- a/packages/target-web3-v1-test/types/DataTypesInput.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/DataTypesInput.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/DataTypesPure.ts b/packages/target-web3-v1-test/types/v0.6.4/DataTypesPure.ts similarity index 98% rename from packages/target-web3-v1-test/types/DataTypesPure.ts rename to packages/target-web3-v1-test/types/v0.6.4/DataTypesPure.ts index 031809758..f4e3b42a8 100644 --- a/packages/target-web3-v1-test/types/DataTypesPure.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/DataTypesPure.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/DataTypesView.ts b/packages/target-web3-v1-test/types/v0.6.4/DataTypesView.ts similarity index 98% rename from packages/target-web3-v1-test/types/DataTypesView.ts rename to packages/target-web3-v1-test/types/v0.6.4/DataTypesView.ts index 8ee2ee025..cbb6568b8 100644 --- a/packages/target-web3-v1-test/types/DataTypesView.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/DataTypesView.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Events.ts b/packages/target-web3-v1-test/types/v0.6.4/Events.ts similarity index 99% rename from packages/target-web3-v1-test/types/Events.ts rename to packages/target-web3-v1-test/types/v0.6.4/Events.ts index 4c9cb5089..df8955d9d 100644 --- a/packages/target-web3-v1-test/types/Events.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/Events.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Issue428_Reproduction.ts b/packages/target-web3-v1-test/types/v0.6.4/Issue428_Reproduction.ts similarity index 88% rename from packages/target-web3-v1-test/types/Issue428_Reproduction.ts rename to packages/target-web3-v1-test/types/v0.6.4/Issue428_Reproduction.ts index 1d04c4879..94b84d82c 100644 --- a/packages/target-web3-v1-test/types/Issue428_Reproduction.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/Issue428_Reproduction.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; @@ -26,13 +26,13 @@ export type Committed = ContractEventLog<{ 0: string[]; }>; -export interface Issue428Reproduction extends BaseContract { +export interface Issue428_Reproduction extends BaseContract { constructor( jsonInterface: any[], address?: string, options?: ContractOptions - ): Issue428Reproduction; - clone(): Issue428Reproduction; + ): Issue428_Reproduction; + clone(): Issue428_Reproduction; methods: {}; events: { Committed(cb?: Callback): EventEmitter; diff --git a/packages/target-web3-v1-test/types/Library.ts b/packages/target-web3-v1-test/types/v0.6.4/Library.ts similarity index 97% rename from packages/target-web3-v1-test/types/Library.ts rename to packages/target-web3-v1-test/types/v0.6.4/Library.ts index bf5e21336..15769f092 100644 --- a/packages/target-web3-v1-test/types/Library.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/Library.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/LibraryConsumer.ts b/packages/target-web3-v1-test/types/v0.6.4/LibraryConsumer.ts similarity index 97% rename from packages/target-web3-v1-test/types/LibraryConsumer.ts rename to packages/target-web3-v1-test/types/v0.6.4/LibraryConsumer.ts index c22e13a2c..61fcca816 100644 --- a/packages/target-web3-v1-test/types/LibraryConsumer.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/LibraryConsumer.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Name-Mangling.ts b/packages/target-web3-v1-test/types/v0.6.4/NameMangling.ts similarity index 97% rename from packages/target-web3-v1-test/types/Name-Mangling.ts rename to packages/target-web3-v1-test/types/v0.6.4/NameMangling.ts index 29ed6880d..067392798 100644 --- a/packages/target-web3-v1-test/types/Name-Mangling.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/NameMangling.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Overloads.ts b/packages/target-web3-v1-test/types/v0.6.4/Overloads.ts similarity index 98% rename from packages/target-web3-v1-test/types/Overloads.ts rename to packages/target-web3-v1-test/types/v0.6.4/Overloads.ts index 515f38f68..9519d4dfa 100644 --- a/packages/target-web3-v1-test/types/Overloads.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/Overloads.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Payable.ts b/packages/target-web3-v1-test/types/v0.6.4/Payable.ts similarity index 97% rename from packages/target-web3-v1-test/types/Payable.ts rename to packages/target-web3-v1-test/types/v0.6.4/Payable.ts index 1428ed2de..d22e83b66 100644 --- a/packages/target-web3-v1-test/types/Payable.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/Payable.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/PayableFactory.ts b/packages/target-web3-v1-test/types/v0.6.4/PayableFactory.ts similarity index 97% rename from packages/target-web3-v1-test/types/PayableFactory.ts rename to packages/target-web3-v1-test/types/v0.6.4/PayableFactory.ts index c4e42239c..708c03fe1 100644 --- a/packages/target-web3-v1-test/types/PayableFactory.ts +++ b/packages/target-web3-v1-test/types/v0.6.4/PayableFactory.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/ERC721.ts b/packages/target-web3-v1-test/types/v0.8.9/ERC721.ts similarity index 99% rename from packages/target-web3-v1-test/types/ERC721.ts rename to packages/target-web3-v1-test/types/v0.8.9/ERC721.ts index 5c592aede..38d8372e2 100644 --- a/packages/target-web3-v1-test/types/ERC721.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/ERC721.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/ERC721Enumerable.ts b/packages/target-web3-v1-test/types/v0.8.9/ERC721Enumerable.ts similarity index 99% rename from packages/target-web3-v1-test/types/ERC721Enumerable.ts rename to packages/target-web3-v1-test/types/v0.8.9/ERC721Enumerable.ts index 44e7d95e4..b1deccfba 100644 --- a/packages/target-web3-v1-test/types/ERC721Enumerable.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/ERC721Enumerable.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/IERC721.ts b/packages/target-web3-v1-test/types/v0.8.9/IERC721.ts similarity index 99% rename from packages/target-web3-v1-test/types/IERC721.ts rename to packages/target-web3-v1-test/types/v0.8.9/IERC721.ts index 4aa5ba19d..75fa85f22 100644 --- a/packages/target-web3-v1-test/types/IERC721.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/IERC721.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/IERC721Enumerable.ts b/packages/target-web3-v1-test/types/v0.8.9/IERC721Enumerable.ts similarity index 99% rename from packages/target-web3-v1-test/types/IERC721Enumerable.ts rename to packages/target-web3-v1-test/types/v0.8.9/IERC721Enumerable.ts index bac807e73..482a8048e 100644 --- a/packages/target-web3-v1-test/types/IERC721Enumerable.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/IERC721Enumerable.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/IERC721Receiver.ts b/packages/target-web3-v1-test/types/v0.8.9/IERC721Receiver.ts similarity index 98% rename from packages/target-web3-v1-test/types/IERC721Receiver.ts rename to packages/target-web3-v1-test/types/v0.8.9/IERC721Receiver.ts index dfa6371f0..d74f51d36 100644 --- a/packages/target-web3-v1-test/types/IERC721Receiver.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/IERC721Receiver.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Issue552_Reproduction.ts b/packages/target-web3-v1-test/types/v0.8.9/Issue552_Reproduction.ts similarity index 87% rename from packages/target-web3-v1-test/types/Issue552_Reproduction.ts rename to packages/target-web3-v1-test/types/v0.8.9/Issue552_Reproduction.ts index 848d681f7..8d779ffed 100644 --- a/packages/target-web3-v1-test/types/Issue552_Reproduction.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/Issue552_Reproduction.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; @@ -21,13 +21,13 @@ export interface EventOptions { topics?: string[]; } -export interface Issue552Reproduction extends BaseContract { +export interface Issue552_Reproduction extends BaseContract { constructor( jsonInterface: any[], address?: string, options?: ContractOptions - ): Issue552Reproduction; - clone(): Issue552Reproduction; + ): Issue552_Reproduction; + clone(): Issue552_Reproduction; methods: { bars( arg0: number | string | BN diff --git a/packages/target-web3-v1-test/types/KingOfTheHill.ts b/packages/target-web3-v1-test/types/v0.8.9/KingOfTheHill.ts similarity index 98% rename from packages/target-web3-v1-test/types/KingOfTheHill.ts rename to packages/target-web3-v1-test/types/v0.8.9/KingOfTheHill.ts index 58bf33be3..7692eef00 100644 --- a/packages/target-web3-v1-test/types/KingOfTheHill.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/KingOfTheHill.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Rarity.ts b/packages/target-web3-v1-test/types/v0.8.9/Rarity.ts similarity index 99% rename from packages/target-web3-v1-test/types/Rarity.ts rename to packages/target-web3-v1-test/types/v0.8.9/Rarity.ts index c62d140b0..8044a233a 100644 --- a/packages/target-web3-v1-test/types/Rarity.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/Rarity.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/Withdrawable.ts b/packages/target-web3-v1-test/types/v0.8.9/Withdrawable.ts similarity index 97% rename from packages/target-web3-v1-test/types/Withdrawable.ts rename to packages/target-web3-v1-test/types/v0.8.9/Withdrawable.ts index 3e015fb01..da8998ee2 100644 --- a/packages/target-web3-v1-test/types/Withdrawable.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/Withdrawable.ts @@ -13,7 +13,7 @@ import type { BlockType, ContractEventLog, BaseContract, -} from "./types"; +} from "../types"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1-test/types/v0.8.9/nested/a/NestedLibrary.ts b/packages/target-web3-v1-test/types/v0.8.9/nested/a/NestedLibrary.ts new file mode 100644 index 000000000..80ad75255 --- /dev/null +++ b/packages/target-web3-v1-test/types/v0.8.9/nested/a/NestedLibrary.ts @@ -0,0 +1,37 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import type BN from "bn.js"; +import type { ContractOptions } from "web3-eth-contract"; +import type { EventLog } from "web3-core"; +import type { EventEmitter } from "events"; +import type { + Callback, + PayableTransactionObject, + NonPayableTransactionObject, + BlockType, + ContractEventLog, + BaseContract, +} from "../../../types"; + +export interface EventOptions { + filter?: object; + fromBlock?: BlockType; + topics?: string[]; +} + +export interface NestedLibrary extends BaseContract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ): NestedLibrary; + clone(): NestedLibrary; + methods: { + getValue(): NonPayableTransactionObject; + }; + events: { + allEvents(options?: EventOptions, cb?: Callback): EventEmitter; + }; +} diff --git a/packages/target-web3-v1-test/types/v0.8.9/nested/b/NestedLibrary.ts b/packages/target-web3-v1-test/types/v0.8.9/nested/b/NestedLibrary.ts new file mode 100644 index 000000000..80ad75255 --- /dev/null +++ b/packages/target-web3-v1-test/types/v0.8.9/nested/b/NestedLibrary.ts @@ -0,0 +1,37 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import type BN from "bn.js"; +import type { ContractOptions } from "web3-eth-contract"; +import type { EventLog } from "web3-core"; +import type { EventEmitter } from "events"; +import type { + Callback, + PayableTransactionObject, + NonPayableTransactionObject, + BlockType, + ContractEventLog, + BaseContract, +} from "../../../types"; + +export interface EventOptions { + filter?: object; + fromBlock?: BlockType; + topics?: string[]; +} + +export interface NestedLibrary extends BaseContract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ): NestedLibrary; + clone(): NestedLibrary; + methods: { + getValue(): NonPayableTransactionObject; + }; + events: { + allEvents(options?: EventOptions, cb?: Callback): EventEmitter; + }; +} diff --git a/packages/target-web3-v1/src/codegen/index.ts b/packages/target-web3-v1/src/codegen/index.ts index 742a69a86..d2106b717 100644 --- a/packages/target-web3-v1/src/codegen/index.ts +++ b/packages/target-web3-v1/src/codegen/index.ts @@ -4,12 +4,14 @@ import { codegenForEvents, codegenForEventsDeclarations, codegenForEventsOnceFns import { codegenForFunctions } from './functions' export function codegen(contract: Contract) { + const typesPath = contract.path.length ? `${new Array(contract.path.length).fill('..').join('/')}/types` : './types' + const template = ` import type BN from "bn.js"; import type { ContractOptions } from "web3-eth-contract"; import type { EventLog } from "web3-core"; import type { EventEmitter } from "events"; - import type { Callback, PayableTransactionObject, NonPayableTransactionObject, BlockType, ContractEventLog, BaseContract } from "./types"; + import type { Callback, PayableTransactionObject, NonPayableTransactionObject, BlockType, ContractEventLog, BaseContract } from "${typesPath}"; export interface EventOptions { filter?: object; diff --git a/packages/target-web3-v1/src/index.ts b/packages/target-web3-v1/src/index.ts index c20dbc7a4..30b8b3315 100644 --- a/packages/target-web3-v1/src/index.ts +++ b/packages/target-web3-v1/src/index.ts @@ -1,11 +1,11 @@ import { readFileSync } from 'fs' -import { join, resolve } from 'path' +import { join, relative, resolve } from 'path' import { Config, + detectInputsRoot, extractAbi, extractDocumentation, FileDescription, - getFilename, parse, TypeChainTarget, } from 'typechain' @@ -22,12 +22,14 @@ export default class Web3V1 extends TypeChainTarget { name = 'Web3-v1' private readonly outDirAbs: string + private readonly inputsRoot: string constructor(config: Config) { super(config) - const { cwd, outDir } = config + const { cwd, outDir, allFiles } = config + this.inputsRoot = detectInputsRoot(allFiles) this.outDirAbs = resolve(cwd, outDir || DEFAULT_OUT_PATH) } @@ -38,13 +40,13 @@ export default class Web3V1 extends TypeChainTarget { return } - const name = getFilename(file.path) + const path = relative(this.inputsRoot, file.path) const documentation = extractDocumentation(file.contents) - const contract = parse(abi, name, documentation) + const contract = parse(abi, path, documentation) return { - path: join(this.outDirAbs, `${name}.ts`), + path: join(this.outDirAbs, ...contract.path, `${contract.name}.ts`), contents: codegen(contract), } } diff --git a/packages/typechain/src/codegen/createBarrelFiles.ts b/packages/typechain/src/codegen/createBarrelFiles.ts new file mode 100644 index 000000000..73570df60 --- /dev/null +++ b/packages/typechain/src/codegen/createBarrelFiles.ts @@ -0,0 +1,82 @@ +import { camelCase, groupBy, mapValues, uniq } from 'lodash' +import { posix } from 'path' + +import { normalizeName } from '../parser/normalizeName' +import { FileDescription } from '../typechain/types' + +/** + * returns barrel files with reexports for all given paths + * + * @see https://github.com/basarat/typescript-book/blob/master/docs/tips/barrel.md + */ +export function createBarrelFiles( + paths: string[], + { typeOnly, postfix = '' }: { typeOnly: boolean; postfix?: string }, +): FileDescription[] { + const fileReexports: Record = mapValues( + groupBy(paths.map(posix.parse), (p) => p.dir), + (ps) => ps.map((p) => p.name), + ) + + const directoryPaths = Object.keys(fileReexports).filter((path) => path.includes('/')) + const directoryReexports: Record = mapValues( + groupBy(directoryPaths.map(posix.parse), (p) => p.dir), + (ps) => ps.map((p) => p.base), + ) + + const barrelPaths = new Set(Object.keys(directoryReexports).concat(Object.keys(fileReexports))) + const newPaths: string[] = [] + + for (const directory of barrelPaths) { + if (!directory) continue + + const path = directory.split('/') + while (path.length) { + const dir = path.slice(0, -1).join('/') + const name = path[path.length - 1] + + if (!(dir in directoryReexports)) { + directoryReexports[dir] = [name] + newPaths.push(dir) + } else if (!directoryReexports[dir]!.find((x) => x === name)) { + directoryReexports[dir]!.push(name) + } + + path.pop() + } + } + + return uniq([...barrelPaths, ...newPaths]).map((path) => { + const nestedDirs = (directoryReexports[path] || []).sort() + + const namespacesExports = nestedDirs + .map((p) => { + const namespaceIdentifier = camelCase(p) + + if (typeOnly) + return [ + `import type * as ${namespaceIdentifier} from './${p}';`, + `export type { ${namespaceIdentifier} };`, + ].join('\n') + + return `export * as ${namespaceIdentifier} from './${p}';` + }) + .join('\n') + + const contracts = (fileReexports[path] || []).sort() + const namedExports = contracts + .map((p) => { + const exportKeyword = typeOnly ? 'export type' : 'export' + const name = `${normalizeName(p)}${postfix}` + // We can't always `export *` because of possible name conflicts. + // @todo possibly a config option for user to decide? + return `${exportKeyword} { ${name} } from './${name}';` + }) + .join('\n') + + return { + path: posix.join(path, 'index.ts'), + contents: (namespacesExports + '\n' + namedExports).trim(), + } + }) +} diff --git a/packages/typechain/src/index.ts b/packages/typechain/src/index.ts index b99e8335c..225410e53 100644 --- a/packages/typechain/src/index.ts +++ b/packages/typechain/src/index.ts @@ -1,3 +1,4 @@ +export * from './codegen/createBarrelFiles' export * from './codegen/syntax' export * from './parser/abiParser' export { normalizeName } from './parser/normalizeName' diff --git a/packages/typechain/src/parser/abiParser.ts b/packages/typechain/src/parser/abiParser.ts index a8c65e56d..7ed869769 100644 --- a/packages/typechain/src/parser/abiParser.ts +++ b/packages/typechain/src/parser/abiParser.ts @@ -1,9 +1,11 @@ import { keccak_256 } from 'js-sha3' import { groupBy, omit } from 'lodash' +import { parse as parsePath } from 'path' import { Dictionary } from 'ts-essentials' import { debug } from '../utils/debug' import { MalformedAbiError } from '../utils/errors' +import { normalizeSlashes } from '../utils/files' import { normalizeName } from './normalizeName' import { EvmOutputType, EvmType, parseEvmType, StructType } from './parseEvmType' @@ -53,6 +55,7 @@ export interface FunctionWithoutInputDeclaration extends FunctionDeclaration { export interface Contract { name: string rawName: string + path: string[] fallback?: FunctionWithoutInputDeclaration | undefined constructor: FunctionWithoutOutputDeclaration[] @@ -132,7 +135,17 @@ export interface DocumentationResult { } } -export function parse(abi: RawAbiDefinition[], rawName: string, documentation?: DocumentationResult): Contract { +export function parseContractPath(path: string) { + const parsedPath = parsePath(normalizeSlashes(path)) + + return { + name: normalizeName(parsedPath.name), + rawName: parsedPath.name, + path: parsedPath.dir.split('/').filter((x) => x), + } +} + +export function parse(abi: RawAbiDefinition[], path: string, documentation?: DocumentationResult): Contract { const constructors: FunctionWithoutOutputDeclaration[] = [] let fallback: FunctionWithoutInputDeclaration | undefined const functions: FunctionDeclaration[] = [] @@ -180,8 +193,7 @@ export function parse(abi: RawAbiDefinition[], rawName: string, documentation?: }) return { - name: normalizeName(rawName), - rawName, + ...parseContractPath(path), fallback, constructor: constructors, functions: groupBy(functions, (f) => f.name), diff --git a/packages/typechain/src/parser/normalizeName.ts b/packages/typechain/src/parser/normalizeName.ts index 56a730e82..d8cdaf8c9 100644 --- a/packages/typechain/src/parser/normalizeName.ts +++ b/packages/typechain/src/parser/normalizeName.ts @@ -7,7 +7,6 @@ export function normalizeName(rawName: string): string { const transformations: ((s: string) => string)[] = [ (s) => s.replace(/\s+/g, '-'), // spaces to - so later we can automatically convert them (s) => s.replace(/\./g, '-'), // replace "." - (s) => s.replace(/_/g, '-'), // replace "_" (s) => s.replace(/-[a-z]/g, (match) => match.substr(-1).toUpperCase()), // delete '-' and capitalize the letter after them (s) => s.replace(/-/g, ''), // delete any '-' left (s) => s.replace(/^\d+/, ''), // removes leading digits diff --git a/packages/typechain/src/typechain/findTarget.ts b/packages/typechain/src/typechain/findTarget.ts index 576dc9e7d..16b7c22f4 100644 --- a/packages/typechain/src/typechain/findTarget.ts +++ b/packages/typechain/src/typechain/findTarget.ts @@ -1,7 +1,7 @@ import _, { compact } from 'lodash' import { debug } from '../utils/debug' -import { ensureAbsPath } from '../utils/files' +import { ensureAbsPath } from '../utils/files/ensureAbsPath' import { tryRequire } from '../utils/modules' import { Config, TypeChainTarget } from './types' diff --git a/packages/typechain/src/utils/files.ts b/packages/typechain/src/utils/files.ts deleted file mode 100644 index 1c7295ce3..000000000 --- a/packages/typechain/src/utils/files.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { isAbsolute, join, parse } from 'path' - -export function getFilename(path: string) { - return parse(path).name -} - -export function getFileExtension(path: string) { - return parse(path).ext -} - -export function ensureAbsPath(path: string): string { - if (isAbsolute(path)) { - return path - } - return join(process.cwd(), path) -} diff --git a/packages/typechain/src/utils/files/detectInputsRoot.ts b/packages/typechain/src/utils/files/detectInputsRoot.ts new file mode 100644 index 000000000..8b06fee37 --- /dev/null +++ b/packages/typechain/src/utils/files/detectInputsRoot.ts @@ -0,0 +1,8 @@ +import { dirname } from 'path' + +import { lowestCommonPath } from './lowestCommonPath' +import { shortenFullJsonFilePath } from './shortenFullJsonFilePath' + +export function detectInputsRoot(allFiles: string[]): string { + return allFiles.length === 1 ? dirname(shortenFullJsonFilePath(allFiles[0])) : lowestCommonPath(allFiles) +} diff --git a/packages/typechain/src/utils/files/ensureAbsPath.ts b/packages/typechain/src/utils/files/ensureAbsPath.ts new file mode 100644 index 000000000..19e9f2e9d --- /dev/null +++ b/packages/typechain/src/utils/files/ensureAbsPath.ts @@ -0,0 +1,8 @@ +import { isAbsolute, join } from 'path' + +export function ensureAbsPath(path: string): string { + if (isAbsolute(path)) { + return path + } + return join(process.cwd(), path) +} diff --git a/packages/typechain/src/utils/files/getFileExtension.ts b/packages/typechain/src/utils/files/getFileExtension.ts new file mode 100644 index 000000000..499124f71 --- /dev/null +++ b/packages/typechain/src/utils/files/getFileExtension.ts @@ -0,0 +1,5 @@ +import { parse } from 'path' + +export function getFileExtension(path: string) { + return parse(path).ext +} diff --git a/packages/typechain/src/utils/files/getFilename.ts b/packages/typechain/src/utils/files/getFilename.ts new file mode 100644 index 000000000..2f1fb9289 --- /dev/null +++ b/packages/typechain/src/utils/files/getFilename.ts @@ -0,0 +1,5 @@ +import { parse } from 'path' + +export function getFilename(path: string) { + return parse(path).name +} diff --git a/packages/typechain/src/utils/files/index.ts b/packages/typechain/src/utils/files/index.ts new file mode 100644 index 000000000..2884c4d47 --- /dev/null +++ b/packages/typechain/src/utils/files/index.ts @@ -0,0 +1,7 @@ +export * from './detectInputsRoot' +export * from './ensureAbsPath' +export * from './getFileExtension' +export * from './getFilename' +export * from './lowestCommonPath' +export * from './normalizeSlashes' +export * from './shortenFullJsonFilePath' diff --git a/packages/typechain/src/utils/files/lowestCommonPath.ts b/packages/typechain/src/utils/files/lowestCommonPath.ts new file mode 100644 index 000000000..4c3bcdbf9 --- /dev/null +++ b/packages/typechain/src/utils/files/lowestCommonPath.ts @@ -0,0 +1,5 @@ +export function lowestCommonPath(paths: string[]) { + const pathParts = paths.map((path) => path.split(/[\\/]/)) + const commonParts = pathParts[0].filter((part, index) => pathParts.every((parts) => parts[index] === part)) + return commonParts.join('/') +} diff --git a/packages/typechain/src/utils/files/normalizeSlashes.ts b/packages/typechain/src/utils/files/normalizeSlashes.ts new file mode 100644 index 000000000..e6ad62637 --- /dev/null +++ b/packages/typechain/src/utils/files/normalizeSlashes.ts @@ -0,0 +1,3 @@ +export function normalizeSlashes(path: string) { + return process.platform === 'win32' ? path.replace(/\\/g, '/') : path +} diff --git a/packages/typechain/src/utils/files/shortenFullJsonFilePath.ts b/packages/typechain/src/utils/files/shortenFullJsonFilePath.ts new file mode 100644 index 000000000..c8b2a1aec --- /dev/null +++ b/packages/typechain/src/utils/files/shortenFullJsonFilePath.ts @@ -0,0 +1,15 @@ +import { posix } from 'path' + +/** + * Transforms all paths matching `ContractName.sol/ContractName.json` + */ +export function shortenFullJsonFilePath(path: string) { + const parsed = posix.parse(path) + + const sourceFileName = `${parsed.name}.sol` + if (parsed.dir.endsWith(sourceFileName)) { + return parsed.dir.slice(0, -sourceFileName.length) + `${parsed.name}.json` + } + + return path +} diff --git a/packages/typechain/test/parser/abiParser.test.ts b/packages/typechain/test/parser/abiParser.test.ts index da3f41f45..fb40616bb 100644 --- a/packages/typechain/test/parser/abiParser.test.ts +++ b/packages/typechain/test/parser/abiParser.test.ts @@ -459,9 +459,17 @@ describe('parse', () => { structs: {}, name: 'Sc1', rawName: 'sc1', + path: [], }) }) }) + + it('preserves file paths', () => { + const actual = parse([], 'a/b/c/d/e/f/g/contract.sol') + + expect(actual.name).toEqual('Contract') + expect(actual.path).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g']) + }) }) export function fixtureFactory(defaults: T): (params?: Partial) => T { diff --git a/packages/typechain/test/parser/normalizeName.test.ts b/packages/typechain/test/parser/normalizeName.test.ts index 0ad3b8141..99683f709 100644 --- a/packages/typechain/test/parser/normalizeName.test.ts +++ b/packages/typechain/test/parser/normalizeName.test.ts @@ -7,7 +7,7 @@ describe('name normalizer', () => { expect(normalizeName('DsToken')).toEqual('DsToken') expect(normalizeName('test')).toEqual('Test') expect(normalizeName('ds-token')).toEqual('DsToken') - expect(normalizeName('ds_token')).toEqual('DsToken') + expect(normalizeName('ds_token')).toEqual('Ds_token') expect(normalizeName('ds token')).toEqual('DsToken') expect(normalizeName('name.abi')).toEqual('NameAbi') expect(normalizeName('1234name.abi')).toEqual('NameAbi') diff --git a/packages/typechain/test/utils/files/lowestCommonPath.test.ts b/packages/typechain/test/utils/files/lowestCommonPath.test.ts new file mode 100644 index 000000000..0c4d190cb --- /dev/null +++ b/packages/typechain/test/utils/files/lowestCommonPath.test.ts @@ -0,0 +1,34 @@ +import { expect } from 'earljs' + +import { lowestCommonPath } from '../../../src/utils/files/lowestCommonPath' + +describe(lowestCommonPath.name, () => { + it('finds lowest common ancestor path', () => { + const paths = [ + '/TypeChain/contracts/compiled/v0.6.4/Payable.abi', + '/TypeChain/contracts/compiled/v0.6.4/PayableFactory.abi', + '/TypeChain/contracts/compiled/v0.8.9/ERC721.abi', + '/TypeChain/contracts/compiled/v0.8.9/nested/a/NestedLibrary.abi', + '/TypeChain/contracts/compiled/v0.8.9/nested/b/NestedLibrary.abi', + '/TypeChain/contracts/compiled/v0.8.9/Rarity.abi', + '/TypeChain/contracts/compiled/v0.8.9/Withdrawable.abi', + ] + + const actual = lowestCommonPath(paths) + expect(actual).toEqual('/TypeChain/contracts/compiled') + }) + + it('works for Windows paths', () => { + const paths = [ + 'D:/workspace/TypeChain/packages/hardhat/test/fixture-projects/hardhat-project/artifacts/contracts/EdgeCases.sol/EdgeCases.json', + 'D:/workspace/TypeChain/packages/hardhat/test/fixture-projects/hardhat-project/artifacts/contracts/lib/SafeMath.sol/SafeMath.json', + 'D:/workspace/TypeChain/packages/hardhat/test/fixture-projects/hardhat-project/artifacts/contracts/TestContract.sol/TestContract.json', + 'D:/workspace/TypeChain/packages/hardhat/test/fixture-projects/hardhat-project/artifacts/contracts/TestContract1.sol/TestContract1.json', + ] + + const actual = lowestCommonPath(paths) + expect(actual).toEqual( + 'D:/workspace/TypeChain/packages/hardhat/test/fixture-projects/hardhat-project/artifacts/contracts', + ) + }) +}) diff --git a/scripts/compile-contracts.ts b/scripts/compile-contracts.ts index 0ef932f0d..6dee35fe0 100644 --- a/scripts/compile-contracts.ts +++ b/scripts/compile-contracts.ts @@ -1,6 +1,8 @@ /* eslint-disable no-console */ import { execSync } from 'child_process' -import { copyFileSync, mkdirSync, readdirSync, renameSync, rmdirSync } from 'fs' +import { mkdirSync, readdirSync, renameSync, rmdirSync } from 'fs' +import { copySync } from 'fs-extra' +import { sync as globSync } from 'glob' import { resolve } from 'path' import { SemVer } from 'semver' @@ -15,6 +17,7 @@ function main() { generateABIs(files) renameUglyNames(files) copyTruffleV5(files) + copyPrebuiltABIs(files) } main() @@ -54,11 +57,14 @@ function findFiles() { }), ) + const prebuiltAbis = globSync('**/*.json', { cwd: contractsDir }) + return { rootDir, contractsDir, outDir, contracts, + prebuiltAbis, } } @@ -147,6 +153,12 @@ function copyTruffleV5({ rootDir, contractsDir, contracts }: Files) { contracts.get(version)!.map((file) => `${version}/${file}`), ) for (const path of contractRelativePaths) { - copyFileSync(resolve(contractsDir, path), resolve(truffleV5ContractsDir, path)) + copySync(resolve(contractsDir, path), resolve(truffleV5ContractsDir, path)) + } +} + +function copyPrebuiltABIs({ prebuiltAbis, outDir, contractsDir }: Files) { + for (const filepath of prebuiltAbis) { + copySync(resolve(contractsDir, filepath), resolve(outDir, filepath.replace('.json', '.abi')), { recursive: true }) } } diff --git a/tsconfig.json b/tsconfig.json index 621f57720..58dec18ec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "declaration": true, - "lib": ["ES2018", "ES2019.Array"], + "lib": ["ES2018", "ES2019.Array", "ES2019.Object"], "module": "CommonJS", "moduleResolution": "node", "strict": true,