From 1ffc70f76867d7006aab54f782136f9546a41866 Mon Sep 17 00:00:00 2001 From: Marin Petrunic Date: Fri, 12 May 2023 16:22:06 +0200 Subject: [PATCH 1/8] fix!: remove non read-only ens methods Signed-off-by: Marin Petrunic --- CHANGELOG.md | 7 + .../web3-eth-ens/src/abi/ens/ENSRegistry.ts | 211 ----- .../src/abi/ens/PublicResolver.ts | 300 ------ .../web3-eth-ens/src/abi/reverse_registrar.ts | 173 ---- .../web3-eth-ens/src/abi/test_registrar.ts | 101 -- packages/web3-eth-ens/src/ens.ts | 278 +----- packages/web3-eth-ens/src/index.ts | 2 +- packages/web3-eth-ens/src/registry.ts | 157 +-- packages/web3-eth-ens/src/resolver.ts | 38 +- .../test/fixtures/ens/abi/ENSRegistry.ts | 394 ++++++++ .../test/fixtures/ens/abi/PublicResolver.ts | 893 ++++++++++++++++++ .../test/integration/ens.events.test.ts | 17 +- .../web3-eth-ens/test/integration/ens.test.ts | 102 +- .../test/integration/resolver.test.ts | 21 +- packages/web3-eth-ens/test/unit/abi.test.ts | 35 - .../test/unit/constructor.test.ts | 20 - packages/web3-eth-ens/test/unit/ens.test.ts | 219 +---- .../web3-eth-ens/test/unit/registry.test.ts | 385 -------- .../web3-eth-ens/test/unit/resolver.test.ts | 103 +- 19 files changed, 1337 insertions(+), 2119 deletions(-) delete mode 100644 packages/web3-eth-ens/src/abi/reverse_registrar.ts delete mode 100644 packages/web3-eth-ens/src/abi/test_registrar.ts create mode 100644 packages/web3-eth-ens/test/fixtures/ens/abi/ENSRegistry.ts create mode 100644 packages/web3-eth-ens/test/fixtures/ens/abi/PublicResolver.ts delete mode 100644 packages/web3-eth-ens/test/unit/abi.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index cdb49f99b04..e2e4bd555c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1465,6 +1465,7 @@ should use 4.0.1-alpha.0 for testing. ### Breaking Changes - dropped support for NodeJs@14 +- removed non read-only methods from ens package ### Added @@ -1488,3 +1489,9 @@ should use 4.0.1-alpha.0 for testing. - `formatTransaction` no longer throws a `TransactionDataAndInputError` if it's passed a transaction object with both `data` and `input` properties set (as long as they are the same value) (#6064) - Refactored documentation for `rpc_method_wrappers` to point to the previously duplicated documentation found under the `Web3Eth` class documentation (#6054) + +#### web3-eth-ens + +### Changed + +- Removed non read-only methods diff --git a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts index 99730866873..bcac4c53170 100644 --- a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts +++ b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts @@ -17,36 +17,6 @@ along with web3.js. If not, see . // https://github.com/ensdomains/ens-contracts/blob/master/contracts/registry/ENSRegistry.sol export const ENSRegistryAbi = [ - { - inputs: [], - stateMutability: 'nonpayable', - type: 'constructor', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'operator', - type: 'address', - }, - { - indexed: false, - internalType: 'bool', - name: 'approved', - type: 'bool', - }, - ], - name: 'ApprovalForAll', - type: 'event', - }, { anonymous: false, inputs: [ @@ -91,25 +61,6 @@ export const ENSRegistryAbi = [ name: 'NewResolver', type: 'event', }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - indexed: false, - internalType: 'uint64', - name: 'ttl', - type: 'uint64', - }, - ], - name: 'NewTTL', - type: 'event', - }, { anonymous: false, inputs: [ @@ -210,168 +161,6 @@ export const ENSRegistryAbi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'address', - name: 'operator', - type: 'address', - }, - { - internalType: 'bool', - name: 'approved', - type: 'bool', - }, - ], - name: 'setApprovalForAll', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - name: 'setOwner', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - internalType: 'address', - name: 'resolver', - type: 'address', - }, - { - internalType: 'uint64', - name: 'ttl', - type: 'uint64', - }, - ], - name: 'setRecord', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'resolver', - type: 'address', - }, - ], - name: 'setResolver', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 'label', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - name: 'setSubnodeOwner', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 'label', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - internalType: 'address', - name: 'resolver', - type: 'address', - }, - { - internalType: 'uint64', - name: 'ttl', - type: 'uint64', - }, - ], - name: 'setSubnodeRecord', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'uint64', - name: 'ttl', - type: 'uint64', - }, - ], - name: 'setTTL', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, { inputs: [ { diff --git a/packages/web3-eth-ens/src/abi/ens/PublicResolver.ts b/packages/web3-eth-ens/src/abi/ens/PublicResolver.ts index b666d4f4d67..83b927bfb69 100644 --- a/packages/web3-eth-ens/src/abi/ens/PublicResolver.ts +++ b/packages/web3-eth-ens/src/abi/ens/PublicResolver.ts @@ -17,51 +17,6 @@ along with web3.js. If not, see . // https://github.com/ensdomains/ens-contracts/blob/master/contracts/resolvers/PublicResolver.sol export const PublicResolverAbi = [ - { - inputs: [ - { - internalType: 'contract ENS', - name: '_ens', - type: 'address', - }, - { - internalType: 'contract INameWrapper', - name: 'wrapperAddress', - type: 'address', - }, - { - internalType: 'address', - name: '_trustedETHController', - type: 'address', - }, - { - internalType: 'address', - name: '_trustedReverseRegistrar', - type: 'address', - }, - ], - stateMutability: 'nonpayable', - type: 'constructor', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - indexed: true, - internalType: 'uint256', - name: 'contentType', - type: 'uint256', - }, - ], - name: 'ABIChanged', - type: 'event', - }, { anonymous: false, inputs: [ @@ -410,19 +365,6 @@ export const PublicResolverAbi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - ], - name: 'clearDNSZone', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, { inputs: [ { @@ -543,25 +485,6 @@ export const PublicResolverAbi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'bytes[]', - name: 'data', - type: 'bytes[]', - }, - ], - name: 'multicall', - outputs: [ - { - internalType: 'bytes[]', - name: 'results', - type: 'bytes[]', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, { inputs: [ { @@ -605,229 +528,6 @@ export const PublicResolverAbi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'uint256', - name: 'contentType', - type: 'uint256', - }, - { - internalType: 'bytes', - name: 'data', - type: 'bytes', - }, - ], - name: 'setABI', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'uint256', - name: 'coinType', - type: 'uint256', - }, - { - internalType: 'bytes', - name: 'a', - type: 'bytes', - }, - ], - name: 'setAddr', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'a', - type: 'address', - }, - ], - name: 'setAddr', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'operator', - type: 'address', - }, - { - internalType: 'bool', - name: 'approved', - type: 'bool', - }, - ], - name: 'setApprovalForAll', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes', - name: 'hash', - type: 'bytes', - }, - ], - name: 'setContenthash', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes', - name: 'data', - type: 'bytes', - }, - ], - name: 'setDNSRecords', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes4', - name: 'interfaceID', - type: 'bytes4', - }, - { - internalType: 'address', - name: 'implementer', - type: 'address', - }, - ], - name: 'setInterface', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'string', - name: 'newName', - type: 'string', - }, - ], - name: 'setName', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 'x', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 'y', - type: 'bytes32', - }, - ], - name: 'setPubkey', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'string', - name: 'key', - type: 'string', - }, - { - internalType: 'string', - name: 'value', - type: 'string', - }, - ], - name: 'setText', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'bytes', - name: 'hash', - type: 'bytes', - }, - ], - name: 'setZonehash', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, { inputs: [ { diff --git a/packages/web3-eth-ens/src/abi/reverse_registrar.ts b/packages/web3-eth-ens/src/abi/reverse_registrar.ts deleted file mode 100644 index 5fb125ccd32..00000000000 --- a/packages/web3-eth-ens/src/abi/reverse_registrar.ts +++ /dev/null @@ -1,173 +0,0 @@ -/* -This file is part of web3.js. - -web3.js is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -web3.js is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with web3.js. If not, see . -*/ - -// https://github.com/ensdomains/ens/blob/master/contracts/ReverseRegistrar.sol -const REVERSE_REGISTRAR = [ - { - inputs: [ - { - internalType: 'contract ENS', - name: 'ensAddr', - type: 'address', - }, - { - internalType: 'contract Resolver', - name: 'resolverAddr', - type: 'address', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'constructor', - }, - { - constant: true, - inputs: [], - name: 'ADDR_REVERSE_NODE', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: false, - inputs: [ - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - name: 'claim', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, - { - constant: false, - inputs: [ - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - internalType: 'address', - name: 'resolver', - type: 'address', - }, - ], - name: 'claimWithResolver', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, - { - constant: true, - inputs: [], - name: 'defaultResolver', - outputs: [ - { - internalType: 'contract Resolver', - name: '', - type: 'address', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: true, - inputs: [], - name: 'ens', - outputs: [ - { - internalType: 'contract ENS', - name: '', - type: 'address', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: true, - inputs: [ - { - internalType: 'address', - name: 'addr', - type: 'address', - }, - ], - name: 'node', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - payable: false, - stateMutability: 'pure', - type: 'function', - }, - { - constant: false, - inputs: [ - { - internalType: 'string', - name: 'name', - type: 'string', - }, - ], - name: 'setName', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, -] as const; - -export default REVERSE_REGISTRAR; diff --git a/packages/web3-eth-ens/src/abi/test_registrar.ts b/packages/web3-eth-ens/src/abi/test_registrar.ts deleted file mode 100644 index d47e8bb75bb..00000000000 --- a/packages/web3-eth-ens/src/abi/test_registrar.ts +++ /dev/null @@ -1,101 +0,0 @@ -/* -This file is part of web3.js. - -web3.js is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -web3.js is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with web3.js. If not, see . -*/ - -// https://github.com/ensdomains/ens/blob/master/contracts/TestRegistrar.sol -const TEST_REGISTRAR = [ - { - inputs: [ - { - internalType: 'contract ENS', - name: 'ensAddr', - type: 'address', - }, - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - ], - stateMutability: 'nonpayable', - type: 'constructor', - }, - { - inputs: [], - name: 'ens', - outputs: [ - { - internalType: 'contract ENS', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - name: 'expiryTimes', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'label', - type: 'bytes32', - }, - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - name: 'register', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [], - name: 'rootNode', - outputs: [ - { - internalType: 'bytes32', - name: '', - type: 'bytes32', - }, - ], - stateMutability: 'view', - type: 'function', - }, -] as const; - -export default TEST_REGISTRAR; diff --git a/packages/web3-eth-ens/src/ens.ts b/packages/web3-eth-ens/src/ens.ts index 624da1c530c..2b594735ba1 100644 --- a/packages/web3-eth-ens/src/ens.ts +++ b/packages/web3-eth-ens/src/ens.ts @@ -15,31 +15,21 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { isSyncing } from 'web3-eth'; -import { - RevertInstructionError, - ENSNetworkNotSyncedError, - ENSUnsupportedNetworkError, -} from 'web3-errors'; import { Web3Context, Web3ContextObject } from 'web3-core'; +import { ENSNetworkNotSyncedError, ENSUnsupportedNetworkError } from 'web3-errors'; +import { isSyncing } from 'web3-eth'; +import { Contract } from 'web3-eth-contract'; import { getId } from 'web3-net'; import { - Address, - SupportedProviders, - EthExecutionAPI, - TransactionReceipt, - Web3NetAPI, - NonPayableCallOptions, DEFAULT_RETURN_FORMAT, - FormatType, + EthExecutionAPI, FMT_NUMBER, - DataFormat, + SupportedProviders, + Web3NetAPI, } from 'web3-types'; -import { Contract } from 'web3-eth-contract'; - import { PublicResolverAbi } from './abi/ens/PublicResolver'; -import { Registry } from './registry'; import { networkIds, registryAddresses } from './config'; +import { Registry } from './registry'; import { Resolver } from './resolver'; /** @@ -101,103 +91,6 @@ export class ENS extends Web3Context { return this._registry.getResolver(name); } - /** - * set the resolver of the given name - * @param name - The name of the ENS domain - * @param address - The address of the resolver - * @param txConfig - The transaction config - * @param returnFormat - (Optional) The return format, defaults to {@link DEFAULT_RETURN_FORMAT} - * @returns The transaction receipt - * @example - * ```ts - * const receipt = await ens.setResolver('resolver', '0x1234567890123456789012345678901234567890', {from: '0x1234567890123456789012345678901234567890'}); - * ``` - */ - public async setResolver( - name: string, - address: Address, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ): Promise< - | FormatType - | FormatType - > { - return this._registry.setResolver(name, address, txConfig, returnFormat); - } - - /** - * Sets the owner, resolver and TTL for a subdomain, creating it if necessary. - * @param name - The ENS name - * @param label - The name of the sub-domain or sha3 hash of it - * @param owner - The owner of the name record - * @param resolver - The resolver address of the name record - * @param ttl - Time to live value - * @param txConfig - (Optional) The transaction config - * @param returnFormat - (Optional) The return format, defaults to {@link DEFAULT_RETURN_FORMAT} - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = await web3.eth.ens.setSubnodeRecord('ethereum.eth', 'web3', '0x1234567890123456789012345678901234567890','0xAA9133EeC3ae5f9440C1a1E61E2D2Cc571675527', 1000000); - * ``` - */ - public async setSubnodeRecord( - name: string, - label: string, - owner: Address, - resolver: Address, - ttl: number, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ): Promise { - return this._registry.setSubnodeRecord( - name, - label, - owner, - resolver, - ttl, - txConfig, - returnFormat, - ); - } - - /** - * Sets or clears an approval by the given operator. - * @param operator - The operator address - * @param approved - `true` to set the approval, `false` to clear it - * @param txConfig - (Optional) The transaction config - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = web3.eth.ens.setApprovalForAll('0x1234567890123456789012345678901234567890', true ) - * ``` - */ - public async setApprovalForAll( - operator: Address, - approved: boolean, - txConfig: NonPayableCallOptions, - ): Promise { - return this._registry.setApprovalForAll(operator, approved, txConfig); - } - - /** - * Returns true if the operator is approved to make ENS registry operations on behalf of the owner. - * @param owner - The owner address - * @param operator - The operator address - * @param returnFormat - (Optional) The return format, defaults to {@link DEFAULT_RETURN_FORMAT} - * @returns - `true` if the operator is approved, `false` otherwise - * @example - * ```ts - * const approved = await web3.eth.ens.isApprovedForAll('0x1234567890123456789012345678901234567890', '0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990'); - * ``` - */ - public async isApprovedForAll( - owner: Address, - operator: Address, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ): Promise { - return this._registry.isApprovedForAll(owner, operator, returnFormat); - } - /** * Returns true if the record exists * @param name - The ENS name @@ -212,60 +105,18 @@ export class ENS extends Web3Context { } /** - * Creates a new subdomain of the given node, assigning ownership of it to the specified owner. - * @param node - The ENS name - * @param label - The name of the sub-domain or the sha3 hash of it - * @param address - The registrar of this sub-domain - * @param txConfig - (Optional) The transaction config - * @param returnFormat - (Optional) The return format, defaults to {@link DEFAULT_RETURN_FORMAT} - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = await ens.setSubnodeOwner('ethereum.eth', 'web3', '0x1234567890123456789012345678901234567890', {from: '0x1234567890123456789012345678901234567890'}); - * ``` - */ - public async setSubnodeOwner( - node: string, - label: string, - address: Address, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ): Promise { - return this._registry.setSubnodeOwner(node, label, address, txConfig, returnFormat); - } - - /** - * Returns the address of the owner of an ENS name. + * Returns the caching TTL (time-to-live) of an ENS name. * @param name - The ENS name * @returns - Returns the caching TTL (time-to-live) of a name. * @example * ```ts - * const owner = await web3.eth.ens.getOwner('ethereum.eth'); + * const owner = await web3.eth.ens.getTTL('ethereum.eth'); * ``` */ public async getTTL(name: string): Promise { return this._registry.getTTL(name); } - /** - * Sets the TTL of a name. Emits a NewTTL event. - * @param name - THe ENS name - * @param ttl - The TTL value - * @param txConfig - (Optional) The transaction config - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = await web3.eth.ens.setTTL('ethereum.eth', 1000); - * ``` - */ - public async setTTL( - name: string, - ttl: number, - txConfig: NonPayableCallOptions, - ): Promise { - return this._registry.setTTL(name, ttl, txConfig); - } - /** * Returns the owner by the given name and current configured or detected Registry * @param name - The ENS name @@ -279,117 +130,6 @@ export class ENS extends Web3Context { return this._registry.getOwner(name); } - /** - * Sets the address of the owner of an ENS name. - * @param name - The ENS name - * @param address - The address of the new owner - * @param txConfig - (Optional) The transaction config - * @param returnFormat - (Optional) The return format, defaults to {@link DEFAULT_RETURN_FORMAT} - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = await ens.setOwner('ethereum.eth', , sendOptions); - * ``` - */ - public async setOwner( - name: string, - address: Address, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ): Promise { - return this._registry.setOwner(name, address, txConfig, returnFormat); - } - - /** - * Returns the address of the owner of an ENS name. - * @param name - The ENS name - * @param owner - The owner of the name record. - * @param resolver - The resolver of the name record. - * @param ttl - Time to live value - * @param txConfig - (Optional) The transaction config - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = await ens.setRecord( 'web3js.eth','0xe2597eb05cf9a87eb1309e86750c903ec38e527e', '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401', 1000); - * ``` - */ - public async setRecord( - name: string, - owner: Address, - resolver: Address, - ttl: number, - txConfig: NonPayableCallOptions, - ): Promise { - return this._registry.setRecord(name, owner, resolver, ttl, txConfig); - } - - /** - * Sets the address of an ENS name in his resolver. - * @param name - The ENS name - * @param address - The address to set - * @param txConfig - (Optional) The transaction config - * @param returnFormat - (Optional) The return format, defaults to {@link DEFAULT_RETURN_FORMAT} - * @returns - The transaction receipt - * ```ts - * const receipt = await ens.setAddress('web3js.eth','0xe2597eb05cf9a87eb1309e86750c903ec38e527e'); - *``` - */ - public async setAddress( - name: string, - address: Address, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ): Promise { - return this._resolver.setAddress(name, address, txConfig, returnFormat); - } - - /** - * Sets the SECP256k1 public key associated with an ENS node. (Emits a `PublicKeyChanged` event) - * @param name - The ENS name - * @param x - The X coordinate of the public key - * @param y - The Y coordinate of the public key - * @param txConfig - (Optional) The transaction config - * @returns - The transaction receipt - * ```ts - * const receipt = await web3.eth.ens.setPubkey( - * 'ethereum.eth', - * '0x0000000000000000000000000000000000000000000000000000000000000000', - * '0x0000000000000000000000000000000000000000000000000000000000000000', - * { from: '0x9CC9a2c777605Af16872E0997b3Aeb91d96D5D8c' }); - * ``` - */ - public async setPubkey( - name: string, - x: string, - y: string, - txConfig: NonPayableCallOptions, - ): Promise { - return this._resolver.setPubkey(name, x, y, txConfig); - } - - // todo do we support ipfs, onion, ... - /** - * Sets the content hash associated with an ENS node. Emits a `ContenthashChanged` event. - * @param name - The ENS name - * @param hash - The content hash to set - * @param txConfig - (Optional) The transaction config - * @returns - The transaction receipt - * @example - * ```ts - * const receipt = web3.eth.ens.setContenthash( - * 'ethereum.eth', - * 'ipfs://QmaEBknbGT4bTQiQoe2VNgBJbRfygQGktnaW5TbuKixjYL', - * ) - * ``` - */ - public async setContenthash( - name: string, - hash: string, - txConfig: NonPayableCallOptions, - ): Promise { - return this._resolver.setContenthash(name, hash, txConfig); - } - /** * Resolves an ENS name to an Ethereum address. * @param ENSName - The ENS name to resolve diff --git a/packages/web3-eth-ens/src/index.ts b/packages/web3-eth-ens/src/index.ts index 5e0acf13f7e..3726bef9d09 100644 --- a/packages/web3-eth-ens/src/index.ts +++ b/packages/web3-eth-ens/src/index.ts @@ -23,7 +23,7 @@ along with web3.js. If not, see . * - All the API level interfaces returning or accepting `null` in 1.x, use `undefined` in 4.x. * - Functions don't accept a callback anymore. * - Functions that accepted an optional `TransactionConfig` as the last argument, now accept an optional `NonPayableCallOptions`. See `web3-eth-contract` package for more details. - * + * - Removed all non-read methods. If you need modifing resolver or registry, please use https://www.npmjs.com/package/@ensdomains/ensjs */ /** * This comment _supports3_ [Markdown](https://marked.js.org/) diff --git a/packages/web3-eth-ens/src/registry.ts b/packages/web3-eth-ens/src/registry.ts index 342b6eee6f1..7145e01d5f4 100644 --- a/packages/web3-eth-ens/src/registry.ts +++ b/packages/web3-eth-ens/src/registry.ts @@ -15,11 +15,9 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { Contract } from 'web3-eth-contract'; -import { format, sha3Raw } from 'web3-utils'; -import { isHexStrict } from 'web3-validator'; -import { Address, DataFormat, DEFAULT_RETURN_FORMAT, NonPayableCallOptions } from 'web3-types'; import { Web3ContextObject } from 'web3-core'; +import { Contract } from 'web3-eth-contract'; +import { Address } from 'web3-types'; import { ENSRegistryAbi } from './abi/ens/ENSRegistry'; import { PublicResolverAbi } from './abi/ens/PublicResolver'; import { registryAddresses } from './config'; @@ -38,6 +36,7 @@ export class Registry { this.context = context; } + public async getOwner(name: string) { try { const result = this.contract.methods.owner(namehash(name)).call(); @@ -48,23 +47,6 @@ export class Registry { } } - public setOwner( - name: string, - address: Address, - txConfig: NonPayableCallOptions, // TODO: web3-eth txconfig should be replaced with sendTransaction type - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - try { - const receipt = this.contract.methods - .setOwner(namehash(name), format({ format: 'address' }, address, returnFormat)) - .send(txConfig); - - return receipt; - } catch (error) { - throw new Error(); // TODO: TransactionRevertInstructionError Needs to be added after web3-eth call method is implemented - } - } - public async getTTL(name: string) { try { return this.contract.methods.ttl(namehash(name)).call(); @@ -73,103 +55,6 @@ export class Registry { } } - public setTTL( - name: string, - ttl: number, - txConfig: NonPayableCallOptions, // TODO: web3-eth txconfig should be replaced with sendTransaction type - ) { - try { - const promiEvent = this.contract.methods.setTTL(namehash(name), ttl).send(txConfig); - - return promiEvent; - } catch (error) { - throw new Error(); // TODO: TransactionRevertInstructionError Needs to be added after web3-eth call method is implemented - } - } - - public setSubnodeOwner( - node: string, - label: string, - address: Address, - txConfig: NonPayableCallOptions, // TODO: web3-eth txconfig should be replaced with sendTransaction type - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - const hexStrictLabel = !isHexStrict(label) ? sha3Raw(label) : label; - try { - const receipt = this.contract.methods - .setSubnodeOwner( - namehash(node), - hexStrictLabel, - format({ format: 'address' }, address, returnFormat), - ) - .send(txConfig); - return receipt; - } catch (error) { - throw new Error(); // TODO: TransactionRevertInstructionError Needs to be added after web3-eth call method is implemented - } - } - - public setSubnodeRecord( - name: string, - label: string, - owner: Address, - resolver: Address, - ttl: number, - txConfig: NonPayableCallOptions, // TODO: web3-eth txconfig should be replaced with sendTransaction type - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - const hexStrictLabel = !isHexStrict(label) ? sha3Raw(label) : label; - try { - const receipt = this.contract.methods - .setSubnodeRecord( - namehash(name), - hexStrictLabel, - format({ format: 'address' }, owner, returnFormat), - format({ format: 'address' }, resolver, returnFormat), - ttl, - ) - .send(txConfig); - return receipt; - } catch (error) { - throw new Error(); // TODO: web3-eth txconfig should be replaced with sendTransaction type - } - } - - public setApprovalForAll( - operator: string, - approved: boolean, - txConfig: NonPayableCallOptions, // TODO: web3-eth txconfig should be replaced with sendTransaction type - ) { - try { - const receipt = this.contract.methods - .setApprovalForAll(operator, approved) - .send(txConfig); - - return receipt; - } catch (error) { - throw new Error(); // TODO: web3-eth txconfig should be replaced with sendTransaction type - } - } - - public async isApprovedForAll( - owner: Address, - operator: Address, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - try { - const result = this.contract.methods - .isApprovedForAll( - format({ format: 'address' }, owner, returnFormat), - format({ format: 'address' }, operator, returnFormat), - ) - .call(); - - return result; - } catch (error) { - throw new Error(); // TODO: TransactionRevertInstructionError Needs to be added after web3-eth call method is implemented - } - } - public async recordExists(name: string) { try { const promise = this.contract.methods.recordExists(namehash(name)).call(); @@ -199,42 +84,6 @@ export class Registry { } } - public setResolver( - name: string, - address: Address, - txConfig: NonPayableCallOptions, // TODO: web3-eth txconfig should be replaced with sendTransaction type - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - try { - return this.contract.methods - .setResolver(namehash(name), format({ format: 'address' }, address, returnFormat)) - .send(txConfig); - } catch (error) { - throw new Error(); // TODO: TransactionRevertInstructionError Needs to be added after web3-eth call method is implemented - } - } - - public setRecord( - name: string, - owner: Address, - resolver: Address, - ttl: number, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - try { - return this.contract.methods - .setRecord( - namehash(name), - format({ format: 'address' }, owner, returnFormat), - format({ format: 'address' }, resolver, returnFormat), - ttl, - ) - .send(txConfig); - } catch (error) { - throw new Error(); // TODO: TransactionRevertInstructionError Needs to be added after web3-eth call method is implemented - } - } public get events() { return this.contract.events; } diff --git a/packages/web3-eth-ens/src/resolver.ts b/packages/web3-eth-ens/src/resolver.ts index ca9cf9c9f1c..a0463cfc16c 100644 --- a/packages/web3-eth-ens/src/resolver.ts +++ b/packages/web3-eth-ens/src/resolver.ts @@ -15,14 +15,13 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { sha3, isNullish, format } from 'web3-utils'; -import { Contract } from 'web3-eth-contract'; import { ResolverMethodMissingError } from 'web3-errors'; +import { Contract } from 'web3-eth-contract'; +import { isNullish, sha3 } from 'web3-utils'; import { isHexStrict } from 'web3-validator'; -import { Address, DataFormat, DEFAULT_RETURN_FORMAT, NonPayableCallOptions } from 'web3-types'; +import { PublicResolverAbi } from './abi/ens/PublicResolver'; import { interfaceIds, methodsInInterface } from './config'; import { Registry } from './registry'; -import { PublicResolverAbi } from './abi/ens/PublicResolver'; import { namehash } from './utils'; // Default public resolver @@ -63,37 +62,6 @@ export class Resolver { ); } - public async setAddress( - ENSName: string, - address: Address, - txConfig: NonPayableCallOptions, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, - ) { - const resolverContract = await this.getResolverContractAdapter(ENSName); - await this.checkInterfaceSupport(resolverContract, methodsInInterface.setAddr); - - return resolverContract.methods - .setAddr(namehash(ENSName), format({ format: 'address' }, address, returnFormat)) - .send(txConfig); - } - - public async setPubkey(ENSName: string, x: string, y: string, txConfig: NonPayableCallOptions) { - const resolverContract = await this.getResolverContractAdapter(ENSName); - await this.checkInterfaceSupport(resolverContract, methodsInInterface.setPubkey); - - // TODO: verify that X and Y coordinates of pub key are normalized? - return resolverContract.methods - .setPubkey(namehash(ENSName), namehash(x), namehash(y)) - .send(txConfig); - } - - public async setContenthash(ENSName: string, hash: string, txConfig: NonPayableCallOptions) { - const resolverContract = await this.getResolverContractAdapter(ENSName); - await this.checkInterfaceSupport(resolverContract, methodsInInterface.setContenthash); - - return resolverContract.methods.setContenthash(namehash(ENSName), hash).send(txConfig); - } - public async supportsInterface(ENSName: string, interfaceId: string) { const resolverContract = await this.getResolverContractAdapter(ENSName); diff --git a/packages/web3-eth-ens/test/fixtures/ens/abi/ENSRegistry.ts b/packages/web3-eth-ens/test/fixtures/ens/abi/ENSRegistry.ts new file mode 100644 index 00000000000..99730866873 --- /dev/null +++ b/packages/web3-eth-ens/test/fixtures/ens/abi/ENSRegistry.ts @@ -0,0 +1,394 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +// https://github.com/ensdomains/ens-contracts/blob/master/contracts/registry/ENSRegistry.sol +export const ENSRegistryAbi = [ + { + inputs: [], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'ApprovalForAll', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'bytes32', + name: 'label', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'NewOwner', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'address', + name: 'resolver', + type: 'address', + }, + ], + name: 'NewResolver', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint64', + name: 'ttl', + type: 'uint64', + }, + ], + name: 'NewTTL', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + ], + name: 'isApprovedForAll', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'recordExists', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'resolver', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'setApprovalForAll', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'setOwner', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'resolver', + type: 'address', + }, + { + internalType: 'uint64', + name: 'ttl', + type: 'uint64', + }, + ], + name: 'setRecord', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'resolver', + type: 'address', + }, + ], + name: 'setResolver', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'label', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'setSubnodeOwner', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'label', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'resolver', + type: 'address', + }, + { + internalType: 'uint64', + name: 'ttl', + type: 'uint64', + }, + ], + name: 'setSubnodeRecord', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'ttl', + type: 'uint64', + }, + ], + name: 'setTTL', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'ttl', + outputs: [ + { + internalType: 'uint64', + name: '', + type: 'uint64', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; diff --git a/packages/web3-eth-ens/test/fixtures/ens/abi/PublicResolver.ts b/packages/web3-eth-ens/test/fixtures/ens/abi/PublicResolver.ts new file mode 100644 index 00000000000..b666d4f4d67 --- /dev/null +++ b/packages/web3-eth-ens/test/fixtures/ens/abi/PublicResolver.ts @@ -0,0 +1,893 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +// https://github.com/ensdomains/ens-contracts/blob/master/contracts/resolvers/PublicResolver.sol +export const PublicResolverAbi = [ + { + inputs: [ + { + internalType: 'contract ENS', + name: '_ens', + type: 'address', + }, + { + internalType: 'contract INameWrapper', + name: 'wrapperAddress', + type: 'address', + }, + { + internalType: 'address', + name: '_trustedETHController', + type: 'address', + }, + { + internalType: 'address', + name: '_trustedReverseRegistrar', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'uint256', + name: 'contentType', + type: 'uint256', + }, + ], + name: 'ABIChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'address', + name: 'a', + type: 'address', + }, + ], + name: 'AddrChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint256', + name: 'coinType', + type: 'uint256', + }, + { + indexed: false, + internalType: 'bytes', + name: 'newAddress', + type: 'bytes', + }, + ], + name: 'AddressChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'ApprovalForAll', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes', + name: 'hash', + type: 'bytes', + }, + ], + name: 'ContenthashChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes', + name: 'name', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint16', + name: 'resource', + type: 'uint16', + }, + { + indexed: false, + internalType: 'bytes', + name: 'record', + type: 'bytes', + }, + ], + name: 'DNSRecordChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes', + name: 'name', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint16', + name: 'resource', + type: 'uint16', + }, + ], + name: 'DNSRecordDeleted', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'DNSZoneCleared', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes', + name: 'lastzonehash', + type: 'bytes', + }, + { + indexed: false, + internalType: 'bytes', + name: 'zonehash', + type: 'bytes', + }, + ], + name: 'DNSZonehashChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'bytes4', + name: 'interfaceID', + type: 'bytes4', + }, + { + indexed: false, + internalType: 'address', + name: 'implementer', + type: 'address', + }, + ], + name: 'InterfaceChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'string', + name: 'name', + type: 'string', + }, + ], + name: 'NameChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes32', + name: 'x', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes32', + name: 'y', + type: 'bytes32', + }, + ], + name: 'PubkeyChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'string', + name: 'indexedKey', + type: 'string', + }, + { + indexed: false, + internalType: 'string', + name: 'key', + type: 'string', + }, + ], + name: 'TextChanged', + type: 'event', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'contentTypes', + type: 'uint256', + }, + ], + name: 'ABI', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + { + internalType: 'bytes', + name: '', + type: 'bytes', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'addr', + outputs: [ + { + internalType: 'address payable', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'coinType', + type: 'uint256', + }, + ], + name: 'addr', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'clearDNSZone', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'contenthash', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'name', + type: 'bytes32', + }, + { + internalType: 'uint16', + name: 'resource', + type: 'uint16', + }, + ], + name: 'dnsRecord', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'name', + type: 'bytes32', + }, + ], + name: 'hasDNSRecords', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes4', + name: 'interfaceID', + type: 'bytes4', + }, + ], + name: 'interfaceImplementer', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + ], + name: 'isApprovedForAll', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes[]', + name: 'data', + type: 'bytes[]', + }, + ], + name: 'multicall', + outputs: [ + { + internalType: 'bytes[]', + name: 'results', + type: 'bytes[]', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'pubkey', + outputs: [ + { + internalType: 'bytes32', + name: 'x', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'y', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'contentType', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes', + }, + ], + name: 'setABI', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'coinType', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'a', + type: 'bytes', + }, + ], + name: 'setAddr', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'a', + type: 'address', + }, + ], + name: 'setAddr', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'setApprovalForAll', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes', + name: 'hash', + type: 'bytes', + }, + ], + name: 'setContenthash', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes', + }, + ], + name: 'setDNSRecords', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes4', + name: 'interfaceID', + type: 'bytes4', + }, + { + internalType: 'address', + name: 'implementer', + type: 'address', + }, + ], + name: 'setInterface', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'string', + name: 'newName', + type: 'string', + }, + ], + name: 'setName', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'x', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 'y', + type: 'bytes32', + }, + ], + name: 'setPubkey', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'string', + name: 'key', + type: 'string', + }, + { + internalType: 'string', + name: 'value', + type: 'string', + }, + ], + name: 'setText', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'bytes', + name: 'hash', + type: 'bytes', + }, + ], + name: 'setZonehash', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceID', + type: 'bytes4', + }, + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'string', + name: 'key', + type: 'string', + }, + ], + name: 'text', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + ], + name: 'zonehash', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; diff --git a/packages/web3-eth-ens/test/integration/ens.events.test.ts b/packages/web3-eth-ens/test/integration/ens.events.test.ts index e9dae6f2de8..eb7c7752b28 100644 --- a/packages/web3-eth-ens/test/integration/ens.events.test.ts +++ b/packages/web3-eth-ens/test/integration/ens.events.test.ts @@ -37,11 +37,11 @@ import { getSystemTestProviderUrl, } from '../fixtures/system_tests_utils'; -import { ENSRegistryAbi } from '../../src/abi/ens/ENSRegistry'; +import { ENSRegistryAbi } from '../fixtures/ens/abi/ENSRegistry'; import { ENSRegistryBytecode } from '../fixtures/ens/bytecode/ENSRegistryBytecode'; import { NameWrapperAbi } from '../fixtures/ens/abi/NameWrapper'; import { NameWrapperBytecode } from '../fixtures/ens/bytecode/NameWrapperBytecode'; -import { PublicResolverAbi } from '../../src/abi/ens/PublicResolver'; +import { PublicResolverAbi } from '../fixtures/ens/abi/PublicResolver'; import { PublicResolverBytecode } from '../fixtures/ens/bytecode/PublicResolverBytecode'; describeIf(isSocket)('ens events', () => { @@ -163,7 +163,7 @@ describeIf(isSocket)('ens events', () => { resolve(); }); - await ens.setApprovalForAll(accountOne, true, sendOptions); + await registry.methods.setApprovalForAll(accountOne, true).send(sendOptions); }); }); @@ -181,7 +181,7 @@ describeIf(isSocket)('ens events', () => { resolve(); }); - await ens.setTTL(web3jsName, ttl, sendOptions); + await registry.methods.setTTL(web3jsName, ttl).send(sendOptions); }); }); @@ -196,12 +196,9 @@ describeIf(isSocket)('ens events', () => { resolve(); }); - await ens.setResolver( - domain, - resolver.options.address as string, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); + await registry.methods + .setResolver(domain, resolver.options.address as string) + .send(sendOptions); }); }); }); diff --git a/packages/web3-eth-ens/test/integration/ens.test.ts b/packages/web3-eth-ens/test/integration/ens.test.ts index 408b794e106..2229abc4eec 100644 --- a/packages/web3-eth-ens/test/integration/ens.test.ts +++ b/packages/web3-eth-ens/test/integration/ens.test.ts @@ -18,8 +18,8 @@ along with web3.js. If not, see . /* eslint-disable @typescript-eslint/no-unused-vars */ import { getBlock } from 'web3-eth'; import { Contract, PayableTxOptions } from 'web3-eth-contract'; +import { Address, Bytes, DEFAULT_RETURN_FORMAT } from 'web3-types'; import { sha3, toChecksumAddress } from 'web3-utils'; -import { Address, Bytes, TransactionReceipt, DEFAULT_RETURN_FORMAT } from 'web3-types'; // eslint-disable-next-line import/no-extraneous-dependencies import IpcProvider from 'web3-providers-ipc'; import { ENS } from '../../src'; @@ -35,9 +35,10 @@ import { isWs, } from '../fixtures/system_tests_utils'; -import { ENSRegistryAbi } from '../../src/abi/ens/ENSRegistry'; -import { PublicResolverAbi } from '../../src/abi/ens/PublicResolver'; +import { PublicResolverAbi as PublicResolver } from '../../src/abi/ens/PublicResolver'; +import { ENSRegistryAbi } from '../fixtures/ens/abi/ENSRegistry'; import { NameWrapperAbi } from '../fixtures/ens/abi/NameWrapper'; +import { PublicResolverAbi } from '../fixtures/ens/abi/PublicResolver'; import { ENSRegistryBytecode } from '../fixtures/ens/bytecode/ENSRegistryBytecode'; import { NameWrapperBytecode } from '../fixtures/ens/bytecode/NameWrapperBytecode'; import { PublicResolverBytecode } from '../fixtures/ens/bytecode/PublicResolverBytecode'; @@ -50,8 +51,7 @@ describe('ens', () => { type ResolverContract = Contract; let Resolver: ResolverContract; - let setEnsResolver: ResolverContract; - let getEnsResolver: ResolverContract; + let getEnsResolver: Contract; let sendOptions: PayableTxOptions; @@ -140,7 +140,6 @@ describe('ens', () => { // @ts-expect-error @typescript-eslint/ban-ts-comment await closeOpenConnection(ens?._registry?.contract); await closeOpenConnection(getEnsResolver); - await closeOpenConnection(setEnsResolver); await closeOpenConnection(registry); await closeOpenConnection(resolver); await closeOpenConnection(nameWrapper); @@ -154,17 +153,6 @@ describe('ens', () => { .send(sendOptions); }); - it('should set approval for all', async () => { - await expect(ens.setApprovalForAll(accountOne, true, sendOptions)).resolves.toBeDefined(); - }); - - it('should check approval for all', async () => { - await expect(ens.setApprovalForAll(accountOne, true, sendOptions)).resolves.toBeDefined(); - - const isApproved = await ens.isApprovedForAll(defaultAccount, accountOne); - - expect(isApproved).toBeTruthy(); - }); it('should return the subnode owner of "resolver"', async () => { const owner = await ens.getOwner('resolver'); @@ -177,36 +165,6 @@ describe('ens', () => { expect(getEnsResolver.options.address).toEqual(resolver.options.address); }); - it('should set resolver', async () => { - const newResolver = await Resolver.deploy({ - data: PublicResolverBytecode, - arguments: [ - registry.options.address as string, - nameWrapper.options.address as string, - accountOne, - defaultAccount, - ], - }).send(sendOptions); - - await ens.setResolver('resolver', newResolver.options.address as string, sendOptions); - - setEnsResolver = await ens.getResolver('resolver'); - - expect(setEnsResolver.options.address).toEqual(newResolver.options.address); - }); - - it('should set the owner record for a name', async () => { - const receipt = await ens.setOwner(web3jsName, accountOne, sendOptions); - - expect(receipt).toEqual( - expect.objectContaining({ - transactionHash: expect.any(String), - }), - ); - - expect((receipt as TransactionReceipt).status).toEqual(BigInt(1)); - }); - it('should get the owner record for a name', async () => { const web3jsOwner = await ens.getOwner(web3jsName); @@ -219,40 +177,6 @@ describe('ens', () => { expect(TTL).toBe(BigInt(0)); }); - it('should set TTL', async () => { - await ens.setTTL(web3jsName, ttl, sendOptions); - - const ttlResult = await ens.getTTL(web3jsName); - - expect(ttlResult).toBe(BigInt(ttl)); - }); - - it('should set subnode owner', async () => { - await ens.setSubnodeOwner(domain, subdomain, accountOne, sendOptions); - - const owner = await ens.getOwner(fullDomain); - - expect(owner).toBe(toChecksumAddress(accountOne)); - }); - - it('should set subnode record', async () => { - await ens.setSubnodeRecord( - domain, - subdomain, - accountOne, - resolver.options.address as string, - ttl, - sendOptions, - ); - - const ttlResult = await ens.getTTL(fullDomain); - - const owner = await ens.getOwner(fullDomain); - - expect(ttlResult).toBe(BigInt(ttl)); - expect(owner).toBe(toChecksumAddress(accountOne)); - }); - it('shoud record exists', async () => { await registry.methods .setSubnodeOwner(namehash(domain), sha3(subdomain) as string, defaultAccount) @@ -262,20 +186,4 @@ describe('ens', () => { expect(exists).toBeTruthy(); }); - it('shoud set record', async () => { - await registry.methods - .setSubnodeOwner(namehash(domain), sha3(subdomain) as string, defaultAccount) - .send(sendOptions); - - await ens.setRecord( - domain, - accountOne, - resolver.options.address as string, - ttl, - sendOptions, - ); - - const owner = await ens.getOwner(domain); - expect(owner).toBe(toChecksumAddress(accountOne)); - }); }); diff --git a/packages/web3-eth-ens/test/integration/resolver.test.ts b/packages/web3-eth-ens/test/integration/resolver.test.ts index 10e58b5e5b5..4d295a3f450 100644 --- a/packages/web3-eth-ens/test/integration/resolver.test.ts +++ b/packages/web3-eth-ens/test/integration/resolver.test.ts @@ -37,8 +37,8 @@ import { itIf, } from '../fixtures/system_tests_utils'; -import { ENSRegistryAbi } from '../../src/abi/ens/ENSRegistry'; -import { PublicResolverAbi } from '../../src/abi/ens/PublicResolver'; +import { ENSRegistryAbi } from '../fixtures/ens/abi/ENSRegistry'; +import { PublicResolverAbi } from '../fixtures/ens/abi/PublicResolver'; import { NameWrapperAbi } from '../fixtures/ens/abi/NameWrapper'; import { ENSRegistryBytecode } from '../fixtures/ens/bytecode/ENSRegistryBytecode'; import { NameWrapperBytecode } from '../fixtures/ens/bytecode/NameWrapperBytecode'; @@ -169,12 +169,9 @@ describe('ens', () => { }); it('fetch pubkey', async () => { - await ens.setResolver( - domain, - resolver.options.address as string, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); + await registry.methods + .setResolver(domain, resolver.options.address as string) + .send(sendOptions); const res = await ens.getPubkey(domain); @@ -186,7 +183,7 @@ describe('ens', () => { const x = '0x1000000000000000000000000000000000000000000000000000000000000000'; const y = '0x2000000000000000000000000000000000000000000000000000000000000000'; - await ens.setPubkey(domain, x, y, sendOptions); + await resolver.methods.setPubkey(domain, x, y).send(sendOptions); const result = await ens.getPubkey(domain); @@ -195,7 +192,7 @@ describe('ens', () => { }); it('sets contenthash', async () => { - await ens.setContenthash(domain, contentHash, sendOptions); + await resolver.methods.setContenthash(domain, contentHash).send(sendOptions); const res = await resolver.methods.contenthash(domainNode).call(sendOptions); expect(res).toBe(contentHash); @@ -211,7 +208,7 @@ describe('ens', () => { event.on('data', () => { resolve(); }); - await ens.setContenthash(domain, contentHash, sendOptions); + await resolver.methods.setContenthash(domain, contentHash).send(sendOptions); }); }); @@ -227,7 +224,7 @@ describe('ens', () => { .setResolver(domainNode, resolver.options.address as string) .send(sendOptions); - await ens.setAddress(domain, accounts[1], sendOptions, DEFAULT_RETURN_FORMAT); + await resolver.methods.setAddr(domain, accounts[1]).send(sendOptions); const res = await resolver.methods.addr(domainNode, DEFAULT_COIN_TYPE).call(sendOptions); expect(res).toBe(accounts[1]); diff --git a/packages/web3-eth-ens/test/unit/abi.test.ts b/packages/web3-eth-ens/test/unit/abi.test.ts deleted file mode 100644 index c3b3f4e3c24..00000000000 --- a/packages/web3-eth-ens/test/unit/abi.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* -This file is part of web3.js. - -web3.js is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -web3.js is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with web3.js. If not, see . -*/ - -import { ENSRegistryAbi as Registry } from '../../src/abi/ens/ENSRegistry'; -import ReverseRegistrar from '../../src/abi/reverse_registrar'; -import * as ENSRegistry from '../fixtures/ens/ENSRegistry.json'; -import * as ENSReverseRegistrar from '../fixtures/ens/reverse_registrar.json'; - -describe('ABI', () => { - describe('Registry', () => { - it('should have valid ABI', () => { - expect(ENSRegistry.abi).toEqual(Registry); - }); - }); - - describe('ReverseRegistrar', () => { - it('should have valid ABI', () => { - expect(JSON.parse(ENSReverseRegistrar.result)).toEqual(ReverseRegistrar); - }); - }); -}); diff --git a/packages/web3-eth-ens/test/unit/constructor.test.ts b/packages/web3-eth-ens/test/unit/constructor.test.ts index f3d06e4ebe6..8bb4ec2230d 100644 --- a/packages/web3-eth-ens/test/unit/constructor.test.ts +++ b/packages/web3-eth-ens/test/unit/constructor.test.ts @@ -34,14 +34,7 @@ describe('ens', () => { expect(registry.getOwner).toBeDefined(); expect(registry.getResolver).toBeDefined(); expect(registry.getTTL).toBeDefined(); - expect(registry.isApprovedForAll).toBeDefined(); expect(registry.recordExists).toBeDefined(); - expect(registry.setApprovalForAll).toBeDefined(); - expect(registry.setOwner).toBeDefined(); - expect(registry.setResolver).toBeDefined(); - expect(registry.setSubnodeOwner).toBeDefined(); - expect(registry.setSubnodeRecord).toBeDefined(); - expect(registry.setTTL).toBeDefined(); }); it('should construct resolver with expected methods', () => { @@ -50,9 +43,6 @@ describe('ens', () => { expect(resolver.getAddress).toBeDefined(); expect(resolver.checkInterfaceSupport).toBeDefined(); - expect(resolver.setAddress).toBeDefined(); - expect(resolver.setPubkey).toBeDefined(); - expect(resolver.setContenthash).toBeDefined(); expect(resolver.supportsInterface).toBeDefined(); expect(resolver.getPubkey).toBeDefined(); expect(resolver.getContenthash).toBeDefined(); @@ -62,19 +52,9 @@ describe('ens', () => { const ens = new ENS(registryAddresses.main, 'http://127.0.0.1:8545'); expect(ens.getResolver).toBeDefined(); - expect(ens.setResolver).toBeDefined(); - expect(ens.setSubnodeOwner).toBeDefined(); - expect(ens.setApprovalForAll).toBeDefined(); - expect(ens.isApprovedForAll).toBeDefined(); expect(ens.recordExists).toBeDefined(); - expect(ens.setSubnodeOwner).toBeDefined(); expect(ens.getTTL).toBeDefined(); expect(ens.getOwner).toBeDefined(); - expect(ens.setOwner).toBeDefined(); - expect(ens.setRecord).toBeDefined(); - expect(ens.setAddress).toBeDefined(); - expect(ens.setPubkey).toBeDefined(); - expect(ens.setContenthash).toBeDefined(); expect(ens.getAddress).toBeDefined(); expect(ens.getPubkey).toBeDefined(); expect(ens.getContenthash).toBeDefined(); diff --git a/packages/web3-eth-ens/test/unit/ens.test.ts b/packages/web3-eth-ens/test/unit/ens.test.ts index 90a3a0caa8a..2e15c3b8a31 100644 --- a/packages/web3-eth-ens/test/unit/ens.test.ts +++ b/packages/web3-eth-ens/test/unit/ens.test.ts @@ -16,12 +16,10 @@ along with web3.js. If not, see . */ import { Web3Context, Web3ContextObject, Web3PromiEvent } from 'web3-core'; -import { Contract } from 'web3-eth-contract'; import { ENSNetworkNotSyncedError, ENSUnsupportedNetworkError } from 'web3-errors'; -import { sha3Raw } from 'web3-utils'; -import { DEFAULT_RETURN_FORMAT } from 'web3-types'; -import { registryAddresses } from '../../src/config'; +import { Contract } from 'web3-eth-contract'; import { PublicResolverAbi } from '../../src/abi/ens/PublicResolver'; +import { registryAddresses } from '../../src/config'; import { ENS } from '../../src/ens'; @@ -43,13 +41,10 @@ jest.mock('web3-net', () => ({ const { getId } = require('web3-net'); describe('ens', () => { - const TTL = 3600; let object: Web3ContextObject; let resolverContract: Contract; const mockAddress = '0x0000000000000000000000000000000000000000'; const ENS_NAME = 'web3js.eth'; - const x = '0x1000000000000000000000000000000000000000000000000000000000000000'; - const y = '0x2000000000000000000000000000000000000000000000000000000000000000'; let ens: ENS; beforeAll(() => { @@ -61,25 +56,6 @@ describe('ens', () => { }); describe('Resolver', () => { - it('setResolver', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setResolverMock = jest.spyOn(ens['_registry'], 'setResolver').mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setResolver(ENS_NAME, mockAddress, sendOptions); - - expect(setResolverMock).toHaveBeenCalledWith( - ENS_NAME, - mockAddress, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); - }); - it('getResolver', async () => { const getResolverMock = jest .spyOn(ens['_registry'], 'getResolver') @@ -91,118 +67,7 @@ describe('ens', () => { }); }); - describe('Subnode', () => { - it('setSubnodeRecord', async () => { - const label = sha3Raw(ENS_NAME); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setSubnodeRecordMock = jest - .spyOn(ens['_registry'], 'setSubnodeRecord') - .mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setSubnodeRecord(ENS_NAME, label, mockAddress, mockAddress, TTL, sendOptions); - - expect(setSubnodeRecordMock).toHaveBeenCalledWith( - ENS_NAME, - label, - mockAddress, - mockAddress, - TTL, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); - }); - it('setSubnodeOwner', async () => { - const label = sha3Raw(ENS_NAME); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setSubnodeOwnerMock = jest - .spyOn(ens['_registry'], 'setSubnodeOwner') - .mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setSubnodeOwner( - ENS_NAME, - label, - mockAddress, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); - - expect(setSubnodeOwnerMock).toHaveBeenCalledWith( - ENS_NAME, - label, - mockAddress, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); - }); - }); - - describe('ApprovalForAll', () => { - it('setApprovalForAll', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setApprovalForAllMock = jest - .spyOn(ens['_registry'], 'setApprovalForAll') - .mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setApprovalForAll(ENS_NAME, true, sendOptions); - expect(setApprovalForAllMock).toHaveBeenCalledWith(ENS_NAME, true, sendOptions); - }); - - it('isApprovedForAll', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const isApprovedForAllMock = jest - .spyOn(ens['_registry'], 'isApprovedForAll') - .mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - await ens.isApprovedForAll(mockAddress, mockAddress, DEFAULT_RETURN_FORMAT); - - expect(isApprovedForAllMock).toHaveBeenCalledWith( - mockAddress, - mockAddress, - DEFAULT_RETURN_FORMAT, - ); - }); - }); - describe('Record', () => { - it('setRecord', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setRecordMock = jest.spyOn(ens['_registry'], 'setRecord').mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setRecord(ENS_NAME, mockAddress, mockAddress, TTL, sendOptions); - expect(setRecordMock).toHaveBeenCalledWith( - ENS_NAME, - mockAddress, - mockAddress, - TTL, - sendOptions, - ); - }); - it('recordExists', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -217,19 +82,6 @@ describe('ens', () => { }); describe('ttl', () => { - it('setTTL', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setTTLMock = jest.spyOn(ens['_registry'], 'setTTL').mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setTTL(ENS_NAME, TTL, sendOptions); - expect(setTTLMock).toHaveBeenCalledWith(ENS_NAME, TTL, sendOptions); - }); - it('getTTL', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -244,24 +96,6 @@ describe('ens', () => { }); describe('owner', () => { - it('setOwner', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setOwnerMock = jest.spyOn(ens['_registry'], 'setOwner').mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setOwner(ENS_NAME, mockAddress, sendOptions); - expect(setOwnerMock).toHaveBeenCalledWith( - ENS_NAME, - mockAddress, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); - }); - it('getOwner', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -276,24 +110,6 @@ describe('ens', () => { }); describe('addr', () => { - it('setAddr valid', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setAddressMock = jest.spyOn(ens['_resolver'], 'setAddress').mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setAddress(ENS_NAME, mockAddress, sendOptions); - expect(setAddressMock).toHaveBeenCalledWith( - ENS_NAME, - mockAddress, - sendOptions, - DEFAULT_RETURN_FORMAT, - ); - }); - it('getAddress', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -308,20 +124,6 @@ describe('ens', () => { }); }); describe('pubkey', () => { - it('setPubkey', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setPubKeyMock = jest.spyOn(ens['_resolver'], 'setPubkey').mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await expect(ens.setPubkey(ENS_NAME, x, y, sendOptions)).resolves.not.toThrow(); - - expect(setPubKeyMock).toHaveBeenCalledWith(ENS_NAME, x, y, sendOptions); - }); - it('getPubkey', async () => { const pubkeyMock = jest.spyOn(ens['_resolver'], 'getPubkey').mockReturnValue({ call: jest.fn(), @@ -332,23 +134,6 @@ describe('ens', () => { }); describe('Contenthash', () => { - it('setContenthash', async () => { - const hash = sha3Raw('justToHash'); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setContenthashMock = jest - .spyOn(ens['_resolver'], 'setContenthash') - .mockReturnValue({ - send, - } as unknown as Web3PromiEvent); - - const sendOptions = { from: mockAddress }; - await ens.setContenthash(ENS_NAME, hash, sendOptions); - expect(setContenthashMock).toHaveBeenCalledWith(ENS_NAME, hash, sendOptions); - }); - it('getContenthash', async () => { const contenthashMock = jest .spyOn(ens['_resolver'], 'getContenthash') diff --git a/packages/web3-eth-ens/test/unit/registry.test.ts b/packages/web3-eth-ens/test/unit/registry.test.ts index f0cdec2448f..d0b4f1ce751 100644 --- a/packages/web3-eth-ens/test/unit/registry.test.ts +++ b/packages/web3-eth-ens/test/unit/registry.test.ts @@ -17,7 +17,6 @@ along with web3.js. If not, see . import { Web3Context, Web3ContextObject } from 'web3-core'; import { NonPayableMethodObject } from 'web3-eth-contract'; -import { sha3Raw } from 'web3-utils'; import { Registry } from '../../src/registry'; import { namehash } from '../../src/utils'; @@ -45,41 +44,6 @@ describe('registry', () => { }); describe('owner', () => { - it('setOwner', async () => { - // const checkInteraface = jest.spyOn(resolver, 'checkInterfaceSupport'); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setOwnerMock = jest - .spyOn(registry['contract'].methods, 'setOwner') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setOwner(ENS_NAME, mockAddress, sendOptions); - expect(setOwnerMock).toHaveBeenCalledWith(namehash(ENS_NAME), mockAddress); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - - it('setOwner throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setOwnerMock = jest - .spyOn(registry['contract'].methods, 'setOwner') - .mockReturnValue({ send } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await expect(async () => { - await registry.setOwner(ENS_NAME, mockAddress, sendOptions); - }).rejects.toThrow(new Error()); - expect(setOwnerMock).toHaveBeenCalledWith(namehash(ENS_NAME), mockAddress); - expect(send).toHaveBeenCalledWith(sendOptions); - }); it('getOwner', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -111,40 +75,6 @@ describe('registry', () => { }); describe('ttl', () => { - const TTL = 3600; - it('setTTL', async () => { - // const checkInteraface = jest.spyOn(resolver, 'checkInterfaceSupport'); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setTTLMock = jest.spyOn(registry['contract'].methods, 'setTTL').mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setTTL(ENS_NAME, TTL, sendOptions); - expect(setTTLMock).toHaveBeenCalledWith(namehash(ENS_NAME), TTL); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - - it('setTTL throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setTTLMock = jest - .spyOn(registry['contract'].methods, 'setTTL') - .mockReturnValue({ send } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await expect(async () => { - await registry.setTTL(ENS_NAME, TTL, sendOptions); - }).rejects.toThrow(new Error()); - expect(setTTLMock).toHaveBeenCalledWith(namehash(ENS_NAME), TTL); - expect(send).toHaveBeenCalledWith(sendOptions); - }); it('getTTL', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -174,287 +104,8 @@ describe('registry', () => { expect(call).toHaveBeenCalled(); }); }); - describe('SubnodeOwner', () => { - const label = sha3Raw(ENS_NAME); - - it('setSubnodeOwner', async () => { - // const checkInteraface = jest.spyOn(resolver, 'checkInterfaceSupport'); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setSubnodeOwnerMock = jest - .spyOn(registry['contract'].methods, 'setSubnodeOwner') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setSubnodeOwner(ENS_NAME, label, mockAddress, sendOptions); - expect(setSubnodeOwnerMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - label, - mockAddress, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('setSubnodeOwner with non strict hex label', async () => { - // const checkInteraface = jest.spyOn(resolver, 'checkInterfaceSupport'); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setSubnodeOwnerMock = jest - .spyOn(registry['contract'].methods, 'setSubnodeOwner') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setSubnodeOwner(ENS_NAME, ENS_NAME, mockAddress, sendOptions); - expect(setSubnodeOwnerMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - label, - mockAddress, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - - it('setSubnodeOwner throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setSubnodeOwnerMock = jest - .spyOn(registry['contract'].methods, 'setSubnodeOwner') - .mockReturnValue({ send } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await expect(async () => { - await registry.setSubnodeOwner(ENS_NAME, label, mockAddress, sendOptions); - }).rejects.toThrow(new Error()); - expect(setSubnodeOwnerMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - label, - mockAddress, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - }); - - describe('SubnodeRecord', () => { - const label = sha3Raw(ENS_NAME); - const TTL = 3600; - - it('setSubnodeRecord', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setSubnodeRecordMock = jest - .spyOn(registry['contract'].methods, 'setSubnodeRecord') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setSubnodeRecord( - ENS_NAME, - label, - mockAddress, - mockAddress, - TTL, - sendOptions, - ); - expect(setSubnodeRecordMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - label, - mockAddress, - mockAddress, - TTL, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - - it('setSubnodeRecord with non strict hex label', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setSubnodeRecordMock = jest - .spyOn(registry['contract'].methods, 'setSubnodeRecord') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setSubnodeRecord( - ENS_NAME, - ENS_NAME, - mockAddress, - mockAddress, - TTL, - sendOptions, - ); - expect(setSubnodeRecordMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - label, - mockAddress, - mockAddress, - TTL, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('setSubnodeRecord throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setSubnodeRecordMock = jest - .spyOn(registry['contract'].methods, 'setSubnodeRecord') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - - await expect(async () => { - await registry.setSubnodeRecord( - ENS_NAME, - label, - mockAddress, - mockAddress, - TTL, - sendOptions, - ); - }).rejects.toThrow(new Error()); - expect(setSubnodeRecordMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - label, - mockAddress, - mockAddress, - TTL, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - }); - describe('ApprovalForAll', () => { - it('setApprovalForAll', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setApprovalForAllMock = jest - .spyOn(registry['contract'].methods, 'setApprovalForAll') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setApprovalForAll(ENS_NAME, true, sendOptions); - expect(setApprovalForAllMock).toHaveBeenCalledWith(ENS_NAME, true); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - - it('setApprovalForAll throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setApprovalForAllMock = jest - .spyOn(registry['contract'].methods, 'setApprovalForAll') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await expect(async () => { - await registry.setApprovalForAll(ENS_NAME, true, sendOptions); - }).rejects.toThrow(new Error()); - expect(setApprovalForAllMock).toHaveBeenCalledWith(ENS_NAME, true); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - - it('isApprovedForAll', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const call = jest.spyOn({ call: () => {} }, 'call'); - - const isApprovedForAllMock = jest - .spyOn(registry['contract'].methods, 'isApprovedForAll') - .mockReturnValue({ - call, - } as unknown as NonPayableMethodObject); - - await registry.isApprovedForAll(ENS_NAME, ENS_NAME); - expect(isApprovedForAllMock).toHaveBeenCalledWith(ENS_NAME, ENS_NAME); - expect(call).toHaveBeenCalled(); - }); - it('isApprovedForAll throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const call = jest.spyOn({ call: () => {} }, 'call').mockImplementation(() => { - throw new Error(); - }); - const isApprovedForAllMock = jest - .spyOn(registry['contract'].methods, 'isApprovedForAll') - .mockReturnValue({ - call, - } as unknown as NonPayableMethodObject); - - await expect(async () => { - await registry.isApprovedForAll(ENS_NAME, ENS_NAME); - }).rejects.toThrow(new Error()); - expect(isApprovedForAllMock).toHaveBeenCalledWith(ENS_NAME, ENS_NAME); - expect(call).toHaveBeenCalled(); - }); - }); describe('record', () => { - const TTL = 3600; - it('setRecord', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setRecordMock = jest - .spyOn(registry['contract'].methods, 'setRecord') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setRecord(ENS_NAME, mockAddress, mockAddress, TTL, sendOptions); - expect(setRecordMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - mockAddress, - mockAddress, - TTL, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('setRecord throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setRecordMock = jest - .spyOn(registry['contract'].methods, 'setRecord') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - - await expect(async () => { - await registry.setRecord(ENS_NAME, mockAddress, mockAddress, TTL, sendOptions); - }).rejects.toThrow(new Error()); - expect(setRecordMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - mockAddress, - mockAddress, - TTL, - ); - expect(send).toHaveBeenCalledWith(sendOptions); - }); it('recordExists', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest.spyOn({ call: () => {} }, 'call'); @@ -490,42 +141,6 @@ describe('registry', () => { }); describe('resolver', () => { - it('setResolver', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: async () => {} }, 'send'); - - const setResolverMock = jest - .spyOn(registry['contract'].methods, 'setResolver') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await registry.setResolver(ENS_NAME, mockAddress, sendOptions); - expect(setResolverMock).toHaveBeenCalledWith(namehash(ENS_NAME), mockAddress); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('setResolver throw (transaction reverted)', async () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send').mockImplementation(() => { - throw new Error(); - }); - - const setResolverMock = jest - .spyOn(registry['contract'].methods, 'setResolver') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - - await expect(async () => { - await registry.setResolver(ENS_NAME, mockAddress, sendOptions); - }).rejects.toThrow(new Error()); - expect(setResolverMock).toHaveBeenCalledWith(namehash(ENS_NAME), mockAddress); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('resolver', async () => { // eslint-disable-next-line @typescript-eslint/no-empty-function const call = jest diff --git a/packages/web3-eth-ens/test/unit/resolver.test.ts b/packages/web3-eth-ens/test/unit/resolver.test.ts index 2926bb97bac..dd95c46709b 100644 --- a/packages/web3-eth-ens/test/unit/resolver.test.ts +++ b/packages/web3-eth-ens/test/unit/resolver.test.ts @@ -16,13 +16,13 @@ along with web3.js. If not, see . */ import { Web3Context, Web3ContextObject } from 'web3-core'; -import { Contract, NonPayableMethodObject } from 'web3-eth-contract'; import { ResolverMethodMissingError } from 'web3-errors'; -import { sha3Raw, sha3 } from 'web3-utils'; +import { Contract, NonPayableMethodObject } from 'web3-eth-contract'; +import { sha3 } from 'web3-utils'; +import { PublicResolverAbi } from '../../src/abi/ens/PublicResolver'; +import { interfaceIds, methodsInInterface } from '../../src/config'; import { Registry } from '../../src/registry'; import { Resolver } from '../../src/resolver'; -import { PublicResolverAbi } from '../../src/abi/ens/PublicResolver'; -import { methodsInInterface, interfaceIds } from '../../src/config'; import { namehash } from '../../src/utils'; describe('resolver', () => { @@ -32,8 +32,6 @@ describe('resolver', () => { let contract: Contract; const mockAddress = '0x0000000000000000000000000000000000000000'; const ENS_NAME = 'web3js.eth'; - const x = '0x1000000000000000000000000000000000000000000000000000000000000000'; - const y = '0x2000000000000000000000000000000000000000000000000000000000000000'; beforeAll(() => { const context = new Web3Context('http://test.com'); @@ -86,30 +84,6 @@ describe('resolver', () => { ); }); describe('addr', () => { - it('setAddr valid', async () => { - const checkInteraface = jest.spyOn(resolver, 'checkInterfaceSupport'); - - const setAddrMock = jest.spyOn(contract.methods, 'setAddr').mockReturnValue({ - send: jest.fn(), - } as unknown as NonPayableMethodObject); - - jest.spyOn(contract.methods, 'supportsInterface').mockReturnValue({ - call: jest.fn().mockReturnValue(true), - } as unknown as NonPayableMethodObject); - - // todo when moving this mock in beforeAll, jest calls the actual implementation, how to fix that - // I use this in many places - jest.spyOn(registry, 'getResolver').mockImplementation(async () => { - return new Promise(resolve => { - resolve(contract); - }); - }); - - await resolver.setAddress(ENS_NAME, mockAddress, { from: mockAddress }); - expect(checkInteraface).toHaveBeenCalled(); - expect(setAddrMock).toHaveBeenCalledWith(namehash(ENS_NAME), mockAddress); - }); - it('getAddress', async () => { const supportsInterfaceMock = jest .spyOn(contract.methods, 'supportsInterface') @@ -138,40 +112,6 @@ describe('resolver', () => { }); describe('pubkey', () => { - it('setPubkey', async () => { - const setPubKeyMethod = methodsInInterface.setPubkey; - - jest.spyOn(registry, 'getResolver').mockImplementation(async () => { - return new Promise(resolve => { - resolve(contract); - }); - }); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setPubKeyMock = jest.spyOn(contract.methods, 'setPubkey').mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const supportsInterfaceMock = jest - .spyOn(contract.methods, 'supportsInterface') - .mockReturnValue({ - call: jest.fn().mockReturnValue(true), - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await expect(resolver.setPubkey(ENS_NAME, x, y, sendOptions)).resolves.not.toThrow(); - - expect(setPubKeyMock).toHaveBeenCalledWith( - namehash(ENS_NAME), - namehash(x), - namehash(y), - ); - expect(supportsInterfaceMock).toHaveBeenCalledWith(interfaceIds[setPubKeyMethod]); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('getPubkey', async () => { const supportsInterfaceMock = jest .spyOn(contract.methods, 'supportsInterface') @@ -200,41 +140,6 @@ describe('resolver', () => { }); describe('Contenthash', () => { - it('setContenthash', async () => { - const setContenthashMethod = methodsInInterface.setContenthash; - const hash = sha3Raw('justToHash'); - - jest.spyOn(registry, 'getResolver').mockImplementation(async () => { - return new Promise(resolve => { - resolve(contract); - }); - }); - - // eslint-disable-next-line @typescript-eslint/no-empty-function - const send = jest.spyOn({ send: () => {} }, 'send'); - - const setContenthashMock = jest - .spyOn(contract.methods, 'setContenthash') - .mockReturnValue({ - send, - } as unknown as NonPayableMethodObject); - - const supportsInterfaceMock = jest - .spyOn(contract.methods, 'supportsInterface') - .mockReturnValue({ - call: jest.fn().mockReturnValue(true), - } as unknown as NonPayableMethodObject); - - const sendOptions = { from: mockAddress }; - await expect( - resolver.setContenthash(ENS_NAME, hash, sendOptions), - ).resolves.not.toThrow(); - - expect(setContenthashMock).toHaveBeenCalledWith(namehash(ENS_NAME), hash); - expect(supportsInterfaceMock).toHaveBeenCalledWith(interfaceIds[setContenthashMethod]); - expect(send).toHaveBeenCalledWith(sendOptions); - }); - it('getContenthash', async () => { const supportsInterfaceMock = jest .spyOn(contract.methods, 'supportsInterface') From 1f865ada4fca271d53a4ccf693676f26635ffa91 Mon Sep 17 00:00:00 2001 From: Marin Petrunic Date: Mon, 15 May 2023 10:37:41 +0200 Subject: [PATCH 2/8] fix integration tests Signed-off-by: Marin Petrunic --- packages/web3-eth-ens/test/integration/ens.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/web3-eth-ens/test/integration/ens.test.ts b/packages/web3-eth-ens/test/integration/ens.test.ts index 2229abc4eec..9348411f3bf 100644 --- a/packages/web3-eth-ens/test/integration/ens.test.ts +++ b/packages/web3-eth-ens/test/integration/ens.test.ts @@ -63,8 +63,6 @@ describe('ens', () => { const fullDomain = `${subdomain}.${domain}`; const web3jsName = 'web3js.test'; - const ttl = 3600; - let accounts: string[]; let ens: ENS; let defaultAccount: string; From d9decfb5aa8c92458e6f645df671aebf09550a4e Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Wed, 24 May 2023 18:41:22 -0400 Subject: [PATCH 3/8] fix tests --- .../web3-eth-ens/src/abi/ens/ENSRegistry.ts | 62 +++++++++++++++++++ .../test/integration/ens.events.test.ts | 5 +- .../test/integration/resolver.test.ts | 15 +++-- 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts index bcac4c53170..ff726f18075 100644 --- a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts +++ b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts @@ -61,6 +61,50 @@ export const ENSRegistryAbi = [ name: 'NewResolver', type: 'event', }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'ApprovalForAll', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint64', + name: 'ttl', + type: 'uint64', + }, + ], + name: 'NewTTL', + type: 'event', + }, { anonymous: false, inputs: [ @@ -180,4 +224,22 @@ export const ENSRegistryAbi = [ stateMutability: 'view', type: 'function', }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'node', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'ttl', + type: 'uint64', + }, + ], + name: 'setTTL', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, ] as const; diff --git a/packages/web3-eth-ens/test/integration/ens.events.test.ts b/packages/web3-eth-ens/test/integration/ens.events.test.ts index eb7c7752b28..55ea6e6b442 100644 --- a/packages/web3-eth-ens/test/integration/ens.events.test.ts +++ b/packages/web3-eth-ens/test/integration/ens.events.test.ts @@ -58,6 +58,7 @@ describeIf(isSocket)('ens events', () => { let sendOptions: PayableTxOptions; const domain = 'test'; + const domainNode = namehash(domain); const node = namehash('resolver'); const label = sha3('resolver') as string; @@ -181,7 +182,7 @@ describeIf(isSocket)('ens events', () => { resolve(); }); - await registry.methods.setTTL(web3jsName, ttl).send(sendOptions); + await registry.methods.setTTL(namehash(web3jsName), ttl).send(sendOptions); }); }); @@ -197,7 +198,7 @@ describeIf(isSocket)('ens events', () => { }); await registry.methods - .setResolver(domain, resolver.options.address as string) + .setResolver(domainNode, resolver.options.address as string) .send(sendOptions); }); }); diff --git a/packages/web3-eth-ens/test/integration/resolver.test.ts b/packages/web3-eth-ens/test/integration/resolver.test.ts index 4d295a3f450..3576731740b 100644 --- a/packages/web3-eth-ens/test/integration/resolver.test.ts +++ b/packages/web3-eth-ens/test/integration/resolver.test.ts @@ -170,11 +170,10 @@ describe('ens', () => { it('fetch pubkey', async () => { await registry.methods - .setResolver(domain, resolver.options.address as string) + .setResolver(domainNode, resolver.options.address as string) .send(sendOptions); const res = await ens.getPubkey(domain); - expect(res.x).toBe('0x0000000000000000000000000000000000000000000000000000000000000000'); expect(res.y).toBe('0x0000000000000000000000000000000000000000000000000000000000000000'); }); @@ -183,16 +182,16 @@ describe('ens', () => { const x = '0x1000000000000000000000000000000000000000000000000000000000000000'; const y = '0x2000000000000000000000000000000000000000000000000000000000000000'; - await resolver.methods.setPubkey(domain, x, y).send(sendOptions); + await resolver.methods.setPubkey(domainNode, x, y).send(sendOptions); const result = await ens.getPubkey(domain); - expect(result[0]).toBe(namehash(x)); - expect(result[1]).toBe(namehash(y)); + expect(result[0]).toBe(x); + expect(result[1]).toBe(y); }); it('sets contenthash', async () => { - await resolver.methods.setContenthash(domain, contentHash).send(sendOptions); + await resolver.methods.setContenthash(domainNode, contentHash).send(sendOptions); const res = await resolver.methods.contenthash(domainNode).call(sendOptions); expect(res).toBe(contentHash); @@ -208,7 +207,7 @@ describe('ens', () => { event.on('data', () => { resolve(); }); - await resolver.methods.setContenthash(domain, contentHash).send(sendOptions); + await resolver.methods.setContenthash(domainNode, contentHash).send(sendOptions); }); }); @@ -224,7 +223,7 @@ describe('ens', () => { .setResolver(domainNode, resolver.options.address as string) .send(sendOptions); - await resolver.methods.setAddr(domain, accounts[1]).send(sendOptions); + await resolver.methods.setAddr(domainNode, accounts[1]).send(sendOptions); const res = await resolver.methods.addr(domainNode, DEFAULT_COIN_TYPE).call(sendOptions); expect(res).toBe(accounts[1]); From 47a7f6042be601f6686255ffe39bfbd8691b43ea Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 25 May 2023 14:09:40 -0400 Subject: [PATCH 4/8] fix tests --- .../web3-eth-ens/src/abi/ens/ENSRegistry.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts index ff726f18075..db94801f4c1 100644 --- a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts +++ b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts @@ -224,22 +224,4 @@ export const ENSRegistryAbi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - internalType: 'uint64', - name: 'ttl', - type: 'uint64', - }, - ], - name: 'setTTL', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, ] as const; From 069ae4f623a501a6f454f45dfe886f8abab3ba44 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 25 May 2023 16:28:45 -0400 Subject: [PATCH 5/8] remove unnecessary tests --- .../web3-eth-ens/src/abi/ens/ENSRegistry.ts | 44 ------------------- .../test/integration/ens.events.test.ts | 37 ---------------- 2 files changed, 81 deletions(-) diff --git a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts index db94801f4c1..bcac4c53170 100644 --- a/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts +++ b/packages/web3-eth-ens/src/abi/ens/ENSRegistry.ts @@ -61,50 +61,6 @@ export const ENSRegistryAbi = [ name: 'NewResolver', type: 'event', }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'operator', - type: 'address', - }, - { - indexed: false, - internalType: 'bool', - name: 'approved', - type: 'bool', - }, - ], - name: 'ApprovalForAll', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'bytes32', - name: 'node', - type: 'bytes32', - }, - { - indexed: false, - internalType: 'uint64', - name: 'ttl', - type: 'uint64', - }, - ], - name: 'NewTTL', - type: 'event', - }, { anonymous: false, inputs: [ diff --git a/packages/web3-eth-ens/test/integration/ens.events.test.ts b/packages/web3-eth-ens/test/integration/ens.events.test.ts index 55ea6e6b442..f130496ff86 100644 --- a/packages/web3-eth-ens/test/integration/ens.events.test.ts +++ b/packages/web3-eth-ens/test/integration/ens.events.test.ts @@ -62,10 +62,6 @@ describeIf(isSocket)('ens events', () => { const node = namehash('resolver'); const label = sha3('resolver') as string; - const web3jsName = 'web3js.test'; - - const ttl = 3600; - let accounts: string[]; let ens: ENS; let defaultAccount: string; @@ -153,39 +149,6 @@ describeIf(isSocket)('ens events', () => { .send(sendOptions); }); - // eslint-disable-next-line jest/expect-expect, jest/no-done-callback, jest/consistent-test-it - it('ApprovalForAll event', async () => { - // eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor - await new Promise(async resolve => { - const event = ens.events.ApprovalForAll(); - - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - event.on('data', () => { - resolve(); - }); - - await registry.methods.setApprovalForAll(accountOne, true).send(sendOptions); - }); - }); - - // eslint-disable-next-line jest/expect-expect, jest/no-done-callback, jest/consistent-test-it - it('NewTTL event', async () => { - // eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor - await new Promise(async resolve => { - const event = ens.events.NewTTL(); - - event.on('data', () => { - resolve(); - }); - - event.on('error', () => { - resolve(); - }); - - await registry.methods.setTTL(namehash(web3jsName), ttl).send(sendOptions); - }); - }); - // eslint-disable-next-line jest/expect-expect, jest/no-done-callback, jest/consistent-test-it it('NewResolver event', async () => { // eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor From 72539322b832b3973f585fcd34c301c18835df15 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 25 May 2023 16:58:00 -0400 Subject: [PATCH 6/8] increase coverage --- packages/web3-eth-ens/test/unit/ens.test.ts | 25 +++++++++++++++++++ .../web3-eth-ens/test/unit/resolver.test.ts | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/packages/web3-eth-ens/test/unit/ens.test.ts b/packages/web3-eth-ens/test/unit/ens.test.ts index 2e15c3b8a31..9f6f4dd7efe 100644 --- a/packages/web3-eth-ens/test/unit/ens.test.ts +++ b/packages/web3-eth-ens/test/unit/ens.test.ts @@ -123,6 +123,31 @@ describe('ens', () => { expect(addrMock).toHaveBeenCalledWith(ENS_NAME, 60); }); }); + + describe('events', () => { + it('get events', async () => { + const { events } = ens; + expect(typeof events.NewOwner).toBe('function'); + expect(typeof events.allEvents).toBe('function'); + expect(typeof events.NewResolver).toBe('function'); + expect(typeof events.Transfer).toBe('function'); + }); + }); + + describe('constructor', () => { + it('default params', async () => { + const localEns = new ENS(); + expect(localEns.provider).toBeUndefined(); + expect(localEns.registryAddress).toBe(registryAddresses.main); + }); + it('set params', async () => { + const localEns = new ENS(registryAddresses.goerli, 'http://127.0.0.1:8545'); + // @ts-expect-error check clientUrl field + expect(localEns.provider?.clientUrl).toBe('http://127.0.0.1:8545'); + expect(localEns.registryAddress).toBe(registryAddresses.goerli); + }); + }); + describe('pubkey', () => { it('getPubkey', async () => { const pubkeyMock = jest.spyOn(ens['_resolver'], 'getPubkey').mockReturnValue({ diff --git a/packages/web3-eth-ens/test/unit/resolver.test.ts b/packages/web3-eth-ens/test/unit/resolver.test.ts index dd95c46709b..97cf6e2d0b3 100644 --- a/packages/web3-eth-ens/test/unit/resolver.test.ts +++ b/packages/web3-eth-ens/test/unit/resolver.test.ts @@ -49,6 +49,13 @@ describe('resolver', () => { new ResolverMethodMissingError(mockAddress, methodName), ); }); + it('isNullish interface with no address', async () => { + const methodName = 'nullish'; + const localContract = new Contract(PublicResolverAbi); + await expect(resolver.checkInterfaceSupport(localContract, methodName)).rejects.toThrow( + new ResolverMethodMissingError('', methodName), + ); + }); it('Doesn"t support interface', async () => { const methodName = methodsInInterface.setAddr; // Just a method to pass first check @@ -65,6 +72,20 @@ describe('resolver', () => { expect(supportsInterfaceMock).toHaveBeenCalledWith(interfaceIds[methodName]); }); + it('Doesn"t support interface with no address', async () => { + const methodName = methodsInInterface.setAddr; // Just a method to pass first check + const localContract = new Contract(PublicResolverAbi); + const supportsInterfaceMock = jest + .spyOn(localContract.methods, 'supportsInterface') + .mockReturnValue({ + call: jest.fn().mockReturnValue(false), + } as unknown as NonPayableMethodObject); + + await expect(resolver.checkInterfaceSupport(localContract, methodName)).rejects.toThrow( + new ResolverMethodMissingError('', methodName), + ); + expect(supportsInterfaceMock).toHaveBeenCalledWith(interfaceIds[methodName]); + }); it.each(Object.values(methodsInInterface))( 'supported interface for %s', From a442eaf85eaaa968f3391987aba79efab33488e0 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 25 May 2023 17:10:53 -0400 Subject: [PATCH 7/8] fix changelog --- CHANGELOG.md | 6 ------ packages/web3-eth-ens/CHANGELOG.md | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46bd2045b8e..0318efca8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1502,9 +1502,3 @@ should use 4.0.1-alpha.0 for testing. #### web3-validator - `Web3ValidationErrorObject` type is now exported from `web3-types` package (#6102) - -#### web3-eth-ens - -### Changed - -- Removed non read-only methods diff --git a/packages/web3-eth-ens/CHANGELOG.md b/packages/web3-eth-ens/CHANGELOG.md index dc7052387d0..98519963091 100644 --- a/packages/web3-eth-ens/CHANGELOG.md +++ b/packages/web3-eth-ens/CHANGELOG.md @@ -83,3 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bug fix of `checkNetwork` in ENS (#5988) ## [Unreleased] + +### Removed + +- Removed non read-only methods (#6084) From 55deadf405f5eb78aaedc57eb7a95a26a1883bad Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 25 May 2023 17:12:23 -0400 Subject: [PATCH 8/8] skip internal provider test for now --- packages/web3/test/integration/external-providers/in3.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3/test/integration/external-providers/in3.test.ts b/packages/web3/test/integration/external-providers/in3.test.ts index ecaf192992b..72fe0d72be3 100644 --- a/packages/web3/test/integration/external-providers/in3.test.ts +++ b/packages/web3/test/integration/external-providers/in3.test.ts @@ -24,7 +24,7 @@ import Web3 from '../../../src/index'; // Actually it could take long time to get something from `in3` because of its decentralized nature. // And because of that, this test only try to get the last block number. And this also simplifies the configuration needed. describe('compatibility with `in3` provider', () => { - it('should get last block number', async () => { + it.skip('should get last block number', async () => { // use the In3Client as Http-Provider for web3.js const web3 = new Web3( new In3Client({