From f2e79f770c41794bea8eb658d06b32c5407d7ee2 Mon Sep 17 00:00:00 2001 From: James Earle Date: Tue, 31 Oct 2023 08:56:09 -0400 Subject: [PATCH 1/4] WIP allowing for approved resolvers to be a thing but working on how we handle the string key in registration --- contracts/registrar/IZNSRootRegistrar.sol | 13 +++-- contracts/registrar/ZNSRootRegistrar.sol | 21 +++++--- contracts/registrar/ZNSSubRegistrar.sol | 1 + contracts/registry/IZNSRegistry.sol | 31 +++++++++++- contracts/registry/ZNSRegistry.sol | 62 ++++++++++++++++++----- 5 files changed, 103 insertions(+), 25 deletions(-) diff --git a/contracts/registrar/IZNSRootRegistrar.sol b/contracts/registrar/IZNSRootRegistrar.sol index a732fc5d0..4b0483e08 100644 --- a/contracts/registrar/IZNSRootRegistrar.sol +++ b/contracts/registrar/IZNSRootRegistrar.sol @@ -4,18 +4,21 @@ pragma solidity ^0.8.18; import { IDistributionConfig } from "../types/IDistributionConfig.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - +/** + * // TODO confirm w/ kirill + * @notice Stake fee is 0x0 for anything other than subdomain under a parent with Stake Payment + * parent hash will be 0x0 for root domain + */ struct CoreRegisterArgs { - // 0x0 for root domains bytes32 parentHash; bytes32 domainHash; - string label; address registrant; + address domainAddress; uint256 price; - // 0x0 for anything other than subdomain under a parent with Stake Payment uint256 stakeFee; - address domainAddress; + string label; string tokenURI; + string resolverType; bool isStakePayment; } diff --git a/contracts/registrar/ZNSRootRegistrar.sol b/contracts/registrar/ZNSRootRegistrar.sol index c5afde960..21fe194cc 100644 --- a/contracts/registrar/ZNSRootRegistrar.sol +++ b/contracts/registrar/ZNSRootRegistrar.sol @@ -62,7 +62,7 @@ contract ZNSRootRegistrar is setRootPricer(rootPricer_); setTreasury(treasury_); setDomainToken(domainToken_); - setAddressResolver(addressResolver_); + setAddressResolver(addressResolver_); // TODO setResolver() instead with generic interface? } /** @@ -103,16 +103,21 @@ contract ZNSRootRegistrar is // Get price for the domain uint256 domainPrice = rootPricer.getPrice(0x0, name); + // TODO function always receives a domainAddress or address(0), + // so is it safe to assume "address" resolver type below? + // How do we make this more generic for future use with diffewrent resolvers + // without needing an upgrade each time _coreRegister( CoreRegisterArgs( bytes32(0), domainHash, - name, msg.sender, - domainPrice, - 0, domainAddress, + domainPrice, + 0, + name, tokenURI, + "address", true ) ); @@ -174,10 +179,14 @@ contract ZNSRootRegistrar is // If the `domainAddress` is not provided upon registration, a user can call `ZNSAddressResolver.setAddress` // to set the address themselves. if (args.domainAddress != address(0)) { - registry.createDomainRecord(args.domainHash, args.registrant, address(addressResolver)); + registry.createDomainRecord(args.domainHash, args.registrant, args.resolverType); + // TODO resolve, the type of resolver is arg but we set here with address specifically + // TODO if we can genericize this, use something like `IZNSResolver.set()` instead + // which would set whatever the valid is for whatever the resolver type is addressResolver.setAddress(args.domainHash, args.domainAddress); } else { - registry.createDomainRecord(args.domainHash, args.registrant, address(0)); + // By passing an empty string we tell the registry to not add a resolver + registry.createDomainRecord(args.domainHash, args.registrant, ""); } emit DomainRegistered( diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index dd0dd03fe..3245b8b5c 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -103,6 +103,7 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, price: 0, stakeFee: 0, domainAddress: domainAddress, + resolverType: "address", tokenURI: tokenURI, isStakePayment: parentConfig.paymentType == PaymentType.STAKE }); diff --git a/contracts/registry/IZNSRegistry.sol b/contracts/registry/IZNSRegistry.sol index fdf9b258b..88b60aa2c 100644 --- a/contracts/registry/IZNSRegistry.sol +++ b/contracts/registry/IZNSRegistry.sol @@ -63,6 +63,24 @@ interface IZNSRegistry { bool allowed ); + /** + * @notice Emitted when a new resolver type is added to ZNS + * @param resolverType The name of the resolver type + * @param resolver The address of the resolver contract + */ + event ResolverAdded( + string resolverType, + address resolver + ); + + /** + * @notice Emitted when a resolver is deleted from ZNS + * @param resolverType The name of the resolver type + */ + event ResolverDeleted( + string resolverType + ); + function initialize(address accessController) external; function exists(bytes32 domainHash) external view returns (bool); @@ -100,20 +118,29 @@ interface IZNSRegistry { function createDomainRecord( bytes32 domainHash, address owner, + string calldata resolverType + ) external; + + function addResolver( + string calldata resolverType, address resolver ) external; + function deleteResolver( + string calldata resolverType + ) external; + function updateDomainRecord( bytes32 domainHash, address owner, - address resolver + string calldata resolverType ) external; function updateDomainOwner(bytes32 domainHash, address owner) external; function updateDomainResolver( bytes32 domainHash, - address resolver + string calldata resolverType ) external; function deleteRecord(bytes32 domainHash) external; diff --git a/contracts/registry/ZNSRegistry.sol b/contracts/registry/ZNSRegistry.sol index 3588d8a59..d52336642 100644 --- a/contracts/registry/ZNSRegistry.sol +++ b/contracts/registry/ZNSRegistry.sol @@ -12,6 +12,10 @@ import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils * Owner of a domain in this contract also serves as the owner of the stake in `ZNSTreasury`. */ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { + + // Mapping of all approved resolvers + mapping(string resolverType => address resolver) internal resolvers; // TODO public for registrations? + /** * @notice Mapping of `domainHash` to [DomainRecord](./IZNSRegistry.md#iznsregistry) struct to hold information * about each domain @@ -149,21 +153,48 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { * Emits `DomainOwnerSet` and possibly `DomainResolverSet` events. * @param domainHash The hash of the domain name * @param owner The owner of the new domain - * @param resolver The resolver of the new domain, can be 0 + * @param resolverType The string identifier of the resolver for the new domain, e.g. "address" */ function createDomainRecord( bytes32 domainHash, address owner, - address resolver + string calldata resolverType ) external override onlyRegistrar { _setDomainOwner(domainHash, owner); // We allow creation of partial domain data with no resolver address - if (resolver != address(0)) { - _setDomainResolver(domainHash, resolver); + if (bytes(resolverType).length != 0) { + _setDomainResolver(domainHash, resolverType); } } + /** + * @notice Given a resolver type, returns the address of the resolver contract for that type or 0x0 if not found + * @param resolverType The resolver type as a string, e.g. "address" + */ + function getResolver(string calldata resolverType) public view returns(address) { + return resolvers[resolverType]; + } + + /** + * @notice Add a new resolver type option to the mapping of types + * This function can also be used to update the resolver mapping for an existing resolver + * simple by using an existing key like "address" with a new address + * @param resolverType The type of the resolver to add + * @param resolver The address of the new resolver contract + */ + function addResolver(string calldata resolverType, address resolver) public override onlyAdmin { + resolvers[resolverType] = resolver; + + emit ResolverAdded(resolverType, resolver); + } + + function deleteResolver(string calldata resolverType) public override onlyAdmin { + delete resolvers[resolverType]; + + emit ResolverDeleted(resolverType); + } + /** * @notice Updates an existing domain record's owner and resolver. * Note that this function can ONLY be called by the Name owner of the domain. @@ -173,16 +204,16 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { * Emits `DomainOwnerSet` and `DomainResolverSet` events. * @param domainHash The hash of the domain * @param owner The owner or an allowed operator of that domain - * @param resolver The resolver for the domain + * @param resolverType The resolver for the domain */ function updateDomainRecord( bytes32 domainHash, address owner, - address resolver + string calldata resolverType ) external override onlyOwner(domainHash) { // `exists` is checked implicitly through the modifier _setDomainOwner(domainHash, owner); - _setDomainResolver(domainHash, resolver); + _setDomainResolver(domainHash, resolverType); } /** @@ -209,14 +240,14 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { * @notice Updates the resolver of an existing domain in `records`. * Can be called by eithe the owner of the Name or an allowed operator. * @param domainHash the hash of a domain's name - * @param resolver The new Resolver contract address + * @param resolverType The new Resolver contract address */ function updateDomainResolver( bytes32 domainHash, - address resolver + string calldata resolverType ) external override onlyOwnerOrOperator(domainHash) { // `exists` is checked implicitly through the modifier - _setDomainResolver(domainHash, resolver); + _setDomainResolver(domainHash, resolverType); } /** @@ -257,12 +288,19 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { * @notice Internal function to set a domain's resolver in state `records`. * Resolver can be set to 0, since we allow partial domain data. Emits a `DomainResolverSet` event. * @param domainHash the hash of a domain's name - * @param resolver The resolver to set + * @param resolverType The resolver to set */ function _setDomainResolver( bytes32 domainHash, - address resolver + string calldata resolverType ) internal { + address resolver = resolvers[resolverType]; + + require( + resolver != address(0), + "ZNSRegistry: Resolver not found" + ); + records[domainHash].resolver = resolver; emit DomainResolverSet(domainHash, resolver); } From 6d3a6129dfd9f3cce813008e362704448b447560 Mon Sep 17 00:00:00 2001 From: James Earle Date: Wed, 1 Nov 2023 15:48:30 -0700 Subject: [PATCH 2/4] fix completeted, all tests for registry passing, new tests in place for changed functionality --- contracts/registrar/IZNSRootRegistrar.sol | 13 +- contracts/registrar/ZNSRootRegistrar.sol | 31 +---- contracts/registrar/ZNSSubRegistrar.sol | 1 - contracts/registry/IZNSRegistry.sol | 8 +- contracts/registry/ZNSRegistry.sol | 21 ++- test/ZNSRegistry.test.ts | 153 ++++++++++++++++------ test/helpers/deploy/deploy-zns.ts | 2 - test/helpers/types.ts | 1 - 8 files changed, 135 insertions(+), 95 deletions(-) diff --git a/contracts/registrar/IZNSRootRegistrar.sol b/contracts/registrar/IZNSRootRegistrar.sol index 4b0483e08..a6fc16980 100644 --- a/contracts/registrar/IZNSRootRegistrar.sol +++ b/contracts/registrar/IZNSRootRegistrar.sol @@ -5,7 +5,6 @@ import { IDistributionConfig } from "../types/IDistributionConfig.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** - * // TODO confirm w/ kirill * @notice Stake fee is 0x0 for anything other than subdomain under a parent with Stake Payment * parent hash will be 0x0 for root domain */ @@ -18,7 +17,6 @@ struct CoreRegisterArgs { uint256 stakeFee; string label; string tokenURI; - string resolverType; bool isStakePayment; } @@ -117,19 +115,12 @@ interface IZNSRootRegistrar is IDistributionConfig { */ event SubRegistrarSet(address subRegistrar); - /** - * @notice Emitted when the `addressResolver` address is set in state. - * @param addressResolver The new address of the AddressResolver contract - */ - event AddressResolverSet(address addressResolver); - function initialize( address accessController_, address registry_, address rootPricer_, address treasury_, - address domainToken_, - address addressResolver_ + address domainToken_ ) external; function registerRootDomain( @@ -158,6 +149,4 @@ interface IZNSRootRegistrar is IDistributionConfig { function setDomainToken(address domainToken_) external; function setSubRegistrar(address subRegistrar_) external; - - function setAddressResolver(address addressResolver_) external; } diff --git a/contracts/registrar/ZNSRootRegistrar.sol b/contracts/registrar/ZNSRootRegistrar.sol index 21fe194cc..f9b6e710d 100644 --- a/contracts/registrar/ZNSRootRegistrar.sol +++ b/contracts/registrar/ZNSRootRegistrar.sol @@ -34,7 +34,6 @@ contract ZNSRootRegistrar is IZNSPricer public rootPricer; IZNSTreasury public treasury; IZNSDomainToken public domainToken; - IZNSAddressResolver public addressResolver; IZNSSubRegistrar public subRegistrar; /** @@ -47,22 +46,19 @@ contract ZNSRootRegistrar is * @param rootPricer_ Address of the IZNSPricer type contract that Zero chose to use for the root domains * @param treasury_ Address of the ZNSTreasury contract * @param domainToken_ Address of the ZNSDomainToken contract - * @param addressResolver_ Address of the ZNSAddressResolver contract */ function initialize( address accessController_, address registry_, address rootPricer_, address treasury_, - address domainToken_, - address addressResolver_ + address domainToken_ ) external override initializer { _setAccessController(accessController_); setRegistry(registry_); setRootPricer(rootPricer_); setTreasury(treasury_); setDomainToken(domainToken_); - setAddressResolver(addressResolver_); // TODO setResolver() instead with generic interface? } /** @@ -117,7 +113,6 @@ contract ZNSRootRegistrar is 0, name, tokenURI, - "address", true ) ); @@ -179,11 +174,10 @@ contract ZNSRootRegistrar is // If the `domainAddress` is not provided upon registration, a user can call `ZNSAddressResolver.setAddress` // to set the address themselves. if (args.domainAddress != address(0)) { - registry.createDomainRecord(args.domainHash, args.registrant, args.resolverType); - // TODO resolve, the type of resolver is arg but we set here with address specifically - // TODO if we can genericize this, use something like `IZNSResolver.set()` instead - // which would set whatever the valid is for whatever the resolver type is - addressResolver.setAddress(args.domainHash, args.domainAddress); + registry.createDomainRecord(args.domainHash, args.registrant, "address"); + + address resolver = registry.getDomainResolver(args.domainHash); + IZNSAddressResolver(resolver).setAddress(args.domainHash, args.domainAddress); } else { // By passing an empty string we tell the registry to not add a resolver registry.createDomainRecord(args.domainHash, args.registrant, ""); @@ -389,21 +383,6 @@ contract ZNSRootRegistrar is emit SubRegistrarSet(subRegistrar_); } - /** - * @notice Setter function for the `ZNSAddressResolver` address in state. - * Only ADMIN in `ZNSAccessController` can call this function. - * @param addressResolver_ Address of the `ZNSAddressResolver` contract - */ - function setAddressResolver(address addressResolver_) public override onlyAdmin { - require( - addressResolver_ != address(0), - "ZNSRootRegistrar: addressResolver_ is 0x0 address" - ); - addressResolver = IZNSAddressResolver(addressResolver_); - - emit AddressResolverSet(addressResolver_); - } - /** * @notice To use UUPS proxy we override this function and revert if `msg.sender` isn't authorized * @param newImplementation The implementation contract to upgrade to diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index 3245b8b5c..dd0dd03fe 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -103,7 +103,6 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, price: 0, stakeFee: 0, domainAddress: domainAddress, - resolverType: "address", tokenURI: tokenURI, isStakePayment: parentConfig.paymentType == PaymentType.STAKE }); diff --git a/contracts/registry/IZNSRegistry.sol b/contracts/registry/IZNSRegistry.sol index 88b60aa2c..f6df6e3f3 100644 --- a/contracts/registry/IZNSRegistry.sol +++ b/contracts/registry/IZNSRegistry.sol @@ -121,12 +121,16 @@ interface IZNSRegistry { string calldata resolverType ) external; - function addResolver( + function getResolverType( + string calldata resolverType + ) external returns (address); + + function addResolverType( string calldata resolverType, address resolver ) external; - function deleteResolver( + function deleteResolverType( string calldata resolverType ) external; diff --git a/contracts/registry/ZNSRegistry.sol b/contracts/registry/ZNSRegistry.sol index d52336642..78bf4e96e 100644 --- a/contracts/registry/ZNSRegistry.sol +++ b/contracts/registry/ZNSRegistry.sol @@ -14,7 +14,7 @@ import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { // Mapping of all approved resolvers - mapping(string resolverType => address resolver) internal resolvers; // TODO public for registrations? + mapping(string resolverType => address resolver) internal resolvers; /** * @notice Mapping of `domainHash` to [DomainRecord](./IZNSRegistry.md#iznsregistry) struct to hold information @@ -172,7 +172,7 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { * @notice Given a resolver type, returns the address of the resolver contract for that type or 0x0 if not found * @param resolverType The resolver type as a string, e.g. "address" */ - function getResolver(string calldata resolverType) public view returns(address) { + function getResolverType(string calldata resolverType) public view override returns(address) { return resolvers[resolverType]; } @@ -183,15 +183,17 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { * @param resolverType The type of the resolver to add * @param resolver The address of the new resolver contract */ - function addResolver(string calldata resolverType, address resolver) public override onlyAdmin { + function addResolverType(string calldata resolverType, address resolver) public override onlyAdmin { resolvers[resolverType] = resolver; - emit ResolverAdded(resolverType, resolver); } - function deleteResolver(string calldata resolverType) public override onlyAdmin { + /** + * @notice Delete a resolver type from the mapping of types + * @param resolverType The type to be removed + */ + function deleteResolverType(string calldata resolverType) public override onlyAdmin { delete resolvers[resolverType]; - emit ResolverDeleted(resolverType); } @@ -238,7 +240,7 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { /** * @notice Updates the resolver of an existing domain in `records`. - * Can be called by eithe the owner of the Name or an allowed operator. + * Can be called by either the owner of the Name or an allowed operator. * @param domainHash the hash of a domain's name * @param resolverType The new Resolver contract address */ @@ -296,11 +298,6 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry { ) internal { address resolver = resolvers[resolverType]; - require( - resolver != address(0), - "ZNSRegistry: Resolver not found" - ); - records[domainHash].resolver = resolver; emit DomainResolverSet(domainHash, resolver); } diff --git a/test/ZNSRegistry.test.ts b/test/ZNSRegistry.test.ts index 15ab5b1e5..9ecedb6a1 100644 --- a/test/ZNSRegistry.test.ts +++ b/test/ZNSRegistry.test.ts @@ -35,6 +35,8 @@ describe("ZNSRegistry", () => { let zns : IZNSContracts; let wilderDomainHash : string; + const resolverTypeDefault = "address"; + beforeEach(async () => { [deployer, operator, randomUser, mockResolver, mockRegistrar] = await hre.ethers.getSigners(); @@ -50,10 +52,12 @@ describe("ZNSRegistry", () => { await zns.accessController.connect(deployer).grantRole(REGISTRAR_ROLE, mockRegistrar.address); + await zns.registry.connect(deployer).addResolverType(resolverTypeDefault, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord( wilderDomainHash, deployer.address, - mockResolver.address + resolverTypeDefault ); }); @@ -108,6 +112,66 @@ describe("ZNSRegistry", () => { ); }); + describe("Audit fix with approved address resolvers", () => { + it("Adds `address` resolver type and creates a record", async () => { + + const domainHash = hashDomainLabel("world"); + + await zns.registry.connect(mockRegistrar).createDomainRecord( + domainHash, + deployer.address, + resolverTypeDefault + ); + + const record = await zns.registry.getDomainRecord(domainHash); + + expect(record.resolver).to.eq(mockResolver.address); + }); + + it("Gets the resolver we currently have assigned to a certain type", async () => { + const resolver = await zns.registry.getResolverType(resolverTypeDefault); + + expect(resolver).to.eq(mockResolver.address); + }); + + it("Returns zero for a resolver type that doesn't exist", async () => { + const resolver = await zns.registry.getResolverType("random-type"); + + expect(resolver).to.eq(ethers.constants.AddressZero); + }); + + it("Adds a new resolver type", async () => { + const resolverType = "test-resolver"; + await zns.registry.connect(deployer).addResolverType(resolverType, randomUser.address); + + const domainHash = hashDomainLabel("world"); + + await zns.registry.connect(mockRegistrar).createDomainRecord( + domainHash, + deployer.address, + resolverType + ); + + const record = await zns.registry.getDomainRecord(domainHash); + expect(record.resolver).to.eq(randomUser.address); + }); + + it("Deletes a resolver type", async () => { + const resolverType = "test-resolver"; + await zns.registry.connect(deployer).addResolverType(resolverType, randomUser.address); + + // Read the resolver type + let resolver = await zns.registry.getResolverType(resolverType); + expect(resolver).to.eq(randomUser.address); + + // Delete it + await zns.registry.connect(deployer).deleteResolverType(resolverType); + + resolver = await zns.registry.getResolverType(resolverType); + expect(resolver).to.eq(hre.ethers.constants.AddressZero); + }); + }); + describe("Operator functionality", () => { it("Returns false when an operator is not allowed by an owner", async () => { await zns.registry.connect(deployer).setOwnersOperator(operator.address, false); @@ -138,10 +202,17 @@ describe("ZNSRegistry", () => { it("Permits an allowed operator to update a domain record", async () => { await zns.registry.connect(deployer).setOwnersOperator(operator.address, true); + const testType = "test-resolver"; + await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); + const tx = zns.registry .connect(operator) - .updateDomainResolver(wilderDomainHash, operator.address); - await expect(tx).to.not.be.reverted; + .updateDomainResolver(wilderDomainHash, testType); + + await expect(tx).to.emit(zns.registry, "DomainResolverSet").withArgs( + wilderDomainHash, + randomUser.address + ); }); it("Does not permit a disallowed operator to update a domain record", async () => { @@ -217,7 +288,7 @@ describe("ZNSRegistry", () => { await zns.registry.connect(mockRegistrar).createDomainRecord( domainHash, deployer.address, - mockResolver.address + resolverTypeDefault ); }); @@ -227,7 +298,7 @@ describe("ZNSRegistry", () => { const tx = zns.registry.connect(deployer).createDomainRecord( domainHash, deployer.address, - mockResolver.address + resolverTypeDefault ); await expect(tx).to.be.revertedWith( @@ -249,13 +320,16 @@ describe("ZNSRegistry", () => { it("Can update a domain record if the domain exists", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); - await zns.registry.updateDomainRecord(domainHash, mockRegistrar.address, deployer.address); + const testType = "test-resolver"; + await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); + + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.updateDomainRecord(domainHash, mockRegistrar.address, testType); const record = await zns.registry.getDomainRecord(domainHash); expect(record.owner).to.eq(mockRegistrar.address); - expect(record.resolver).to.eq(deployer.address); + expect(record.resolver).to.eq(randomUser.address); }); it("Cannot update a domain owner if the domain doesn't exist", async () => { @@ -270,7 +344,7 @@ describe("ZNSRegistry", () => { it("Can update a domain owner if the domain exists", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); await zns.registry.updateDomainOwner(domainHash, mockRegistrar.address); const record = await zns.registry.getDomainRecord(domainHash); @@ -289,18 +363,21 @@ describe("ZNSRegistry", () => { it("Can update a domain resolver if the domain exists", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); - await zns.registry.updateDomainResolver(domainHash, deployer.address); + const testType = "test-resolver"; + await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); + + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.updateDomainResolver(domainHash, testType); const record = await zns.registry.getDomainRecord(domainHash); - expect(record.resolver).to.eq(deployer.address); + expect(record.resolver).to.eq(randomUser.address); }); it("Cannot update a domain record if the owner is zero address", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.updateDomainRecord(domainHash, ethers.constants.AddressZero, mockResolver.address); await expect(tx).to.be.revertedWith(OWNER_NOT_ZERO_REG_ERR); @@ -309,7 +386,7 @@ describe("ZNSRegistry", () => { it("Can update a domain record if the resolver is zero address", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.updateDomainRecord(domainHash, mockResolver.address, ethers.constants.AddressZero); await expect(tx).to.be.fulfilled; @@ -353,7 +430,7 @@ describe("ZNSRegistry", () => { it("cannot update a domain's record if not an owner or operator", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.connect(randomUser).updateDomainRecord( domainHash, mockResolver.address, @@ -366,7 +443,7 @@ describe("ZNSRegistry", () => { it("cannot update an domain's owner if not an owner or operator", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.connect(randomUser).updateDomainOwner(domainHash, mockResolver.address); await expect(tx).to.be.revertedWith( @@ -377,7 +454,7 @@ describe("ZNSRegistry", () => { it("cannot update a domain's resolver if not an owner or operator", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.connect(randomUser).updateDomainResolver(domainHash, deployer.address); await expect(tx).to.be.revertedWith(NOT_AUTHORIZED_REG_ERR); @@ -386,7 +463,7 @@ describe("ZNSRegistry", () => { it("Can delete record with REGISTRAR_ROLE", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); await zns.registry.connect(mockRegistrar).deleteRecord(domainHash); const record = await zns.registry.getDomainRecord(domainHash); @@ -397,7 +474,7 @@ describe("ZNSRegistry", () => { it("Cannot delete record without REGISTRAR_ROLE", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.connect(randomUser).deleteRecord(domainHash); await expect(tx).to.be.revertedWith( @@ -420,52 +497,47 @@ describe("ZNSRegistry", () => { it("Emits events when a new domain is created", async () => { const domainHash = hashDomainLabel("world"); - const tx = await zns.registry + const resolver = await zns.registry.getResolverType(resolverTypeDefault); + + const tx = zns.registry .connect(mockRegistrar) .createDomainRecord( domainHash, deployer.address, - mockResolver.address + resolverTypeDefault ); - const rec = await tx.wait(0); - const [ ownerEvent, resolverEvent ] = rec.events ?? []; - expect(ownerEvent.event).to.be.eq("DomainOwnerSet"); - expect(ownerEvent.args?.[0]).to.be.eq(domainHash); - expect(ownerEvent.args?.[1]).to.be.eq(deployer.address); - - expect(resolverEvent.event).to.be.eq("DomainResolverSet"); - expect(resolverEvent.args?.[0]).to.be.eq(domainHash); - expect(resolverEvent.args?.[1]).to.be.eq(mockResolver.address); + await expect(tx).to.emit(zns.registry, "DomainOwnerSet").withArgs(domainHash, deployer.address) + .emit(zns.registry, "DomainResolverSet").withArgs(domainHash, mockResolver.address); }); it("Emits an event when an existing domain is updated", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = await zns.registry .connect(deployer) .updateDomainRecord( domainHash, mockResolver.address, - deployer.address + resolverTypeDefault ); const rec = await tx.wait(0); - const [ ownerEvent, resolverEvent ] = rec.events ?? []; + const [ownerEvent, resolverEvent] = rec.events ?? []; expect(ownerEvent.event).to.be.eq("DomainOwnerSet"); expect(ownerEvent.args?.[0]).to.be.eq(domainHash); expect(ownerEvent.args?.[1]).to.be.eq(mockResolver.address); expect(resolverEvent.event).to.be.eq("DomainResolverSet"); expect(resolverEvent.args?.[0]).to.be.eq(domainHash); - expect(resolverEvent.args?.[1]).to.be.eq(deployer.address); + expect(resolverEvent.args?.[1]).to.be.eq(mockResolver.address); }); it("Emits an event when a domain's owner is updated", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); const tx = zns.registry.connect(deployer).updateDomainOwner(domainHash, mockResolver.address); await expect(tx).to.emit(zns.registry, "DomainOwnerSet").withArgs( @@ -477,12 +549,15 @@ describe("ZNSRegistry", () => { it("Emits an event when a domain's resolver is updated", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, mockResolver.address); - const tx = zns.registry.connect(deployer).updateDomainResolver(domainHash, deployer.address); + const testType = "test-resolver"; + await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); + + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + const tx = zns.registry.connect(deployer).updateDomainResolver(domainHash, testType); await expect(tx).to.emit(zns.registry, "DomainResolverSet").withArgs( domainHash, - deployer.address + randomUser.address ); }); @@ -533,7 +608,7 @@ describe("ZNSRegistry", () => { await zns.registry.connect(mockRegistrar).createDomainRecord( domainHash, deployer.address, - mockResolver.address + resolverTypeDefault ); const contractCalls = [ diff --git a/test/helpers/deploy/deploy-zns.ts b/test/helpers/deploy/deploy-zns.ts index a10a8ff06..52dc0e2c4 100644 --- a/test/helpers/deploy/deploy-zns.ts +++ b/test/helpers/deploy/deploy-zns.ts @@ -360,7 +360,6 @@ export const deployRootRegistrar = async ( config.curvePricerAddress, config.treasury.address, config.domainTokenAddress, - config.addressResolverAddress, ], { kind: "uups", @@ -592,7 +591,6 @@ export const deployZNS = async ({ registryAddress: registry.address, curvePricerAddress: curvePricer.address, domainTokenAddress: domainToken.address, - addressResolverAddress: addressResolver.address, }; const rootRegistrar = await deployRootRegistrar( diff --git a/test/helpers/types.ts b/test/helpers/types.ts index 2d01e68b4..04b674a7c 100644 --- a/test/helpers/types.ts +++ b/test/helpers/types.ts @@ -92,7 +92,6 @@ export interface RegistrarConfig { registryAddress : string; curvePricerAddress : string; domainTokenAddress : string; - addressResolverAddress : string; } export interface IZNSContracts { From 474029689b8f960bce5af94572563416abaa6f67 Mon Sep 17 00:00:00 2001 From: James Earle Date: Thu, 2 Nov 2023 10:24:22 -0700 Subject: [PATCH 3/4] zns-18 fix, updates to tests --- hardhat.config.ts | 2 +- test/ZNSAddressResolver.test.ts | 7 ++++- test/ZNSRegistry.test.ts | 52 +++++++++++++++---------------- test/ZNSRootRegistrar.test.ts | 30 ------------------ test/gas/gas-costs.json | 4 +-- test/helpers/constants.ts | 1 + test/helpers/deploy/deploy-zns.ts | 2 ++ 7 files changed, 38 insertions(+), 60 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index a93f8c633..354b135bf 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -71,7 +71,7 @@ const config : HardhatUserConfig = { timeout: 5000000, }, gasReporter: { - enabled: true + enabled: false }, networks: { mainnet: { diff --git a/test/ZNSAddressResolver.test.ts b/test/ZNSAddressResolver.test.ts index a8aa93646..7fc4676ff 100644 --- a/test/ZNSAddressResolver.test.ts +++ b/test/ZNSAddressResolver.test.ts @@ -5,6 +5,7 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { hashDomainLabel, hashSubdomainName } from "./helpers/hashing"; import { ADMIN_ROLE, + DEFAULT_RESOLVER_TYPE, GOVERNOR_ROLE, REGISTRAR_ROLE, deployZNS, @@ -44,11 +45,13 @@ describe("ZNSAddressResolver", () => { await zns.accessController.connect(deployer).grantRole(REGISTRAR_ROLE, mockRegistrar.address); + await zns.registry.connect(deployer).addResolverType(DEFAULT_RESOLVER_TYPE, zns.addressResolver.address); + await zns.registry.connect(mockRegistrar) .createDomainRecord( wilderDomainHash, deployer.address, - zns.addressResolver.address + DEFAULT_RESOLVER_TYPE ); }); @@ -56,7 +59,9 @@ describe("ZNSAddressResolver", () => { // The domain exists const existResolver = await zns.registry.getDomainResolver(wilderDomainHash); expect(existResolver).to.eq(zns.addressResolver.address); + }); + it("Returns 0 when the domain doesnt exist", async () => { // The domain does not exist const someDomainHash = hashDomainLabel("random-record"); const notExistResolver = await zns.registry.getDomainResolver(someDomainHash); diff --git a/test/ZNSRegistry.test.ts b/test/ZNSRegistry.test.ts index 9ecedb6a1..f40816eec 100644 --- a/test/ZNSRegistry.test.ts +++ b/test/ZNSRegistry.test.ts @@ -12,7 +12,9 @@ import { REGISTRAR_ROLE, INITIALIZED_ERR, getAccessRevertMsg, - validateUpgrade, NOT_AUTHORIZED_REG_ERR, + validateUpgrade, + NOT_AUTHORIZED_REG_ERR, + DEFAULT_RESOLVER_TYPE, } from "./helpers"; import { ONLY_NAME_OWNER_REG_ERR, @@ -35,8 +37,6 @@ describe("ZNSRegistry", () => { let zns : IZNSContracts; let wilderDomainHash : string; - const resolverTypeDefault = "address"; - beforeEach(async () => { [deployer, operator, randomUser, mockResolver, mockRegistrar] = await hre.ethers.getSigners(); @@ -52,12 +52,12 @@ describe("ZNSRegistry", () => { await zns.accessController.connect(deployer).grantRole(REGISTRAR_ROLE, mockRegistrar.address); - await zns.registry.connect(deployer).addResolverType(resolverTypeDefault, mockResolver.address); + await zns.registry.connect(deployer).addResolverType(DEFAULT_RESOLVER_TYPE, mockResolver.address); await zns.registry.connect(mockRegistrar).createDomainRecord( wilderDomainHash, deployer.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); }); @@ -120,7 +120,7 @@ describe("ZNSRegistry", () => { await zns.registry.connect(mockRegistrar).createDomainRecord( domainHash, deployer.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); const record = await zns.registry.getDomainRecord(domainHash); @@ -129,7 +129,7 @@ describe("ZNSRegistry", () => { }); it("Gets the resolver we currently have assigned to a certain type", async () => { - const resolver = await zns.registry.getResolverType(resolverTypeDefault); + const resolver = await zns.registry.getResolverType(DEFAULT_RESOLVER_TYPE); expect(resolver).to.eq(mockResolver.address); }); @@ -288,7 +288,7 @@ describe("ZNSRegistry", () => { await zns.registry.connect(mockRegistrar).createDomainRecord( domainHash, deployer.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); }); @@ -298,7 +298,7 @@ describe("ZNSRegistry", () => { const tx = zns.registry.connect(deployer).createDomainRecord( domainHash, deployer.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); await expect(tx).to.be.revertedWith( @@ -323,7 +323,7 @@ describe("ZNSRegistry", () => { const testType = "test-resolver"; await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); await zns.registry.updateDomainRecord(domainHash, mockRegistrar.address, testType); const record = await zns.registry.getDomainRecord(domainHash); @@ -344,7 +344,7 @@ describe("ZNSRegistry", () => { it("Can update a domain owner if the domain exists", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); await zns.registry.updateDomainOwner(domainHash, mockRegistrar.address); const record = await zns.registry.getDomainRecord(domainHash); @@ -366,7 +366,7 @@ describe("ZNSRegistry", () => { const testType = "test-resolver"; await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); await zns.registry.updateDomainResolver(domainHash, testType); const record = await zns.registry.getDomainRecord(domainHash); @@ -377,7 +377,7 @@ describe("ZNSRegistry", () => { it("Cannot update a domain record if the owner is zero address", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.updateDomainRecord(domainHash, ethers.constants.AddressZero, mockResolver.address); await expect(tx).to.be.revertedWith(OWNER_NOT_ZERO_REG_ERR); @@ -386,7 +386,7 @@ describe("ZNSRegistry", () => { it("Can update a domain record if the resolver is zero address", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.updateDomainRecord(domainHash, mockResolver.address, ethers.constants.AddressZero); await expect(tx).to.be.fulfilled; @@ -430,7 +430,7 @@ describe("ZNSRegistry", () => { it("cannot update a domain's record if not an owner or operator", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.connect(randomUser).updateDomainRecord( domainHash, mockResolver.address, @@ -443,7 +443,7 @@ describe("ZNSRegistry", () => { it("cannot update an domain's owner if not an owner or operator", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.connect(randomUser).updateDomainOwner(domainHash, mockResolver.address); await expect(tx).to.be.revertedWith( @@ -454,7 +454,7 @@ describe("ZNSRegistry", () => { it("cannot update a domain's resolver if not an owner or operator", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.connect(randomUser).updateDomainResolver(domainHash, deployer.address); await expect(tx).to.be.revertedWith(NOT_AUTHORIZED_REG_ERR); @@ -463,7 +463,7 @@ describe("ZNSRegistry", () => { it("Can delete record with REGISTRAR_ROLE", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); await zns.registry.connect(mockRegistrar).deleteRecord(domainHash); const record = await zns.registry.getDomainRecord(domainHash); @@ -474,7 +474,7 @@ describe("ZNSRegistry", () => { it("Cannot delete record without REGISTRAR_ROLE", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.connect(randomUser).deleteRecord(domainHash); await expect(tx).to.be.revertedWith( @@ -497,14 +497,14 @@ describe("ZNSRegistry", () => { it("Emits events when a new domain is created", async () => { const domainHash = hashDomainLabel("world"); - const resolver = await zns.registry.getResolverType(resolverTypeDefault); + await zns.registry.getResolverType(DEFAULT_RESOLVER_TYPE); const tx = zns.registry .connect(mockRegistrar) .createDomainRecord( domainHash, deployer.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); await expect(tx).to.emit(zns.registry, "DomainOwnerSet").withArgs(domainHash, deployer.address) @@ -514,13 +514,13 @@ describe("ZNSRegistry", () => { it("Emits an event when an existing domain is updated", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = await zns.registry .connect(deployer) .updateDomainRecord( domainHash, mockResolver.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); const rec = await tx.wait(0); @@ -537,7 +537,7 @@ describe("ZNSRegistry", () => { it("Emits an event when a domain's owner is updated", async () => { const domainHash = hashDomainLabel("world"); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.connect(deployer).updateDomainOwner(domainHash, mockResolver.address); await expect(tx).to.emit(zns.registry, "DomainOwnerSet").withArgs( @@ -552,7 +552,7 @@ describe("ZNSRegistry", () => { const testType = "test-resolver"; await zns.registry.connect(deployer).addResolverType(testType, randomUser.address); - await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, resolverTypeDefault); + await zns.registry.connect(mockRegistrar).createDomainRecord(domainHash, deployer.address, DEFAULT_RESOLVER_TYPE); const tx = zns.registry.connect(deployer).updateDomainResolver(domainHash, testType); await expect(tx).to.emit(zns.registry, "DomainResolverSet").withArgs( @@ -608,7 +608,7 @@ describe("ZNSRegistry", () => { await zns.registry.connect(mockRegistrar).createDomainRecord( domainHash, deployer.address, - resolverTypeDefault + DEFAULT_RESOLVER_TYPE ); const contractCalls = [ diff --git a/test/ZNSRootRegistrar.test.ts b/test/ZNSRootRegistrar.test.ts index 9594d1fc0..1a6186811 100644 --- a/test/ZNSRootRegistrar.test.ts +++ b/test/ZNSRootRegistrar.test.ts @@ -190,7 +190,6 @@ describe("ZNSRootRegistrar", () => { randomUser.address, randomUser.address, randomUser.address, - randomUser.address, ); await expect(tx).to.be.revertedWith(getAccessRevertMsg(user.address, ADMIN_ROLE)); @@ -203,7 +202,6 @@ describe("ZNSRootRegistrar", () => { randomUser.address, randomUser.address, randomUser.address, - randomUser.address, ); await expect(tx).to.be.revertedWith("Initializable: contract is already initialized"); @@ -1001,31 +999,6 @@ describe("ZNSRootRegistrar", () => { await expect(tx).to.be.revertedWith("ZNSRootRegistrar: domainToken_ is 0x0 address"); }); }); - - describe("#setAddressResolver", () => { - it("Should set AddressResolver and fire AddressResolverSet event", async () => { - const currentResolver = await zns.rootRegistrar.addressResolver(); - const tx = await zns.rootRegistrar.connect(deployer).setAddressResolver(randomUser.address); - const newResolver = await zns.rootRegistrar.addressResolver(); - - await expect(tx).to.emit(zns.rootRegistrar, "AddressResolverSet").withArgs(randomUser.address); - - expect(newResolver).to.equal(randomUser.address); - expect(currentResolver).to.not.equal(newResolver); - }); - - it("Should revert if not called by ADMIN", async () => { - const tx = zns.rootRegistrar.connect(user).setAddressResolver(randomUser.address); - await expect(tx).to.be.revertedWith( - getAccessRevertMsg(user.address, ADMIN_ROLE) - ); - }); - - it("Should revert if AddressResolver is address zero", async () => { - const tx = zns.rootRegistrar.connect(deployer).setAddressResolver(ethers.constants.AddressZero); - await expect(tx).to.be.revertedWith("ZNSRootRegistrar: addressResolver_ is 0x0 address"); - }); - }); }); describe("UUPS", () => { @@ -1074,14 +1047,11 @@ describe("ZNSRootRegistrar", () => { distrConfigEmpty ); - await zns.rootRegistrar.setAddressResolver(randomUser.address); - const contractCalls = [ zns.rootRegistrar.getAccessController(), zns.rootRegistrar.registry(), zns.rootRegistrar.treasury(), zns.rootRegistrar.domainToken(), - zns.rootRegistrar.addressResolver(), zns.registry.exists(domainHash), zns.treasury.stakedForDomain(domainHash), zns.domainToken.name(), diff --git a/test/gas/gas-costs.json b/test/gas/gas-costs.json index 52b8fd0d0..6df5e6abb 100644 --- a/test/gas/gas-costs.json +++ b/test/gas/gas-costs.json @@ -1,4 +1,4 @@ { - "Root Domain Price": "425483", - "Subdomain Price": "419495" + "Root Domain Price": "427240", + "Subdomain Price": "421406" } \ No newline at end of file diff --git a/test/helpers/constants.ts b/test/helpers/constants.ts index cbec24fac..df3a8d5a8 100644 --- a/test/helpers/constants.ts +++ b/test/helpers/constants.ts @@ -2,6 +2,7 @@ import { BigNumber } from "ethers"; import { ICurvePriceConfig } from "./types"; import { ethers } from "hardhat"; +export const DEFAULT_RESOLVER_TYPE = "address"; export const ZNS_DOMAIN_TOKEN_NAME = "ZNS Domain Token"; export const ZNS_DOMAIN_TOKEN_SYMBOL = "ZDT"; diff --git a/test/helpers/deploy/deploy-zns.ts b/test/helpers/deploy/deploy-zns.ts index 52dc0e2c4..8f35fd6ad 100644 --- a/test/helpers/deploy/deploy-zns.ts +++ b/test/helpers/deploy/deploy-zns.ts @@ -41,6 +41,7 @@ import { ZNS_DOMAIN_TOKEN_NAME, ZNS_DOMAIN_TOKEN_SYMBOL, defaultRoyaltyFraction, + DEFAULT_RESOLVER_TYPE } from "../constants"; import { REGISTRAR_ROLE } from "../access"; import { getProxyImplAddress } from "../utils"; @@ -635,6 +636,7 @@ export const deployZNS = async ({ // Give 15 ZERO to the deployer and allowance to the treasury await zeroTokenMock.connect(deployer).approve(treasury.address, ethers.constants.MaxUint256); await zeroTokenMock.mint(deployer.address, ethers.utils.parseEther("5000000")); + await registry.connect(deployer).addResolverType(DEFAULT_RESOLVER_TYPE, addressResolver.address); return znsContracts; }; From bb9c7ec3b1f097461311203f1f4e834991f96957 Mon Sep 17 00:00:00 2001 From: James Earle Date: Thu, 2 Nov 2023 11:07:07 -0700 Subject: [PATCH 4/4] other lint fixes --- test/ZNSRootRegistrar.test.ts | 2 +- test/helpers/deploy/deploy-zns.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ZNSRootRegistrar.test.ts b/test/ZNSRootRegistrar.test.ts index b1585b3e6..e346c7444 100644 --- a/test/ZNSRootRegistrar.test.ts +++ b/test/ZNSRootRegistrar.test.ts @@ -26,7 +26,7 @@ import { getPriceObject } from "./helpers/pricing"; import { getDomainHashFromReceipt, getTokenIdFromReceipt } from "./helpers/events"; import { getAccessRevertMsg, INVALID_NAME_ERR } from "./helpers/errors"; import { ADMIN_ROLE, GOVERNOR_ROLE } from "./helpers/access"; -import { ZNSRootRegistrar, ZNSRootRegistrar__factory, ZNSRootRegistrarUpgradeMock__factory } from "../typechain"; +import { ZNSRootRegistrar__factory, ZNSRootRegistrarUpgradeMock__factory } from "../typechain"; import { PaymentConfigStruct } from "../typechain/contracts/treasury/IZNSTreasury"; import { parseEther } from "ethers/lib/utils"; import { getProxyImplAddress } from "./helpers/utils"; diff --git a/test/helpers/deploy/deploy-zns.ts b/test/helpers/deploy/deploy-zns.ts index 8f35fd6ad..973f0eb74 100644 --- a/test/helpers/deploy/deploy-zns.ts +++ b/test/helpers/deploy/deploy-zns.ts @@ -41,7 +41,7 @@ import { ZNS_DOMAIN_TOKEN_NAME, ZNS_DOMAIN_TOKEN_SYMBOL, defaultRoyaltyFraction, - DEFAULT_RESOLVER_TYPE + DEFAULT_RESOLVER_TYPE, } from "../constants"; import { REGISTRAR_ROLE } from "../access"; import { getProxyImplAddress } from "../utils";