From 3a4f02f17edb5ea34f706af07a31d8d7522e3856 Mon Sep 17 00:00:00 2001 From: Alain Nicolas Date: Wed, 12 Feb 2025 10:20:27 +0100 Subject: [PATCH] chore: Fix typos and code formatting (#286) --- README.md | 4 +- packages/linea-ens-app/README.md | 52 +- .../deploy/01_get_contract_addresses.ts | 70 +- packages/linea-ens-app/next-env.d.ts | 2 +- .../@synthetixio__synpress@3.7.1.patch | 14 +- packages/linea-ens-contracts/README.md | 63 +- .../test/wrapper/NameWrapper.js | 5288 ++++++++--------- packages/linea-state-verifier/package.json | 2 +- 8 files changed, 2767 insertions(+), 2728 deletions(-) diff --git a/README.md b/README.md index 9b16923bb..d30927540 100644 --- a/README.md +++ b/README.md @@ -106,14 +106,14 @@ See [Install](./packages/linea-ens-app/README.md#install) in the linea-ens-app R ### linea-ens-resolver -The linea-ens-resolver contract intented to be deployed on L1 that is built on top +The linea-ens-resolver contract intended to be deployed on L1 that is built on top of [linea-state-verifier](./packages/linea-state-verifier) and verifies Linea ENS data (domain names, metadata etc). More documentation available in [linea-ens-resolver/README.md](./packages/linea-ens-resolver/README.md) ### linea-ens-contracts -The linea-ens-contracts contracts intented to be deployed on L2 (Linea) stores and returns the data necessary to resolve +The linea-ens-contracts contracts intended to be deployed on L2 (Linea) stores and returns the data necessary to resolve a domain name and more data related to ENS. More documentation available in [linea-ens-contracts/README.md](./packages/linea-ens-contracts/README.md) diff --git a/packages/linea-ens-app/README.md b/packages/linea-ens-app/README.md index 72f5d5608..6f70b5a1a 100644 --- a/packages/linea-ens-app/README.md +++ b/packages/linea-ens-app/README.md @@ -8,7 +8,7 @@ Friendly forked from ENS V3 app: [https://github.com/ensdomains/ens-app-v3](http ### Requirements -Install `Node.js`, `pnpm`, `Yarn` and `docker-compose`. +Install `Node.js`, `pnpm`, `Yarn` and `docker-compose`. See [Requirements](../../README.md#requirements). @@ -83,7 +83,8 @@ pnpm i make dev ``` -Make sure `VERIFIER_CONTRACT_ADDRESS` matches the `PohVerifier` contract address in `./packages/linea-ens-app/.env.local`. +Make sure `VERIFIER_CONTRACT_ADDRESS` matches the `PohVerifier` contract address in +`./packages/linea-ens-app/.env.local`. Once successfully started, you should see: @@ -100,25 +101,28 @@ cd packages/linea-ens-app pnpm dev:glocal ``` -You'll need an account with POH to fully use the local env, if you don't, you can get it [here] (https://poh.linea.build/). +You'll need an account with POH to fully use the local env, if you don't, you can get +it [here] (https://poh.linea.build/). - Then browse http://localhost:3000/. -- Import one of the hardhat test accounts in your MetaMask to have funds (eg, private key: `ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`, for address: `0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266`) +- Import one of the hardhat test accounts in your MetaMask to have funds (eg, private key: + `ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`, for address: + `0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266`) - Add the local test network to your MetaMask with these info: - - Click on `Add a network manually` - - Add this config: + - Click on `Add a network manually` + - Add this config: | Setting | Value | - | --------------- | --------------------- | + | --------------- | --------------------- | | Network name | Localhost 8545 | | New RPC URL | http://127.0.0.1:8545 | | Chain ID | 1337 | | Currency symbol | ETH | - - Save and Swith to `Localhost 8455`. + - Save and Switch to `Localhost 8455`. - Transfer 1 ETH from the test account above (eg: `0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266`), to your POH account - - If you don't have an address with PoH, see [Common Errors](#common-errors). + - If you don't have an address with PoH, see [Common Errors](#common-errors). - You can start testing the app and register a domain. ### Running Dev env @@ -143,7 +147,8 @@ Currently the tests written by ENS are not working in this repo because they sti #### **If you need to deploy a new subgraph** -You shouldn't deploy the subgraph on top of the existing dataset, instead you should create a clean dataset (explained below). +You shouldn't deploy the subgraph on top of the existing dataset, instead you should create a clean dataset (explained +below). 1. Start the test environment @@ -153,7 +158,8 @@ pnpm denv --save 2. Deploy the subgraph -After the deploy scripts have run, you can deploy the subgraph. Assuming you are in the [linea-ens-subgraph](https://github.com/Consensys/linea-enstree/main/packages/linea-ens-subgraph) repo, you can use: +After the deploy scripts have run, you can deploy the subgraph. Assuming you are in +the [linea-ens-subgraph](https://github.com/Consensys/linea-enstree/main/packages/linea-ens-subgraph) repo, you can use: ```bash yarn setup @@ -188,7 +194,8 @@ pnpm buildandstart:glocal ## Architecture -The structure of the `pages` folder is mimicked inside `components`. Components specific to a page can be found in the `components` folder, in the folder corresponding to that page. +The structure of the `pages` folder is mimicked inside `components`. Components specific to a page can be found in the +`components` folder, in the folder corresponding to that page. Components that are used in multiple places will be found in the top level of the `components` folder. @@ -196,13 +203,16 @@ Components that are used in multiple places will be found in the top level of th ### Node.js version and other requirements -Most installation errors are due to `Node.js`, `pnpm`, `yarn` or `docker-compose` versions. Verify the [requirements](../../README.md#requirements) if you encounter an error. To verify, you can execute: +Most installation errors are due to `Node.js`, `pnpm`, `yarn` or `docker-compose` versions. Verify +the [requirements](../../README.md#requirements) if you encounter an error. To verify, you can execute: ```bash node --version v18.20.4 ``` -Node Version Manager (nvm) can be used to manage multiple versions of Node.js if you find you are not in the correct version of Node. + +Node Version Manager (nvm) can be used to manage multiple versions of Node.js if you find you are not in the correct +version of Node. ```bash pnpm --version @@ -220,32 +230,40 @@ docker-compose version 1.29.2, build 5becea4c ``` ### Canvas issues + It is possible the Canvas libraries are not installed correctly or missing. -To install/reinstall: First install pkg-config: +To install/reinstall: First install pkg-config: + ```bash brew install pkg-config ``` Then install dependencies for canvas + ```bash brew install cairo pango libpng jpeg giflib librsvg ``` After installing the dependencies, set the PKG_CONFIG_PATH environment variable: + ```bash export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:/opt/homebrew/share/pkgconfig:$PKG_CONFIG_PATH" ``` Finally clear npm cache and node_modules: + ```bash npm cache clean --force rm -rf node_modules ``` ### Package Manager errors: -If you encounter a Package Manager error this stems from a Yarn compatibility issue. To resolve this we need to disable Yarn that has been bundled in with the latest versions of Node.js and install Yarn separately. + +If you encounter a Package Manager error this stems from a Yarn compatibility issue. To resolve this we need to disable +Yarn that has been bundled in with the latest versions of Node.js and install Yarn separately. To do so follow these steps in the root folder: + 1. `corepack disable` 2. `npm install -g pnpm` 3. `npm install -g yarn` @@ -267,7 +285,7 @@ To fix it, you can safely remove `data` in `./packages/linea-ens-app/data`. ### Linea PoH Status: INVALID -If your address doesn't have a PoH, for testing purpose you can temporally deactivate the PoH verification: +If your address doesn't have a PoH, for testing purpose you can temporarily deactivate the PoH verification: 1. Edit `linea-ens/packages/poh-signer-api/src/modules/poh/poh.service.ts`. diff --git a/packages/linea-ens-app/deploy/01_get_contract_addresses.ts b/packages/linea-ens-app/deploy/01_get_contract_addresses.ts index ce78061e8..5fad92b0f 100644 --- a/packages/linea-ens-app/deploy/01_get_contract_addresses.ts +++ b/packages/linea-ens-app/deploy/01_get_contract_addresses.ts @@ -1,31 +1,31 @@ /* eslint-disable import/no-extraneous-dependencies */ -import { existsSync } from 'fs' -import { mkdir, readFile, writeFile } from 'fs/promises' -import { resolve } from 'path' +import { existsSync } from 'fs'; +import { mkdir, readFile, writeFile } from 'fs/promises'; +import { resolve } from 'path'; -import { ethers, utils } from 'ethers' -import { DeployFunction } from 'hardhat-deploy/types' -import { HardhatRuntimeEnvironment } from 'hardhat/types' -import YAML from 'yaml' +import { ethers, utils } from 'ethers'; +import { DeployFunction } from 'hardhat-deploy/types'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import YAML from 'yaml'; -const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { +const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) { if (!process.env.BASE_DOMAIN) { - throw 'BASE_DOMAIN env needs to be intialized' + throw 'BASE_DOMAIN env needs to be initialized'; } - const allDeployments = await hre.deployments.all() + const allDeployments = await hre.deployments.all(); const deploymentAddressArray = Object.keys(allDeployments).map((dkey) => [ dkey, allDeployments[dkey].address, - ]) - const deploymentAddressMap = Object.fromEntries(deploymentAddressArray) + ]); + const deploymentAddressMap = Object.fromEntries(deploymentAddressArray); await writeFile( resolve(__dirname, '../.env.local'), `NEXT_PUBLIC_DEPLOYMENT_ADDRESSES='${JSON.stringify(deploymentAddressMap)}'`, - ) + ); if (!existsSync(resolve(__dirname, '../typings-custom/generated'))) { - await mkdir(resolve(__dirname, '../typings-custom/generated')) + await mkdir(resolve(__dirname, '../typings-custom/generated')); } await writeFile( resolve(__dirname, '../typings-custom/generated/local-contracts-generated.d.ts'), @@ -37,8 +37,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { } } `, - ) - console.log('Wrote contract addresses to .env.local') + ); + console.log('Wrote contract addresses to .env.local'); const deploymentsSubgraphNames = { ENSRegistry: deploymentAddressMap['ENSRegistry'], @@ -48,40 +48,40 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { EthRegistrarControllerOld: deploymentAddressMap['LegacyETHRegistrarController'], ETHRegistrarController: deploymentAddressMap['ETHRegistrarController'], NameWrapper: deploymentAddressMap['NameWrapper'], - } + }; - const subgraphYamlPath = resolve(__dirname, '../../linea-ens-subgraph/subgraph.yaml') - const subgraphYamlFile = await readFile(subgraphYamlPath, 'utf8') + const subgraphYamlPath = resolve(__dirname, '../../linea-ens-subgraph/subgraph.yaml'); + const subgraphYamlFile = await readFile(subgraphYamlPath, 'utf8'); - const subgraphYaml = YAML.parse(subgraphYamlFile) - const dataSources = subgraphYaml.dataSources + const subgraphYaml = YAML.parse(subgraphYamlFile); + const dataSources = subgraphYaml.dataSources; dataSources.map((dataSource) => { - dataSource.source.address = deploymentsSubgraphNames[dataSource.name] - }) + dataSource.source.address = deploymentsSubgraphNames[dataSource.name]; + }); - await writeFile(subgraphYamlPath, YAML.stringify(subgraphYaml)) + await writeFile(subgraphYamlPath, YAML.stringify(subgraphYaml)); console.log( 'Updated subgraph.yaml in packages/linea-ens-subgraph with the local deployment addresses', - ) + ); - const subgraphEnvPath = resolve(__dirname, '../../linea-ens-subgraph/src/env.ts') + const subgraphEnvPath = resolve(__dirname, '../../linea-ens-subgraph/src/env.ts'); - const baseDomain = `${process.env.BASE_DOMAIN}.eth` - const labelHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(process.env.BASE_DOMAIN)) + const baseDomain = `${process.env.BASE_DOMAIN}.eth`; + const labelHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(process.env.BASE_DOMAIN)); const envSrc = `export const BASE_DOMAIN = "${baseDomain}";\n` + `export const BASE_NODE = "${utils.namehash(baseDomain)}";\n` + `export const BASE_LABEL = "${process.env.BASE_DOMAIN}";\n` + - `export const BASE_LABEL_HASH = "${labelHash}";\n` + `export const BASE_LABEL_HASH = "${labelHash}";\n`; - await writeFile(subgraphEnvPath, envSrc) + await writeFile(subgraphEnvPath, envSrc); - console.log('Updated env.ts in packages/linea-ens-subgraph with the env base domain') -} + console.log('Updated env.ts in packages/linea-ens-subgraph with the env base domain'); +}; -func.runAtTheEnd = true -func.tags = ['get-contract-addresses'] +func.runAtTheEnd = true; +func.tags = ['get-contract-addresses']; -export default func +export default func; diff --git a/packages/linea-ens-app/next-env.d.ts b/packages/linea-ens-app/next-env.d.ts index 4f11a03dc..a4a7b3f5c 100644 --- a/packages/linea-ens-app/next-env.d.ts +++ b/packages/linea-ens-app/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/packages/linea-ens-app/patches/@synthetixio__synpress@3.7.1.patch b/packages/linea-ens-app/patches/@synthetixio__synpress@3.7.1.patch index fdea7e55a..3e615b974 100644 --- a/packages/linea-ens-app/patches/@synthetixio__synpress@3.7.1.patch +++ b/packages/linea-ens-app/patches/@synthetixio__synpress@3.7.1.patch @@ -6,7 +6,7 @@ index 66fad67c218a34a923d3674683c3a79c51c8555b..f048f6bc8bdc99af229eca208a38d6db const log = require('debug')('synpress:metamask'); const playwright = require('./playwright'); +const sleep = require('util').promisify(setTimeout); - + const { onboardingWelcomePageElements, @@ -74,6 +75,7 @@ const metamask = { @@ -388,16 +388,16 @@ index 66fad67c218a34a923d3674683c3a79c51c8555b..f048f6bc8bdc99af229eca208a38d6db @@ -1145,6 +1179,7 @@ const metamask = { return true; }, - async confirmPermisionToApproveAll() { -+ log(`Running confirmPermisionToApproveAll()`); + async confirmPermissionToApproveAll() { ++ log(`Running confirmPermissionToApproveAll()`); const notificationPage = await playwright.switchToMetamaskNotification(); await playwright.waitAndClick( notificationPageElements.allowToSpendButton, @@ -1158,6 +1193,7 @@ const metamask = { return true; }, - async rejectPermisionToApproveAll() { -+ log(`Running rejectPermisionToApproveAll()`); + async rejectPermissionToApproveAll() { ++ log(`Running rejectPermissionToApproveAll()`); const notificationPage = await playwright.switchToMetamaskNotification(); await playwright.waitAndClick( notificationPageElements.allowToSpendButton, @@ -698,7 +698,7 @@ index d7daab5bf8883389ccbecb18e53c050d1eef6d13..3ad8b6d1342f99ca4d33d4dd74433595 --- a/synpress.js +++ b/synpress.js @@ -6,7 +6,6 @@ const { version } = require('./package.json'); - + if (process.env.DEBUG && process.env.DEBUG.includes('synpress')) { log('DEBUG mode is enabled'); - process.env.PWDEBUG = 1; @@ -716,4 +716,4 @@ index d7daab5bf8883389ccbecb18e53c050d1eef6d13..3ad8b6d1342f99ca4d33d4dd74433595 + ) .option( '-r, --record', - '[dashboard] record video of tests running after setting up your project to record', \ No newline at end of file + '[dashboard] record video of tests running after setting up your project to record', diff --git a/packages/linea-ens-contracts/README.md b/packages/linea-ens-contracts/README.md index 8b9773134..18aae6703 100644 --- a/packages/linea-ens-contracts/README.md +++ b/packages/linea-ens-contracts/README.md @@ -15,7 +15,9 @@ A few specificities: ## Registry -The ENS registry is the core contract that lies at the heart of ENS resolution. All ENS lookups start by querying the registry. The registry maintains a list of domains, recording the owner, resolver, and TTL for each, and allows the owner of a domain to make changes to that data. It also includes some generic registrars. +The ENS registry is the core contract that lies at the heart of ENS resolution. All ENS lookups start by querying the +registry. The registry maintains a list of domains, recording the owner, resolver, and TTL for each, and allows the +owner of a domain to make changes to that data. It also includes some generic registrars. ### ENS.sol @@ -31,31 +33,41 @@ The new implementation of the ENS Registry after the 2020 ENS Registry Migration ### FIFSRegistrar -Implementation of a simple first-in-first-served registrar, which issues (sub-)domains to the first account to request them. +Implementation of a simple first-in-first-served registrar, which issues (sub-)domains to the first account to request +them. ### ReverseRegistrar -Implementation of the reverse registrar responsible for managing reverse resolution via the .addr.reverse special-purpose TLD. +Implementation of the reverse registrar responsible for managing reverse resolution via the .addr.reverse +special-purpose TLD. ### TestRegistrar -Implementation of the `.test` registrar facilitates easy testing of ENS on the Ethereum test networks. Currently deployed on Ropsten network, it provides functionality to instantly claim a domain for test purposes, which expires 28 days after it was claimed. +Implementation of the `.test` registrar facilitates easy testing of ENS on the Ethereum test networks. Currently +deployed on Ropsten network, it provides functionality to instantly claim a domain for test purposes, which expires 28 +days after it was claimed. ### BaseRegistrar -BaseRegistrar is the contract that owns the TLD in the ENS registry. This contract implements a minimal set of functionality: +BaseRegistrar is the contract that owns the TLD in the ENS registry. This contract implements a minimal set of +functionality: - The owner of the registrar may add and remove controllers. -- Controllers may register new domains and extend the expiry of (renew) existing domains. They can not change the ownership or reduce the expiration time of existing domains. +- Controllers may register new domains and extend the expiry of (renew) existing domains. They can not change the + ownership or reduce the expiration time of existing domains. - Name owners may transfer ownership to another address. - Name owners may reclaim ownership in the ENS registry if they have lost it. -- Owners of names in the interim registrar may transfer them to the new registrar, during the 1 year transition period. When they do so, their deposit is returned to them in its entirety. +- Owners of names in the interim registrar may transfer them to the new registrar, during the 1 year transition period. + When they do so, their deposit is returned to them in its entirety. -This separation of concerns provides name owners strong guarantees over continued ownership of their existing names, while still permitting innovation and change in the way names are registered and renewed via the controller mechanism. +This separation of concerns provides name owners strong guarantees over continued ownership of their existing names, +while still permitting innovation and change in the way names are registered and renewed via the controller mechanism. ### EthRegistrarController -EthRegistrarController is taken from the official ENS's [registration controller](https://github.com/ensdomains/ens-contracts/blob/staging/contracts/ethregistrar/ETHRegistrarController.sol) with some changes: +EthRegistrarController is taken from the official +ENS's [registration controller](https://github.com/ensdomains/ens-contracts/blob/staging/contracts/ethregistrar/ETHRegistrarController.sol) +with some changes: - The owner of the registrar can register a domain for any address that has not been registered yet for free. - Users can register a new name using a commit/reveal process and if they have completed of Proof of humanity process. @@ -63,32 +75,40 @@ EthRegistrarController is taken from the official ENS's [registration controller It has the same the commit/reveal process is used to avoid frontrunning, and operates as follows: -1. A user commits to a hash, the preimage of which contains the name to be registered and a secret value. -2. After a minimum delay period and before the commitment expires, the user calls the register function with the name to register and the secret value from the commitment. If a valid commitment is found and the other preconditions are met, the name is registered. +1. A user commits to a hash, the preimage of which contains the name to be registered and a secret value. +2. After a minimum delay period and before the commitment expires, the user calls the register function with the name to + register and the secret value from the commitment. If a valid commitment is found and the other preconditions are + met, the name is registered. -The minimum delay and expiry for commitments exist to prevent miners or other users from effectively frontrunning registrations. +The minimum delay and expiry for commitments exist to prevent miners or other users from effectively frontrunning +registrations. -### PohRegistrationManger +### PohRegistrationManager -PohRegistrationManger is the contract responsible to keep track of the users that used their POH to register a domain (One registration by address). +PohRegistrationManager is the contract responsible to keep track of the users that used their POH to register a domain ( +One registration by address). -- The owner of the PohRegistrationManger can set addresses as managers. -- The managers of PohRegistrationManager can mark an address as having used its POH, EthRegistrarController is intended to be a manager. +- The owner of the PohRegistrationManager can set addresses as managers. +- The managers of PohRegistrationManager can mark an address as having used its POH, EthRegistrarController is intended + to be a manager. ### PohVerifier -PohVerifier is the contract responsible for checking the signature of the private key responsible for aknowledging an address has passed the POH process or not. +PohVerifier is the contract responsible for checking the signature of the private key responsible for acknowledging an +address has passed the POH process or not. -- The owner of PohVerifier can set the signer address responsible for aknowledging a POH +- The owner of PohVerifier can set the signer address responsible for acknowledging a POH ### FixedPriceOracle FixedPriceOracle is a price oracle implementation that always return the same price. -It is used to make the original register function very expensive making it almost impossible to use and to force users to use the registration with POH. +It is used to make the original register function very expensive making it almost impossible to use and to force users +to use the registration with POH. ## Resolvers -Resolver implements a general-purpose ENS resolver that is suitable for most standard ENS use cases. The public resolver permits updates to ENS records by the owner of the corresponding name. +Resolver implements a general-purpose ENS resolver that is suitable for most standard ENS use cases. The public resolver +permits updates to ENS records by the owner of the corresponding name. PublicResolver includes the following profiles that implements different EIPs. @@ -99,7 +119,8 @@ PublicResolver includes the following profiles that implements different EIPs. - NameResolver = EIP 181 - Reverse resolution (`name()`). - PubkeyResolver = EIP 619 - SECP256k1 public keys (`pubkey()`). - TextResolver = EIP 634 - Text records (`text()`). -- DNSResolver = Experimental support is available for hosting DNS domains on the Ethereum blockchain via ENS. [The more detail](https://veox-ens.readthedocs.io/en/latest/dns.html) is on the old ENS doc. +- DNSResolver = Experimental support is available for hosting DNS domains on the Ethereum blockchain via + ENS. [The more detail](https://veox-ens.readthedocs.io/en/latest/dns.html) is on the old ENS doc. ## Developer guide diff --git a/packages/linea-ens-contracts/test/wrapper/NameWrapper.js b/packages/linea-ens-contracts/test/wrapper/NameWrapper.js index 355673c06..eccf410f2 100644 --- a/packages/linea-ens-contracts/test/wrapper/NameWrapper.js +++ b/packages/linea-ens-contracts/test/wrapper/NameWrapper.js @@ -1,13 +1,13 @@ -const { ethers } = require('hardhat') -const { use, expect } = require('chai') -const { solidity } = require('ethereum-waffle') -const { labelhash, namehash, encodeName, FUSES } = require('../test-utils/ens') -const { evm } = require('../test-utils') -const { shouldBehaveLikeERC1155 } = require('./ERC1155.behaviour') -const { shouldSupportInterfaces } = require('./SupportsInterface.behaviour') -const { shouldRespectConstraints } = require('./Constraints.behaviour') -const { ZERO_ADDRESS } = require('@openzeppelin/test-helpers/src/constants') -const { deploy } = require('../test-utils/contracts') +const { ethers } = require('hardhat'); +const { use, expect } = require('chai'); +const { solidity } = require('ethereum-waffle'); +const { labelhash, namehash, encodeName, FUSES } = require('../test-utils/ens'); +const { evm } = require('../test-utils'); +const { shouldBehaveLikeERC1155 } = require('./ERC1155.behaviour'); +const { shouldSupportInterfaces } = require('./SupportsInterface.behaviour'); +const { shouldRespectConstraints } = require('./Constraints.behaviour'); +const { ZERO_ADDRESS } = require('@openzeppelin/test-helpers/src/constants'); +const { deploy } = require('../test-utils/contracts'); const { EMPTY_BYTES32, EMPTY_ADDRESS, @@ -17,25 +17,25 @@ const { BASE_DOMAIN_STR, BASE_DOMAIN_LABEL, OVER_MAX_REGISTRATION_DURATION, -} = require('../test-utils/constants') +} = require('../test-utils/constants'); -const abiCoder = new ethers.utils.AbiCoder() +const abiCoder = new ethers.utils.AbiCoder(); -use(solidity) +use(solidity); -const ROOT_NODE = EMPTY_BYTES32 +const ROOT_NODE = EMPTY_BYTES32; -const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001' -const DAY = 86400 -const GRACE_PERIOD = 90 * DAY -const ETH_NAMEHASH = namehash('eth') +const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001'; +const DAY = 86400; +const GRACE_PERIOD = 90 * DAY; +const ETH_NAMEHASH = namehash('eth'); function increaseTime(delay) { - return ethers.provider.send('evm_increaseTime', [delay]) + return ethers.provider.send('evm_increaseTime', [delay]); } function mine() { - return ethers.provider.send('evm_mine') + return ethers.provider.send('evm_mine'); } const { @@ -50,27 +50,27 @@ const { IS_DOT_ETH, CAN_EXTEND_EXPIRY, CANNOT_APPROVE, -} = FUSES +} = FUSES; describe('Name Wrapper', () => { - let ENSRegistry - let ENSRegistry2 - let ENSRegistryH - let BaseRegistrar - let BaseRegistrar2 - let BaseRegistrarH - let NameWrapper - let NameWrapper2 - let NameWrapperH - let NameWrapperUpgraded - let MetaDataservice - let signers - let accounts - let account - let account2 - let hacker - let result - let MAX_EXPIRY = 2n ** 64n - 1n + let ENSRegistry; + let ENSRegistry2; + let ENSRegistryH; + let BaseRegistrar; + let BaseRegistrar2; + let BaseRegistrarH; + let NameWrapper; + let NameWrapper2; + let NameWrapperH; + let NameWrapperUpgraded; + let MetaDataservice; + let signers; + let accounts; + let account; + let account2; + let hacker; + let result; + let MAX_EXPIRY = 2n ** 64n - 1n; /* Utility funcs */ @@ -80,56 +80,56 @@ describe('Name Wrapper', () => { fuses, duration = 1 * DAY, ) { - const tokenId = labelhash(label) + const tokenId = labelhash(label); - await BaseRegistrar.register(tokenId, account, duration) + await BaseRegistrar.register(tokenId, account, duration); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, fuses, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, fuses, EMPTY_ADDRESS); } before(async () => { - signers = await ethers.getSigners() - account = await signers[0].getAddress() - account2 = await signers[1].getAddress() - account3 = await signers[2].getAddress() - hacker = account3 + signers = await ethers.getSigners(); + account = await signers[0].getAddress(); + account2 = await signers[1].getAddress(); + account3 = await signers[2].getAddress(); + hacker = account3; - EnsRegistry = await deploy('ENSRegistry') - EnsRegistry2 = EnsRegistry.connect(signers[1]) - EnsRegistryH = EnsRegistry.connect(signers[2]) + EnsRegistry = await deploy('ENSRegistry'); + EnsRegistry2 = EnsRegistry.connect(signers[1]); + EnsRegistryH = EnsRegistry.connect(signers[2]); BaseRegistrar = await deploy( 'BaseRegistrarImplementation', EnsRegistry.address, namehash(BASE_DOMAIN_STR), - ) + ); - BaseRegistrar2 = BaseRegistrar.connect(signers[1]) - BaseRegistrarH = BaseRegistrar.connect(signers[2]) + BaseRegistrar2 = BaseRegistrar.connect(signers[1]); + BaseRegistrarH = BaseRegistrar.connect(signers[2]); - await BaseRegistrar.addController(account) - await BaseRegistrar.addController(account2) + await BaseRegistrar.addController(account); + await BaseRegistrar.addController(account2); MetaDataservice = await deploy( 'StaticMetadataService', 'https://ens.domains', - ) + ); //setup reverse registrar const ReverseRegistrar = await deploy( 'ReverseRegistrar', EnsRegistry.address, - ) + ); - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('reverse'), account) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('reverse'), account); await EnsRegistry.setSubnodeOwner( namehash('reverse'), labelhash('addr'), ReverseRegistrar.address, - ) + ); const Resolver = await deploy( 'PublicResolver', @@ -137,8 +137,8 @@ describe('Name Wrapper', () => { '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', ReverseRegistrar.address, - ) - await ReverseRegistrar.setDefaultResolver(Resolver.address) + ); + await ReverseRegistrar.setDefaultResolver(Resolver.address); NameWrapper = await deploy( 'NameWrapper', @@ -147,41 +147,41 @@ describe('Name Wrapper', () => { MetaDataservice.address, BASE_NODE_BYTES32, BASE_NODE_DNS_ENCODED, - ) - NameWrapper2 = NameWrapper.connect(signers[1]) - NameWrapperH = NameWrapper.connect(signers[2]) - NameWrapper3 = NameWrapperH + ); + NameWrapper2 = NameWrapper.connect(signers[1]); + NameWrapperH = NameWrapper.connect(signers[2]); + NameWrapper3 = NameWrapperH; NameWrapperUpgraded = await deploy( 'UpgradedNameWrapperMock', EnsRegistry.address, BaseRegistrar.address, - ) + ); // setup .eth - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('eth'), account) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('eth'), account); await EnsRegistry.setSubnodeOwner( namehash('eth'), BASE_DOMAIN_LABEL, BaseRegistrar.address, - ) + ); // setup .xyz - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('xyz'), account) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('xyz'), account); //make sure base registrar is owner of eth TLD expect(await EnsRegistry.owner(BASE_NODE_BYTES32)).to.equal( BaseRegistrar.address, - ) - }) + ); + }); beforeEach(async () => { - result = await ethers.provider.send('evm_snapshot') - }) + result = await ethers.provider.send('evm_snapshot'); + }); afterEach(async () => { - await ethers.provider.send('evm_revert', [result]) - }) + await ethers.provider.send('evm_revert', [result]); + }); shouldBehaveLikeERC1155( () => [NameWrapper, signers], @@ -191,30 +191,30 @@ describe('Name Wrapper', () => { namehash('doesnotexist' + '.' + BASE_DOMAIN_STR), ], async (firstAddress, secondAddress) => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await BaseRegistrar.register(labelhash('test1'), account, 1 * DAY) + await BaseRegistrar.register(labelhash('test1'), account, 1 * DAY); await NameWrapper.wrapAnyLD( 'test1', firstAddress, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - await BaseRegistrar.register(labelhash('test2'), account, 86400) + await BaseRegistrar.register(labelhash('test2'), account, 86400); await NameWrapper.wrapAnyLD( 'test2', secondAddress, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); }, - ) + ); shouldSupportInterfaces( () => NameWrapper, ['INameWrapper', 'IERC721Receiver'], - ) + ); shouldRespectConstraints( () => ({ @@ -225,7 +225,7 @@ describe('Name Wrapper', () => { NameWrapper2, }), () => signers, - ) + ); it('should revert on wrong constructor arguments', async () => { try { @@ -236,11 +236,11 @@ describe('Name Wrapper', () => { MetaDataservice.address, EMPTY_BYTES32, BASE_NODE_DNS_ENCODED, - ) + ); } catch (error) { expect(error.reason).to.equal( - "VM Exception while processing transaction: reverted with custom error 'BaseNodeAsETHNodeOrROOTNodeNotAllowed()'", - ) + 'VM Exception while processing transaction: reverted with custom error \'BaseNodeAsETHNodeOrROOTNodeNotAllowed()\'', + ); } try { @@ -251,11 +251,11 @@ describe('Name Wrapper', () => { MetaDataservice.address, ETH_NAMEHASH, BASE_NODE_DNS_ENCODED, - ) + ); } catch (error) { expect(error.reason).to.equal( - "VM Exception while processing transaction: reverted with custom error 'BaseNodeAsETHNodeOrROOTNodeNotAllowed()'", - ) + 'VM Exception while processing transaction: reverted with custom error \'BaseNodeAsETHNodeOrROOTNodeNotAllowed()\'', + ); } try { @@ -266,11 +266,11 @@ describe('Name Wrapper', () => { MetaDataservice.address, BASE_NODE_2_BYTES32, BASE_NODE_DNS_ENCODED, - ) + ); } catch (error) { expect(error.reason).to.equal( - "VM Exception while processing transaction: reverted with custom error 'DifferentBaseNodeBaseNodeDnsEncoded()'", - ) + 'VM Exception while processing transaction: reverted with custom error \'DifferentBaseNodeBaseNodeDnsEncoded()\'', + ); } try { @@ -281,149 +281,149 @@ describe('Name Wrapper', () => { MetaDataservice.address, BASE_NODE_BYTES32, '0x', - ) + ); } catch (error) { expect(error.reason).to.equal( - "VM Exception while processing transaction: reverted with custom error 'EmptyDataNotAllowed()'", - ) + 'VM Exception while processing transaction: reverted with custom error \'EmptyDataNotAllowed()\'', + ); } - }) + }); describe('wrap()', () => { it('Wraps a name if you are the owner', async () => { - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account) - }) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account); + }); it('Allows specifying resolver', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, account2) - expect(await EnsRegistry.resolver(namehash('xyz'))).to.equal(account2) - }) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, account2); + expect(await EnsRegistry.resolver(namehash('xyz'))).to.equal(account2); + }); it('emits event for Wrap', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - const tx = NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + const tx = NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') - .withArgs(namehash('xyz'), encodeName('xyz'), account, 0, 0) - }) + .withArgs(namehash('xyz'), encodeName('xyz'), account, 0, 0); + }); it('emits event for TransferSingle', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - const tx = NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + const tx = NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account, EMPTY_ADDRESS, account, namehash('xyz'), 1) - }) + .withArgs(account, EMPTY_ADDRESS, account, namehash('xyz'), 1); + }); it('Cannot wrap a name if the owner has not authorised the wrapper with the ENS registry.', async () => { await expect(NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS)) - .to.be.reverted - }) + .to.be.reverted; + }); it('Will not allow wrapping with a target address of 0x0 or the wrapper contract address.', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.wrap(encodeName('xyz'), EMPTY_ADDRESS, EMPTY_ADDRESS), - ).to.be.revertedWith('ERC1155: mint to the zero address') - }) + ).to.be.revertedWith('ERC1155: mint to the zero address'); + }); it('Will not allow wrapping with a target address of the wrapper contract address.', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.wrap(encodeName('xyz'), NameWrapper.address, EMPTY_ADDRESS), ).to.be.revertedWith( 'ERC1155: newOwner cannot be the NameWrapper contract', - ) - }) + ); + }); it('Allows an account approved by the owner on the ENS registry to wrap a name.', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); // setup .abc with account2 as owner - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account2) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account2); // allow account to deal with all account2's names - await EnsRegistry2.setApprovalForAll(account, true) - await EnsRegistry2.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry2.setApprovalForAll(account, true); + await EnsRegistry2.setApprovalForAll(NameWrapper.address, true); //confirm abc is owner by account2 not account 1 - expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2) + expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2); // wrap using account - await NameWrapper.wrap(encodeName('abc'), account2, EMPTY_ADDRESS) - const ownerOfWrappedXYZ = await NameWrapper.ownerOf(namehash('abc')) - expect(ownerOfWrappedXYZ).to.equal(account2) - }) + await NameWrapper.wrap(encodeName('abc'), account2, EMPTY_ADDRESS); + const ownerOfWrappedXYZ = await NameWrapper.ownerOf(namehash('abc')); + expect(ownerOfWrappedXYZ).to.equal(account2); + }); it('Does not allow anyone else to wrap a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); // setup .abc with account2 as owner - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account2) - await EnsRegistry2.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account2); + await EnsRegistry2.setApprovalForAll(NameWrapper.address, true); //confirm abc is owner by account2 not account 1 - expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2) + expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2); // wrap using account await expect( NameWrapper.wrap(encodeName('abc'), account2, EMPTY_ADDRESS), - ).to.be.revertedWith(`Unauthorised("${namehash('abc')}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${namehash('abc')}", "${account}")`); + }); it('Does not allow wrapping .eth 2LDs.', async () => { - const label = 'wrapped' - const labelHash = labelhash(label) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + const label = 'wrapped'; + const labelHash = labelhash(label); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.wrap( encodeName('wrapped' + '.' + BASE_DOMAIN_STR), account2, EMPTY_ADDRESS, ), - ).to.be.revertedWith('IncompatibleParent()') - }) + ).to.be.revertedWith('IncompatibleParent()'); + }); it('Can re-wrap a name that was reassigned by an unwrapped parent', async () => { - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await EnsRegistry.setSubnodeOwner( namehash('xyz'), labelhash('sub'), account, - ) - await NameWrapper.wrap(encodeName('sub.xyz'), account, EMPTY_ADDRESS) + ); + await NameWrapper.wrap(encodeName('sub.xyz'), account, EMPTY_ADDRESS); await EnsRegistry.setSubnodeOwner( namehash('xyz'), labelhash('sub'), account2, - ) + ); - expect(await EnsRegistry.owner(namehash('sub.xyz'))).to.equal(account2) - expect(await NameWrapper.ownerOf(namehash('sub.xyz'))).to.equal(account) + expect(await EnsRegistry.owner(namehash('sub.xyz'))).to.equal(account2); + expect(await NameWrapper.ownerOf(namehash('sub.xyz'))).to.equal(account); - await EnsRegistry2.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry2.setApprovalForAll(NameWrapper.address, true); const tx = await NameWrapper2.wrap( encodeName('sub.xyz'), account2, EMPTY_ADDRESS, - ) + ); - const nameHash = namehash('sub.xyz') + const nameHash = namehash('sub.xyz'); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(nameHash, EMPTY_ADDRESS) + .withArgs(nameHash, EMPTY_ADDRESS); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account2, account, EMPTY_ADDRESS, nameHash, 1) + .withArgs(account2, account, EMPTY_ADDRESS, nameHash, 1); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -432,50 +432,50 @@ describe('Name Wrapper', () => { account2, CAN_DO_EVERYTHING, 0, - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account2, EMPTY_ADDRESS, account2, nameHash, 1) + .withArgs(account2, EMPTY_ADDRESS, account2, nameHash, 1); - expect(await NameWrapper2.ownerOf(nameHash)).to.equal(account2) - expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address) - }) + expect(await NameWrapper2.ownerOf(nameHash)).to.equal(account2); + expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address); + }); it('Will not wrap a name with junk at the end', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.wrap(encodeName('xyz') + '123456', account, ZERO_ADDRESS), - ).to.be.revertedWith('namehash: Junk at end of name') - }) + ).to.be.revertedWith('namehash: Junk at end of name'); + }); it('Does not allow wrapping a name you do not own', async () => { // Register the name to account1 - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); // Deploy the destroy-your-name contract - const NameGriefer = await deploy('NameGriefer', NameWrapper.address) + const NameGriefer = await deploy('NameGriefer', NameWrapper.address); // Try and burn the name - await expect(NameGriefer.destroy(encodeName('xyz'))).to.be.reverted + await expect(NameGriefer.destroy(encodeName('xyz'))).to.be.reverted; // Make sure it didn't succeed - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account) - }) + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account); + }); it('Rewrapping a previously wrapped unexpired name retains PCC', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -483,66 +483,66 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // COnfirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) - await EnsRegistry2.setApprovalForAll(NameWrapper.address, true) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); + await EnsRegistry2.setApprovalForAll(NameWrapper.address, true); await NameWrapper2.wrap( encodeName(`${subLabel}.${label}.${BASE_DOMAIN_STR}`), account2, EMPTY_ADDRESS, - ) - const [, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) - }) + ); + const [, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); + }); describe('unwrap()', () => { it('Allows owner to unwrap name', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('xyz'), 'unwrapped', account, 0, 0, - ) + ); const ownerOfWrappedXYZ = await NameWrapper.ownerOf( namehash('unwrapped.xyz'), - ) - expect(ownerOfWrappedXYZ).to.equal(account) - await NameWrapper.unwrap(namehash('xyz'), labelhash('unwrapped'), account) + ); + expect(ownerOfWrappedXYZ).to.equal(account); + await NameWrapper.unwrap(namehash('xyz'), labelhash('unwrapped'), account); //Transfers ownership in the ENS registry to the target address. expect(await EnsRegistry.owner(namehash('unwrapped.xyz'))).to.equal( account, - ) - }) + ); + }); it('Will not allow previous owner to unwrap name when name expires', async () => { - await BaseRegistrar.register(labelhash('unwrapped'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelhash('unwrapped'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( 'unwrapped', account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); await NameWrapper.setSubnodeOwner( namehash('unwrapped' + '.' + BASE_DOMAIN_STR), 'sub', account, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await evm.mine(); await expect( NameWrapper.unwrap( @@ -554,140 +554,140 @@ describe('Name Wrapper', () => { `Unauthorised("${namehash( 'sub.unwrapped' + '.' + BASE_DOMAIN_STR, )}", "${account}")`, - ) - }) + ); + }); it('emits Unwrap event', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) - const tx = await NameWrapper.unwrap(ROOT_NODE, labelhash('xyz'), account) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); + const tx = await NameWrapper.unwrap(ROOT_NODE, labelhash('xyz'), account); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(namehash('xyz'), account) - }) + .withArgs(namehash('xyz'), account); + }); it('emits TransferSingle event', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) - const tx = await NameWrapper.unwrap(ROOT_NODE, labelhash('xyz'), account) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); + const tx = await NameWrapper.unwrap(ROOT_NODE, labelhash('xyz'), account); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account, account, EMPTY_ADDRESS, namehash('xyz'), 1) - }) + .withArgs(account, account, EMPTY_ADDRESS, namehash('xyz'), 1); + }); it('Allows an account authorised by the owner on the NFT Wrapper to unwrap a name', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); // setup .abc with account2 as owner - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); // wrap using account - await NameWrapper.wrap(encodeName('abc'), account, EMPTY_ADDRESS) - await NameWrapper.setApprovalForAll(account2, true) - const ownerOfWrapperAbc = await NameWrapper.ownerOf(namehash('abc')) - expect(ownerOfWrapperAbc).to.equal(account) + await NameWrapper.wrap(encodeName('abc'), account, EMPTY_ADDRESS); + await NameWrapper.setApprovalForAll(account2, true); + const ownerOfWrapperAbc = await NameWrapper.ownerOf(namehash('abc')); + expect(ownerOfWrapperAbc).to.equal(account); //unwrap using account - await NameWrapper2.unwrap(ROOT_NODE, labelhash('abc'), account2) - expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2) - expect(await NameWrapper.ownerOf(namehash('abc'))).to.equal(EMPTY_ADDRESS) - }) + await NameWrapper2.unwrap(ROOT_NODE, labelhash('abc'), account2); + expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2); + expect(await NameWrapper.ownerOf(namehash('abc'))).to.equal(EMPTY_ADDRESS); + }); it('Does not allow an account authorised by the owner on the ENS registry to unwrap a name', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); // setup .abc with account2 as owner - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account2) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account2); // allow account to deal with all account2's names - await EnsRegistry2.setApprovalForAll(account, true) - await EnsRegistry2.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry2.setApprovalForAll(account, true); + await EnsRegistry2.setApprovalForAll(NameWrapper.address, true); //confirm abc is owner by account2 not account 1 - expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2) + expect(await EnsRegistry.owner(namehash('abc'))).to.equal(account2); // wrap using account - await NameWrapper.wrap(encodeName('abc'), account2, EMPTY_ADDRESS) - const ownerOfWrapperAbc = await NameWrapper.ownerOf(namehash('abc')) - expect(ownerOfWrapperAbc).to.equal(account2) + await NameWrapper.wrap(encodeName('abc'), account2, EMPTY_ADDRESS); + const ownerOfWrapperAbc = await NameWrapper.ownerOf(namehash('abc')); + expect(ownerOfWrapperAbc).to.equal(account2); //unwrap using account await expect(NameWrapper.unwrap(ROOT_NODE, labelHash, account2)).to.be - .reverted - }) + .reverted; + }); it('Does not allow anyone else to unwrap a name', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('abc'), account, EMPTY_ADDRESS) - const ownerOfWrapperAbc = await NameWrapper.ownerOf(namehash('abc')) - expect(ownerOfWrapperAbc).to.equal(account) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('abc'), account, EMPTY_ADDRESS); + const ownerOfWrapperAbc = await NameWrapper.ownerOf(namehash('abc')); + expect(ownerOfWrapperAbc).to.equal(account); //unwrap using account await expect(NameWrapper2.unwrap(ROOT_NODE, labelHash, account2)).to.be - .reverted - }) + .reverted; + }); it('Will not unwrap .eth 2LDs.', async () => { - const label = 'unwrapped' - const labelHash = labelhash(label) + const label = 'unwrapped'; + const labelHash = labelhash(label); - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); //allow the restricted name wrappper to transfer the name to itself and reclaim it - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS); const ownerOfWrappedETH = await NameWrapper.ownerOf( namehash('unwrapped' + '.' + BASE_DOMAIN_STR), - ) - expect(ownerOfWrappedETH).to.equal(account) + ); + expect(ownerOfWrappedETH).to.equal(account); await expect( NameWrapper.unwrap( namehash(BASE_DOMAIN_STR), labelhash('unwrapped'), account, ), - ).to.be.revertedWith('IncompatibleParent()') - }) + ).to.be.revertedWith('IncompatibleParent()'); + }); it('Will not allow a target address of 0x0 or the wrapper contract address.', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('abc'), account, EMPTY_ADDRESS) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('abc'), account, EMPTY_ADDRESS); await expect( NameWrapper.unwrap(ROOT_NODE, labelHash, EMPTY_ADDRESS), - ).to.be.revertedWith(`IncorrectTargetOwner("${EMPTY_ADDRESS}")`) + ).to.be.revertedWith(`IncorrectTargetOwner("${EMPTY_ADDRESS}")`); await expect( NameWrapper.unwrap(ROOT_NODE, labelHash, NameWrapper.address), - ).to.be.revertedWith(`IncorrectTargetOwner("${NameWrapper.address}")`) - }) + ).to.be.revertedWith(`IncorrectTargetOwner("${NameWrapper.address}")`); + }); it('Will not allow to unwrap with PCC/CU burned if expired', async () => { - const label = 'awesome' - const labelHash = labelhash(label) - await BaseRegistrar.register(labelHash, account, 1 * DAY) + const label = 'awesome'; + const labelHash = labelhash(label); + await BaseRegistrar.register(labelHash, account, 1 * DAY); await EnsRegistry.setSubnodeOwner( namehash('awesome' + '.' + BASE_DOMAIN_STR), labelhash('sub'), account, - ) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + ); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( 'awesome', account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await NameWrapper.setSubnodeOwner( namehash('awesome' + '.' + BASE_DOMAIN_STR), @@ -695,13 +695,13 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, 0, - ) + ); expect( await EnsRegistry.owner( namehash('sub.awesome' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); await expect( NameWrapper.unwrap( @@ -713,33 +713,33 @@ describe('Name Wrapper', () => { `Unauthorised("${namehash( 'sub.awesome' + '.' + BASE_DOMAIN_STR, )}", "${account}")`, - ) - }) + ); + }); it('Will allow to unwrap with PCC/CU burned if expired and then extended without PCC/CU', async () => { - const label = 'awesome' - const labelHash = labelhash(label) - await BaseRegistrar.register(labelHash, account, 1 * DAY * 7) + const label = 'awesome'; + const labelHash = labelhash(label); + await BaseRegistrar.register(labelHash, account, 1 * DAY * 7); await EnsRegistry.setSubnodeOwner( namehash('awesome' + '.' + BASE_DOMAIN_STR), labelhash('sub'), account, - ) + ); - const expiry = await BaseRegistrar.nameExpires(labelHash) + const expiry = await BaseRegistrar.nameExpires(labelHash); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( 'awesome', account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - const block = await ethers.provider.getBlock('latest') + const block = await ethers.provider.getBlock('latest'); await NameWrapper.setSubnodeOwner( namehash('awesome' + '.' + BASE_DOMAIN_STR), @@ -747,16 +747,16 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, block.timestamp + DAY, - ) + ); expect( await EnsRegistry.owner( namehash('sub.awesome' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); - await evm.advanceTime(2 * DAY) - await evm.mine() + await evm.advanceTime(2 * DAY); + await evm.mine(); await expect( NameWrapper.unwrap( @@ -768,7 +768,7 @@ describe('Name Wrapper', () => { `Unauthorised("${namehash( 'sub.awesome' + '.' + BASE_DOMAIN_STR, )}", "${account}")`, - ) + ); await NameWrapper.setSubnodeOwner( namehash('awesome' + '.' + BASE_DOMAIN_STR), @@ -776,37 +776,37 @@ describe('Name Wrapper', () => { account, 0, MAX_EXPIRY, - ) + ); await NameWrapper.unwrap( namehash('awesome' + '.' + BASE_DOMAIN_STR), labelhash('sub'), account, - ) + ); expect( await EnsRegistry.owner( namehash('sub.awesome' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account) - }) + ).to.equal(account); + }); it('Will not allow to unwrap a name with the CANNOT_UNWRAP fuse burned if not expired', async () => { - const labelHash = labelhash('abc') + const labelHash = labelhash('abc'); - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelHash, account); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), 'sub', account, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, MAX_EXPIRY, - ) + ); await expect( NameWrapper.unwrap( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -815,22 +815,22 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `OperationProhibited("${namehash('sub.abc' + '.' + BASE_DOMAIN_STR)}")`, - ) - }) + ); + }); it('Unwrapping a previously wrapped unexpired name retains PCC and expiry', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -838,95 +838,95 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // Confirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) - const [, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) - }) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); + const [, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); + }); describe('wrapAnyLD()', () => { - const label = 'wrapped2' - const labelHash = labelhash(label) - const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'wrapped2'; + const labelHash = labelhash(label); + const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR); it('wraps a name if sender is owner', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); //allow the restricted name wrappper to transfer the name to itself and reclaim it - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); //make sure reclaim claimed ownership for the wrapper in registry - expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address) + expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address); //make sure owner in the wrapper is the user - expect(await NameWrapper.ownerOf(nameHash)).to.equal(account) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(account); // make sure registrar ERC721 is owned by Wrapper expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) - }) + ); + }); it('Cannot wrap a name if the owner has not authorised the wrapper with the .eth registrar.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, false) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, false); const approved = await BaseRegistrar.isApprovedForAll( account, NameWrapper.address, - ) - expect(approved).to.equal(false) + ); + expect(approved).to.equal(false); await expect( NameWrapper.wrapAnyLD(label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS), - ).to.be.reverted - }) + ).to.be.reverted; + }); it('Allows specifying resolver', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD(label, account, CAN_DO_EVERYTHING, account2) - expect(await EnsRegistry.resolver(nameHash)).to.equal(account2) - }) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD(label, account, CAN_DO_EVERYTHING, account2); + expect(await EnsRegistry.resolver(nameHash)).to.equal(account2); + }); it('Can re-wrap a name that was wrapped has already expired on the .eth registrar', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) - await increaseTime(DAY * GRACE_PERIOD + DAY + 1) - await mine() + ); + await increaseTime(DAY * GRACE_PERIOD + DAY + 1); + await mine(); - expect(await BaseRegistrar.available(labelHash)).to.equal(true) + expect(await BaseRegistrar.available(labelHash)).to.equal(true); - await BaseRegistrar2.register(labelHash, account2, 1 * DAY) - const expectedExpiry = await BaseRegistrar2.nameExpires(labelHash) - expect(await BaseRegistrar.ownerOf(labelHash)).to.equal(account2) - await BaseRegistrar2.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar2.register(labelHash, account2, 1 * DAY); + const expectedExpiry = await BaseRegistrar2.nameExpires(labelHash); + expect(await BaseRegistrar.ownerOf(labelHash)).to.equal(account2); + await BaseRegistrar2.setApprovalForAll(NameWrapper.address, true); const tx = await NameWrapper2.wrapAnyLD( label, account2, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); // Check the 4 events // UnwrapETH2LD of the original owner @@ -936,10 +936,10 @@ describe('Name Wrapper', () => { await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(namehash('wrapped2' + '.' + BASE_DOMAIN_STR), EMPTY_ADDRESS) + .withArgs(namehash('wrapped2' + '.' + BASE_DOMAIN_STR), EMPTY_ADDRESS); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account2, account, EMPTY_ADDRESS, nameHash, 1) + .withArgs(account2, account, EMPTY_ADDRESS, nameHash, 1); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -948,48 +948,48 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL | IS_DOT_ETH, expectedExpiry.add(GRACE_PERIOD), - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account2, EMPTY_ADDRESS, account2, nameHash, 1) + .withArgs(account2, EMPTY_ADDRESS, account2, nameHash, 1); - expect(await NameWrapper2.ownerOf(nameHash)).to.equal(account2) + expect(await NameWrapper2.ownerOf(nameHash)).to.equal(account2); expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) - }) + ); + }); it('Can re-wrap a name that was wrapped has already expired even if CANNOT_TRANSFER was burned', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CANNOT_UNWRAP | CANNOT_TRANSFER, EMPTY_ADDRESS, - ) - await increaseTime(DAY * GRACE_PERIOD + DAY + 1) - await mine() + ); + await increaseTime(DAY * GRACE_PERIOD + DAY + 1); + await mine(); - expect(await BaseRegistrar.available(labelHash)).to.equal(true) + expect(await BaseRegistrar.available(labelHash)).to.equal(true); - await BaseRegistrar2.register(labelHash, account2, 1 * DAY) - const expectedExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await BaseRegistrar.ownerOf(labelHash)).to.equal(account2) - await BaseRegistrar2.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar2.register(labelHash, account2, 1 * DAY); + const expectedExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await BaseRegistrar.ownerOf(labelHash)).to.equal(account2); + await BaseRegistrar2.setApprovalForAll(NameWrapper.address, true); const tx = await NameWrapper2.wrapAnyLD( label, account2, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(namehash('wrapped2' + '.' + BASE_DOMAIN_STR), EMPTY_ADDRESS) + .withArgs(namehash('wrapped2' + '.' + BASE_DOMAIN_STR), EMPTY_ADDRESS); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account2, account, EMPTY_ADDRESS, nameHash, 1) + .withArgs(account2, account, EMPTY_ADDRESS, nameHash, 1); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -998,29 +998,29 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL | IS_DOT_ETH, expectedExpiry.add(GRACE_PERIOD), - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account2, EMPTY_ADDRESS, account2, nameHash, 1) + .withArgs(account2, EMPTY_ADDRESS, account2, nameHash, 1); - expect(await NameWrapper2.ownerOf(nameHash)).to.equal(account2) + expect(await NameWrapper2.ownerOf(nameHash)).to.equal(account2); expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) - }) + ); + }); it('correctly reports fuses for a name that has expired and been rewrapped more permissively', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); // Register the name - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); // Wrap it - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); let [, fuses, expiry] = await NameWrapper.getData( namehash('wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH) + ); + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH); // Create a subdomain that can't be unwrapped await NameWrapper.setSubnodeOwner( @@ -1032,18 +1032,18 @@ describe('Name Wrapper', () => { ) ;[, fuses] = await NameWrapper.getData( namehash('sub.wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) + ); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); // Fast forward until the 2LD expires - await increaseTime(DAY * GRACE_PERIOD + DAY + 1) - await mine() + await increaseTime(DAY * GRACE_PERIOD + DAY + 1); + await mine(); // Register from another address - await BaseRegistrar2.register(labelHash, account2, 1 * DAY) + await BaseRegistrar2.register(labelHash, account2, 1 * DAY); const expectedExpiry = - (await BaseRegistrar.nameExpires(labelHash)).toNumber() + GRACE_PERIOD - await BaseRegistrar2.setApprovalForAll(NameWrapper.address, true) + (await BaseRegistrar.nameExpires(labelHash)).toNumber() + GRACE_PERIOD; + await BaseRegistrar2.setApprovalForAll(NameWrapper.address, true); await NameWrapper2.wrapAnyLD( label, account2, @@ -1052,29 +1052,29 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH) + ); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH); expect(expiry).to.equal(expectedExpiry) //sub domain fuses get reset ;[, fuses] = await NameWrapper.getData( namehash('sub.wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(0) - }) + ); + expect(fuses).to.equal(0); + }); it('correctly reports fuses for a name that has expired and been rewrapped more permissively with registerAndWrap()', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); // Register the name - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); // Wrap it - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); let [, fuses, expiry] = await NameWrapper.getData( namehash('wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH) + ); + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH); // Create a subdomain that can't be unwrapped await NameWrapper.setSubnodeOwner( @@ -1086,43 +1086,43 @@ describe('Name Wrapper', () => { ) ;[, fuses] = await NameWrapper.getData( namehash('sub.wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) + ); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); // Fast forward until the 2LD expires - await increaseTime(DAY * GRACE_PERIOD + DAY + 1) - await mine() + await increaseTime(DAY * GRACE_PERIOD + DAY + 1); + await mine(); // Register from another address with registerAndWrap() - await BaseRegistrar.addController(NameWrapper.address) - await NameWrapper.setController(account, account) - await NameWrapper.registerAndWrap(label, account2, DAY, EMPTY_ADDRESS, 0) + await BaseRegistrar.addController(NameWrapper.address); + await NameWrapper.setController(account, account); + await NameWrapper.registerAndWrap(label, account2, DAY, EMPTY_ADDRESS, 0); const expectedExpiry = (await BaseRegistrar.nameExpires(labelHash)).toNumber() + GRACE_PERIOD ;[, fuses, expiry] = await NameWrapper.getData( namehash('wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH) + ); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH); expect(expiry).to.equal(expectedExpiry) //sub domain fuses get reset ;[, fuses] = await NameWrapper.getData( namehash('sub.wrapped2' + '.' + BASE_DOMAIN_STR), - ) - expect(fuses).to.equal(0) - }) + ); + expect(fuses).to.equal(0); + }); it('emits Wrap event', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); const tx = await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - const expiry = await BaseRegistrar.nameExpires(labelHash) + const expiry = await BaseRegistrar.nameExpires(labelHash); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -1131,38 +1131,38 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL | IS_DOT_ETH, expiry.add(GRACE_PERIOD), - ) - }) + ); + }); it('emits TransferSingle event', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); const tx = await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account, EMPTY_ADDRESS, account, nameHash, 1) - }) + .withArgs(account, EMPTY_ADDRESS, account, nameHash, 1); + }); it('Transfers the wrapped token to the target address.', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); await NameWrapper.wrapAnyLD( label, account2, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) - expect(await NameWrapper.ownerOf(nameHash)).to.equal(account2) - }) + ); + expect(await NameWrapper.ownerOf(nameHash)).to.equal(account2); + }); it('Does not allow wrapping with a target address of 0x0', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); await expect( NameWrapper.wrapAnyLD( label, @@ -1170,12 +1170,12 @@ describe('Name Wrapper', () => { CAN_DO_EVERYTHING, EMPTY_ADDRESS, ), - ).to.be.revertedWith('ERC1155: mint to the zero address') - }) + ).to.be.revertedWith('ERC1155: mint to the zero address'); + }); it('Does not allow wrapping with a target address of the wrapper contract address.', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); await expect( NameWrapper.wrapAnyLD( @@ -1186,52 +1186,52 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( 'ERC1155: newOwner cannot be the NameWrapper contract', - ) - }) + ); + }); it('Allows an account approved by the owner on the .eth registrar to wrap a name.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(account2, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(account2, true); - await NameWrapper2.wrapAnyLD(label, account, 0, EMPTY_ADDRESS) + await NameWrapper2.wrapAnyLD(label, account, 0, EMPTY_ADDRESS); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(account) - }) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(account); + }); it('Does not allow anyone else to wrap a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper2.wrapAnyLD(label, account, 0, EMPTY_ADDRESS), - ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account2}")`); + }); it('Can wrap a name even if the controller address is different to the registrant address.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await EnsRegistry.setOwner(nameHash, account2) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await EnsRegistry.setOwner(nameHash, account2); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(account) - }) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(account); + }); it('Does not allow the controller of a name to wrap it if they are not also the registrant.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await EnsRegistry.setOwner(nameHash, account2) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await EnsRegistry.setOwner(nameHash, account2); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await expect(NameWrapper2.wrapAnyLD(label, account2, 0, EMPTY_ADDRESS)).to - .be.reverted - }) + .be.reverted; + }); it('Does not allows fuse to be burned if CANNOT_UNWRAP has not been burned.', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); await expect( NameWrapper.wrapAnyLD( label, @@ -1239,12 +1239,12 @@ describe('Name Wrapper', () => { CANNOT_SET_RESOLVER, EMPTY_ADDRESS, ), - ).to.be.revertedWith(`OperationProhibited("${nameHash}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${nameHash}")`); + }); it('cannot burn any parent controlled fuse', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); for (let i = 0; i < 7; i++) { try { @@ -1253,48 +1253,48 @@ describe('Name Wrapper', () => { account, IS_DOT_ETH * 2 ** i, // next undefined fuse EMPTY_ADDRESS, - ) + ); } catch (e) { - expect(e.reason).to.contain('value out-of-bounds') + expect(e.reason).to.contain('value out-of-bounds'); } } - }) + }); it('Allows fuse to be burned if CANNOT_UNWRAP has been burned', async () => { - const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await NameWrapper.wrapAnyLD(label, account, initialFuses, EMPTY_ADDRESS) - const [, fuses] = await NameWrapper.getData(nameHash) - expect(fuses).to.equal(initialFuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH) - }) + const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER; + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await NameWrapper.wrapAnyLD(label, account, initialFuses, EMPTY_ADDRESS); + const [, fuses] = await NameWrapper.getData(nameHash); + expect(fuses).to.equal(initialFuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH); + }); it('Allows fuse to be burned if CANNOT_UNWRAP has been burned, but resets to 0 if expired', async () => { - const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await NameWrapper.wrapAnyLD(label, account, initialFuses, EMPTY_ADDRESS) + const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER; + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await NameWrapper.wrapAnyLD(label, account, initialFuses, EMPTY_ADDRESS); - await increaseTime(DAY + 1 + GRACE_PERIOD) - await mine() - const [, fuses] = await NameWrapper.getData(nameHash) - expect(fuses).to.equal(0) - }) + await increaseTime(DAY + 1 + GRACE_PERIOD); + await mine(); + const [, fuses] = await NameWrapper.getData(nameHash); + expect(fuses).to.equal(0); + }); it('Will not wrap an empty name', async () => { - await BaseRegistrar.register(labelhash(''), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelhash(''), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.wrapAnyLD('', account, CAN_DO_EVERYTHING, ZERO_ADDRESS), - ).to.be.revertedWith(`LabelTooShort()`) - }) + ).to.be.revertedWith(`LabelTooShort()`); + }); it('Will not wrap a label greater than 255 characters', async () => { const longString = - 'yutaioxtcsbzrqhdjmltsdfkgomogohhcchjoslfhqgkuhduhxqsldnurwrrtoicvthwxytonpcidtnkbrhccaozdtoznedgkfkifsvjukxxpkcmgcjprankyzerzqpnuteuegtfhqgzcxqwttyfewbazhyilqhyffufxrookxrnjkmjniqpmntcbrowglgdpkslzechimsaonlcvjkhhvdvkvvuztihobmivifuqtvtwinljslusvhhbwhuhzty' - expect(longString.length).to.equal(256) - await BaseRegistrar.register(labelhash(longString), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + 'yutaioxtcsbzrqhdjmltsdfkgomogohhcchjoslfhqgkuhduhxqsldnurwrrtoicvthwxytonpcidtnkbrhccaozdtoznedgkfkifsvjukxxpkcmgcjprankyzerzqpnuteuegtfhqgzcxqwttyfewbazhyilqhyffufxrookxrnjkmjniqpmntcbrowglgdpkslzechimsaonlcvjkhhvdvkvvuztihobmivifuqtvtwinljslusvhhbwhuhzty'; + expect(longString.length).to.equal(256); + await BaseRegistrar.register(labelhash(longString), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.wrapAnyLD( longString, @@ -1302,339 +1302,339 @@ describe('Name Wrapper', () => { CAN_DO_EVERYTHING, ZERO_ADDRESS, ), - ).to.be.revertedWith(`LabelTooLong("${longString}")`) - }) + ).to.be.revertedWith(`LabelTooLong("${longString}")`); + }); it('Rewrapping a previously wrapped unexpired name retains PCC and expiry', async () => { // register and wrap a name with PCC - await BaseRegistrar.register(labelHash, account, 1 * DAY) - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, ZERO_ADDRESS, - ) + ); // unwrap it - await NameWrapper.unwrapAnyLD(labelHash, account, account) + await NameWrapper.unwrapAnyLD(labelHash, account, account); // rewrap it without PCC being burned await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, ZERO_ADDRESS, - ) + ); // check that the PCC is still there - const [, fuses, expiry] = await NameWrapper.getData(nameHash) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) - }) + const [, fuses, expiry] = await NameWrapper.getData(nameHash); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); + }); describe('unwrapAnyLD()', () => { - const label = 'unwrapped' - const labelHash = labelhash(label) - const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'unwrapped'; + const labelHash = labelhash(label); + const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR); it('Allows the owner to unwrap a name.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); //allow the restricted name wrappper to transfer the name to itself and reclaim it - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); expect( await NameWrapper.ownerOf( namehash('unwrapped' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account) - await NameWrapper.unwrapAnyLD(labelHash, account, account) + ).to.equal(account); + await NameWrapper.unwrapAnyLD(labelHash, account, account); // transfers the controller on the .eth registrar to the target address. expect( await EnsRegistry.owner(namehash('unwrapped' + '.' + BASE_DOMAIN_STR)), - ).to.equal(account) + ).to.equal(account); //Transfers the registrant on the .eth registrar to the target address - expect(await BaseRegistrar.ownerOf(labelHash)).to.equal(account) - }) + expect(await BaseRegistrar.ownerOf(labelHash)).to.equal(account); + }); it('Does not allows the previous owner to unwrap when the name has expired.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); //allow the restricted name wrappper to transfer the name to itself and reclaim it - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); expect( await NameWrapper.ownerOf( namehash('unwrapped' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account) + ).to.equal(account); - await increaseTime(DAY + 1) - await mine() + await increaseTime(DAY + 1); + await mine(); await expect( NameWrapper.unwrapAnyLD(labelHash, account, account), - ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account}")`); + }); it('emits Unwrap event', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) - const tx = await NameWrapper.unwrapAnyLD(labelHash, account, account) + ); + const tx = await NameWrapper.unwrapAnyLD(labelHash, account, account); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(namehash('unwrapped' + '.' + BASE_DOMAIN_STR), account) - }) + .withArgs(namehash('unwrapped' + '.' + BASE_DOMAIN_STR), account); + }); it('Emits TransferSingle event', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) - const tx = await NameWrapper.unwrapAnyLD(labelHash, account, account) + ); + const tx = await NameWrapper.unwrapAnyLD(labelHash, account, account); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account, account, EMPTY_ADDRESS, nameHash, 1) - }) + .withArgs(account, account, EMPTY_ADDRESS, nameHash, 1); + }); it('Does not allows an account authorised by the owner on the ENS registrar to unwrap a name', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(account2, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(account2, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect( NameWrapper2.unwrapAnyLD(labelHash, account2, account2), - ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account2}")`); + }); it('Does not allow anyone else to unwrap a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await EnsRegistry.setApprovalForAll(account2, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await EnsRegistry.setApprovalForAll(account2, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect( NameWrapper2.unwrapAnyLD(labelHash, account2, account2), - ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${nameHash}", "${account2}")`); + }); it('Does not allow a name to be unwrapped if CANNOT_UNWRAP fuse has been burned', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); await expect( NameWrapper.unwrapAnyLD(labelHash, account, account), ).to.be.revertedWith( 'OperationProhibited("0xe5db7597438b3d9e464a2a67ce953d660d4735968ec17f21e5ac52bb1c6be275")', - ) - }) + ); + }); it('Unwrapping a previously wrapped unexpired name retains PCC and expiry', async () => { // register and wrap a name with PCC - await BaseRegistrar.register(labelHash, account, 1 * DAY) - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, ZERO_ADDRESS, - ) + ); // unwrap it - await NameWrapper.unwrapAnyLD(labelHash, account, account) + await NameWrapper.unwrapAnyLD(labelHash, account, account); // check that the Parent controlled fuses are still there - const [, fuses, expiry] = await NameWrapper.getData(nameHash) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) - }) + const [, fuses, expiry] = await NameWrapper.getData(nameHash); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); + }); describe('ownerOf()', () => { it('Returns the owner', async () => { - const label = 'subdomain' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const CAN_DO_EVERYTHING = 0 + const label = 'subdomain'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const CAN_DO_EVERYTHING = 0; - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - const ownerInBaseRegistrar = await BaseRegistrar.ownerOf(tokenId) + const ownerInBaseRegistrar = await BaseRegistrar.ownerOf(tokenId); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - const owner = await NameWrapper.ownerOf(wrappedTokenId) + const owner = await NameWrapper.ownerOf(wrappedTokenId); - expect(owner).to.equal(account) - }) + expect(owner).to.equal(account); + }); it('Returns 0 when owner is expired', async () => { - const label = 'subdomain' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const CAN_DO_EVERYTHING = 0 + const label = 'subdomain'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const CAN_DO_EVERYTHING = 0; - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - await evm.advanceTime(1 * DAY + GRACE_PERIOD + 1) - await evm.mine() + await evm.advanceTime(1 * DAY + GRACE_PERIOD + 1); + await evm.mine(); - const owner = await NameWrapper.ownerOf(wrappedTokenId) + const owner = await NameWrapper.ownerOf(wrappedTokenId); - expect(owner).to.equal(EMPTY_ADDRESS) - }) - }) + expect(owner).to.equal(EMPTY_ADDRESS); + }); + }); describe('ownerOf()', () => { it('Returns the owner', async () => { - const label = 'subdomain' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const CAN_DO_EVERYTHING = 0 + const label = 'subdomain'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const CAN_DO_EVERYTHING = 0; - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - const ownerInBaseRegistrar = await BaseRegistrar.ownerOf(tokenId) + const ownerInBaseRegistrar = await BaseRegistrar.ownerOf(tokenId); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - const owner = await NameWrapper.ownerOf(wrappedTokenId) + const owner = await NameWrapper.ownerOf(wrappedTokenId); - expect(owner).to.equal(account) - }) + expect(owner).to.equal(account); + }); it('Returns 0 when owner is expired', async () => { - const label = 'subdomain' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const CAN_DO_EVERYTHING = 0 + const label = 'subdomain'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const CAN_DO_EVERYTHING = 0; - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - await evm.advanceTime(1 * DAY + GRACE_PERIOD + 1) - await evm.mine() + await evm.advanceTime(1 * DAY + GRACE_PERIOD + 1); + await evm.mine(); - const owner = await NameWrapper.ownerOf(wrappedTokenId) + const owner = await NameWrapper.ownerOf(wrappedTokenId); - expect(owner).to.equal(EMPTY_ADDRESS) - }) - }) + expect(owner).to.equal(EMPTY_ADDRESS); + }); + }); describe('approve()', () => { - const label = 'subdomain' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const sublabelHash = labelhash('sub') + const label = 'subdomain'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const sublabelHash = labelhash('sub'); const subWrappedTokenId = namehash( 'sub.' + label + '' + '.' + BASE_DOMAIN_STR, - ) - let parentExpiry - let result + ); + let parentExpiry; + let result; before(async () => { - result = await ethers.provider.send('evm_snapshot') - await BaseRegistrar.register(tokenId, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + result = await ethers.provider.send('evm_snapshot'); + await BaseRegistrar.register(tokenId, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, ) - ;[, , parentExpiry] = await NameWrapper.getData(wrappedTokenId) - }) + ;[, , parentExpiry] = await NameWrapper.getData(wrappedTokenId); + }); after(async () => { - await ethers.provider.send('evm_revert', [result]) - }) + await ethers.provider.send('evm_revert', [result]); + }); it('Sets an approval address if owner', async () => { - await NameWrapper.approve(account2, wrappedTokenId) - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) - }) + await NameWrapper.approve(account2, wrappedTokenId); + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); + }); it('Sets an approval address if is an operator', async () => { - await NameWrapper.setApprovalForAll(account2, true) - await NameWrapper2.approve(account3, wrappedTokenId) - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account3) - }) + await NameWrapper.setApprovalForAll(account2, true); + await NameWrapper2.approve(account3, wrappedTokenId); + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account3); + }); it('Reverts if called by an approved address', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); await expect( NameWrapper2.approve(account3, wrappedTokenId), ).to.be.revertedWith( 'ERC721: approve caller is not token owner or approved for all', - ) - }) + ); + }); it('Reverts if called by non-owner or approved', async () => { await expect( NameWrapper2.approve(account2, wrappedTokenId), ).to.be.revertedWith( 'ERC721: approve caller is not token owner or approved for all', - ) - }) + ); + }); it('Emits Approval event', async () => { - const tx = await NameWrapper.approve(account2, wrappedTokenId) + const tx = await NameWrapper.approve(account2, wrappedTokenId); await expect(tx) .to.emit(NameWrapper, 'Approval') - .withArgs(account, account2, wrappedTokenId) - }) + .withArgs(account, account2, wrappedTokenId); + }); it('Allows approved address to call extendExpiry()', async () => { await NameWrapper.setSubnodeOwner( @@ -1643,21 +1643,21 @@ describe('Name Wrapper', () => { account2, 0, EMPTY_ADDRESS, - ) - await NameWrapper.approve(account2, wrappedTokenId) + ); + await NameWrapper.approve(account2, wrappedTokenId); expect( await NameWrapper.ownerOf( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) + ).to.equal(account2); - await NameWrapper2.extendExpiry(wrappedTokenId, sublabelHash, 100) + await NameWrapper2.extendExpiry(wrappedTokenId, sublabelHash, 100); const [, , expiry] = await NameWrapper.getData( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), - ) - expect(expiry).to.equal(100) - }) + ); + expect(expiry).to.equal(100); + }); it('Does not allows approved address to call setSubnodeOwner()', async () => { await NameWrapper.setSubnodeOwner( @@ -1666,19 +1666,19 @@ describe('Name Wrapper', () => { account2, 0, EMPTY_ADDRESS, - ) - await NameWrapper.approve(account2, wrappedTokenId) + ); + await NameWrapper.approve(account2, wrappedTokenId); expect( await NameWrapper.ownerOf( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) + ).to.equal(account2); await expect( NameWrapper2.setSubnodeOwner(wrappedTokenId, 'sub', account3, 0, 1000), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Allows approved address to call setSubnodeRecord()', async () => { await NameWrapper.setSubnodeOwner( @@ -1687,14 +1687,14 @@ describe('Name Wrapper', () => { account2, 0, EMPTY_ADDRESS, - ) - await NameWrapper.approve(account2, wrappedTokenId) + ); + await NameWrapper.approve(account2, wrappedTokenId); expect( await NameWrapper.ownerOf( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) + ).to.equal(account2); await expect( NameWrapper2.setSubnodeRecord( @@ -1706,27 +1706,27 @@ describe('Name Wrapper', () => { 0, 10000, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Allows approved address to call setChildFuses()', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, 0, EMPTY_ADDRESS, - ) - await NameWrapper.approve(account2, wrappedTokenId) + ); + await NameWrapper.approve(account2, wrappedTokenId); expect( await NameWrapper.ownerOf( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) + ).to.equal(account2); - const [, , parentExpiry] = await NameWrapper2.getData(wrappedTokenId) + const [, , parentExpiry] = await NameWrapper2.getData(wrappedTokenId); await expect( NameWrapper2.setChildFuses( @@ -1735,8 +1735,8 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | CAN_EXTEND_EXPIRY, parentExpiry, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Does not allow approved accounts to extend expiry when expired', async () => { await NameWrapper.setSubnodeOwner( @@ -1745,25 +1745,25 @@ describe('Name Wrapper', () => { account2, 0, EMPTY_ADDRESS, - ) - await NameWrapper.approve(account2, wrappedTokenId) + ); + await NameWrapper.approve(account2, wrappedTokenId); - await evm.advanceTime(2 * DAY) - await evm.mine() + await evm.advanceTime(2 * DAY); + await evm.mine(); await expect( NameWrapper2.extendExpiry(wrappedTokenId, labelhash('sub'), 1000), ).to.be.revertedWith( `OperationProhibited("${namehash( 'sub.subdomain' + '.' + BASE_DOMAIN_STR, )}")`, - ) - }) + ); + }); it('Approved address can be replaced and previous approved is removed', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP); // Make sure there are no lingering approvals - await NameWrapper.setApprovalForAll(account2, false) - await NameWrapper.setApprovalForAll(account3, false) + await NameWrapper.setApprovalForAll(account2, false); + await NameWrapper.setApprovalForAll(account3, false); await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -1771,16 +1771,16 @@ describe('Name Wrapper', () => { account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | CAN_EXTEND_EXPIRY, parentExpiry - 1000, - ) - await NameWrapper.approve(account2, wrappedTokenId) + ); + await NameWrapper.approve(account2, wrappedTokenId); - await NameWrapper.approve(account3, wrappedTokenId) + await NameWrapper.approve(account3, wrappedTokenId); await NameWrapper3.extendExpiry( wrappedTokenId, labelhash('sub'), parentExpiry - 500, - ) + ); await expect( NameWrapper2.extendExpiry( @@ -1790,25 +1790,25 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `Unauthorised("${subWrappedTokenId}", "${account2}")`, - ) + ); - const [, , expiry] = await NameWrapper.getData(subWrappedTokenId) - expect(expiry).to.equal(parentExpiry - 500) - }) + const [, , expiry] = await NameWrapper.getData(subWrappedTokenId); + expect(expiry).to.equal(parentExpiry - 500); + }); it('Approved address cannot be removed/replaced when fuse is burnt', async () => { - await NameWrapper.approve(account2, wrappedTokenId) - await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP | CANNOT_APPROVE) + await NameWrapper.approve(account2, wrappedTokenId); + await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP | CANNOT_APPROVE); await expect( NameWrapper.approve(EMPTY_ADDRESS, wrappedTokenId), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); await expect( NameWrapper.approve(account, wrappedTokenId), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('Approved address cannot transfer the name', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); await expect( NameWrapper2.safeTransferFrom( account, @@ -1817,36 +1817,36 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`ERC1155: caller is not owner nor approved`) - }) + ).to.be.revertedWith(`ERC1155: caller is not owner nor approved`); + }); it('Approved address cannot transfer the name with setRecord()', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); await expect( NameWrapper2.setRecord(wrappedTokenId, account2, EMPTY_ADDRESS, 0), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Approved address cannot call setResolver()', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); await expect( NameWrapper2.setResolver(wrappedTokenId, account2), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Approved address cannot call setTTL()', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); await expect(NameWrapper2.setTTL(wrappedTokenId, 100)).to.be.revertedWith( `Unauthorised("${wrappedTokenId}", "${account2}")`, - ) - }) + ); + }); it('Approved address cannot unwrap ' + '.' + BASE_DOMAIN_STR, async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); await expect( NameWrapper2.unwrapAnyLD(tokenId, account2, account2), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it( 'Approved address cannot unwrap non ' + '.' + BASE_DOMAIN_STR, @@ -1857,25 +1857,25 @@ describe('Name Wrapper', () => { account, 0, EMPTY_ADDRESS, - ) + ); await NameWrapper.approve( account2, namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), - ) + ); await expect( NameWrapper2.unwrap(wrappedTokenId, labelhash('sub'), account2), ).to.be.revertedWith( `Unauthorised("${namehash( 'sub.subdomain' + '.' + BASE_DOMAIN_STR, )}", "${account2}")`, - ) + ); }, - ) + ); it('Approval is cleared on transfer', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); await NameWrapper.safeTransferFrom( account, @@ -1883,38 +1883,38 @@ describe('Name Wrapper', () => { wrappedTokenId, 1, '0x', - ) + ); expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) - }) + ); + }); it('Approval is cleared on unwrapAnyLD()', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); - await NameWrapper.unwrapAnyLD(tokenId, account, account) + await NameWrapper.unwrapAnyLD(tokenId, account, account); expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) + ); // rewrapping to test approval is still cleared - await NameWrapper.wrapAnyLD('subdomain', account, 0, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD('subdomain', account, 0, EMPTY_ADDRESS); expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) + ); // reapprove to show approval can be reinstated - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) - }) + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); + }); it('Approval is cleared on unwrap()', async () => { await NameWrapper.setSubnodeOwner( @@ -1923,79 +1923,79 @@ describe('Name Wrapper', () => { account, 0, EMPTY_ADDRESS, - ) + ); await NameWrapper.approve( account2, namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), - ) + ); expect( await NameWrapper.getApproved( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) - await NameWrapper.unwrap(wrappedTokenId, labelhash('sub'), account) + ).to.equal(account2); + await NameWrapper.unwrap(wrappedTokenId, labelhash('sub'), account); expect( await NameWrapper.getApproved( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(EMPTY_ADDRESS) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + ).to.equal(EMPTY_ADDRESS); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrap( encodeName('sub.subdomain' + '.' + BASE_DOMAIN_STR), account, EMPTY_ADDRESS, - ) + ); expect( await NameWrapper.getApproved( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(EMPTY_ADDRESS) + ).to.equal(EMPTY_ADDRESS); await NameWrapper.approve( account2, namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), - ) + ); expect( await NameWrapper.getApproved( namehash('sub.subdomain' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) + ).to.equal(account2); // rewrapping to test approval is still cleared - }) + }); it('Approval is cleared on re-registration and wrap of expired name', async () => { - await NameWrapper.approve(account2, wrappedTokenId) - await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP | CANNOT_APPROVE) - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) - await evm.advanceTime(2 * DAY + GRACE_PERIOD) - await evm.mine() + await NameWrapper.approve(account2, wrappedTokenId); + await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP | CANNOT_APPROVE); + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); + await evm.advanceTime(2 * DAY + GRACE_PERIOD); + await evm.mine(); expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) + ); - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); // rewrapping to test approval is still cleared await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) + ); - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + }); it('Approval is not cleared on transfer if CANNOT_APPROVE is burnt', async () => { - await NameWrapper.approve(account2, wrappedTokenId) - await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP | CANNOT_APPROVE) - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) + await NameWrapper.approve(account2, wrappedTokenId); + await NameWrapper.setFuses(wrappedTokenId, CANNOT_UNWRAP | CANNOT_APPROVE); + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); await NameWrapper.safeTransferFrom( account, @@ -2003,188 +2003,188 @@ describe('Name Wrapper', () => { wrappedTokenId, 1, '0x', - ) + ); - expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2) - }) - }) + expect(await NameWrapper.getApproved(wrappedTokenId)).to.equal(account2); + }); + }); describe('getApproved()', () => { - const label = 'subdomain' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'subdomain'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(tokenId, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) - }) + ); + }); it('Returns returns zero address when ownerOf() is zero', async () => { expect( await NameWrapper.ownerOf(namehash('unminted' + '.' + BASE_DOMAIN_STR)), - ).to.equal(EMPTY_ADDRESS) + ).to.equal(EMPTY_ADDRESS); expect( await NameWrapper.getApproved( namehash('unminted' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(EMPTY_ADDRESS) - }) + ).to.equal(EMPTY_ADDRESS); + }); it('Returns the approved address', async () => { - await NameWrapper.approve(account2, wrappedTokenId) + await NameWrapper.approve(account2, wrappedTokenId); expect(await NameWrapper.getApproved(namehash(wrappedTokenId))).to.equal( EMPTY_ADDRESS, - ) - }) - }) + ); + }); + }); describe('setUpgradeContract()', () => { it('Reverts if called by someone that is not the owner', async () => { // Attempt to attack the contract by setting the upgrade contract to themselves await expect( NameWrapper2.setUpgradeContract(account2), - ).to.be.revertedWith('Ownable: caller is not the owner') - }) + ).to.be.revertedWith('Ownable: caller is not the owner'); + }); it('Will setApprovalForAll for the upgradeContract addresses in the registrar and registry to true', async () => { expect( await BaseRegistrar.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(false) + ).to.equal(false); expect( await EnsRegistry.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(false) + ).to.equal(false); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); expect( await BaseRegistrar.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(true) + ).to.equal(true); expect( await EnsRegistry.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(true) - }) + ).to.equal(true); + }); it('Will setApprovalForAll for the old upgradeContract addresses in the registrar and registry to false', async () => { //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(DUMMY_ADDRESS) + await NameWrapper.setUpgradeContract(DUMMY_ADDRESS); expect( await BaseRegistrar.isApprovedForAll( NameWrapper.address, DUMMY_ADDRESS, ), - ).to.equal(true) + ).to.equal(true); expect( await EnsRegistry.isApprovedForAll(NameWrapper.address, DUMMY_ADDRESS), - ).to.equal(true) + ).to.equal(true); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); expect( await BaseRegistrar.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(true) + ).to.equal(true); expect( await EnsRegistry.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(true) + ).to.equal(true); expect( await BaseRegistrar.isApprovedForAll( NameWrapper.address, DUMMY_ADDRESS, ), - ).to.equal(false) + ).to.equal(false); expect( await EnsRegistry.isApprovedForAll(NameWrapper.address, DUMMY_ADDRESS), - ).to.equal(false) - }) + ).to.equal(false); + }); it('Will not setApprovalForAll for the new upgrade address if it is the address(0)', async () => { //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); expect( await BaseRegistrar.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(true) + ).to.equal(true); expect( await EnsRegistry.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, ), - ).to.equal(true) + ).to.equal(true); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(ZERO_ADDRESS) + await NameWrapper.setUpgradeContract(ZERO_ADDRESS); expect( await BaseRegistrar.isApprovedForAll(NameWrapper.address, ZERO_ADDRESS), - ).to.equal(false) + ).to.equal(false); expect( await EnsRegistry.isApprovedForAll(NameWrapper.address, ZERO_ADDRESS), - ).to.equal(false) - }) - }) + ).to.equal(false); + }); + }); describe('upgrade()', () => { describe('' + '.' + BASE_DOMAIN_STR, () => { - const encodedName = encodeName('wrapped2' + '.' + BASE_DOMAIN_STR) - const label = 'wrapped2' - const labelHash = labelhash(label) - const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const encodedName = encodeName('wrapped2' + '.' + BASE_DOMAIN_STR); + const label = 'wrapped2'; + const labelHash = labelhash(label); + const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR); it('Upgrades a .eth name if sender is owner', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - const expectedExpiry = await BaseRegistrar.nameExpires(labelHash) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + const expectedExpiry = await BaseRegistrar.nameExpires(labelHash); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); //make sure reclaim claimed ownership for the wrapper in registry - expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address) - expect(await NameWrapper.ownerOf(nameHash)).to.equal(account) + expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address); + expect(await NameWrapper.ownerOf(nameHash)).to.equal(account); expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) + ); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); await BaseRegistrar.isApprovedForAll( NameWrapper.address, NameWrapperUpgraded.address, - ) - const tx = await NameWrapper.upgrade(encodedName, 0) + ); + const tx = await NameWrapper.upgrade(encodedName, 0); // check the upgraded namewrapper is called with all parameters required @@ -2197,30 +2197,30 @@ describe('Name Wrapper', () => { expectedExpiry.add(GRACE_PERIOD), EMPTY_ADDRESS, '0x00', - ) - }) + ); + }); it('Upgrades a .eth name if sender is authorised by the owner', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - const expectedExpiry = await BaseRegistrar.nameExpires(labelHash) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.setApprovalForAll(account2, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + const expectedExpiry = await BaseRegistrar.nameExpires(labelHash); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.setApprovalForAll(account2, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address) - expect(await NameWrapper.ownerOf(nameHash)).to.equal(account) + expect(await EnsRegistry.owner(nameHash)).to.equal(NameWrapper.address); + expect(await NameWrapper.ownerOf(nameHash)).to.equal(account); expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) + ); - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - const tx = await NameWrapper2.upgrade(encodedName, 0) + const tx = await NameWrapper2.upgrade(encodedName, 0); await expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') @@ -2231,69 +2231,69 @@ describe('Name Wrapper', () => { expectedExpiry.add(GRACE_PERIOD), EMPTY_ADDRESS, '0x00', - ) - }) + ); + }); it('Cannot upgrade a name if the upgradeContract has not been set.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); //allow the restricted name wrappper to transfer the name to itself and reclaim it - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect(NameWrapper.upgrade(encodedName, 0)).to.be.revertedWith( `CannotUpgrade()`, - ) - }) + ); + }); it('Cannot upgrade a name if the upgradeContract has been set and then set back to the 0 address.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + ); + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); expect(await NameWrapper.upgradeContract()).to.equal( NameWrapperUpgraded.address, - ) + ); - await NameWrapper.setUpgradeContract(EMPTY_ADDRESS) + await NameWrapper.setUpgradeContract(EMPTY_ADDRESS); await expect(NameWrapper.upgrade(encodedName, 0)).to.be.revertedWith( `CannotUpgrade()`, - ) - }) + ); + }); it('Will pass fuses and expiry to the upgradedContract without any changes.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); //allow the restricted name wrappper to transfer the name to itself and reclaim it - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CANNOT_UNWRAP | CANNOT_SET_RESOLVER, EMPTY_ADDRESS, - ) + ); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); const expectedExpiry = (await BaseRegistrar.nameExpires(labelHash)).add( GRACE_PERIOD, - ) + ); - const tx = await NameWrapper.upgrade(encodedName, 0) + const tx = await NameWrapper.upgrade(encodedName, 0); // assert the fuses and expiry have been passed through to the new NameWrapper await expect(tx) @@ -2302,81 +2302,81 @@ describe('Name Wrapper', () => { encodedName, account, PARENT_CANNOT_CONTROL | - CANNOT_UNWRAP | - CANNOT_SET_RESOLVER | - IS_DOT_ETH, + CANNOT_UNWRAP | + CANNOT_SET_RESOLVER | + IS_DOT_ETH, expectedExpiry, EMPTY_ADDRESS, '0x00', - ) - }) + ); + }); it('Will burn the token, fuses and expiry of the name in the NameWrapper contract when upgraded.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); await NameWrapper.wrapAnyLD( label, account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - await NameWrapper.upgrade(encodedName, 0) + await NameWrapper.upgrade(encodedName, 0); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS); - const [, fuses, expiry] = await NameWrapper.getData(nameHash) + const [, fuses, expiry] = await NameWrapper.getData(nameHash); expect(fuses).to.equal( CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('will revert if called twice by the original owner', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - await NameWrapper.upgrade(encodedName, 0) + await NameWrapper.upgrade(encodedName, 0); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS); await expect(NameWrapper.upgrade(encodedName, 0)).to.be.revertedWith( `Unauthorised("${nameHash}", "${account}")`, - ) - }) + ); + }); it('Will allow you to pass through extra data on upgrade', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) + await BaseRegistrar.register(labelHash, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CANNOT_UNWRAP | CANNOT_SET_RESOLVER, EMPTY_ADDRESS, - ) + ); - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); const expectedExpiry = (await BaseRegistrar.nameExpires(labelHash)).add( GRACE_PERIOD, - ) + ); - const tx = await NameWrapper.upgrade(encodedName, '0x01') + const tx = await NameWrapper.upgrade(encodedName, '0x01'); await expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') @@ -2384,95 +2384,95 @@ describe('Name Wrapper', () => { encodedName, account, PARENT_CANNOT_CONTROL | - CANNOT_UNWRAP | - CANNOT_SET_RESOLVER | - IS_DOT_ETH, + CANNOT_UNWRAP | + CANNOT_SET_RESOLVER | + IS_DOT_ETH, expectedExpiry, EMPTY_ADDRESS, '0x01', - ) - }) + ); + }); it('Does not allow anyone else to upgrade a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - await BaseRegistrar.register(labelHash, account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.register(labelHash, account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); await expect(NameWrapper2.upgrade(encodedName, 0)).to.be.revertedWith( `Unauthorised("${nameHash}", "${account2}")`, - ) - }) - }) + ); + }); + }); describe('other', () => { - const label = 'to-upgrade' - const parentLabel = 'wrapped2' - const name = label + '.' + parentLabel + '' + '.' + BASE_DOMAIN_STR - const parentLabelHash = labelhash(parentLabel) - const parentHash = namehash(parentLabel + '' + '.' + BASE_DOMAIN_STR) - const nameHash = namehash(name) - const encodedName = encodeName(name) + const label = 'to-upgrade'; + const parentLabel = 'wrapped2'; + const name = label + '.' + parentLabel + '' + '.' + BASE_DOMAIN_STR; + const parentLabelHash = labelhash(parentLabel); + const parentHash = namehash(parentLabel + '' + '.' + BASE_DOMAIN_STR); + const nameHash = namehash(name); + const encodedName = encodeName(name); it('Allows owner to upgrade name', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(parentLabelHash, account, 1 * DAY) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(parentLabelHash, account, 1 * DAY); await NameWrapper.wrapAnyLD( parentLabel, account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); await NameWrapper.setSubnodeOwner( parentHash, 'to-upgrade', account, 0, 0, - ) - const ownerOfWrapped = await NameWrapper.ownerOf(nameHash) - expect(ownerOfWrapped).to.equal(account) + ); + const ownerOfWrapped = await NameWrapper.ownerOf(nameHash); + expect(ownerOfWrapped).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - const tx = await NameWrapper.upgrade(encodedName, 0) + const tx = await NameWrapper.upgrade(encodedName, 0); await expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') - .withArgs(encodedName, account, 0, 0, EMPTY_ADDRESS, '0x00') - }) + .withArgs(encodedName, account, 0, 0, EMPTY_ADDRESS, '0x00'); + }); it('upgrades a name if sender is authorized by the owner', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.setApprovalForAll(account2, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.setApprovalForAll(account2, true); - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('xyz'), 'to-upgrade', account, 0, 0, - ) + ); const ownerOfWrappedXYZ = await NameWrapper.ownerOf( namehash('to-upgrade.xyz'), - ) - expect(ownerOfWrappedXYZ).to.equal(account) + ); + expect(ownerOfWrappedXYZ).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - const tx = await NameWrapper2.upgrade(encodeName('to-upgrade.xyz'), 0) + const tx = await NameWrapper2.upgrade(encodeName('to-upgrade.xyz'), 0); await expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') @@ -2483,57 +2483,57 @@ describe('Name Wrapper', () => { 0, EMPTY_ADDRESS, '0x00', - ) - }) + ); + }); it('Cannot upgrade a name if the upgradeContract has not been set.', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('xyz'), 'to-upgrade', account, 0, 0, - ) + ); const ownerOfWrappedXYZ = await NameWrapper.ownerOf( namehash('to-upgrade.xyz'), - ) - expect(ownerOfWrappedXYZ).to.equal(account) + ); + expect(ownerOfWrappedXYZ).to.equal(account); await expect( NameWrapper.upgrade(encodeName('to-upgrade.xyz'), 0), - ).to.be.revertedWith(`CannotUpgrade()`) - }) + ).to.be.revertedWith(`CannotUpgrade()`); + }); it('Will pass fuses and expiry to the upgradedContract without any changes.', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(parentLabelHash, account, 1 * DAY) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(parentLabelHash, account, 1 * DAY); await NameWrapper.wrapAnyLD( parentLabel, account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); const expectedFuses = - PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER + PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER; await NameWrapper.setSubnodeOwner( parentHash, label, account, expectedFuses, MAX_EXPIRY, - ) - const ownerOfWrapped = await NameWrapper.ownerOf(namehash(name)) - expect(ownerOfWrapped).to.equal(account) + ); + const ownerOfWrapped = await NameWrapper.ownerOf(namehash(name)); + expect(ownerOfWrapped).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - const tx = await NameWrapper.upgrade(encodeName(name), 0) + const tx = await NameWrapper.upgrade(encodeName(name), 0); - const expectedExpiry = await BaseRegistrar.nameExpires(parentLabelHash) + const expectedExpiry = await BaseRegistrar.nameExpires(parentLabelHash); await expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') @@ -2544,80 +2544,80 @@ describe('Name Wrapper', () => { expectedExpiry.add(GRACE_PERIOD), EMPTY_ADDRESS, '0x00', - ) - }) + ); + }); it('Will burn the token of the name in the NameWrapper contract when upgraded, but keep expiry and fuses', async () => { - const FUSES = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(parentLabelHash, account, 1 * DAY) - const parentExpiry = await BaseRegistrar.nameExpires(parentLabelHash) + const FUSES = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER; + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(parentLabelHash, account, 1 * DAY); + const parentExpiry = await BaseRegistrar.nameExpires(parentLabelHash); await NameWrapper.wrapAnyLD( parentLabel, account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); await NameWrapper.setSubnodeOwner( parentHash, label, account, FUSES, MAX_EXPIRY, - ) - const ownerOfWrapped = await NameWrapper.ownerOf(nameHash) - expect(ownerOfWrapped).to.equal(account) + ); + const ownerOfWrapped = await NameWrapper.ownerOf(nameHash); + expect(ownerOfWrapped).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - await NameWrapper.upgrade(encodedName, 0) + await NameWrapper.upgrade(encodedName, 0); - expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(nameHash)).to.equal(EMPTY_ADDRESS); - const [, fuses, expiry] = await NameWrapper.getData(nameHash) + const [, fuses, expiry] = await NameWrapper.getData(nameHash); - expect(fuses).to.equal(FUSES) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(FUSES); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('reverts if called twice by the original owner', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(parentLabelHash, account, 1 * DAY) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(parentLabelHash, account, 1 * DAY); await NameWrapper.wrapAnyLD( parentLabel, account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); await NameWrapper.setSubnodeOwner( parentHash, label, account, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER, MAX_EXPIRY, - ) - const ownerOfWrapped = await NameWrapper.ownerOf(nameHash) - expect(ownerOfWrapped).to.equal(account) + ); + const ownerOfWrapped = await NameWrapper.ownerOf(nameHash); + expect(ownerOfWrapped).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - await NameWrapper.upgrade(encodedName, 0) + await NameWrapper.upgrade(encodedName, 0); await expect(NameWrapper.upgrade(encodedName, 0)).to.be.revertedWith( `Unauthorised("${namehash( 'to-upgrade.wrapped2' + '.' + BASE_DOMAIN_STR, )}", "${account}")`, - ) - }) + ); + }); it('Keep approval information on upgrade', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await NameWrapper.setSubnodeRecord( namehash('xyz'), @@ -2627,31 +2627,31 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); const ownerOfWrappedXYZ = await NameWrapper.ownerOf( namehash('to-upgrade.xyz'), - ) - expect(ownerOfWrappedXYZ).to.equal(account) + ); + expect(ownerOfWrappedXYZ).to.equal(account); // set approval - await NameWrapper.approve(account3, namehash('to-upgrade.xyz')) + await NameWrapper.approve(account3, namehash('to-upgrade.xyz')); expect( await NameWrapper.getApproved(namehash('to-upgrade.xyz')), - ).to.equal(account3) + ).to.equal(account3); // set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); - const tx = await NameWrapper.upgrade(encodeName('to-upgrade.xyz'), '0x') + const tx = await NameWrapper.upgrade(encodeName('to-upgrade.xyz'), '0x'); expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') - .withArgs(encodeName('to-upgrade.xyz'), account, 0, 0, account3, '0x') - }) + .withArgs(encodeName('to-upgrade.xyz'), account, 0, 0, account3, '0x'); + }); it('Will allow you to pass through extra data on upgrade', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await NameWrapper.setSubnodeRecord( namehash('xyz'), @@ -2661,19 +2661,19 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); const ownerOfWrappedXYZ = await NameWrapper.ownerOf( namehash('to-upgrade.xyz'), - ) - expect(ownerOfWrappedXYZ).to.equal(account) + ); + expect(ownerOfWrappedXYZ).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); const tx = await NameWrapper.upgrade( encodeName('to-upgrade.xyz'), '0x01', - ) + ); expect(tx) .to.emit(NameWrapperUpgraded, 'NameUpgraded') @@ -2684,13 +2684,13 @@ describe('Name Wrapper', () => { 0, EMPTY_ADDRESS, '0x01', - ) - }) + ); + }); it('Does not allow anyone else to upgrade a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('xyz'), @@ -2698,34 +2698,34 @@ describe('Name Wrapper', () => { account, 0, 0, - ) + ); const ownerOfWrappedXYZ = await NameWrapper.ownerOf( namehash('to-upgrade.xyz'), - ) - expect(ownerOfWrappedXYZ).to.equal(account) + ); + expect(ownerOfWrappedXYZ).to.equal(account); //set the upgradeContract of the NameWrapper contract - await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address) + await NameWrapper.setUpgradeContract(NameWrapperUpgraded.address); await expect( NameWrapper2.upgrade(encodeName('to-upgrade.xyz'), 0), ).to.be.revertedWith( `Unauthorised("${namehash('to-upgrade.xyz')}", "${account2}")`, - ) - }) - }) - }) + ); + }); + }); + }); describe('setFuses()', () => { - const label = 'fuses' - const tokenId = labelhash('fuses') - const wrappedTokenId = namehash('fuses' + '.' + BASE_DOMAIN_STR) + const label = 'fuses'; + const tokenId = labelhash('fuses'); + const wrappedTokenId = namehash('fuses' + '.' + BASE_DOMAIN_STR); it('cannot burn PARENT_CANNOT_CONTROL', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -2733,22 +2733,22 @@ describe('Name Wrapper', () => { account, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) + ); try { await NameWrapper.setFuses( namehash('sub.abc' + '.' + BASE_DOMAIN_STR), PARENT_CANNOT_CONTROL, - ) + ); } catch (e) { - expect(e.reason).to.equal('value out-of-bounds') + expect(e.reason).to.equal('value out-of-bounds'); } - }) + }); it('cannot burn any parent controlled fuse', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -2756,7 +2756,7 @@ describe('Name Wrapper', () => { account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // check the 7 fuses above PCC for (let i = 0; i < 7; i++) { @@ -2764,17 +2764,17 @@ describe('Name Wrapper', () => { await NameWrapper.setFuses( namehash('sub.abc' + '.' + BASE_DOMAIN_STR), IS_DOT_ETH * 2 ** i, - ) + ); } catch (e) { - expect(e.reason).to.contain('value out-of-bounds') + expect(e.reason).to.contain('value out-of-bounds'); } } - }) + }); it('Errors when manually changing calldata to incorrect type', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -2782,31 +2782,31 @@ describe('Name Wrapper', () => { account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); const tx = await NameWrapper.populateTransaction.setFuses( namehash('sub.abc' + '.' + BASE_DOMAIN_STR), 4, - ) - const rogueFuse = '40000' // 2 ** 18 in hex - tx.data = tx.data.substring(0, tx.data.length - rogueFuse.length) - tx.data += String(rogueFuse) + ); + const rogueFuse = '40000'; // 2 ** 18 in hex + tx.data = tx.data.substring(0, tx.data.length - rogueFuse.length); + tx.data += String(rogueFuse); try { - await signers[0].sendTransaction(tx) + await signers[0].sendTransaction(tx); } catch (e) { expect(e.message).to.equal( `Transaction reverted: function was called with incorrect parameters`, - ) + ); } - }) + }); it('cannot burn fuses as the previous owner of a .eth when the name has expired', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await evm.mine(); await expect( NameWrapper.setFuses( @@ -2817,13 +2817,13 @@ describe('Name Wrapper', () => { `Unauthorised("${namehash( 'abc' + '.' + BASE_DOMAIN_STR, )}", "${account}")`, - ) - }) + ); + }); it('cannot burn fuses as a previous owner of a non .eth when the name has expired', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -2831,10 +2831,10 @@ describe('Name Wrapper', () => { account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await evm.mine(); await expect( NameWrapper.setFuses( @@ -2845,13 +2845,13 @@ describe('Name Wrapper', () => { `Unauthorised("${namehash( 'sub.abc' + '.' + BASE_DOMAIN_STR, )}", "${account}")`, - ) - }) + ); + }); it('Will not allow burning fuses if PARENT_CANNOT_CONTROL has not been burned', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -2859,7 +2859,7 @@ describe('Name Wrapper', () => { account, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) + ); await expect( NameWrapper.setFuses( @@ -2868,13 +2868,13 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `OperationProhibited("0xd38c24c7d9e9cab5d2d760f9f82230cbd32757c1e9d63aa59fabe5e6eeed0c45")`, - ) - }) + ); + }); it('Will not allow burning fuses of subdomains if CANNOT_UNWRAP has not been burned', async () => { - await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY) - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash('abc'), account, 1 * DAY); + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrapAnyLD('abc', account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( namehash('abc' + '.' + BASE_DOMAIN_STR), @@ -2882,7 +2882,7 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); await expect( NameWrapper.setFuses( @@ -2891,220 +2891,220 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `OperationProhibited("0xd38c24c7d9e9cab5d2d760f9f82230cbd32757c1e9d63aa59fabe5e6eeed0c45")`, - ) - }) + ); + }); it('Will not allow burning fuses of .eth names unless CANNOT_UNWRAP is also burned.', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect( NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('Can be called by the owner', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); - let [, fuses] = await NameWrapper.getData(wrappedTokenId) - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH) + let [, fuses] = await NameWrapper.getData(wrappedTokenId); + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH); await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER) - ;[, fuses] = await NameWrapper.getData(wrappedTokenId) + ;[, fuses] = await NameWrapper.getData(wrappedTokenId); expect(fuses).to.equal( CANNOT_UNWRAP | CANNOT_TRANSFER | PARENT_CANNOT_CONTROL | IS_DOT_ETH, - ) - }) + ); + }); it('Emits FusesSet event', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); const expectedExpiry = - (await BaseRegistrar.nameExpires(tokenId)).toNumber() + GRACE_PERIOD - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + (await BaseRegistrar.nameExpires(tokenId)).toNumber() + GRACE_PERIOD; + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); - const tx = await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER) + const tx = await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER); await expect(tx) .to.emit(NameWrapper, 'FusesSet') .withArgs( wrappedTokenId, CANNOT_UNWRAP | CANNOT_TRANSFER | PARENT_CANNOT_CONTROL | IS_DOT_ETH, - ) + ); - const [, fuses, expiry] = await NameWrapper.getData(wrappedTokenId) + const [, fuses, expiry] = await NameWrapper.getData(wrappedTokenId); expect(fuses).to.equal( CANNOT_UNWRAP | CANNOT_TRANSFER | PARENT_CANNOT_CONTROL | IS_DOT_ETH, - ) - expect(expiry).to.equal(expectedExpiry) - }) + ); + expect(expiry).to.equal(expectedExpiry); + }); it('Returns the correct fuses', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); const expectedExpiry = - (await BaseRegistrar.nameExpires(tokenId)).toNumber() + GRACE_PERIOD - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + (await BaseRegistrar.nameExpires(tokenId)).toNumber() + GRACE_PERIOD; + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); // The function callStatic is called to get the return value of the function. // Note: callStatic does not modify the state of the contract. const fusesReturned = await NameWrapper.callStatic.setFuses( wrappedTokenId, CANNOT_TRANSFER, - ) + ); expect(fusesReturned).to.equal( CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH, - ) - }) + ); + }); it('Can be called by an account authorised by the owner', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); - await NameWrapper.setApprovalForAll(account2, true) + await NameWrapper.setApprovalForAll(account2, true); - await NameWrapper2.setFuses(wrappedTokenId, CANNOT_UNWRAP) + await NameWrapper2.setFuses(wrappedTokenId, CANNOT_UNWRAP); - const [, fuses] = await NameWrapper.getData(wrappedTokenId) - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH) - }) + const [, fuses] = await NameWrapper.getData(wrappedTokenId); + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH); + }); it('Cannot be called by an unauthorised account', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); await expect( NameWrapper2.setFuses( wrappedTokenId, CAN_DO_EVERYTHING | CANNOT_UNWRAP, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Allows burning unknown fuses', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); // Each fuse is represented by the next bit, 64 is the next undefined fuse - await NameWrapper.setFuses(wrappedTokenId, 64) + await NameWrapper.setFuses(wrappedTokenId, 64); - const [, fuses] = await NameWrapper.getData(wrappedTokenId) + const [, fuses] = await NameWrapper.getData(wrappedTokenId); expect(fuses).to.equal( CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH | 64, - ) - }) + ); + }); it('Logically ORs passed in fuses with already-burned fuses.', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); await NameWrapper.wrapAnyLD( label, account, CANNOT_UNWRAP | CANNOT_TRANSFER, EMPTY_ADDRESS, - ) + ); - await NameWrapper.setFuses(wrappedTokenId, 64 | CANNOT_TRANSFER) + await NameWrapper.setFuses(wrappedTokenId, 64 | CANNOT_TRANSFER); - const [, fuses] = await NameWrapper.getData(wrappedTokenId) + const [, fuses] = await NameWrapper.getData(wrappedTokenId); expect(fuses).to.equal( CANNOT_UNWRAP | - PARENT_CANNOT_CONTROL | - IS_DOT_ETH | - 64 | - CANNOT_TRANSFER, - ) - }) + PARENT_CANNOT_CONTROL | + IS_DOT_ETH | + 64 | + CANNOT_TRANSFER, + ); + }); it('can set fuses and then burn ability to burn fuses', async () => { - const label = 'burnabilitytoburn' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const CAN_DO_EVERYTHING = 0 + const label = 'burnabilitytoburn'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const CAN_DO_EVERYTHING = 0; - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); - await NameWrapper.setFuses(wrappedTokenId, CANNOT_BURN_FUSES) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_BURN_FUSES); - const ownerInWrapper = await NameWrapper.ownerOf(wrappedTokenId) + const ownerInWrapper = await NameWrapper.ownerOf(wrappedTokenId); - expect(ownerInWrapper).to.equal(account) + expect(ownerInWrapper).to.equal(account); // check flag in the wrapper expect( await NameWrapper.allFusesBurned(wrappedTokenId, CANNOT_BURN_FUSES), - ).to.equal(true) + ).to.equal(true); //try to set the resolver and ttl await expect( NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}"`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}"`); + }); it('can set fuses and burn transfer', async () => { - const [, signer2] = await ethers.getSigners() - const account2 = await signer2.getAddress() - const label = 'fuses3' - const tokenId = labelhash('fuses3') - const wrappedTokenId = namehash('fuses3' + '.' + BASE_DOMAIN_STR) + const [, signer2] = await ethers.getSigners(); + const account2 = await signer2.getAddress(); + const label = 'fuses3'; + const tokenId = labelhash('fuses3'); + const wrappedTokenId = namehash('fuses3' + '.' + BASE_DOMAIN_STR); - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); - await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER); - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // check flag in the wrapper expect( await NameWrapper.allFusesBurned(wrappedTokenId, CANNOT_TRANSFER), - ).to.equal(true) + ).to.equal(true); //Transfer should revert await expect( @@ -3115,27 +3115,27 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('can set fuses and burn canSetResolver and canSetTTL', async () => { - const label = 'fuses1' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const CAN_DO_EVERYTHING = 0 + const label = 'fuses1'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const CAN_DO_EVERYTHING = 0; - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setFuses( wrappedTokenId, CANNOT_SET_RESOLVER | CANNOT_SET_TTL, - ) + ); - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // check flag in the wrapper expect( @@ -3143,35 +3143,35 @@ describe('Name Wrapper', () => { wrappedTokenId, CANNOT_SET_RESOLVER | CANNOT_SET_TTL, ), - ).to.equal(true) + ).to.equal(true); //try to set the resolver and ttl await expect( NameWrapper.setResolver(wrappedTokenId, account), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); await expect(NameWrapper.setTTL(wrappedTokenId, 1000)).to.be.revertedWith( `OperationProhibited("${wrappedTokenId}")`, - ) - }) + ); + }); it('can set fuses and burn canCreateSubdomains', async () => { - const label = 'fuses2' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'fuses2'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); expect( await NameWrapper.allFusesBurned( wrappedTokenId, CANNOT_CREATE_SUBDOMAIN, ), - ).to.equal(false) + ).to.equal(false); // can create before burn @@ -3182,35 +3182,35 @@ describe('Name Wrapper', () => { account, CAN_DO_EVERYTHING, 0, - ) + ); expect( await EnsRegistry.owner( namehash('creatable.fuses2' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); expect( await NameWrapper.ownerOf( namehash('creatable.fuses2' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account) + ).to.equal(account); await NameWrapper.setFuses( wrappedTokenId, CAN_DO_EVERYTHING | CANNOT_CREATE_SUBDOMAIN, - ) + ); - const ownerInWrapper = await NameWrapper.ownerOf(wrappedTokenId) + const ownerInWrapper = await NameWrapper.ownerOf(wrappedTokenId); - expect(ownerInWrapper).to.equal(account) + expect(ownerInWrapper).to.equal(account); expect( await NameWrapper.allFusesBurned( wrappedTokenId, CANNOT_CREATE_SUBDOMAIN, ), - ).to.equal(true) + ).to.equal(true); //try to create a subdomain @@ -3226,33 +3226,33 @@ describe('Name Wrapper', () => { `OperationProhibited("${namehash( 'uncreatable.fuses2' + '.' + BASE_DOMAIN_STR, )}")`, - ) - }) - }) + ); + }); + }); describe('extendExpiry()', () => { - const label = 'fuses' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(`${label}.${BASE_DOMAIN_STR}`) - const subWrappedTokenId = namehash(`sub.${label}.${BASE_DOMAIN_STR}`) + const label = 'fuses'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(`${label}.${BASE_DOMAIN_STR}`); + const subWrappedTokenId = namehash(`sub.${label}.${BASE_DOMAIN_STR}`); it('Allows parent owner to set expiry without CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry - 3600) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper.extendExpiry( wrappedTokenId, @@ -3261,31 +3261,31 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Allows parent owner to set expiry with CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper.extendExpiry( wrappedTokenId, @@ -3294,33 +3294,33 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Allows parent owner to set expiry with same child owner and CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper.extendExpiry( wrappedTokenId, @@ -3329,34 +3329,34 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Allows approved operators of parent owner to set expiry without CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry - 3600) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry - 3600); // approve hacker for anything account owns - await NameWrapper.setApprovalForAll(hacker, true) + await NameWrapper.setApprovalForAll(hacker, true); await NameWrapperH.extendExpiry( wrappedTokenId, @@ -3365,34 +3365,34 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Allows approved operators of parent owner to set expiry with CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); // approve hacker for anything account owns - await NameWrapper.setApprovalForAll(hacker, true) + await NameWrapper.setApprovalForAll(hacker, true); await NameWrapperH.extendExpiry( wrappedTokenId, @@ -3401,56 +3401,56 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Does not allow child owner to set expiry without CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry - 3600) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry - 3600); await expect( NameWrapper2.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Allows child owner to set expiry with CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper2.extendExpiry( wrappedTokenId, @@ -3459,62 +3459,62 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Does not allow approved operator of child owner to set expiry without CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry - 3600) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry - 3600); // approve hacker for anything account2 owns - await NameWrapper2.setApprovalForAll(hacker, true) + await NameWrapper2.setApprovalForAll(hacker, true); await expect( NameWrapperH.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Allows approved operator of child owner to set expiry with CAN_EXTEND_EXPIRY burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); // approve hacker for anything account2 owns - await NameWrapper2.setApprovalForAll(hacker, true) + await NameWrapper2.setApprovalForAll(hacker, true); await NameWrapperH.extendExpiry( wrappedTokenId, @@ -3523,70 +3523,70 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Does not allow accounts other than parent/child owners or approved operators to set expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await expect( NameWrapperH.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`Unauthorised("${subWrappedTokenId}", "${hacker}")`) - }) + ).to.be.revertedWith(`Unauthorised("${subWrappedTokenId}", "${hacker}")`); + }); it('Does not allow owner of .eth 2LD to set expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); let [, fuses, expiry] = await NameWrapper.getData( namehash('fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(IS_DOT_ETH | PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) + expect(fuses).to.equal(IS_DOT_ETH | PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); await expect( NameWrapper.extendExpiry(namehash(BASE_DOMAIN_STR), tokenId, expiry), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('Allows parent owner of non-Emancipated name to set expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, 0, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry - 3600) + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper.extendExpiry( wrappedTokenId, @@ -3595,29 +3595,29 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Allows child owner of non-Emancipated name to set expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(CAN_EXTEND_EXPIRY) - expect(expiry).to.equal(parentExpiry - 3600) + expect(fuses).to.equal(CAN_EXTEND_EXPIRY); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper2.extendExpiry( wrappedTokenId, @@ -3626,31 +3626,31 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(CAN_EXTEND_EXPIRY) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(CAN_EXTEND_EXPIRY); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Expiry is normalized to old expiry if too low', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper2.extendExpiry( wrappedTokenId, @@ -3659,33 +3659,33 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) - }) + ); + expect(expiry).to.equal(parentExpiry - 3600); + }); it('Expiry is normalized to parent expiry if too high', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper2.extendExpiry( wrappedTokenId, @@ -3694,33 +3694,33 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Expiry is not normalized to new value if between old expiry and parent expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 3600) + ); + expect(expiry).to.equal(parentExpiry - 3600); await NameWrapper2.extendExpiry( wrappedTokenId, @@ -3729,64 +3729,64 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry - 1800) - }) + ); + expect(expiry).to.equal(parentExpiry - 1800); + }); it('Does not allow .eth 2LD owner to set expiry on child if the .eth 2LD is expired but grace period has not ended', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, parentExpiry.add(GRACE_PERIOD - 3600), - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD - 3600)) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD - 3600)); // Fast forward until the 2LD expires - await increaseTime(DAY + 1) - await mine() + await increaseTime(DAY + 1); + await mine(); await expect( NameWrapper.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`Unauthorised("${subWrappedTokenId}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${subWrappedTokenId}", "${account}")`); + }); it('Allows child owner to set expiry if parent .eth 2LD is expired but grace period has not ended', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry.add(GRACE_PERIOD - 3600), - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD - 3600)) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD - 3600)); // Fast forward until the 2LD expires - await increaseTime(DAY + 1) - await mine() + await increaseTime(DAY + 1); + await mine(); await NameWrapper2.extendExpiry( wrappedTokenId, @@ -3795,124 +3795,124 @@ describe('Name Wrapper', () => { ) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, - ) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + ); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Does not allow child owner to set expiry if Emancipated child name has expired', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CAN_EXTEND_EXPIRY, parentExpiry - DAY + 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CAN_EXTEND_EXPIRY) - expect(expiry).to.equal(parentExpiry - DAY + 3600) + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CAN_EXTEND_EXPIRY); + expect(expiry).to.equal(parentExpiry - DAY + 3600); // Fast forward until the child name expires - await increaseTime(3601) - await mine() + await increaseTime(3601); + await mine(); await expect( NameWrapper2.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`NameIsNotWrapped()`) - }) + ).to.be.revertedWith(`NameIsNotWrapped()`); + }); it('Does not allow child owner to set expiry if non-Emancipated child name has reached its expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, CAN_EXTEND_EXPIRY, parentExpiry - DAY + 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(CAN_EXTEND_EXPIRY) - expect(expiry).to.equal(parentExpiry - DAY + 3600) + expect(fuses).to.equal(CAN_EXTEND_EXPIRY); + expect(expiry).to.equal(parentExpiry - DAY + 3600); // Fast forward until the child name expires - await increaseTime(3601) - await mine() + await increaseTime(3601); + await mine(); await expect( NameWrapper2.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Does not allow parent owner to set expiry if Emancipated child name has expired', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL, parentExpiry - DAY + 3600, - ) + ); let [owner, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(owner).to.equal(account2) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(parentExpiry - DAY + 3600) + expect(owner).to.equal(account2); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(parentExpiry - DAY + 3600); // Fast forward until the child name expires - await increaseTime(3601) + await increaseTime(3601); await mine() ;[owner, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(owner).to.equal(EMPTY_ADDRESS) - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry - DAY + 3600) + expect(owner).to.equal(EMPTY_ADDRESS); + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry - DAY + 3600); await expect( NameWrapper.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`NameIsNotWrapped()`) - }) + ).to.be.revertedWith(`NameIsNotWrapped()`); + }); it('Allows parent owner to set expiry if non-Emancipated child name has reached its expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, 0, parentExpiry - DAY + 3600, - ) + ); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry - DAY + 3600) + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry - DAY + 3600); // Fast forward until the child name expires - await increaseTime(3601) - await mine() + await increaseTime(3601); + await mine(); await NameWrapper.extendExpiry( wrappedTokenId, @@ -3921,33 +3921,33 @@ describe('Name Wrapper', () => { ) ;[owner, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(owner).to.equal(account2) - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(owner).to.equal(account2); + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Does not allow extendExpiry() to be called on unregistered names (not registered ever)', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); let [owner, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(owner).to.equal(EMPTY_ADDRESS) - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(owner).to.equal(EMPTY_ADDRESS); + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); await expect( NameWrapper.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`NameIsNotWrapped()`) - }) + ).to.be.revertedWith(`NameIsNotWrapped()`); + }); it('Does not allow extendExpiry() to be called on unregistered names (expired w/ PCC burnt)', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP, 10 * DAY) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP, 10 * DAY); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -3955,21 +3955,21 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL, parentExpiry - 5 * DAY, - ) + ); // Advance time so the subdomain expires, but not the parent - await evm.advanceTime(5 * DAY + 1) - await evm.mine() + await evm.advanceTime(5 * DAY + 1); + await evm.mine(); // extendExpiry() on the unregistered name will be reverted await expect( NameWrapper.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`NameIsNotWrapped()`) - }) + ).to.be.revertedWith(`NameIsNotWrapped()`); + }); it('Allow extendExpiry() to be called on wrapped names', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP, 10 * DAY) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP, 10 * DAY); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -3977,188 +3977,188 @@ describe('Name Wrapper', () => { account, CAN_EXTEND_EXPIRY, parentExpiry - 5 * DAY, - ) + ); // Advance time so the subdomain expires, but not the parent - await evm.advanceTime(5 * DAY + 1) - await evm.mine() + await evm.advanceTime(5 * DAY + 1); + await evm.mine(); await NameWrapper.extendExpiry( wrappedTokenId, labelhash('sub'), MAX_EXPIRY, - ) + ); let [owner, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(owner).to.equal(account) - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - }) + expect(owner).to.equal(account); + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + }); it('Does not allow extendExpiry() to be called on unwrapped names', async () => { - await registerSetupAndWrapName('fuses', account, 0) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, 0); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, 0, parentExpiry - 3600, - ) + ); // First unwrap the parent - await NameWrapper.unwrapAnyLD(tokenId, account, account) + await NameWrapper.unwrapAnyLD(tokenId, account, account); // Then manually change the registry owner outside of the wrapper await EnsRegistry.setSubnodeOwner( wrappedTokenId, labelhash('sub'), account, - ) + ); // Rewrap the parent await NameWrapper.wrapAnyLD( 'fuses', account, CANNOT_UNWRAP, EMPTY_ADDRESS, - ) + ); let [owner, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(owner).to.equal(account) - expect(fuses).to.equal(0) - expect(expiry).to.equal(parentExpiry - 3600) + expect(owner).to.equal(account); + expect(fuses).to.equal(0); + expect(expiry).to.equal(parentExpiry - 3600); // Verify the registry owner is the account and not the wrapper contract let registryOwner = await EnsRegistry.owner( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) - expect(registryOwner).to.equal(account) + ); + expect(registryOwner).to.equal(account); await expect( NameWrapper.extendExpiry(wrappedTokenId, labelhash('sub'), MAX_EXPIRY), - ).to.be.revertedWith(`NameIsNotWrapped()`) - }) + ).to.be.revertedWith(`NameIsNotWrapped()`); + }); it('Emits Expiry Extended event', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(tokenId) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CAN_EXTEND_EXPIRY, parentExpiry - 3600, - ) + ); const tx = await NameWrapper2.extendExpiry( wrappedTokenId, labelhash('sub'), MAX_EXPIRY, - ) + ); await expect(tx) .to.emit(NameWrapper, 'ExpiryExtended') .withArgs( namehash(`sub.${label}.${BASE_DOMAIN_STR}`), parentExpiry.add(GRACE_PERIOD), - ) - }) - }) + ); + }); + }); describe('setChildFuses()', () => { - const label = 'fuses' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(`${label}.${BASE_DOMAIN_STR}`) - const subWrappedTokenId = namehash(`sub.${label}.${BASE_DOMAIN_STR}`) + const label = 'fuses'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(`${label}.${BASE_DOMAIN_STR}`); + const subWrappedTokenId = namehash(`sub.${label}.${BASE_DOMAIN_STR}`); it('Allows parent owners to set fuses/expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); const expectedExpiry = await BaseRegistrar.nameExpires(tokenId) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)); + }); it('Emits a FusesSet event and ExpiryExtended event', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); const tx = await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); const expectedExpiry = await BaseRegistrar.nameExpires(tokenId) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)) + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)); await expect(tx) .to.emit(NameWrapper, 'FusesSet') - .withArgs(subWrappedTokenId, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL) + .withArgs(subWrappedTokenId, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL); await expect(tx) .to.emit(NameWrapper, 'ExpiryExtended') - .withArgs(subWrappedTokenId, expectedExpiry.add(GRACE_PERIOD)) - }) + .withArgs(subWrappedTokenId, expectedExpiry.add(GRACE_PERIOD)); + }); it('Allows special cased TLD owners to set fuses/expiry', async () => { await EnsRegistry.setSubnodeOwner( ROOT_NODE, labelhash('anothertld'), account, - ) + ); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('anothertld'), account, ZERO_ADDRESS) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('anothertld'), account, ZERO_ADDRESS); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); const block = await ethers.provider.getBlock( await ethers.provider.getBlockNumber(), - ) + ); - const expectedExpiry = block.timestamp + 1000 + const expectedExpiry = block.timestamp + 1000; await NameWrapper.setChildFuses( ROOT_NODE, @@ -4166,22 +4166,22 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, expectedExpiry, ) - ;[, fuses, expiry] = await NameWrapper.getData(namehash('anothertld')) + ;[, fuses, expiry] = await NameWrapper.getData(namehash('anothertld')); - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(expectedExpiry) - }) + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(expectedExpiry); + }); it('does not allow parent owners to burn IS_DOT_ETH fuse', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); await expect( NameWrapper.setChildFuses( @@ -4190,51 +4190,51 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH, MAX_EXPIRY, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Allow parent owners to burn parent controlled fuses without burning PCC', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), IS_DOT_ETH * 2, //Next undefined parent controlled fuse MAX_EXPIRY, - ) + ); const [, fusesAfter] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fusesAfter).to.equal(IS_DOT_ETH * 2) - }) + expect(fusesAfter).to.equal(IS_DOT_ETH * 2); + }); it('Does not allow parent owners to burn parent controlled fuses after burning PCC', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); await expect( NameWrapper.setChildFuses( wrappedTokenId, @@ -4246,48 +4246,48 @@ describe('Name Wrapper', () => { `OperationProhibited("${namehash( 'sub.fuses' + '.' + BASE_DOMAIN_STR, )}")`, - ) - }) + ); + }); it('Allows accounts authorised by the parent node owner to set fuses/expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); let [, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); // approve account2 for anything account owns - await NameWrapper.setApprovalForAll(account2, true) + await NameWrapper.setApprovalForAll(account2, true); await NameWrapper2.setChildFuses( wrappedTokenId, labelhash('sub'), CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); const expectedExpiry = await BaseRegistrar.nameExpires(tokenId) ;[, fuses, expiry] = await NameWrapper.getData( namehash('sub.fuses' + '.' + BASE_DOMAIN_STR), - ) + ); - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)) - }) + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)); + }); it('Does not allow non-parent owners to set child fuses', async () => { - const subWrappedTokenId = namehash('sub.fuses' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + const subWrappedTokenId = namehash('sub.fuses' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); - let [, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId) + let [, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); await expect( NameWrapper2.setChildFuses( @@ -4296,41 +4296,41 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Normalises expiry to the parent expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); - let [, , expiry] = await NameWrapper.getData(subWrappedTokenId) + let [, , expiry] = await NameWrapper.getData(subWrappedTokenId); - expect(expiry).to.equal(0) + expect(expiry).to.equal(0); await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // expiry of parent const [, , expectedExpiry] = await NameWrapper.getData(wrappedTokenId) - ;[, , expiry] = await NameWrapper.getData(subWrappedTokenId) + ;[, , expiry] = await NameWrapper.getData(subWrappedTokenId); - expect(expiry).to.equal(expectedExpiry) - }) + expect(expiry).to.equal(expectedExpiry); + }); it('Normalises expiry to the old expiry', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 1000) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 1000); - let [, , expiry] = await NameWrapper.getData(subWrappedTokenId) + let [, , expiry] = await NameWrapper.getData(subWrappedTokenId); - expect(expiry).to.equal(1000) + expect(expiry).to.equal(1000); await NameWrapper.setChildFuses( wrappedTokenId, @@ -4338,16 +4338,16 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, 500, ) - ;[, , expiry] = await NameWrapper.getData(subWrappedTokenId) + ;[, , expiry] = await NameWrapper.getData(subWrappedTokenId); // normalises to 1000 instead of using 500 - expect(expiry).to.equal(1000) - }) + expect(expiry).to.equal(1000); + }); it('Does not allow burning fuses if PARENT_CANNOT_CONTROL is not burnt', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); await expect( NameWrapper.setChildFuses( @@ -4356,11 +4356,11 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP, MAX_EXPIRY, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('should not allow .eth to call setChildFuses()', async () => { - await registerSetupAndWrapName('fuses', account, 0) + await registerSetupAndWrapName('fuses', account, 0); await expect( NameWrapper.setChildFuses( @@ -4371,13 +4371,13 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `Unauthorised("${namehash(BASE_DOMAIN_STR)}", "${account}")`, - ) - }) + ); + }); it('Does not allow burning fuses if CANNOT_UNWRAP is not burnt', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - const timestamp = (await ethers.provider.getBlock('latest')).timestamp + const timestamp = (await ethers.provider.getBlock('latest')).timestamp; // set up child's PCC await NameWrapper.setSubnodeOwner( @@ -4386,7 +4386,7 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL, timestamp + 10000, - ) + ); // attempt to burn a fuse without CANNOT_UNWRAP await expect( @@ -4396,22 +4396,22 @@ describe('Name Wrapper', () => { CANNOT_SET_RESOLVER, 0, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Does not allow burning fuses if PARENT_CANNOT_CONTROL is already burned', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); - const originalFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP + const originalFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP; await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), originalFuses, MAX_EXPIRY, - ) + ); await expect( NameWrapper.setChildFuses( @@ -4420,42 +4420,42 @@ describe('Name Wrapper', () => { CANNOT_SET_RESOLVER | CANNOT_BURN_FUSES, MAX_EXPIRY, ), - ).be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Does not allow burning fuses if PARENT_CANNOT_CONTROL is already burned even if PARENT_CANNOT_CONTROL is added as a fuse', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); - const originalFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP + const originalFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP; await NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), originalFuses, MAX_EXPIRY, - ) + ); await expect( NameWrapper.setChildFuses( wrappedTokenId, labelhash('sub'), PARENT_CANNOT_CONTROL | - CANNOT_UNWRAP | - CANNOT_SET_RESOLVER | - CANNOT_BURN_FUSES, + CANNOT_UNWRAP | + CANNOT_SET_RESOLVER | + CANNOT_BURN_FUSES, MAX_EXPIRY, ), - ).be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Does not allow burning PARENT_CANNOT_CONTROL if CU on the parent is not burned', async () => { - await registerSetupAndWrapName('fuses', account, CAN_DO_EVERYTHING) + await registerSetupAndWrapName('fuses', account, CAN_DO_EVERYTHING); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); - const originalFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP + const originalFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP; await expect( NameWrapper.setChildFuses( @@ -4464,13 +4464,13 @@ describe('Name Wrapper', () => { originalFuses, MAX_EXPIRY, ), - ).be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Fuses and owner are set to 0 if expired', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); await NameWrapper.setChildFuses( wrappedTokenId, @@ -4478,17 +4478,17 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_SET_RESOLVER, 0, ) - ;[owner, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId) + ;[owner, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) - expect(owner).to.equal(EMPTY_ADDRESS) - }) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); + expect(owner).to.equal(EMPTY_ADDRESS); + }); it('Fuses and owner are set to 0 if expired and fuses cannot be burnt after expiry using setChildFuses()', async () => { - await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP) + await registerSetupAndWrapName('fuses', account, CANNOT_UNWRAP); - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); await NameWrapper.setChildFuses( wrappedTokenId, @@ -4496,13 +4496,13 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, 0, ) - ;[owner, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId) + ;[owner, fuses, expiry] = await NameWrapper.getData(subWrappedTokenId); - expect(fuses).to.equal(0) - expect(expiry).to.equal(0) - expect(owner).to.equal(EMPTY_ADDRESS) + expect(fuses).to.equal(0); + expect(expiry).to.equal(0); + expect(owner).to.equal(EMPTY_ADDRESS); - const block = await ethers.provider.getBlock('latest') + const block = await ethers.provider.getBlock('latest'); await expect( NameWrapper.setChildFuses( @@ -4511,70 +4511,70 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, block.timestamp + 1 * DAY, ), - ).to.be.revertedWith(`NameIsNotWrapped()`) - }) - }) + ).to.be.revertedWith(`NameIsNotWrapped()`); + }); + }); describe('setSubnodeOwner()', async () => { - const label = 'ownerandwrap' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'ownerandwrap'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - }) + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + }); it('Can be called by the owner of a name and sets this contract as owner on the ENS registry.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, CAN_DO_EVERYTHING, 0, - ) + ); expect( await EnsRegistry.owner(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account) - }) + ).to.equal(account); + }); it('Can be called by an account authorised by the owner.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setApprovalForAll(account2, true) - await NameWrapper2.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setApprovalForAll(account2, true); + await NameWrapper2.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); expect( await EnsRegistry.owner(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account) - }) + ).to.equal(account); + }); it('Transfers the wrapped token to the target address.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, CAN_DO_EVERYTHING, 0, - ) + ); expect( await EnsRegistry.owner(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account2) - }) + ).to.equal(account2); + }); it('Will not allow wrapping with a target address of 0x0.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); await expect( NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4583,8 +4583,8 @@ describe('Name Wrapper', () => { 0, CAN_DO_EVERYTHING, ), - ).to.be.revertedWith('ERC1155: mint to the zero address') - }) + ).to.be.revertedWith('ERC1155: mint to the zero address'); + }); it('Will not allow wrapping with a target address of the wrapper contract address', async () => { await expect( NameWrapper.setSubnodeOwner( @@ -4596,11 +4596,11 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( 'ERC1155: newOwner cannot be the NameWrapper contract', - ) - }) + ); + }); it('Does not allow anyone else to wrap a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await EnsRegistry.setApprovalForAll(account2, true) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await EnsRegistry.setApprovalForAll(account2, true); await expect( NameWrapper2.setSubnodeOwner( wrappedTokenId, @@ -4609,14 +4609,14 @@ describe('Name Wrapper', () => { CAN_DO_EVERYTHING, 0, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Fuses cannot be burned if the name does not have PARENT_CANNOT_CONTROL burned', async () => { - const label = 'subdomain2' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const label2 = 'sub' - await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING) + const label = 'subdomain2'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const label2 = 'sub'; + await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING); await expect( NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4629,14 +4629,14 @@ describe('Name Wrapper', () => { `OperationProhibited("${namehash( `${label2}.${label}.${BASE_DOMAIN_STR}`, )}")`, - ) - }) + ); + }); it('Does not allow fuses to be burned if CANNOT_UNWRAP is not burned.', async () => { - const label = 'subdomain2' - const label2 = 'sub' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING) + const label = 'subdomain2'; + const label2 = 'sub'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING); await expect( NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4649,112 +4649,112 @@ describe('Name Wrapper', () => { `OperationProhibited("${namehash( `${label2}.${label}.${BASE_DOMAIN_STR}`, )}")`, - ) - }) + ); + }); it('Allows fuses to be burned if CANNOT_UNWRAP and PARENT_CANNOT_CONTROL is burned and is not expired', async () => { - const label = 'subdomain2' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + const label = 'subdomain2'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | CANNOT_SET_RESOLVER, MAX_EXPIRY, - ) + ); expect( await NameWrapper.allFusesBurned( namehash(`sub.${label}.${BASE_DOMAIN_STR}`), CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | CANNOT_SET_RESOLVER, ), - ).to.equal(true) - }) + ).to.equal(true); + }); it('Does not allow IS_DOT_ETH to be burned', async () => { - const label = 'subdomain2' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + const label = 'subdomain2'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); await expect( NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, CANNOT_UNWRAP | - PARENT_CANNOT_CONTROL | - CANNOT_SET_RESOLVER | - IS_DOT_ETH, + PARENT_CANNOT_CONTROL | + CANNOT_SET_RESOLVER | + IS_DOT_ETH, MAX_EXPIRY, ), ).to.be.revertedWith( `OperationProhibited("${namehash(`sub.${label}.${BASE_DOMAIN_STR}`)}")`, - ) - }) + ); + }); it('Does not allow fuses to be burned if CANNOT_UNWRAP and PARENT_CANNOT_CONTROL are burned, but the name is expired', async () => { - const label = 'subdomain2' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'subdomain2'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); await registerSetupAndWrapName( label, account, CAN_DO_EVERYTHING | CANNOT_UNWRAP, - ) - const [, parentFuses, expiry] = await NameWrapper.getData(wrappedTokenId) + ); + const [, parentFuses, expiry] = await NameWrapper.getData(wrappedTokenId); expect(parentFuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | IS_DOT_ETH, - ) + ); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, 0, // set expiry to 0 - ) + ); expect( await NameWrapper.allFusesBurned( namehash(`sub.${label}.${BASE_DOMAIN_STR}`), PARENT_CANNOT_CONTROL, ), - ).to.equal(false) - }) + ).to.equal(false); + }); - it("normalises the max expiry of a subdomain to the parent's expiry", async () => { - const label = 'subdomain2' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + it('normalises the max expiry of a subdomain to the parent\'s expiry', async () => { + const label = 'subdomain2'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); await registerSetupAndWrapName( label, account, CAN_DO_EVERYTHING | CANNOT_UNWRAP, - ) - const expectedExpiry = await BaseRegistrar.nameExpires(tokenId) + ); + const expectedExpiry = await BaseRegistrar.nameExpires(tokenId); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); const [, , expiry] = await NameWrapper.getData( namehash(`sub.${label}.${BASE_DOMAIN_STR}`), - ) + ); - expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)) - }) + expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)); + }); it('Emits Wrap event', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); const tx = await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, 0, 0, - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -4763,18 +4763,18 @@ describe('Name Wrapper', () => { account2, 0, 0, - ) - }) + ); + }); it('Emits TransferSingle event', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); const tx = await NameWrapper.setSubnodeOwner( wrappedTokenId, 'sub', account2, 0, 0, - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') .withArgs( @@ -4783,11 +4783,11 @@ describe('Name Wrapper', () => { account2, namehash(`sub.${label}.${BASE_DOMAIN_STR}`), 1, - ) - }) + ); + }); it('Will not create a subdomain with an empty label', async () => { - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4796,30 +4796,30 @@ describe('Name Wrapper', () => { CAN_DO_EVERYTHING, 0, ), - ).to.be.revertedWith(`LabelTooShort()`) - }) + ).to.be.revertedWith(`LabelTooShort()`); + }); it('should be able to call twice and change the owner', async () => { - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account) - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account2, 0, 0) + ).to.equal(account); + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account2, 0, 0); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account2) - }) + ).to.equal(account2); + }); it('setting owner to 0 burns and unwraps', async () => { - const label = 'test' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' + const label = 'test'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4827,7 +4827,7 @@ describe('Name Wrapper', () => { account2, 0, MAX_EXPIRY, - ) + ); tx = await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4835,28 +4835,28 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(subWrappedTokenId, EMPTY_ADDRESS) - }) + .withArgs(subWrappedTokenId, EMPTY_ADDRESS); + }); it('Unwrapping within an external contract does not create any state inconsistencies', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - await BaseRegistrar.register(labelhash('test'), account, 1 * DAY) + await BaseRegistrar.register(labelhash('test'), account, 1 * DAY); await NameWrapper.wrapAnyLD( 'test', account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); const testReentrancy = await deploy( 'TestNameWrapperReentrancy', @@ -4864,8 +4864,8 @@ describe('Name Wrapper', () => { NameWrapper.address, namehash('test' + '.' + BASE_DOMAIN_STR), labelhash('sub'), - ) - await NameWrapper.setApprovalForAll(testReentrancy.address, true) + ); + await NameWrapper.setApprovalForAll(testReentrancy.address, true); // set self as sub.test.eth owner await NameWrapper.setSubnodeOwner( @@ -4874,7 +4874,7 @@ describe('Name Wrapper', () => { account, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) + ); // attempt to move owner to testReentrancy, which unwraps domain itself to account while keeping ERC1155 to testReentrancy await expect( @@ -4885,25 +4885,25 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, ), - ).to.be.reverted + ).to.be.reverted; // reverts because CANNOT_UNWRAP/PCC are burned first, and then unwrap is attempted inside contract, which fails, because CU has already been burned - }) + }); it('Unwrapping a previously wrapped unexpired name retains PCC and so reverts setSubnodeRecord', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4911,36 +4911,36 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // Confirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) - expect(owner).to.equal(EMPTY_ADDRESS) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) + ); + expect(owner).to.equal(EMPTY_ADDRESS); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); await expect( NameWrapper.setSubnodeOwner(wrappedTokenId, subLabel, account2, 0, 0), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Rewrapping a name that had PCC burned, but has now expired is possible and resets fuses', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -4948,68 +4948,68 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, parentExpiry - DAY / 2, - ) + ); // Confirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) + ); - expect(owner).to.equal(EMPTY_ADDRESS) - expect(expiry).to.equal(parentExpiry - DAY / 2) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) + expect(owner).to.equal(EMPTY_ADDRESS); + expect(expiry).to.equal(parentExpiry - DAY / 2); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); // Advance time so the subdomain expires, but not the parent - await evm.advanceTime(DAY / 2 + 1) - await evm.mine() + await evm.advanceTime(DAY / 2 + 1); + await evm.mine(); const [, fusesAfter, expiryAfter] = await NameWrapper.getData( subWrappedTokenId, - ) - expect(expiryAfter).to.equal(parentExpiry - DAY / 2) - expect(fusesAfter).to.equal(0) + ); + expect(expiryAfter).to.equal(parentExpiry - DAY / 2); + expect(fusesAfter).to.equal(0); await NameWrapper.setSubnodeOwner( wrappedTokenId, subLabel, account2, 0, 0, - ) + ); const block1 = await ethers.provider.getBlock( await ethers.provider.getBlockNumber(), - ) + ); - const owner3 = await NameWrapper.ownerOf(subWrappedTokenId) + const owner3 = await NameWrapper.ownerOf(subWrappedTokenId); const [rawOwner, rawFuses, expiry2] = await NameWrapper.getData( subWrappedTokenId, - ) - const [, activeFuses] = await NameWrapper.getData(subWrappedTokenId) - expect(activeFuses).to.equal(0) - expect(rawFuses).to.equal(0) - expect(rawOwner).to.equal(account2) - expect(expiry2).to.be.below(block1.timestamp) - expect(owner3).to.equal(account2) - }) + ); + const [, activeFuses] = await NameWrapper.getData(subWrappedTokenId); + expect(activeFuses).to.equal(0); + expect(rawFuses).to.equal(0); + expect(rawOwner).to.equal(account2); + expect(expiry2).to.be.below(block1.timestamp); + expect(owner3).to.equal(account2); + }); it('Expired subnames should still be protected by CANNOT_CREATE_SUBDOMAIN on the parent', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabel2 = 'sub2' + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabel2 = 'sub2'; const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) + ); const subWrappedTokenId2 = namehash( `${subLabel2}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -5017,9 +5017,9 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, parentExpiry - DAY / 2, - ) + ); - await NameWrapper.setFuses(wrappedTokenId, CANNOT_CREATE_SUBDOMAIN) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_CREATE_SUBDOMAIN); await expect( NameWrapper.setSubnodeOwner( @@ -5029,21 +5029,21 @@ describe('Name Wrapper', () => { 0, parentExpiry - DAY / 2, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId2}")`) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId2}")`); - await evm.advanceTime(DAY / 2 + 1) - await evm.mine() + await evm.advanceTime(DAY / 2 + 1); + await evm.mine(); - const block = await ethers.provider.getBlock('latest') + const block = await ethers.provider.getBlock('latest'); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) + ); // subdomain is expired - expect(owner).to.equal(EMPTY_ADDRESS) - expect(fuses).to.equal(0) - expect(parseInt(expiry)).to.be.lessThan(parseInt(block.timestamp)) + expect(owner).to.equal(EMPTY_ADDRESS); + expect(fuses).to.equal(0); + expect(parseInt(expiry)).to.be.lessThan(parseInt(block.timestamp)); await expect( NameWrapper.setSubnodeOwner( @@ -5053,23 +5053,23 @@ describe('Name Wrapper', () => { 0, parentExpiry - DAY / 2, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Burning a name still protects it from the parent as long as it is unexpired and has PCC burnt', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -5077,23 +5077,23 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // Confirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); // Unwrap to 0 to burn the name - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) - await EnsRegistry2.setOwner(subWrappedTokenId, EMPTY_ADDRESS) + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); + await EnsRegistry2.setOwner(subWrappedTokenId, EMPTY_ADDRESS); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) - const registryOwner = await EnsRegistry2.owner(subWrappedTokenId) - const block = await ethers.provider.getBlock('latest') - expect(owner).to.equal(EMPTY_ADDRESS) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - expect(parseInt(expiry)).to.be.greaterThan(parseInt(block.timestamp)) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) - expect(registryOwner).to.equal(EMPTY_ADDRESS) + ); + const registryOwner = await EnsRegistry2.owner(subWrappedTokenId); + const block = await ethers.provider.getBlock('latest'); + expect(owner).to.equal(EMPTY_ADDRESS); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + expect(parseInt(expiry)).to.be.greaterThan(parseInt(block.timestamp)); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); + expect(registryOwner).to.equal(EMPTY_ADDRESS); // attempt to take back the name await expect( @@ -5104,23 +5104,23 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL, MAX_EXPIRY, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); + }); describe('setSubnodeRecord()', async () => { - const label = 'subdomain2' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - let resolver + const label = 'subdomain2'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + let resolver; before(async () => { - resolver = account // dummy address for resolver - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - }) + resolver = account; // dummy address for resolver + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + }); it('Can be called by the owner of a name', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); await NameWrapper.setSubnodeRecord( wrappedTokenId, 'sub', @@ -5129,20 +5129,20 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); expect( await EnsRegistry.owner(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account) - }) + ).to.equal(account); + }); it('Can be called by an account authorised by the owner.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setApprovalForAll(account2, true) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setApprovalForAll(account2, true); await NameWrapper2.setSubnodeRecord( wrappedTokenId, 'sub', @@ -5151,16 +5151,16 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); expect( await EnsRegistry.owner(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(NameWrapper.address) + ).to.equal(NameWrapper.address); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account) - }) + ).to.equal(account); + }); it('Transfers the wrapped token to the target address.', async () => { await NameWrapper.setSubnodeRecord( @@ -5171,12 +5171,12 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account2) - }) + ).to.equal(account2); + }); it('Will not allow wrapping with a target address of 0x0', async () => { await expect( @@ -5189,8 +5189,8 @@ describe('Name Wrapper', () => { 0, 0, ), - ).to.be.revertedWith('ERC1155: mint to the zero address') - }) + ).to.be.revertedWith('ERC1155: mint to the zero address'); + }); it('Will not allow wrapping with a target address of the wrapper contract address.', async () => { await expect( @@ -5205,12 +5205,12 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( 'ERC1155: newOwner cannot be the NameWrapper contract', - ) - }) + ); + }); it('Does not allow anyone else to wrap a name even if the owner has authorised the wrapper with the ENS registry.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await EnsRegistry.setApprovalForAll(account2, true) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await EnsRegistry.setApprovalForAll(account2, true); await expect( NameWrapper2.setSubnodeRecord( wrappedTokenId, @@ -5221,14 +5221,14 @@ describe('Name Wrapper', () => { 0, 0, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Does not allow fuses to be burned if PARENT_CANNOT_CONTROL is not burned.', async () => { - const label = 'subdomain3' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING) + const label = 'subdomain3'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING); await expect( NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5241,14 +5241,14 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `OperationProhibited("${namehash(`sub.${label}.${BASE_DOMAIN_STR}`)}")`, - ) - }) + ); + }); it('Does not allow fuses to be burned if CANNOT_UNWRAP is not burned', async () => { - const label = 'subdomain3' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING) + const label = 'subdomain3'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CAN_DO_EVERYTHING); await expect( NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5261,14 +5261,14 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `OperationProhibited("${namehash(`sub.${label}.${BASE_DOMAIN_STR}`)}")`, - ) - }) + ); + }); it('Fuses will remain 0 if expired', async () => { - const label = 'subdomain3' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + const label = 'subdomain3'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); NameWrapper.setSubnodeRecord( wrappedTokenId, 'sub', @@ -5277,18 +5277,18 @@ describe('Name Wrapper', () => { 0, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER, 0, - ) + ); const [, fuses] = await NameWrapper.getData( namehash(`sub.${label}.${BASE_DOMAIN_STR}`), - ) - expect(fuses).to.equal(0) - }) + ); + expect(fuses).to.equal(0); + }); it('Allows fuses to be burned if not expired and PARENT_CANNOT_CONTROL/CANNOT_UNWRAP are burned', async () => { - const label = 'subdomain3' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + const label = 'subdomain3'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); NameWrapper.setSubnodeRecord( wrappedTokenId, 'sub', @@ -5297,20 +5297,20 @@ describe('Name Wrapper', () => { 0, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER, MAX_EXPIRY, - ) + ); const [, fuses] = await NameWrapper.getData( namehash(`sub.${label}.${BASE_DOMAIN_STR}`), - ) + ); expect(fuses).to.equal( PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_TRANSFER, - ) - }) + ); + }); it('does not allow burning IS_DOT_ETH', async () => { - const label = 'subdomain3' - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + const label = 'subdomain3'; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); await expect( NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5323,8 +5323,8 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( `OperationProhibited("${namehash(`sub.${label}.${BASE_DOMAIN_STR}`)}")`, - ) - }) + ); + }); it('Emits Wrap event', async () => { const tx = await NameWrapper.setSubnodeRecord( @@ -5335,7 +5335,7 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -5344,8 +5344,8 @@ describe('Name Wrapper', () => { account2, 0, 0, - ) - }) + ); + }); it('Emits TransferSingle event', async () => { const tx = await NameWrapper.setSubnodeRecord( @@ -5356,7 +5356,7 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') .withArgs( @@ -5365,8 +5365,8 @@ describe('Name Wrapper', () => { account2, namehash(`sub.${label}.${BASE_DOMAIN_STR}`), 1, - ) - }) + ); + }); it('Sets the appropriate values on the ENS registry', async () => { await NameWrapper.setSubnodeRecord( @@ -5377,17 +5377,17 @@ describe('Name Wrapper', () => { 100, 0, 0, - ) + ); - const node = namehash(`sub.${label}.${BASE_DOMAIN_STR}`) + const node = namehash(`sub.${label}.${BASE_DOMAIN_STR}`); - expect(await EnsRegistry.owner(node)).to.equal(NameWrapper.address) - expect(await EnsRegistry.resolver(node)).to.equal(resolver) - expect(await EnsRegistry.ttl(node)).to.equal(100) - }) + expect(await EnsRegistry.owner(node)).to.equal(NameWrapper.address); + expect(await EnsRegistry.resolver(node)).to.equal(resolver); + expect(await EnsRegistry.ttl(node)).to.equal(100); + }); it('Will not create a subdomain with an empty label', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); await expect( NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5398,8 +5398,8 @@ describe('Name Wrapper', () => { 0, 0, ), - ).to.be.revertedWith(`LabelTooShort()`) - }) + ).to.be.revertedWith(`LabelTooShort()`); + }); it('should be able to call twice and change the owner', async () => { await NameWrapper.setSubnodeRecord( @@ -5410,10 +5410,10 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account) + ).to.equal(account); await NameWrapper.setSubnodeRecord( wrappedTokenId, 'sub', @@ -5422,22 +5422,22 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); expect( await NameWrapper.ownerOf(namehash(`sub.${label}.${BASE_DOMAIN_STR}`)), - ).to.equal(account2) - }) + ).to.equal(account2); + }); it('setting owner to 0 burns and unwraps', async () => { - const label = 'test' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' + const label = 'test'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5447,9 +5447,9 @@ describe('Name Wrapper', () => { 0, 0, MAX_EXPIRY, - ) + ); - expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal(account2) + expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal(account2); const tx = await NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5459,28 +5459,28 @@ describe('Name Wrapper', () => { 0, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(subWrappedTokenId, EMPTY_ADDRESS) - }) + .withArgs(subWrappedTokenId, EMPTY_ADDRESS); + }); it('Unwrapping within an external contract does not create any state inconsistencies', async () => { - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); - await BaseRegistrar.register(labelhash('test'), account, 1 * DAY) + await BaseRegistrar.register(labelhash('test'), account, 1 * DAY); await NameWrapper.wrapAnyLD( 'test', account, CAN_DO_EVERYTHING, EMPTY_ADDRESS, - ) + ); const testReentrancy = await deploy( 'TestNameWrapperReentrancy', @@ -5488,8 +5488,8 @@ describe('Name Wrapper', () => { NameWrapper.address, namehash('test' + '.' + BASE_DOMAIN_STR), labelhash('sub'), - ) - await NameWrapper.setApprovalForAll(testReentrancy.address, true) + ); + await NameWrapper.setApprovalForAll(testReentrancy.address, true); // set self as sub.test.eth owner await NameWrapper.setSubnodeRecord( @@ -5500,7 +5500,7 @@ describe('Name Wrapper', () => { 0, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) + ); // move owner to testReentrancy, which unwraps domain itself to account while keeping ERC1155 to testReentrancy await expect( @@ -5513,25 +5513,25 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, ), - ).to.be.reverted + ).to.be.reverted; // reverts because CANNOT_UNWRAP/PCC are burned first, and then unwrap is attempted inside contract, which fails, because CU has already been burned - }) + }); it('Unwrapping a previously wrapped unexpired name retains PCC and so reverts setSubnodeRecord', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -5539,20 +5539,20 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // Confirm fuses are set const [ownerBefore, fusesBefore, expiryBefore] = - await NameWrapper.getData(subWrappedTokenId) - expect(ownerBefore).to.equal(account2) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) - expect(expiryBefore).to.equal(parentExpiry.add(GRACE_PERIOD)) - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) + await NameWrapper.getData(subWrappedTokenId); + expect(ownerBefore).to.equal(account2); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); + expect(expiryBefore).to.equal(parentExpiry.add(GRACE_PERIOD)); + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) - expect(owner).to.equal(EMPTY_ADDRESS) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) + ); + expect(owner).to.equal(EMPTY_ADDRESS); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); // attempt to rewrap with PCC still burnt await expect( NameWrapper.setSubnodeRecord( @@ -5564,23 +5564,23 @@ describe('Name Wrapper', () => { 0, 0, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Rewrapping a name that had PCC burned, but has now expired is possible', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeOwner( wrappedTokenId, @@ -5588,28 +5588,28 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL, parentExpiry - DAY / 2, - ) + ); // Confirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) - expect(owner).to.equal(EMPTY_ADDRESS) - expect(expiry).to.equal(parentExpiry - DAY / 2) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) + ); + expect(owner).to.equal(EMPTY_ADDRESS); + expect(expiry).to.equal(parentExpiry - DAY / 2); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); // Advance time so the subname expires, but not the parent - await evm.advanceTime(DAY / 2 + 1) - await evm.mine() + await evm.advanceTime(DAY / 2 + 1); + await evm.mine(); const [, fusesAfter, expiryAfter] = await NameWrapper.getData( subWrappedTokenId, - ) - expect(expiryAfter).to.equal(parentExpiry - DAY / 2) - expect(fusesAfter).to.equal(0) + ); + expect(expiryAfter).to.equal(parentExpiry - DAY / 2); + expect(fusesAfter).to.equal(0); await NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5619,25 +5619,25 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) - }) + ); + }); it('Expired subnames should still be protected by CANNOT_CREATE_SUBDOMAIN on the parent', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabel2 = 'sub2' + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabel2 = 'sub2'; const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) + ); const subWrappedTokenId2 = namehash( `${subLabel2}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeRecord to account2 await NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5647,9 +5647,9 @@ describe('Name Wrapper', () => { 0, PARENT_CANNOT_CONTROL, parentExpiry - DAY / 2, - ) + ); - await NameWrapper.setFuses(wrappedTokenId, CANNOT_CREATE_SUBDOMAIN) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_CREATE_SUBDOMAIN); await expect( NameWrapper.setSubnodeRecord( @@ -5661,21 +5661,21 @@ describe('Name Wrapper', () => { 0, parentExpiry - DAY / 2, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId2}")`) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId2}")`); - await evm.advanceTime(DAY / 2 + 1) - await evm.mine() + await evm.advanceTime(DAY / 2 + 1); + await evm.mine(); - const block = await ethers.provider.getBlock('latest') + const block = await ethers.provider.getBlock('latest'); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) + ); // subdomain is expired - expect(owner).to.equal(EMPTY_ADDRESS) - expect(fuses).to.equal(0) - expect(parseInt(expiry)).to.be.lessThan(parseInt(block.timestamp)) + expect(owner).to.equal(EMPTY_ADDRESS); + expect(fuses).to.equal(0); + expect(parseInt(expiry)).to.be.lessThan(parseInt(block.timestamp)); await expect( NameWrapper.setSubnodeRecord( @@ -5687,23 +5687,23 @@ describe('Name Wrapper', () => { 0, parentExpiry - DAY / 2, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Burning a name still protects it from the parent as long as it is unexpired and has PCC burnt', async () => { - const label = 'test' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) + const label = 'test'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); const subWrappedTokenId = namehash( `${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + ); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); // Confirm that the name is wrapped - const parentExpiry = await BaseRegistrar.nameExpires(labelHash) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + const parentExpiry = await BaseRegistrar.nameExpires(labelHash); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // NameWrapper.setSubnodeOwner to account2 await NameWrapper.setSubnodeRecord( wrappedTokenId, @@ -5713,23 +5713,23 @@ describe('Name Wrapper', () => { 0, PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) + ); // Confirm fuses are set - const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId) - expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL) + const [, fusesBefore] = await NameWrapper.getData(subWrappedTokenId); + expect(fusesBefore).to.equal(PARENT_CANNOT_CONTROL); // Unwrap to 0 to burn the name - await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2) - await EnsRegistry2.setOwner(subWrappedTokenId, EMPTY_ADDRESS) + await NameWrapper2.unwrap(wrappedTokenId, subLabelHash, account2); + await EnsRegistry2.setOwner(subWrappedTokenId, EMPTY_ADDRESS); const [owner, fuses, expiry] = await NameWrapper.getData( subWrappedTokenId, - ) - const registryOwner = await EnsRegistry2.owner(subWrappedTokenId) - const block = await ethers.provider.getBlock('latest') - expect(owner).to.equal(EMPTY_ADDRESS) - expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)) - expect(parseInt(expiry)).to.be.greaterThan(parseInt(block.timestamp)) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL) - expect(registryOwner).to.equal(EMPTY_ADDRESS) + ); + const registryOwner = await EnsRegistry2.owner(subWrappedTokenId); + const block = await ethers.provider.getBlock('latest'); + expect(owner).to.equal(EMPTY_ADDRESS); + expect(expiry).to.equal(parentExpiry.add(GRACE_PERIOD)); + expect(parseInt(expiry)).to.be.greaterThan(parseInt(block.timestamp)); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL); + expect(registryOwner).to.equal(EMPTY_ADDRESS); // attempt to take back the name await expect( @@ -5742,225 +5742,225 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL, MAX_EXPIRY, ), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); + }); describe('setRecord()', () => { - const label = 'setrecord' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'setrecord'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - }) + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + }); it('Can be called by the owner', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setRecord(wrappedTokenId, account2, account, 50) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setRecord(wrappedTokenId, account2, account, 50); + }); it('Performs the appropriate function on the ENS registry and Wrapper', async () => { - await NameWrapper.setRecord(wrappedTokenId, account2, account, 50) + await NameWrapper.setRecord(wrappedTokenId, account2, account, 50); - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account2) - expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account) - expect(await EnsRegistry.ttl(wrappedTokenId)).to.equal(50) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account2); + expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account); + expect(await EnsRegistry.ttl(wrappedTokenId)).to.equal(50); + }); it('Can be called by an account authorised by the owner.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setApprovalForAll(account2, true) - await NameWrapper2.setRecord(wrappedTokenId, account2, account, 50) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setApprovalForAll(account2, true); + await NameWrapper2.setRecord(wrappedTokenId, account2, account, 50); + }); it('Cannot be called by anyone else.', async () => { await expect( NameWrapper2.setRecord(wrappedTokenId, account2, account, 50), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Cannot be called if CANNOT_TRANSFER is burned.', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER); await expect( NameWrapper.setRecord(wrappedTokenId, account2, account, 50), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('Cannot be called if CANNOT_SET_RESOLVER is burned.', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_RESOLVER) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_RESOLVER); await expect( NameWrapper.setRecord(wrappedTokenId, account2, account, 50), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('Cannot be called if CANNOT_SET_TTL is burned.', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_TTL) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_TTL); await expect( NameWrapper.setRecord(wrappedTokenId, account2, account, 50), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('Setting the owner to 0 reverts if CANNOT_UNWRAP is burned', async () => { - await registerSetupAndWrapName('setrecord2', account, CANNOT_UNWRAP) - const wrappedTokenId2 = namehash('setrecord2' + '.' + BASE_DOMAIN_STR) + await registerSetupAndWrapName('setrecord2', account, CANNOT_UNWRAP); + const wrappedTokenId2 = namehash('setrecord2' + '.' + BASE_DOMAIN_STR); const subWrappedTokenId = namehash( 'sub.setrecord2' + '.' + BASE_DOMAIN_STR, - ) + ); await NameWrapper.setSubnodeOwner( wrappedTokenId2, 'sub', account, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL, MAX_EXPIRY, - ) - expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal(account) + ); + expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal(account); await expect( NameWrapper.setRecord(subWrappedTokenId, EMPTY_ADDRESS, account, 50), - ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${subWrappedTokenId}")`); + }); it('Setting the owner of a subdomain to 0 unwraps the name and passes through resolver/ttl', async () => { - await registerSetupAndWrapName('setrecord2', account, 0) - const wrappedTokenId2 = namehash('setrecord2' + '.' + BASE_DOMAIN_STR) + await registerSetupAndWrapName('setrecord2', account, 0); + const wrappedTokenId2 = namehash('setrecord2' + '.' + BASE_DOMAIN_STR); const subWrappedTokenId = namehash( 'sub.setrecord2' + '.' + BASE_DOMAIN_STR, - ) - await NameWrapper.setSubnodeOwner(wrappedTokenId2, 'sub', account, 0, 0) - expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal(account) + ); + await NameWrapper.setSubnodeOwner(wrappedTokenId2, 'sub', account, 0, 0); + expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal(account); const tx = await NameWrapper.setRecord( subWrappedTokenId, EMPTY_ADDRESS, account, 50, - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameUnwrapped') - .withArgs(subWrappedTokenId, EMPTY_ADDRESS) + .withArgs(subWrappedTokenId, EMPTY_ADDRESS); expect(await NameWrapper.ownerOf(subWrappedTokenId)).to.equal( EMPTY_ADDRESS, - ) - expect(await EnsRegistry.owner(subWrappedTokenId)).to.equal(EMPTY_ADDRESS) - expect(await EnsRegistry.resolver(subWrappedTokenId)).to.equal(account) - expect(await EnsRegistry.ttl(subWrappedTokenId)).to.equal(50) - }) + ); + expect(await EnsRegistry.owner(subWrappedTokenId)).to.equal(EMPTY_ADDRESS); + expect(await EnsRegistry.resolver(subWrappedTokenId)).to.equal(account); + expect(await EnsRegistry.ttl(subWrappedTokenId)).to.equal(50); + }); it('Setting the owner to 0 on a .eth reverts', async () => { - await registerSetupAndWrapName('setrecord2', account, 0) - const wrappedTokenId2 = namehash('setrecord2' + '.' + BASE_DOMAIN_STR) - expect(await NameWrapper.ownerOf(wrappedTokenId2)).to.equal(account) + await registerSetupAndWrapName('setrecord2', account, 0); + const wrappedTokenId2 = namehash('setrecord2' + '.' + BASE_DOMAIN_STR); + expect(await NameWrapper.ownerOf(wrappedTokenId2)).to.equal(account); const tx = await expect( NameWrapper.setRecord(wrappedTokenId2, EMPTY_ADDRESS, account, 50), - ).to.be.revertedWith(`IncorrectTargetOwner("${EMPTY_ADDRESS}")`) - }) - }) + ).to.be.revertedWith(`IncorrectTargetOwner("${EMPTY_ADDRESS}")`); + }); + }); describe('setResolver', () => { - const label = 'setresolver' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'setresolver'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - }) + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + }); it('Can be called by the owner', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setResolver(wrappedTokenId, account2) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setResolver(wrappedTokenId, account2); + }); it('Performs the appropriate function on the ENS registry.', async () => { - expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(EMPTY_ADDRESS) - await NameWrapper.setResolver(wrappedTokenId, account2) - expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account2) - }) + expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(EMPTY_ADDRESS); + await NameWrapper.setResolver(wrappedTokenId, account2); + expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account2); + }); it('Can be called by an account authorised by the owner.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setApprovalForAll(account2, true) - await NameWrapper2.setResolver(wrappedTokenId, account2) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setApprovalForAll(account2, true); + await NameWrapper2.setResolver(wrappedTokenId, account2); + }); it('Cannot be called by anyone else.', async () => { await expect( NameWrapper2.setResolver(wrappedTokenId, account2), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Cannot be called if CANNOT_SET_RESOLVER is burned', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_RESOLVER) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_RESOLVER); await expect( NameWrapper.setResolver(wrappedTokenId, account2), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); + }); describe('setTTL', () => { - const label = 'setttl' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'setttl'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - }) + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + }); it('Can be called by the owner', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setTTL(wrappedTokenId, 100) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setTTL(wrappedTokenId, 100); + }); it('Performs the appropriate function on the ENS registry.', async () => { - expect(await EnsRegistry.ttl(wrappedTokenId)).to.equal(EMPTY_ADDRESS) - await NameWrapper.setTTL(wrappedTokenId, 100) - expect(await EnsRegistry.ttl(wrappedTokenId)).to.equal(100) - }) + expect(await EnsRegistry.ttl(wrappedTokenId)).to.equal(EMPTY_ADDRESS); + await NameWrapper.setTTL(wrappedTokenId, 100); + expect(await EnsRegistry.ttl(wrappedTokenId)).to.equal(100); + }); it('Can be called by an account authorised by the owner.', async () => { - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - await NameWrapper.setApprovalForAll(account2, true) - await NameWrapper2.setTTL(wrappedTokenId, 100) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + await NameWrapper.setApprovalForAll(account2, true); + await NameWrapper2.setTTL(wrappedTokenId, 100); + }); it('Cannot be called by anyone else.', async () => { await expect( NameWrapper2.setTTL(wrappedTokenId, 3600), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account2}")`); + }); it('Cannot be called if CANNOT_SET_TTL is burned', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_TTL) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_SET_TTL); await expect(NameWrapper.setTTL(wrappedTokenId, 100)).to.be.revertedWith( `OperationProhibited("${wrappedTokenId}")`, - ) - }) - }) + ); + }); + }); describe('onERC721Received', () => { - const label = 'send2contract' - const name = label + '' + '.' + BASE_DOMAIN_STR - const tokenId = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const types = ['string', 'address', 'uint32', 'address'] + const label = 'send2contract'; + const name = label + '' + '.' + BASE_DOMAIN_STR; + const tokenId = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const types = ['string', 'address', 'uint32', 'address']; it('Wraps a name transferred to it and sets the owner to the provided address', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, NameWrapper.address, tokenId, abiCoder.encode(types, [label, account2, '0x0', EMPTY_ADDRESS]), - ) + ); - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account2) - expect(await BaseRegistrar.ownerOf(tokenId)).to.equal(NameWrapper.address) - }) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account2); + expect(await BaseRegistrar.ownerOf(tokenId)).to.equal(NameWrapper.address); + }); it('Reverts if called by anything other than the ENS registrar address', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); await expect( NameWrapper.onERC721Received( @@ -5969,40 +5969,40 @@ describe('Name Wrapper', () => { tokenId, abiCoder.encode(types, [label, account, '0x00000001', EMPTY_ADDRESS]), ), - ).to.be.revertedWith('IncorrectTokenType()') - }) + ).to.be.revertedWith('IncorrectTokenType()'); + }); it('Accepts fuse values from the data field', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, NameWrapper.address, tokenId, abiCoder.encode(types, [label, account, '0x00000001', EMPTY_ADDRESS]), - ) - const [, fuses] = await NameWrapper.getData(wrappedTokenId) - expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH) + ); + const [, fuses] = await NameWrapper.getData(wrappedTokenId); + expect(fuses).to.equal(CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | IS_DOT_ETH); expect( await NameWrapper.allFusesBurned(wrappedTokenId, CANNOT_UNWRAP), - ).to.equal(true) - }) + ).to.equal(true); + }); - it('Allows specifiying resolver address', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + it('Allows specifying resolver address', async () => { + await BaseRegistrar.register(tokenId, account, 1 * DAY); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, NameWrapper.address, tokenId, abiCoder.encode(types, [label, account, '0x00000001', account2]), - ) + ); - expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account2) - }) + expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account2); + }); it('Reverts if transferred without data', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); await expect( BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( @@ -6011,10 +6011,10 @@ describe('Name Wrapper', () => { tokenId, '0x', ), - ).to.be.revertedWith('ERC721: transfer to non ERC721Receiver implementer') - }) + ).to.be.revertedWith('ERC721: transfer to non ERC721Receiver implementer'); + }); it('Rejects transfers where the data field label does not match the tokenId', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); await expect( BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( @@ -6028,12 +6028,12 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, ]), ), - ).to.be.revertedWith('LabelMismatch') - }) + ).to.be.revertedWith('LabelMismatch'); + }); it('Reverts if CANNOT_UNWRAP is not burned and attempts to burn other fuses', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) - await EnsRegistry.setOwner(wrappedTokenId, account2) + await BaseRegistrar.register(tokenId, account, 1 * DAY); + await EnsRegistry.setOwner(wrappedTokenId, account2); await expect( BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( @@ -6042,30 +6042,30 @@ describe('Name Wrapper', () => { tokenId, abiCoder.encode(types, [label, account, '0x00000002', EMPTY_ADDRESS]), ), - ).to.be.revertedWith('OperationProhibited') - }) + ).to.be.revertedWith('OperationProhibited'); + }); it('Reverts when manually changing fuse calldata to incorrect type', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); const tx = await BaseRegistrar.populateTransaction[ 'safeTransferFrom(address,address,uint256,bytes)' - ]( + ]( account, NameWrapper.address, tokenId, abiCoder.encode(types, [label, account, 273, EMPTY_ADDRESS]), - ) - const rogueFuse = '40000' // 2 ** 18 in hex - tx.data = tx.data.replace('00111', rogueFuse) + ); + const rogueFuse = '40000'; // 2 ** 18 in hex + tx.data = tx.data.replace('00111', rogueFuse); await expect(signers[0].sendTransaction(tx)).to.be.revertedWith( 'ERC721: transfer to non ERC721Receiver implementer', - ) - }) + ); + }); it('Allows burning other fuses if CAN_UNWRAP has been burnt', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) - await EnsRegistry.setOwner(wrappedTokenId, account2) + await BaseRegistrar.register(tokenId, account, 1 * DAY); + await EnsRegistry.setOwner(wrappedTokenId, account2); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, @@ -6075,28 +6075,28 @@ describe('Name Wrapper', () => { types, [label, account, 5, EMPTY_ADDRESS], // CANNOT_UNWRAP | CANNOT_TRANSFER ), - ) + ); expect(await EnsRegistry.owner(wrappedTokenId)).to.equal( NameWrapper.address, - ) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + ); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); expect((await NameWrapper.getData(wrappedTokenId))[1]).to.equal( CANNOT_UNWRAP | CANNOT_TRANSFER | PARENT_CANNOT_CONTROL | IS_DOT_ETH, - ) + ); expect( await NameWrapper.allFusesBurned( wrappedTokenId, CANNOT_UNWRAP | CANNOT_TRANSFER | PARENT_CANNOT_CONTROL, ), - ).to.equal(true) - }) + ).to.equal(true); + }); it('Allows burning other fuses if CAN_UNWRAP has been burnt, but resets fuses if expired', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) - await EnsRegistry.setOwner(wrappedTokenId, account2) + await BaseRegistrar.register(tokenId, account, 1 * DAY); + await EnsRegistry.setOwner(wrappedTokenId, account2); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, @@ -6108,46 +6108,46 @@ describe('Name Wrapper', () => { CANNOT_UNWRAP | CANNOT_TRANSFER, EMPTY_ADDRESS, ]), - ) + ); - await evm.advanceTime(GRACE_PERIOD + 1 * DAY) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY); + await evm.mine(); expect(await EnsRegistry.owner(wrappedTokenId)).to.equal( NameWrapper.address, - ) + ); - const [, fuses] = await NameWrapper.getData(wrappedTokenId) - const owner = await NameWrapper.ownerOf(wrappedTokenId) + const [, fuses] = await NameWrapper.getData(wrappedTokenId); + const owner = await NameWrapper.ownerOf(wrappedTokenId); // owner should be 0 as expired - expect(owner).to.equal(EMPTY_ADDRESS) - expect(fuses).to.equal(0) + expect(owner).to.equal(EMPTY_ADDRESS); + expect(fuses).to.equal(0); expect( await NameWrapper.allFusesBurned( wrappedTokenId, CANNOT_UNWRAP | PARENT_CANNOT_CONTROL | CANNOT_TRANSFER, ), - ).to.equal(false) - }) + ).to.equal(false); + }); it('Sets the controller in the ENS registry to the wrapper contract', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, NameWrapper.address, tokenId, abiCoder.encode(types, [label, account, '0x00000000', EMPTY_ADDRESS]), - ) + ); expect(await EnsRegistry.owner(wrappedTokenId)).to.equal( NameWrapper.address, - ) - }) + ); + }); it('Can wrap a name even if the controller address is different to the registrant address', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) - await EnsRegistry.setOwner(wrappedTokenId, account2) + await BaseRegistrar.register(tokenId, account, 1 * DAY); + await EnsRegistry.setOwner(wrappedTokenId, account2); await BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( account, @@ -6157,20 +6157,20 @@ describe('Name Wrapper', () => { types, ['send2contract', account, '0x00000000', EMPTY_ADDRESS], // CANNOT_UNWRAP | CANNOT_TRANSFER ), - ) + ); expect(await EnsRegistry.owner(wrappedTokenId)).to.equal( NameWrapper.address, - ) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - }) + ); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + }); it('emits NameWrapped Event', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) - const expectedExpiry = await BaseRegistrar.nameExpires(tokenId) + await BaseRegistrar.register(tokenId, account, 1 * DAY); + const expectedExpiry = await BaseRegistrar.nameExpires(tokenId); const tx = await BaseRegistrar[ 'safeTransferFrom(address,address,uint256,bytes)' - ]( + ]( account, NameWrapper.address, tokenId, @@ -6178,7 +6178,7 @@ describe('Name Wrapper', () => { types, [label, account, 5, EMPTY_ADDRESS], // CANNOT_UNWRAP | CANNOT_TRANSFER ), - ) + ); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') @@ -6188,14 +6188,14 @@ describe('Name Wrapper', () => { account, CANNOT_UNWRAP | CANNOT_TRANSFER | PARENT_CANNOT_CONTROL | IS_DOT_ETH, expectedExpiry.add(GRACE_PERIOD), - ) - }) + ); + }); it('emits TransferSingle Event', async () => { - await BaseRegistrar.register(tokenId, account, 1 * DAY) + await BaseRegistrar.register(tokenId, account, 1 * DAY); const tx = await BaseRegistrar[ 'safeTransferFrom(address,address,uint256,bytes)' - ]( + ]( account, NameWrapper.address, tokenId, @@ -6203,7 +6203,7 @@ describe('Name Wrapper', () => { types, [label, account, 5, EMPTY_ADDRESS], // CANNOT_UNWRAP | CANNOT_TRANSFER ), - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') @@ -6213,11 +6213,11 @@ describe('Name Wrapper', () => { account, wrappedTokenId, 1, - ) - }) + ); + }); it('will not wrap a name with an empty label', async () => { - await BaseRegistrar.register(labelhash(''), account, 1 * DAY) + await BaseRegistrar.register(labelhash(''), account, 1 * DAY); await expect( BaseRegistrar['safeTransferFrom(address,address,uint256,bytes)']( @@ -6226,21 +6226,21 @@ describe('Name Wrapper', () => { labelhash(''), abiCoder.encode(types, ['', account, 0, EMPTY_ADDRESS]), ), - ).to.be.revertedWith('LabelTooShort') - }) - }) + ).to.be.revertedWith('LabelTooShort'); + }); + }); describe('Transfer', () => { - const label = 'transfer' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'transfer'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - }) + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + }); it('safeTransfer cannot be called if CANNOT_TRANSFER is burned and is not expired', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER); await expect( NameWrapper.safeTransferFrom( @@ -6250,11 +6250,11 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); it('safeBatchTransfer cannot be called if CANNOT_TRANSFER is burned and is not expired', async () => { - await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER) + await NameWrapper.setFuses(wrappedTokenId, CANNOT_TRANSFER); await expect( NameWrapper.safeBatchTransferFrom( @@ -6264,68 +6264,68 @@ describe('Name Wrapper', () => { [1], '0x', ), - ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`) - }) - }) + ).to.be.revertedWith(`OperationProhibited("${wrappedTokenId}")`); + }); + }); describe('getData', () => { - const label = 'getfuses' - const labelHash = labelhash(label) - const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' - const subLabelHash = labelhash(subLabel) - const subNameHash = namehash(`${subLabel}.${label}.${BASE_DOMAIN_STR}`) - const subSubLabel = 'subsub' - const subSubLabelhash = labelhash(subSubLabel) + const label = 'getfuses'; + const labelHash = labelhash(label); + const nameHash = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; + const subLabelHash = labelhash(subLabel); + const subNameHash = namehash(`${subLabel}.${label}.${BASE_DOMAIN_STR}`); + const subSubLabel = 'subsub'; + const subSubLabelhash = labelhash(subSubLabel); const subSubNameHash = namehash( `${subSubLabel}.${subLabel}.${label}.${BASE_DOMAIN_STR}`, - ) + ); it('returns the correct fuses and expiry', async () => { - const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - const expectedExpiry = await BaseRegistrar.nameExpires(labelHash) - await NameWrapper.wrapAnyLD(label, account, initialFuses, EMPTY_ADDRESS) - const [, fuses, expiry] = await NameWrapper.getData(nameHash) - expect(fuses).to.equal(initialFuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH) - expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)) - }) + const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER; + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + const expectedExpiry = await BaseRegistrar.nameExpires(labelHash); + await NameWrapper.wrapAnyLD(label, account, initialFuses, EMPTY_ADDRESS); + const [, fuses, expiry] = await NameWrapper.getData(nameHash); + expect(fuses).to.equal(initialFuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH); + expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)); + }); it('clears fuses when domain is expired', async () => { - const initialFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP - await BaseRegistrar.setApprovalForAll(NameWrapper.address, true) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - const expectedExpiry = await BaseRegistrar.nameExpires(labelHash) - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + const initialFuses = PARENT_CANNOT_CONTROL | CANNOT_UNWRAP; + await BaseRegistrar.setApprovalForAll(NameWrapper.address, true); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + const expectedExpiry = await BaseRegistrar.nameExpires(labelHash); + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await NameWrapper.setSubnodeOwner( nameHash, subLabel, account, initialFuses, MAX_EXPIRY, - ) + ); - await increaseTime(DAY + 1 + GRACE_PERIOD) - await mine() + await increaseTime(DAY + 1 + GRACE_PERIOD); + await mine(); - let [, fuses, expiry] = await NameWrapper.getData(subNameHash) + let [, fuses, expiry] = await NameWrapper.getData(subNameHash); - expect(fuses).to.equal(0) - expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)) - }) - }) + expect(fuses).to.equal(0); + expect(expiry).to.equal(expectedExpiry.add(GRACE_PERIOD)); + }); + }); describe('registerAndWrap()', () => { - const label = 'register' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'register'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await BaseRegistrar.addController(NameWrapper.address) - await NameWrapper.setController(account, true) - }) + await BaseRegistrar.addController(NameWrapper.address); + await NameWrapper.setController(account, true); + }); it('should register and wrap names', async () => { await NameWrapper.registerAndWrap( @@ -6334,16 +6334,16 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) + ); expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) + ); expect(await EnsRegistry.owner(wrappedTokenId)).to.equal( NameWrapper.address, - ) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) - }) + ); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); + }); it('allows specifying a resolver address', async () => { await NameWrapper.registerAndWrap( @@ -6352,13 +6352,13 @@ describe('Name Wrapper', () => { 86400, account2, CAN_DO_EVERYTHING, - ) + ); - expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account2) - }) + expect(await EnsRegistry.resolver(wrappedTokenId)).to.equal(account2); + }); it('does not allow non controllers to register names', async () => { - await NameWrapper.setController(account, false) + await NameWrapper.setController(account, false); await expect( NameWrapper.registerAndWrap( label, @@ -6367,8 +6367,8 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, CAN_DO_EVERYTHING, ), - ).to.be.revertedWith('Controllable: Caller is not a controller') - }) + ).to.be.revertedWith('Controllable: Caller is not a controller'); + }); it('Transfers the wrapped token to the target address.', async () => { await NameWrapper.registerAndWrap( @@ -6377,9 +6377,9 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account2) - }) + ); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account2); + }); it('Does not allow wrapping with a target address of 0x0', async () => { await expect( @@ -6390,8 +6390,8 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, CAN_DO_EVERYTHING, ), - ).to.be.revertedWith('ERC1155: mint to the zero address') - }) + ).to.be.revertedWith('ERC1155: mint to the zero address'); + }); it('Does not allow wrapping with a target address of the wrapper contract address.', async () => { await expect( @@ -6404,8 +6404,8 @@ describe('Name Wrapper', () => { ), ).to.be.revertedWith( 'ERC1155: newOwner cannot be the NameWrapper contract', - ) - }) + ); + }); it('Does not allows fuse to be burned if CANNOT_UNWRAP has not been burned.', async () => { await expect( @@ -6420,21 +6420,21 @@ describe('Name Wrapper', () => { `OperationProhibited("${namehash( label + '' + '.' + BASE_DOMAIN_STR, )}")`, - ) - }) + ); + }); it('Allows fuse to be burned if CANNOT_UNWRAP has been burned and expiry set', async () => { - const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER + const initialFuses = CANNOT_UNWRAP | CANNOT_SET_RESOLVER; await NameWrapper.registerAndWrap( label, account, 86400, EMPTY_ADDRESS, initialFuses, - ) - const [, fuses] = await NameWrapper.getData(wrappedTokenId) - expect(fuses).to.equal(initialFuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH) - }) + ); + const [, fuses] = await NameWrapper.getData(wrappedTokenId); + expect(fuses).to.equal(initialFuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH); + }); it('automatically sets PARENT_CANNOT_CONTROL and IS_DOT_ETH', async () => { await NameWrapper.registerAndWrap( @@ -6443,10 +6443,10 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) - const [, fuses] = await NameWrapper.getData(wrappedTokenId) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH) - }) + ); + const [, fuses] = await NameWrapper.getData(wrappedTokenId); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | IS_DOT_ETH); + }); it('Errors when adding a number greater than uint16 for fuses', async () => { const tx = await NameWrapper.populateTransaction.registerAndWrap( @@ -6455,18 +6455,18 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, 273, - ) + ); - const rogueFuse = '40000' // 2 ** 18 in hex - tx.data = tx.data.replace('00111', rogueFuse) + const rogueFuse = '40000'; // 2 ** 18 in hex + tx.data = tx.data.replace('00111', rogueFuse); try { - await signers[0].sendTransaction(tx) + await signers[0].sendTransaction(tx); } catch (e) { expect(e.message).to.equal( 'Transaction reverted: function was called with incorrect parameters', - ) + ); } - }) + }); it('Errors when passing a parent-controlled fuse', async () => { for (let i = 0; i < 7; i++) { @@ -6477,12 +6477,12 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, IS_DOT_ETH * 2 ** i, - ) + ); } catch (e) { - expect(e.reason).to.equal('value out-of-bounds') + expect(e.reason).to.equal('value out-of-bounds'); } } - }) + }); it('Will not wrap a name with an empty label', async () => { await expect( @@ -6493,13 +6493,13 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, CAN_DO_EVERYTHING, ), - ).to.be.revertedWith(`LabelTooShort()`) - }) + ).to.be.revertedWith(`LabelTooShort()`); + }); it('Will not wrap a name with a label more than 255 characters', async () => { const longString = - 'yutaioxtcsbzrqhdjmltsdfkgomogohhcchjoslfhqgkuhduhxqsldnurwrrtoicvthwxytonpcidtnkbrhccaozdtoznedgkfkifsvjukxxpkcmgcjprankyzerzqpnuteuegtfhqgzcxqwttyfewbazhyilqhyffufxrookxrnjkmjniqpmntcbrowglgdpkslzechimsaonlcvjkhhvdvkvvuztihobmivifuqtvtwinljslusvhhbwhuhzty' - expect(longString.length).to.equal(256) + 'yutaioxtcsbzrqhdjmltsdfkgomogohhcchjoslfhqgkuhduhxqsldnurwrrtoicvthwxytonpcidtnkbrhccaozdtoznedgkfkifsvjukxxpkcmgcjprankyzerzqpnuteuegtfhqgzcxqwttyfewbazhyilqhyffufxrookxrnjkmjniqpmntcbrowglgdpkslzechimsaonlcvjkhhvdvkvvuztihobmivifuqtvtwinljslusvhhbwhuhzty'; + expect(longString.length).to.equal(256); await expect( NameWrapper.registerAndWrap( longString, @@ -6508,8 +6508,8 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, CAN_DO_EVERYTHING, ), - ).to.be.revertedWith(`LabelTooLong("${longString}")`) - }) + ).to.be.revertedWith(`LabelTooLong("${longString}")`); + }); it('emits Wrap event', async () => { const tx = await NameWrapper.registerAndWrap( @@ -6518,9 +6518,9 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) + ); - const expiry = await BaseRegistrar.nameExpires(labelhash(label)) + const expiry = await BaseRegistrar.nameExpires(labelhash(label)); await expect(tx) .to.emit(NameWrapper, 'NameWrapped') .withArgs( @@ -6529,8 +6529,8 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL | IS_DOT_ETH, expiry.add(GRACE_PERIOD), - ) - }) + ); + }); it('Emits TransferSingle event', async () => { const tx = await NameWrapper.registerAndWrap( @@ -6539,22 +6539,22 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) + ); await expect(tx) .to.emit(NameWrapper, 'TransferSingle') - .withArgs(account, EMPTY_ADDRESS, account, wrappedTokenId, 1) - }) - }) + .withArgs(account, EMPTY_ADDRESS, account, wrappedTokenId, 1); + }); + }); describe('renew()', () => { - const label = 'register' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) + const label = 'register'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); before(async () => { - await BaseRegistrar.addController(NameWrapper.address) - await NameWrapper.setController(account, true) - }) + await BaseRegistrar.addController(NameWrapper.address); + await NameWrapper.setController(account, true); + }); it('Renews names', async () => { await NameWrapper.registerAndWrap( @@ -6563,13 +6563,13 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) - const expires = await BaseRegistrar.nameExpires(labelHash) - await NameWrapper.renew(labelHash, 86400) + ); + const expires = await BaseRegistrar.nameExpires(labelHash); + await NameWrapper.renew(labelHash, 86400); expect(await BaseRegistrar.nameExpires(labelHash)).to.equal( expires.toNumber() + 86400, - ) - }) + ); + }); it('Renews names and can extend wrapper expiry', async () => { await NameWrapper.registerAndWrap( @@ -6578,18 +6578,18 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) - const expires = await BaseRegistrar.nameExpires(labelHash) - const expectedExpiry = expires.toNumber() + 86400 - await NameWrapper.renew(labelHash, 86400) + ); + const expires = await BaseRegistrar.nameExpires(labelHash); + const expectedExpiry = expires.toNumber() + 86400; + await NameWrapper.renew(labelHash, 86400); expect(await BaseRegistrar.nameExpires(labelHash)).to.equal( expires.toNumber() + 86400, - ) - const [owner, , expiry] = await NameWrapper.getData(wrappedTokenId) + ); + const [owner, , expiry] = await NameWrapper.getData(wrappedTokenId); - expect(expiry).to.equal(expectedExpiry + GRACE_PERIOD) - expect(owner).to.equal(account) - }) + expect(expiry).to.equal(expectedExpiry + GRACE_PERIOD); + expect(owner).to.equal(account); + }); it('Renewing name less than required to unexpire it still has original owner/fuses', async () => { await NameWrapper.registerAndWrap( @@ -6598,34 +6598,34 @@ describe('Name Wrapper', () => { DAY, EMPTY_ADDRESS, CANNOT_UNWRAP | CANNOT_SET_RESOLVER, - ) + ); - await evm.advanceTime(DAY * 2) - await mine() + await evm.advanceTime(DAY * 2); + await mine(); - const [, , expiryBefore] = await NameWrapper.getData(wrappedTokenId) - const block1 = await ethers.provider.getBlock('latest') + const [, , expiryBefore] = await NameWrapper.getData(wrappedTokenId); + const block1 = await ethers.provider.getBlock('latest'); //confirm expired - expect(expiryBefore).to.be.at.most(block1.timestamp + GRACE_PERIOD) + expect(expiryBefore).to.be.at.most(block1.timestamp + GRACE_PERIOD); //renew for less than the grace period - await NameWrapper.renew(labelHash, 1 * DAY) + await NameWrapper.renew(labelHash, 1 * DAY); const [ownerAfter, fusesAfter, expiryAfter] = await NameWrapper.getData( wrappedTokenId, - ) - expect(ownerAfter).to.equal(account) + ); + expect(ownerAfter).to.equal(account); // fuses remain the same expect(fusesAfter).to.equal( CANNOT_UNWRAP | - CANNOT_SET_RESOLVER | - IS_DOT_ETH | - PARENT_CANNOT_CONTROL, - ) + CANNOT_SET_RESOLVER | + IS_DOT_ETH | + PARENT_CANNOT_CONTROL, + ); // still expired - expect(expiryAfter).to.be.at.most(block1.timestamp + GRACE_PERIOD) - }) + expect(expiryAfter).to.be.at.most(block1.timestamp + GRACE_PERIOD); + }); it('should revert when registering with a duration too long', async () => { await expect( @@ -6636,8 +6636,8 @@ describe('Name Wrapper', () => { EMPTY_ADDRESS, CAN_DO_EVERYTHING, ), - ).to.be.revertedWith(`SafeCast: value doesn't fit in 64 bits`) - }) + ).to.be.revertedWith(`SafeCast: value doesn't fit in 64 bits`); + }); it('should revert when renewing with a duration too long', async () => { await NameWrapper.registerAndWrap( @@ -6646,92 +6646,92 @@ describe('Name Wrapper', () => { 86400, EMPTY_ADDRESS, CAN_DO_EVERYTHING, - ) + ); await expect( NameWrapper.renew(labelHash, OVER_MAX_REGISTRATION_DURATION), - ).to.be.revertedWith(`SafeCast: value doesn't fit in 64 bits`) - }) - }) + ).to.be.revertedWith(`SafeCast: value doesn't fit in 64 bits`); + }); + }); describe('Controllable', () => { it('allows the owner to add and remove controllers', async () => { - const tx = await NameWrapper.setController(account, true) + const tx = await NameWrapper.setController(account, true); expect(tx) .to.emit(NameWrapper, 'ControllerChanged') - .withArgs(account, true) + .withArgs(account, true); - const tx2 = await NameWrapper.setController(account, false) + const tx2 = await NameWrapper.setController(account, false); expect(tx2) .to.emit(NameWrapper, 'ControllerChanged') - .withArgs(account, false) - }) + .withArgs(account, false); + }); it('does not allow non-owners to add or remove controllers', async () => { - await NameWrapper.setController(account, true) + await NameWrapper.setController(account, true); - await expect(NameWrapper2.setController(account2, true)).to.be.reverted - await expect(NameWrapper2.setController(account, false)).to.be.reverted - }) - }) + await expect(NameWrapper2.setController(account2, true)).to.be.reverted; + await expect(NameWrapper2.setController(account, false)).to.be.reverted; + }); + }); describe('isWrapped(bytes32 node)', () => { - const label = 'something' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - let result - let parentExpiry + const label = 'something'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + let result; + let parentExpiry; before(async () => { - result = await ethers.provider.send('evm_snapshot') - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - let [, , expiry] = await NameWrapper.getData(wrappedTokenId) - parentExpiry = expiry - }) + result = await ethers.provider.send('evm_snapshot'); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + let [, , expiry] = await NameWrapper.getData(wrappedTokenId); + parentExpiry = expiry; + }); after(async () => { - await ethers.provider.send('evm_revert', [result]) - }) + await ethers.provider.send('evm_revert', [result]); + }); it('identifies a wrapped .eth name', async () => { expect(await NameWrapper['isWrapped(bytes32)'](wrappedTokenId)).to.equal( true, - ) - }) + ); + }); it('identifies an expired .eth name as unwrapped', async () => { - const label = 'expired' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP, 1 * DAY) - await evm.advanceTime(1 * DAY + 1) - await evm.mine() + const label = 'expired'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP, 1 * DAY); + await evm.advanceTime(1 * DAY + 1); + await evm.mine(); expect(await NameWrapper['isWrapped(bytes32)'](wrappedTokenId)).to.equal( false, - ) - }) + ); + }); it('identifies an eth name registered on old controller as unwrapped', async () => { - const label = 'oldcontroller' - const labelHash = labelhash(label) - const tokenId = namehash('oldcontroller' + '.' + BASE_DOMAIN_STR) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - expect(await BaseRegistrar.ownerOf(labelHash)).equal(account) - expect(await NameWrapper['isWrapped(bytes32)'](tokenId)).to.equal(false) - }) + const label = 'oldcontroller'; + const labelHash = labelhash(label); + const tokenId = namehash('oldcontroller' + '.' + BASE_DOMAIN_STR); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + expect(await BaseRegistrar.ownerOf(labelHash)).equal(account); + expect(await NameWrapper['isWrapped(bytes32)'](tokenId)).to.equal(false); + }); it('identifies an unregistered .eth name as unwrapped', async () => { - const tokenId = namehash('abcdefghijklmnop' + '.' + BASE_DOMAIN_STR) - expect(await NameWrapper['isWrapped(bytes32)'](tokenId)).to.equal(false) - }) + const tokenId = namehash('abcdefghijklmnop' + '.' + BASE_DOMAIN_STR); + expect(await NameWrapper['isWrapped(bytes32)'](tokenId)).to.equal(false); + }); it('identifies an unregistered tld as unwrapped', async () => { - const tokenId = namehash('abc') - expect(await NameWrapper['isWrapped(bytes32)'](tokenId)).to.equal(false) - }) + const tokenId = namehash('abc'); + expect(await NameWrapper['isWrapped(bytes32)'](tokenId)).to.equal(false); + }); it('identifies a wrapped subname', async () => { - await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0) - const subTokenId = namehash('sub.something' + '.' + BASE_DOMAIN_STR) - expect(await NameWrapper['isWrapped(bytes32)'](subTokenId)).to.equal(true) - }) + await NameWrapper.setSubnodeOwner(wrappedTokenId, 'sub', account, 0, 0); + const subTokenId = namehash('sub.something' + '.' + BASE_DOMAIN_STR); + expect(await NameWrapper['isWrapped(bytes32)'](subTokenId)).to.equal(true); + }); it('identifies an expired wrapped subname with PCC burnt as unwrapped', async () => { await NameWrapper.setSubnodeOwner( @@ -6740,34 +6740,34 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL, parentExpiry + 100, - ) - const subTokenId = namehash('sub.something' + '.' + BASE_DOMAIN_STR) - expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account) - await evm.advanceTime(DAY + GRACE_PERIOD + 101) - await evm.mine() - expect(await NameWrapper.ownerOf(subTokenId)).to.equal(EMPTY_ADDRESS) + ); + const subTokenId = namehash('sub.something' + '.' + BASE_DOMAIN_STR); + expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account); + await evm.advanceTime(DAY + GRACE_PERIOD + 101); + await evm.mine(); + expect(await NameWrapper.ownerOf(subTokenId)).to.equal(EMPTY_ADDRESS); expect(await NameWrapper['isWrapped(bytes32)'](subTokenId)).to.equal( false, - ) - }) - }) + ); + }); + }); describe('isWrapped(bytes32 parentNode, bytes32 labelhash)', () => { - const label = 'something' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - let result - let parentExpiry + const label = 'something'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + let result; + let parentExpiry; before(async () => { - result = await ethers.provider.send('evm_snapshot') - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - let [, , expiry] = await NameWrapper.getData(wrappedTokenId) - parentExpiry = expiry - }) + result = await ethers.provider.send('evm_snapshot'); + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); + let [, , expiry] = await NameWrapper.getData(wrappedTokenId); + parentExpiry = expiry; + }); after(async () => { - await ethers.provider.send('evm_revert', [result]) - }) + await ethers.provider.send('evm_revert', [result]); + }); it('identifies a wrapped .eth name', async () => { expect( @@ -6775,34 +6775,34 @@ describe('Name Wrapper', () => { namehash(BASE_DOMAIN_STR), labelhash('something'), ), - ).to.equal(true) - }) + ).to.equal(true); + }); it('identifies an expired .eth name as unwrapped', async () => { - const label = 'expired' - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP, 1 * DAY) - await evm.advanceTime(1 * DAY + 1) - await evm.mine() + const label = 'expired'; + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP, 1 * DAY); + await evm.advanceTime(1 * DAY + 1); + await evm.mine(); expect( await NameWrapper['isWrapped(bytes32,bytes32)']( namehash('eth'), labelhash('expired'), ), - ).to.equal(false) - }) + ).to.equal(false); + }); it('identifies an eth name registered on old controller as unwrapped', async () => { - const label = 'oldcontroller' - const labelHash = labelhash(label) - await BaseRegistrar.register(labelHash, account, 1 * DAY) - expect(await BaseRegistrar.ownerOf(labelHash)).equal(account) + const label = 'oldcontroller'; + const labelHash = labelhash(label); + await BaseRegistrar.register(labelHash, account, 1 * DAY); + expect(await BaseRegistrar.ownerOf(labelHash)).equal(account); expect( await NameWrapper['isWrapped(bytes32,bytes32)']( namehash('eth'), labelHash, ), - ).to.equal(false) - }) + ).to.equal(false); + }); it('identifies an unregistered .eth name as unwrapped', async () => { expect( @@ -6810,8 +6810,8 @@ describe('Name Wrapper', () => { namehash('eth'), labelhash('abcdefghijklmnop'), ), - ).to.equal(false) - }) + ).to.equal(false); + }); it('identifies an unregistered tld as unwrapped', async () => { expect( @@ -6819,19 +6819,19 @@ describe('Name Wrapper', () => { ROOT_NODE, labelhash('abc'), ), - ).to.equal(false) - }) + ).to.equal(false); + }); it('identifies a wrapped subname', async () => { - const label = 'sub' - await NameWrapper.setSubnodeOwner(wrappedTokenId, label, account, 0, 0) + const label = 'sub'; + await NameWrapper.setSubnodeOwner(wrappedTokenId, label, account, 0, 0); expect( await NameWrapper['isWrapped(bytes32,bytes32)']( namehash('something' + '.' + BASE_DOMAIN_STR), labelhash(label), ), - ).to.equal(true) - }) + ).to.equal(true); + }); it('identifies an expired wrapped subname with PCC burnt as unwrapped', async () => { await NameWrapper.setSubnodeOwner( @@ -6840,98 +6840,98 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL, parentExpiry + 100, - ) - const subTokenId = namehash('sub.something' + '.' + BASE_DOMAIN_STR) - expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account) - await evm.advanceTime(DAY + GRACE_PERIOD + 101) - await evm.mine() - expect(await NameWrapper.ownerOf(subTokenId)).to.equal(EMPTY_ADDRESS) + ); + const subTokenId = namehash('sub.something' + '.' + BASE_DOMAIN_STR); + expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account); + await evm.advanceTime(DAY + GRACE_PERIOD + 101); + await evm.mine(); + expect(await NameWrapper.ownerOf(subTokenId)).to.equal(EMPTY_ADDRESS); expect( await NameWrapper['isWrapped(bytes32,bytes32)']( wrappedTokenId, labelhash(label), ), - ).to.equal(false) - }) - }) + ).to.equal(false); + }); + }); describe('MetadataService', () => { it('uri() returns url', async () => { - expect(await NameWrapper.uri(123)).to.equal('https://ens.domains') - }) + expect(await NameWrapper.uri(123)).to.equal('https://ens.domains'); + }); it('owner can set a new MetadataService', async () => { - await NameWrapper.setMetadataService(account2) - expect(await NameWrapper.metadataService()).to.equal(account2) - }) + await NameWrapper.setMetadataService(account2); + expect(await NameWrapper.metadataService()).to.equal(account2); + }); it('non-owner cannot set a new MetadataService', async () => { await expect( NameWrapper2.setMetadataService(account2), - ).to.be.revertedWith('Ownable: caller is not the owner') - }) - }) + ).to.be.revertedWith('Ownable: caller is not the owner'); + }); + }); describe('NameWrapper.names preimage dictionary', () => { it('Does not allow manipulating the preimage db by manually setting owner as NameWrapper', async () => { - const label = 'base' - const labelHash = labelhash(label) - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - await BaseRegistrar.register(labelHash, hacker, 1 * DAY) - await BaseRegistrarH.setApprovalForAll(NameWrapper.address, true) - await NameWrapperH.wrapAnyLD(label, hacker, CANNOT_UNWRAP, EMPTY_ADDRESS) + const label = 'base'; + const labelHash = labelhash(label); + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + await BaseRegistrar.register(labelHash, hacker, 1 * DAY); + await BaseRegistrarH.setApprovalForAll(NameWrapper.address, true); + await NameWrapperH.wrapAnyLD(label, hacker, CANNOT_UNWRAP, EMPTY_ADDRESS); expect(await BaseRegistrar.ownerOf(labelHash)).to.equal( NameWrapper.address, - ) + ); expect(await EnsRegistry.owner(wrappedTokenId)).to.equal( NameWrapper.address, - ) - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(hacker) + ); + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(hacker); // signed a submomain for the hacker, with a soon-expired expiry - const sub1Label = 'sub1' - const sub1LabelHash = labelhash(sub1Label) - const sub1Domain = sub1Label + '.' + label + '' + '.' + BASE_DOMAIN_STR // sub1.base.eth - const wrappedSub1TokenId = namehash(sub1Domain) + const sub1Label = 'sub1'; + const sub1LabelHash = labelhash(sub1Label); + const sub1Domain = sub1Label + '.' + label + '' + '.' + BASE_DOMAIN_STR; // sub1.base.eth + const wrappedSub1TokenId = namehash(sub1Domain); const block = await ethers.provider.getBlock( await ethers.provider.getBlockNumber(), - ) + ); await NameWrapperH.setSubnodeOwner( wrappedTokenId, sub1Label, hacker, 0, block.timestamp + 3600, // soonly expired - ) + ); expect(await EnsRegistry.owner(wrappedSub1TokenId)).to.equal( NameWrapper.address, - ) - expect(await NameWrapper.ownerOf(wrappedSub1TokenId)).to.equal(hacker) - expect((await NameWrapper.getData(wrappedSub1TokenId))[1]).to.equal(0) + ); + expect(await NameWrapper.ownerOf(wrappedSub1TokenId)).to.equal(hacker); + expect((await NameWrapper.getData(wrappedSub1TokenId))[1]).to.equal(0); // the hacker unwraps his wrappedSubTokenId - await evm.advanceTime(7200) - await NameWrapperH.unwrap(wrappedTokenId, sub1LabelHash, hacker) - expect(await EnsRegistry.owner(wrappedSub1TokenId)).to.equal(hacker) + await evm.advanceTime(7200); + await NameWrapperH.unwrap(wrappedTokenId, sub1LabelHash, hacker); + expect(await EnsRegistry.owner(wrappedSub1TokenId)).to.equal(hacker); // the hacker setSubnodeOwner, to set the owner of wrappedSub2TokenId as NameWrapper - const sub2Label = 'sub2' - const sub2LabelHash = labelhash(sub2Label) - const sub2Domain = sub2Label + '.' + sub1Domain // sub2.sub1.base.eth - const wrappedSub2TokenId = namehash(sub2Domain) + const sub2Label = 'sub2'; + const sub2LabelHash = labelhash(sub2Label); + const sub2Domain = sub2Label + '.' + sub1Domain; // sub2.sub1.base.eth + const wrappedSub2TokenId = namehash(sub2Domain); await EnsRegistryH.setSubnodeOwner( wrappedSub1TokenId, sub2LabelHash, NameWrapper.address, - ) + ); expect(await EnsRegistry.owner(wrappedSub2TokenId)).to.equal( NameWrapper.address, - ) + ); // the hacker re-wraps the sub1node - await EnsRegistryH.setApprovalForAll(NameWrapper.address, true) - await NameWrapperH.wrap(encodeName(sub1Domain), hacker, EMPTY_ADDRESS) - expect(await NameWrapper.ownerOf(wrappedSub1TokenId)).to.equal(hacker) + await EnsRegistryH.setApprovalForAll(NameWrapper.address, true); + await NameWrapperH.wrap(encodeName(sub1Domain), hacker, EMPTY_ADDRESS); + expect(await NameWrapper.ownerOf(wrappedSub1TokenId)).to.equal(hacker); // the hackers setSubnodeOwner // XXX: till now, the hacker gets sub2Domain with no name in Namewrapper @@ -6941,48 +6941,48 @@ describe('Name Wrapper', () => { hacker, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) - expect(await NameWrapper.ownerOf(wrappedSub2TokenId)).to.equal(hacker) + ); + expect(await NameWrapper.ownerOf(wrappedSub2TokenId)).to.equal(hacker); expect(await NameWrapper.names(wrappedSub2TokenId)).to.equal( encodeName(sub2Domain), - ) + ); expect(await NameWrapper.names(wrappedSub2TokenId)).to.equal( encodeName(sub2Domain), - ) + ); // the hacker forge a fake root node - const sub3Label = 'eth' - const sub3LabelHash = labelhash(sub3Label) - const sub3Domain = sub3Label + '.' + sub2Domain // eth.sub2.sub1.base.eth - const wrappedSub3TokenId = namehash(sub3Domain) + const sub3Label = 'eth'; + const sub3LabelHash = labelhash(sub3Label); + const sub3Domain = sub3Label + '.' + sub2Domain; // eth.sub2.sub1.base.eth + const wrappedSub3TokenId = namehash(sub3Domain); await NameWrapperH.setSubnodeOwner( wrappedSub2TokenId, sub3Label, hacker, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) - expect(await NameWrapper.ownerOf(wrappedSub3TokenId)).to.equal(hacker) + ); + expect(await NameWrapper.ownerOf(wrappedSub3TokenId)).to.equal(hacker); expect(await NameWrapper.names(wrappedSub3TokenId)).to.equal( encodeName(sub3Domain), - ) - }) - }) + ); + }); + }); describe('Grace period tests', () => { - const label = 'test' - const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR) - const subLabel = 'sub' + const label = 'test'; + const wrappedTokenId = namehash(label + '' + '.' + BASE_DOMAIN_STR); + const subLabel = 'sub'; const subTokenId = namehash( subLabel + '.' + label + '' + '.' + BASE_DOMAIN_STR, - ) - let parentExpiry + ); + let parentExpiry; before(async () => { await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) - ;[, , parentExpiry] = await NameWrapper.getData(wrappedTokenId) + ;[, , parentExpiry] = await NameWrapper.getData(wrappedTokenId); // Confirm that the name is wrapped - expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account) + expect(await NameWrapper.ownerOf(wrappedTokenId)).to.equal(account); // create a subdomain for other tests await NameWrapper.setSubnodeOwner( @@ -6991,27 +6991,27 @@ describe('Name Wrapper', () => { account2, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, parentExpiry - DAY / 2, - ) + ); // move .eth name to expired and be within grace period - await evm.advanceTime(2 * DAY) - await evm.mine() - const [, , expiry] = await NameWrapper.getData(wrappedTokenId) + await evm.advanceTime(2 * DAY); + await evm.mine(); + const [, , expiry] = await NameWrapper.getData(wrappedTokenId); const block = await ethers.provider.getBlock( await ethers.provider.getBlockNumber(), - ) + ); // expect name to be expired, but inside grace period - expect(parseInt(expiry) - GRACE_PERIOD).to.be.below(block.timestamp) - expect(parseInt(expiry) + GRACE_PERIOD).to.be.above(block.timestamp) + expect(parseInt(expiry) - GRACE_PERIOD).to.be.below(block.timestamp); + expect(parseInt(expiry) + GRACE_PERIOD).to.be.above(block.timestamp); - const [, , subExpiry] = await NameWrapper.getData(subTokenId) + const [, , subExpiry] = await NameWrapper.getData(subTokenId); const block2 = await ethers.provider.getBlock( await ethers.provider.getBlockNumber(), - ) + ); // subdomain is not expired - expect(subExpiry).to.be.above(block2.timestamp) - }) + expect(subExpiry).to.be.above(block2.timestamp); + }); it('When a .eth name is in grace period it cannot call setSubnodeOwner', async () => { await expect( NameWrapper.setSubnodeOwner( @@ -7021,8 +7021,8 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL, parentExpiry - DAY / 2, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`); + }); it('When a .eth name is in grace period it cannot call setSubnodeRecord', async () => { await expect( @@ -7035,14 +7035,14 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL, parentExpiry - DAY / 2, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`); + }); it('When a .eth name is in grace period it cannot call setRecord', async () => { await expect( NameWrapper.setRecord(wrappedTokenId, account2, EMPTY_ADDRESS, 0), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`); + }); it('When a .eth name is in grace period it cannot call safeTransferFrom', async () => { await expect( @@ -7053,8 +7053,8 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) - }) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); + }); it('When a .eth name is in grace period it cannot call batchSafeTransferFrom', async () => { await expect( @@ -7065,38 +7065,38 @@ describe('Name Wrapper', () => { [1], '0x', ), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) - }) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); + }); it('When a .eth name is in grace period it cannot call setResolver', async () => { await expect( NameWrapper.setResolver(wrappedTokenId, EMPTY_ADDRESS), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`); + }); it('When a .eth name is in grace period it cannot call setTTL', async () => { await expect(NameWrapper.setTTL(wrappedTokenId, 0)).to.be.revertedWith( `Unauthorised("${wrappedTokenId}", "${account}")`, - ) - }) + ); + }); it('When a .eth name is in grace period it cannot call setFuses', async () => { await expect(NameWrapper.setFuses(wrappedTokenId, 0)).to.be.revertedWith( `Unauthorised("${wrappedTokenId}", "${account}")`, - ) - }) + ); + }); it('When a .eth name is in grace period it cannot call setChildFuses', async () => { await expect( NameWrapper.setChildFuses(wrappedTokenId, labelhash('sub'), 0, 0), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${account}")`); + }); it('When a .eth name is in grace period, unexpired subdomains can call setFuses', async () => { - await NameWrapper2.setFuses(subTokenId, CANNOT_UNWRAP) - const [, fuses] = await NameWrapper.getData(subTokenId) - expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) - }) + await NameWrapper2.setFuses(subTokenId, CANNOT_UNWRAP); + const [, fuses] = await NameWrapper.getData(subTokenId); + expect(fuses).to.equal(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP); + }); it('When a .eth name is in grace period, unexpired subdomains can transfer', async () => { await NameWrapper2.safeTransferFrom( @@ -7105,36 +7105,36 @@ describe('Name Wrapper', () => { subTokenId, 1, '0x', - ) - expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account) - }) + ); + expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account); + }); it('When a .eth name is in grace period, unexpired subdomains can set resolver', async () => { - await NameWrapper2.setResolver(subTokenId, account) - expect(await EnsRegistry.resolver(subTokenId)).to.equal(account) - }) + await NameWrapper2.setResolver(subTokenId, account); + expect(await EnsRegistry.resolver(subTokenId)).to.equal(account); + }); it('When a .eth name is in grace period, unexpired subdomains can set ttl', async () => { - await NameWrapper2.setTTL(subTokenId, 100) - expect(await EnsRegistry.ttl(subTokenId)).to.equal(100) - }) + await NameWrapper2.setTTL(subTokenId, 100); + expect(await EnsRegistry.ttl(subTokenId)).to.equal(100); + }); it('When a .eth name is in grace period, unexpired subdomains can call setRecord', async () => { - await NameWrapper2.setRecord(subTokenId, account, account2, 100) - expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account) - expect(await EnsRegistry.owner(subTokenId)).to.equal(NameWrapper.address) - expect(await EnsRegistry.resolver(subTokenId)).to.equal(account2) - expect(await EnsRegistry.ttl(subTokenId)).to.equal(100) - }) + await NameWrapper2.setRecord(subTokenId, account, account2, 100); + expect(await NameWrapper.ownerOf(subTokenId)).to.equal(account); + expect(await EnsRegistry.owner(subTokenId)).to.equal(NameWrapper.address); + expect(await EnsRegistry.resolver(subTokenId)).to.equal(account2); + expect(await EnsRegistry.ttl(subTokenId)).to.equal(100); + }); it('When a .eth name is in grace period, unexpired subdomains can call setSubnodeOwner', async () => { - await NameWrapper2.setSubnodeOwner(subTokenId, 'sub2', account2, 0, 0) + await NameWrapper2.setSubnodeOwner(subTokenId, 'sub2', account2, 0, 0); expect( await NameWrapper.ownerOf( namehash('sub2.sub.test' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) - }) + ).to.equal(account2); + }); it('When a .eth name is in grace period, unexpired subdomains can call setSubnodeRecord', async () => { await NameWrapper2.setSubnodeRecord( @@ -7145,51 +7145,51 @@ describe('Name Wrapper', () => { 0, 0, 0, - ) + ); expect( await NameWrapper.ownerOf( namehash('sub2.sub.test' + '.' + BASE_DOMAIN_STR), ), - ).to.equal(account2) - }) + ).to.equal(account2); + }); it('When a .eth name is in grace period, unexpired subdomains can call setChildFuses if the subdomain exists', async () => { - await NameWrapper2.setSubnodeOwner(subTokenId, 'sub2', account2, 0, 0) - await NameWrapper2.setChildFuses(subTokenId, labelhash('sub2'), 0, 100) + await NameWrapper2.setSubnodeOwner(subTokenId, 'sub2', account2, 0, 0); + await NameWrapper2.setChildFuses(subTokenId, labelhash('sub2'), 0, 100); const [owner, fuses, expiry] = await NameWrapper.getData( namehash('sub2.sub.test' + '.' + BASE_DOMAIN_STR), - ) - expect(owner).to.equal(account2) - expect(expiry).to.equal(100) - expect(fuses).to.equal(0) - }) - }) + ); + expect(owner).to.equal(account2); + expect(expiry).to.equal(100); + expect(fuses).to.equal(0); + }); + }); describe('Registrar tests', () => { - const label1 = 'sub1' - const labelHash1 = labelhash('sub1') - const wrappedTokenId1 = namehash('sub1' + '.' + BASE_DOMAIN_STR) + const label1 = 'sub1'; + const labelHash1 = labelhash('sub1'); + const wrappedTokenId1 = namehash('sub1' + '.' + BASE_DOMAIN_STR); - const label2 = 'sub2' + const label2 = 'sub2'; it('Reverts when attempting to call token owner protected function on an unwrapped name', async () => { - await registerSetupAndWrapName(label1, account, CANNOT_UNWRAP) + await registerSetupAndWrapName(label1, account, CANNOT_UNWRAP); //wait the ETH2LD expired and re-register to the hacker himself - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await evm.mine(); // XXX: note that at this step, the hackler should use the current .eth // registrar to directly register `sub1.${BASE_DOMAIN_STR}` to himself, without wrapping // the name. - await BaseRegistrar.register(labelHash1, hacker, 10 * DAY) - expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal(hacker) - expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal(hacker) + await BaseRegistrar.register(labelHash1, hacker, 10 * DAY); + expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal(hacker); + expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal(hacker); // set `EnsRegistry.owner` as NameWrapper. Note that this step is used to // bypass the newly-introduced checks for [ZZ-001] // // XXX: corrently, `sub1.${BASE_DOMAIN_STR}` becomes a normal node - await EnsRegistryH.setOwner(wrappedTokenId1, NameWrapper.address) + await EnsRegistryH.setOwner(wrappedTokenId1, NameWrapper.address); // create `sub2.sub1.${BASE_DOMAIN_STR}` to the victim user with `PARENT_CANNOT_CONTROL` // burnt. @@ -7201,45 +7201,45 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL | CANNOT_UNWRAP, MAX_EXPIRY, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId1}", "${hacker}")`) - }) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId1}", "${hacker}")`); + }); + }); describe('ERC1155 additional tests', () => { - const label = 'erc1155' - const labelHash = labelhash - const wrappedTokenId = namehash(`${label}.${BASE_DOMAIN_STR}`) + const label = 'erc1155'; + const labelHash = labelhash; + const wrappedTokenId = namehash(`${label}.${BASE_DOMAIN_STR}`); it('Transferring a token that is not owned by the owner reverts', async () => { - await registerSetupAndWrapName(label, account, CANNOT_UNWRAP) + await registerSetupAndWrapName(label, account, CANNOT_UNWRAP); await expect( NameWrapperH.safeTransferFrom(hacker, account, wrappedTokenId, 1, '0x'), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) - }) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); + }); it('Approval on the Wrapper does not give permission to wrap the .eth name', async () => { - await BaseRegistrar.register(labelhash(label), account, 1 * DAY) - await NameWrapper.setApprovalForAll(hacker, true) + await BaseRegistrar.register(labelhash(label), account, 1 * DAY); + await NameWrapper.setApprovalForAll(hacker, true); await expect( NameWrapperH.wrapAnyLD(label, hacker, 0, EMPTY_ADDRESS), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${hacker}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId}", "${hacker}")`); + }); it('Approval on the Wrapper does not give permission to wrap a non .eth name', async () => { - expect(await EnsRegistry.owner(namehash('xyz'))).to.equal(account) - await NameWrapper.setApprovalForAll(hacker, true) - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) + expect(await EnsRegistry.owner(namehash('xyz'))).to.equal(account); + await NameWrapper.setApprovalForAll(hacker, true); + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); await expect( NameWrapperH.wrap(encodeName('xyz'), hacker, EMPTY_ADDRESS), - ).to.be.revertedWith(`Unauthorised("${namehash('xyz')}", "${hacker}")`) - }) + ).to.be.revertedWith(`Unauthorised("${namehash('xyz')}", "${hacker}")`); + }); - it('When .eth name expires, it is untransferrable', async () => { - await BaseRegistrar.register(labelhash(label), account, 1 * DAY) - await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS) + it('When .eth name expires, it is untransferable', async () => { + await BaseRegistrar.register(labelhash(label), account, 1 * DAY); + await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS); - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await mine(); await expect( NameWrapper.safeTransferFrom( @@ -7249,16 +7249,16 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) - }) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); + }); it('Approval on the Wrapper does not give permission to transfer after expiry', async () => { - await BaseRegistrar.register(labelhash(label), account, 1 * DAY) - await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS) - await NameWrapper.setApprovalForAll(hacker, true) + await BaseRegistrar.register(labelhash(label), account, 1 * DAY); + await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS); + await NameWrapper.setApprovalForAll(hacker, true); - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await mine(); await expect( NameWrapper.safeTransferFrom( @@ -7268,26 +7268,26 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); await expect( NameWrapperH.safeTransferFrom(account, hacker, wrappedTokenId, 1, '0x'), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) - }) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); + }); it('When emancipated names expire, they are untransferrible', async () => { - await BaseRegistrar.register(labelhash(label), account, 86400) - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash(label), account, 86400); + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); await NameWrapper.setSubnodeOwner( wrappedTokenId, 'test', account, PARENT_CANNOT_CONTROL, 3600 + (await ethers.provider.getBlock('latest')).timestamp, - ) + ); - await evm.advanceTime(3601) - await mine() + await evm.advanceTime(3601); + await mine(); await expect( NameWrapper.safeTransferFrom( @@ -7297,24 +7297,24 @@ describe('Name Wrapper', () => { 1, '0x', ), - ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`) - }) + ).to.be.revertedWith(`ERC1155: insufficient balance for transfer`); + }); it('Returns a balance of 0 for expired names', async () => { - await BaseRegistrar.register(labelhash(label), account, 86400) - await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash(label), account, 86400); + await NameWrapper.wrapAnyLD(label, account, 0, EMPTY_ADDRESS); - expect(await NameWrapper.balanceOf(account, wrappedTokenId)).to.equal(1) + expect(await NameWrapper.balanceOf(account, wrappedTokenId)).to.equal(1); - await evm.advanceTime(86401 + GRACE_PERIOD) - await evm.mine() + await evm.advanceTime(86401 + GRACE_PERIOD); + await evm.mine(); - expect(await NameWrapper.balanceOf(account, wrappedTokenId)).to.equal(0) - }) + expect(await NameWrapper.balanceOf(account, wrappedTokenId)).to.equal(0); + }); it('Reregistering an expired name does not inherit its previous parent fuses', async () => { - await BaseRegistrar.register(labelhash(label), account, 86400) - await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS) + await BaseRegistrar.register(labelhash(label), account, 86400); + await NameWrapper.wrapAnyLD(label, account, CANNOT_UNWRAP, EMPTY_ADDRESS); // Mint the subdomain await NameWrapper.setSubnodeOwner( @@ -7323,11 +7323,11 @@ describe('Name Wrapper', () => { account, PARENT_CANNOT_CONTROL, 3600 + (await ethers.provider.getBlock('latest')).timestamp, - ) + ); // Let it expire - await evm.advanceTime(3601) - await mine() + await evm.advanceTime(3601); + await mine(); // Mint it again, without PCC await NameWrapper.setSubnodeOwner( @@ -7336,29 +7336,29 @@ describe('Name Wrapper', () => { account, 0, 3600 + (await ethers.provider.getBlock('latest')).timestamp, - ) + ); // Check PCC isn't set const [owner, fuses, expiry] = await NameWrapper.getData( namehash(`test.${label}.${BASE_DOMAIN_STR}`), - ) - expect(fuses).to.equal(0) - }) - }) + ); + expect(fuses).to.equal(0); + }); + }); describe('Implicit Unwrap tests', () => { - const label1 = 'sub1' - const labelHash1 = labelhash('sub1') - const wrappedTokenId1 = namehash('sub1' + '.' + BASE_DOMAIN_STR) + const label1 = 'sub1'; + const labelHash1 = labelhash('sub1'); + const wrappedTokenId1 = namehash('sub1' + '.' + BASE_DOMAIN_STR); - const label2 = 'sub2' - const labelHash2 = labelhash('sub2') - const wrappedTokenId2 = namehash('sub2.sub1' + '.' + BASE_DOMAIN_STR) + const label2 = 'sub2'; + const labelHash2 = labelhash('sub2'); + const wrappedTokenId2 = namehash('sub2.sub1' + '.' + BASE_DOMAIN_STR); before(async () => { - await BaseRegistrar.addController(NameWrapper.address) - await NameWrapper.setController(account, true) - }) + await BaseRegistrar.addController(NameWrapper.address); + await NameWrapper.setController(account, true); + }); it('Trying to burn child fuses when re-registering a name on the old controller reverts', async () => { await NameWrapper.registerAndWrap( label1, @@ -7366,7 +7366,7 @@ describe('Name Wrapper', () => { 1 * DAY, EMPTY_ADDRESS, CANNOT_UNWRAP, - ) + ); // create `sub2.sub1.${BASE_DOMAIN_STR}` w/o fuses burnt await NameWrapperH.setSubnodeOwner( @@ -7375,30 +7375,30 @@ describe('Name Wrapper', () => { hacker, CAN_DO_EVERYTHING, MAX_EXPIRY, - ) - expect(await NameWrapper.ownerOf(wrappedTokenId2)).to.equal(hacker) + ); + expect(await NameWrapper.ownerOf(wrappedTokenId2)).to.equal(hacker); // wait the ETH2LD expired and re-register to the hacker himself - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await evm.mine(); // XXX: note that at this step, the hackler should use the current .eth // registrar to directly register `sub1.${BASE_DOMAIN_STR}` to himself, without wrapping // the name. - await BaseRegistrar.register(labelHash1, hacker, 10 * DAY) - expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal(hacker) - expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal(hacker) + await BaseRegistrar.register(labelHash1, hacker, 10 * DAY); + expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal(hacker); + expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal(hacker); // XXX: PREPARE HACK! // set `EnsRegistry.owner` of `sub1.${BASE_DOMAIN_STR}` as the hacker himself. - await EnsRegistryH.setOwner(wrappedTokenId1, hacker) + await EnsRegistryH.setOwner(wrappedTokenId1, hacker); // XXX: PREPARE HACK! // set controller owner as the NameWrapper contract, to bypass the check - await BaseRegistrarH.transferFrom(hacker, NameWrapper.address, labelHash1) + await BaseRegistrarH.transferFrom(hacker, NameWrapper.address, labelHash1); expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal( NameWrapper.address, - ) + ); // set `sub2.sub1.${BASE_DOMAIN_STR}` to the victim user w fuses burnt // XXX: do this via `setChildFuses` @@ -7410,8 +7410,8 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_CREATE_SUBDOMAIN, MAX_EXPIRY, ), - ).to.be.revertedWith(`Unauthorised("${wrappedTokenId1}", "${hacker}")`) - }) + ).to.be.revertedWith(`Unauthorised("${wrappedTokenId1}", "${hacker}")`); + }); it('Renewing a wrapped, but expired name .eth in the wrapper, but unexpired on the registrar resyncs expiry', async () => { await NameWrapper.registerAndWrap( label1, @@ -7419,57 +7419,57 @@ describe('Name Wrapper', () => { 1 * DAY, EMPTY_ADDRESS, CANNOT_UNWRAP, - ) + ); - await BaseRegistrar.renew(labelHash1, 365 * DAY) + await BaseRegistrar.renew(labelHash1, 365 * DAY); - let owner = await NameWrapper.ownerOf(wrappedTokenId1) - expect(owner).to.equal(account) + let owner = await NameWrapper.ownerOf(wrappedTokenId1); + expect(owner).to.equal(account); // expired but in grace period - await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1) - await evm.mine() + await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1); + await evm.mine(); - owner = await NameWrapper.ownerOf(wrappedTokenId1) - expect(owner).to.equal(EMPTY_ADDRESS) + owner = await NameWrapper.ownerOf(wrappedTokenId1); + expect(owner).to.equal(EMPTY_ADDRESS); expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal( NameWrapper.address, - ) + ); expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal( NameWrapper.address, - ) + ); - await NameWrapper.renew(labelHash1, 1) + await NameWrapper.renew(labelHash1, 1); - owner = await NameWrapper.ownerOf(wrappedTokenId1) - let [, , expiry] = await NameWrapper.getData(wrappedTokenId1) - let registrarExpiry = await BaseRegistrar.nameExpires(labelHash1) - expect(owner).to.equal(account) + owner = await NameWrapper.ownerOf(wrappedTokenId1); + let [, , expiry] = await NameWrapper.getData(wrappedTokenId1); + let registrarExpiry = await BaseRegistrar.nameExpires(labelHash1); + expect(owner).to.equal(account); expect(parseInt(expiry)).to.equal( parseInt(registrarExpiry) + GRACE_PERIOD, - ) - }) - }) + ); + }); + }); describe('TLD recovery', () => { it('Wraps a name which get stuck forever can be recovered by ROOT owner', async () => { - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS) + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS); - await EnsRegistry.setApprovalForAll(NameWrapper.address, true) - await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS) - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account) + await EnsRegistry.setApprovalForAll(NameWrapper.address, true); + await NameWrapper.wrap(encodeName('xyz'), account, EMPTY_ADDRESS); + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account); await NameWrapper.setChildFuses( ROOT_NODE, labelhash('xyz'), PARENT_CANNOT_CONTROL, 0, - ) - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS) + ); + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(EMPTY_ADDRESS); expect(await EnsRegistry.owner(namehash('xyz'))).to.equal( NameWrapper.address, - ) + ); await expect( NameWrapper.setChildFuses( ROOT_NODE, @@ -7477,16 +7477,16 @@ describe('Name Wrapper', () => { PARENT_CANNOT_CONTROL, 100000000000000, ), - ).to.be.revertedWith(`NameIsNotWrapped()`) + ).to.be.revertedWith(`NameIsNotWrapped()`); - await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('xyz'), account2) - await EnsRegistry2.setApprovalForAll(NameWrapper.address, true) - await NameWrapper2.wrap(encodeName('xyz'), account2, EMPTY_ADDRESS) + await EnsRegistry.setSubnodeOwner(ROOT_NODE, labelhash('xyz'), account2); + await EnsRegistry2.setApprovalForAll(NameWrapper.address, true); + await NameWrapper2.wrap(encodeName('xyz'), account2, EMPTY_ADDRESS); - expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account2) + expect(await NameWrapper.ownerOf(namehash('xyz'))).to.equal(account2); expect(await EnsRegistry.owner(namehash('xyz'))).to.equal( NameWrapper.address, - ) - }) - }) -}) + ); + }); + }); +}); diff --git a/packages/linea-state-verifier/package.json b/packages/linea-state-verifier/package.json index af2303f88..0d786eab8 100644 --- a/packages/linea-state-verifier/package.json +++ b/packages/linea-state-verifier/package.json @@ -1,7 +1,7 @@ { "name": "@consensys/linea-state-verifier", "version": "1.0.1", - "description": "This library is intended to be used specifacilly to resolve any Linea storage state on L1", + "description": "This library is intended to be used specifically to resolve any Linea storage state on L1", "scripts": { "compile": "hardhat compile", "clean": "rm -fr artifacts cache node_modules typechain-types"