Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: name clashes #887

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/clean-cameras-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@typechain/ethers-v5': patch
'@typechain/ethers-v6': patch
---

Fix clashes with built-in contract properties
20 changes: 20 additions & 0 deletions contracts/v0.8.9/NameClashes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity ^0.8.7;

contract NameClashes {
address public target;
address public runner;
address public filters;
address public connect;
address public attach;
address public getAddress;
address public getDeployedCode;
address public getFunction;
address public on;
address public off;
address public once;
address public listeners;
address public signer;
address public provider;
address public deployed;
address public then;
}
8 changes: 7 additions & 1 deletion packages/target-ethers-v5/src/codegen/reserved-keywords.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export const reservedKeywords = new Set(['signer', 'provider', 'deployTransaction', 'deployed', 'fallback', 'connect'])
import { BaseContract } from 'ethers'

export const reservedKeywords = new Set([
'then',
...Object.getOwnPropertyNames(BaseContract.prototype), // for methods
...Object.keys(new BaseContract('0x', [])), // for readOnly properties
])
18 changes: 18 additions & 0 deletions packages/target-ethers-v6-test/test/NameClashes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { BaseContract } from 'ethers'
import type { AssertTrue, Has } from 'test-utils'

import type { NameClashes } from '../types/v0.8.9/NameClashes'

type _testTarget = AssertTrue<Has<NameClashes['target'], BaseContract['target']>>
type _testRunner = AssertTrue<Has<NameClashes['runner'], BaseContract['runner']>>
type _testFilters = AssertTrue<Has<NameClashes['filters'], BaseContract['filters']>>
type _testGetAddress = AssertTrue<Has<NameClashes['getAddress'], BaseContract['getAddress']>>
type _testGetDeployedCode = AssertTrue<Has<NameClashes['getDeployedCode'], BaseContract['getDeployedCode']>>
type _testGetFunction = AssertTrue<Has<NameClashes['getFunction'], BaseContract['getFunction']>>
type _testOn = AssertTrue<Has<NameClashes['on'], BaseContract['on']>>
type _testOff = AssertTrue<Has<NameClashes['off'], BaseContract['off']>>
type _testOnce = AssertTrue<Has<NameClashes['once'], BaseContract['once']>>
type _testListeners = AssertTrue<Has<NameClashes['listeners'], BaseContract['listeners']>>

// "then" won't be passed through by ethers as it's listed in `passProperties` (see: https://github.com/ethers-io/ethers.js/blob/6ee1a5f8bb38ec31fa84c00aae7f091e1d3d6837/src.ts/contract/contract.ts#L779)
type _testThen = AssertTrue<'then' extends keyof NameClashes ? false : true>
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */

import { Contract, Interface, type ContractRunner } from "ethers";
import type {
NameClashes,
NameClashesInterface,
} from "../../v0.8.9/NameClashes";

const _abi = [
{
inputs: [],
name: "attach",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "connect",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "filters",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "getAddress",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "getDeployedCode",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "getFunction",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "listeners",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "off",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "on",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "once",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "runner",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "target",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "then",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
] as const;

export class NameClashes__factory {
static readonly abi = _abi;
static createInterface(): NameClashesInterface {
return new Interface(_abi) as NameClashesInterface;
}
static connect(address: string, runner?: ContractRunner | null): NameClashes {
return new Contract(address, _abi, runner) as unknown as NameClashes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * as rarity from "./Rarity";
export * as nested from "./nested";
export { ISimpleToken__factory } from "./ISimpleToken__factory";
export { Issue552_Reproduction__factory } from "./Issue552_Reproduction__factory";
export { NameClashes__factory } from "./NameClashes__factory";
export { SimpleToken__factory } from "./SimpleToken__factory";
2 changes: 2 additions & 0 deletions packages/target-ethers-v6-test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type { KingOfTheHill } from "./v0.8.9/KingOfTheHill/KingOfTheHill";
export { KingOfTheHill__factory } from "./factories/v0.8.9/KingOfTheHill/KingOfTheHill__factory";
export type { Withdrawable } from "./v0.8.9/KingOfTheHill/Withdrawable";
export { Withdrawable__factory } from "./factories/v0.8.9/KingOfTheHill/Withdrawable__factory";
export type { NameClashes } from "./v0.8.9/NameClashes";
export { NameClashes__factory } from "./factories/v0.8.9/NameClashes__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 { ERC721 } from "./v0.8.9/Rarity/ERC721";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export interface NAME12mangling extends BaseContract {
event?: TCEvent
): Promise<this>;

provider: TypedContractMethod<[], [boolean], "view">;

works: TypedContractMethod<[], [boolean], "view">;

getFunction<T extends ContractMethod = ContractMethod>(
Expand Down