From f09082275564ecf2c3cc5c3de178f51e61a7a411 Mon Sep 17 00:00:00 2001 From: James Earle Date: Fri, 19 Jan 2024 14:47:10 -0800 Subject: [PATCH 1/7] restrict minting for free to only owners with both the token and domain name ; fixing tests --- contracts/registrar/ZNSSubRegistrar.sol | 34 +++++- test/ZNSSubRegistrar.test.ts | 144 +++++++++++++++++++++--- test/gas/gas-costs.json | 2 +- 3 files changed, 160 insertions(+), 20 deletions(-) diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index cd01d86a..bd2b3598 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -37,6 +37,14 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, uint256 ownerIndex; } + + // TODO natspec + struct Ownership { + address owner; + bool ownsBoth; + bool isOperatorForOwner; + } + /** * @notice Mapping of domainHash to mintlist set by the domain owner/operator. * These configs are used to determine who can register subdomains for every parent @@ -102,11 +110,23 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, DistributionConfig memory parentConfig = distrConfigs[parentHash]; - bool isOwnerOrOperator = registry.isOwnerOrOperator(parentHash, msg.sender); - require( - parentConfig.accessType != AccessType.LOCKED || isOwnerOrOperator, - "ZNSSubRegistrar: Parent domain's distribution is locked or parent does not exist" - ); + Ownership memory parent = Ownership({ + owner: registry.getDomainOwner(parentHash), + ownsBoth: false, + isOperatorForOwner: false + }); + + parent.ownsBoth = rootRegistrar.isOwnerOf(parentHash, parent.owner, IZNSRootRegistrar.OwnerOf.BOTH); + parent.isOperatorForOwner = registry.isOperatorFor(msg.sender, parent.owner); + + if (parentConfig.accessType == AccessType.LOCKED) { + require( + // Require that the parent owns both the token and the domain name + // as well as that the caller either is the parent owner, or an allowed operator + parent.ownsBoth && (parent.isOperatorForOwner || address(msg.sender) == parent.owner), + "ZNSSubRegistrar: Parent domain's distribution is locked or parent does not exist" + ); + } if (parentConfig.accessType == AccessType.MINTLIST) { require( @@ -131,7 +151,9 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, paymentConfig: paymentConfig }); - if (!isOwnerOrOperator) { + // If parent owns both and caller is either parent or an operator, mint for free + // If parent does not own both or the call is not an operator or the owner, pay to mint + if (!parent.ownsBoth || !(parent.isOperatorForOwner || address(msg.sender) == parent.owner)) { if (coreRegisterArgs.isStakePayment) { (coreRegisterArgs.price, coreRegisterArgs.stakeFee) = IZNSPricer(address(parentConfig.pricerContract)) .getPriceAndFee( diff --git a/test/ZNSSubRegistrar.test.ts b/test/ZNSSubRegistrar.test.ts index cf1592bd..33bf8db6 100644 --- a/test/ZNSSubRegistrar.test.ts +++ b/test/ZNSSubRegistrar.test.ts @@ -139,6 +139,123 @@ describe("ZNSSubRegistrar", () => { expect(config.beneficiary).to.eq(lvl2SubOwner.address); }); + it("Allows the owner of parent domain and token to register for free", async () => { + const subdomain = "another-subs"; + + const balanceBefore = await zns.meowToken.balanceOf(rootOwner.address); + + await zns.subRegistrar.connect(rootOwner).registerSubdomain( + rootHash, + subdomain, + rootOwner.address, + subTokenURI, + distrConfigEmpty, + { + token: await zns.meowToken.getAddress(), + beneficiary: rootOwner.address, + }, + ); + + const balanceAfter = await zns.meowToken.balanceOf(rootOwner.address); + + expect(balanceAfter).to.eq(balanceBefore); + }); + + // cant any user now register for free if owner owns both? + it("Allows an operator to register for free if the owner owns both", async () => { + const subdomain = "another-sub"; + + const balanceBefore = await zns.meowToken.balanceOf(lvl2SubOwner.address); + + await zns.meowToken.connect(lvl2SubOwner).approve(await zns.treasury.getAddress(), ethers.MaxUint256); + + await zns.registry.connect(rootOwner).setOwnersOperator(lvl2SubOwner.address, true); + + await zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( + rootHash, + subdomain, + rootOwner.address, + subTokenURI, + distrConfigEmpty, + { + token: await zns.meowToken.getAddress(), + beneficiary: rootOwner.address, + }, + ); + + const balanceAfter = await zns.meowToken.balanceOf(lvl2SubOwner.address); + + // Disable operator after check + await zns.registry.connect(rootOwner).setOwnersOperator(lvl2SubOwner.address, false); + + expect(balanceAfter).to.eq(balanceBefore); + }); + + it("Charges a price for an owner that does not own both the token and name", async () => { + const subdomain = "no-diggity"; + + const balanceBefore = await zns.meowToken.balanceOf(rootOwner.address); + + // Give token to lvl2SubOwner + await zns.domainToken.connect(rootOwner).transferFrom(rootOwner.address, lvl2SubOwner.address, rootHash); + + await zns.subRegistrar.connect(rootOwner).registerSubdomain( + rootHash, + subdomain, + rootOwner.address, + subTokenURI, + distrConfigEmpty, + { + token: await zns.meowToken.getAddress(), + beneficiary: rootOwner.address, + }, + ); + + // Restore token owner + await zns.domainToken.connect(lvl2SubOwner).transferFrom(lvl2SubOwner.address, rootOwner.address, rootHash); + + const balanceAfter = await zns.meowToken.balanceOf(rootOwner.address); + + expect(balanceAfter).to.not.eq(balanceBefore); + }); + + it("Charges a price for an operator of an owner that does not own both the token and name", async () => { + const subdomain = "no-diggities"; + + const balanceBefore = await zns.meowToken.balanceOf(lvl2SubOwner.address); + + // Give token to lvl2SubOwner + await zns.domainToken.connect(rootOwner).transferFrom(rootOwner.address, lvl2SubOwner.address, rootHash); + + await zns.registry.connect(rootOwner).setOwnersOperator(lvl2SubOwner.address, true); + + await zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( + rootHash, + subdomain, + lvl2SubOwner.address, + subTokenURI, + distrConfigEmpty, + { + token: await zns.meowToken.getAddress(), + beneficiary: rootOwner.address, + }, + ); + + // Restore token owner + await zns.domainToken.connect(lvl2SubOwner).transferFrom(lvl2SubOwner.address, rootOwner.address, rootHash); + + await zns.registry.connect(rootOwner).setOwnersOperator(lvl2SubOwner.address, false); + + const balanceAfter = await zns.meowToken.balanceOf(lvl2SubOwner.address); + + expect(balanceAfter).to.not.eq(balanceBefore); + }); + + // disallows an owner from registering for free if they don't own both + // disallows an operator from registering for free if the owner does not own both + // owner surpasses locked domains + // operator surpasses locked domains, maybe already tested these two + it("Does not set the payment config when the beneficiary is the zero address", async () => { const subdomain = "not-world-subdomain"; await expect( @@ -342,24 +459,25 @@ describe("ZNSSubRegistrar", () => { )).to.be.revertedWith(INVALID_NAME_ERR); }); - it("should revert when trying to register a subdomain under a non-existent parent", async () => { + it.only("should revert when trying to register a subdomain under a non-existent parent", async () => { // check that 0x0 hash can NOT be passed as parentHash - await expect( - zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( - ethers.ZeroHash, - "sub", - lvl2SubOwner.address, - subTokenURI, - distrConfigEmpty, - paymentConfigEmpty, - ) - ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR - ); + // await expect( + // zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( + // ethers.ZeroHash, + // "sub", + // lvl2SubOwner.address, + // subTokenURI, + // distrConfigEmpty, + // paymentConfigEmpty, + // ) + // ).to.be.revertedWith( + // "ERC721: invalid token ID" + // ); // check that a random non-existent hash can NOT be passed as parentHash const randomHash = ethers.keccak256(ethers.toUtf8Bytes("random")); await expect( + // erc721 invalid token id?? zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( randomHash, "sub", diff --git a/test/gas/gas-costs.json b/test/gas/gas-costs.json index 0e8224f1..b5f11f66 100644 --- a/test/gas/gas-costs.json +++ b/test/gas/gas-costs.json @@ -1,4 +1,4 @@ { "Root Domain Price": "475352", - "Subdomain Price": "469054" + "Subdomain Price": "477553" } \ No newline at end of file From 1bfc752623ddfa7877c82d64da38a2b783891298 Mon Sep 17 00:00:00 2001 From: James Earle Date: Fri, 19 Jan 2024 16:45:02 -0800 Subject: [PATCH 2/7] update tests --- contracts/registrar/ZNSSubRegistrar.sol | 6 +++- test/ZNSSubRegistrar.test.ts | 48 +++++++++++++------------ test/gas/gas-costs.json | 2 +- test/helpers/errors.ts | 3 +- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index bd2b3598..cea86bf6 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -107,6 +107,10 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, !registry.exists(domainHash), "ZNSSubRegistrar: Subdomain already exists" ); + require( + registry.exists(parentHash), + "ZNSSubRegistrar: Parent domain does not exist" + ); DistributionConfig memory parentConfig = distrConfigs[parentHash]; @@ -124,7 +128,7 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, // Require that the parent owns both the token and the domain name // as well as that the caller either is the parent owner, or an allowed operator parent.ownsBoth && (parent.isOperatorForOwner || address(msg.sender) == parent.owner), - "ZNSSubRegistrar: Parent domain's distribution is locked or parent does not exist" + "ZNSSubRegistrar: Parent domain's distribution is locked" ); } diff --git a/test/ZNSSubRegistrar.test.ts b/test/ZNSSubRegistrar.test.ts index 33bf8db6..1b5b942d 100644 --- a/test/ZNSSubRegistrar.test.ts +++ b/test/ZNSSubRegistrar.test.ts @@ -6,7 +6,6 @@ import { DEFAULT_TOKEN_URI, deployZNS, distrConfigEmpty, - DISTRIBUTION_LOCKED_NOT_EXIST_ERR, fullDistrConfigEmpty, getAccessRevertMsg, getPriceObject, @@ -20,6 +19,8 @@ import { DECAULT_PRECISION, DEFAULT_PRICE_CONFIG, validateUpgrade, + PARENT_NOT_EXIST_ERR, + DISTRIBUTION_LOCKED_ERR, } from "./helpers"; import * as hre from "hardhat"; import * as ethers from "ethers"; @@ -38,6 +39,7 @@ import { } from "../typechain"; import { deployCustomDecToken } from "./helpers/deploy/mocks"; import { getProxyImplAddress } from "./helpers/utils"; +import { parentPort } from "worker_threads"; describe("ZNSSubRegistrar", () => { @@ -459,25 +461,24 @@ describe("ZNSSubRegistrar", () => { )).to.be.revertedWith(INVALID_NAME_ERR); }); - it.only("should revert when trying to register a subdomain under a non-existent parent", async () => { + it("should revert when trying to register a subdomain under a non-existent parent", async () => { // check that 0x0 hash can NOT be passed as parentHash - // await expect( - // zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( - // ethers.ZeroHash, - // "sub", - // lvl2SubOwner.address, - // subTokenURI, - // distrConfigEmpty, - // paymentConfigEmpty, - // ) - // ).to.be.revertedWith( - // "ERC721: invalid token ID" - // ); + await expect( + zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( + ethers.ZeroHash, + "sub", + lvl2SubOwner.address, + subTokenURI, + distrConfigEmpty, + paymentConfigEmpty, + ) + ).to.be.revertedWith( + INVALID_TOKENID_ERC_ERR + ); // check that a random non-existent hash can NOT be passed as parentHash const randomHash = ethers.keccak256(ethers.toUtf8Bytes("random")); await expect( - // erc721 invalid token id?? zns.subRegistrar.connect(lvl2SubOwner).registerSubdomain( randomHash, "sub", @@ -487,7 +488,8 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR + // ERC721's `_requireMinted()` will fail when parent hash doesn't exist + PARENT_NOT_EXIST_ERR ); }); @@ -1058,7 +1060,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR + PARENT_NOT_EXIST_ERR ); const dataFromReg = await zns.registry.getDomainRecord(domainHash); @@ -1123,7 +1125,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR + PARENT_NOT_EXIST_ERR ); const dataFromReg = await zns.registry.getDomainRecord(domainHash); @@ -1350,7 +1352,7 @@ describe("ZNSSubRegistrar", () => { distrConfigEmpty, paymentConfigEmpty, ) - ).to.be.revertedWith(DISTRIBUTION_LOCKED_NOT_EXIST_ERR); + ).to.be.revertedWith(PARENT_NOT_EXIST_ERR); // register root back for other tests await registrationWithSetup({ @@ -1382,7 +1384,7 @@ describe("ZNSSubRegistrar", () => { distrConfigEmpty, paymentConfigEmpty, ) - ).to.be.revertedWith(DISTRIBUTION_LOCKED_NOT_EXIST_ERR); + ).to.be.revertedWith(PARENT_NOT_EXIST_ERR); }); // eslint-disable-next-line max-len @@ -2662,7 +2664,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR + DISTRIBUTION_LOCKED_ERR ); }); @@ -2886,7 +2888,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR + DISTRIBUTION_LOCKED_ERR ); // switch to mintlist @@ -2968,7 +2970,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - DISTRIBUTION_LOCKED_NOT_EXIST_ERR + DISTRIBUTION_LOCKED_ERR ); }); }); diff --git a/test/gas/gas-costs.json b/test/gas/gas-costs.json index b5f11f66..256031de 100644 --- a/test/gas/gas-costs.json +++ b/test/gas/gas-costs.json @@ -1,4 +1,4 @@ { "Root Domain Price": "475352", - "Subdomain Price": "477553" + "Subdomain Price": "478990" } \ No newline at end of file diff --git a/test/helpers/errors.ts b/test/helpers/errors.ts index 2d6cdf0e..6d3927c7 100644 --- a/test/helpers/errors.ts +++ b/test/helpers/errors.ts @@ -26,7 +26,8 @@ export const NOT_BOTH_OWNER_RAR_ERR = "ZNSRootRegistrar: Not the owner of both N // Subdomain Registrar // eslint-disable-next-line max-len -export const DISTRIBUTION_LOCKED_NOT_EXIST_ERR = "ZNSSubRegistrar: Parent domain's distribution is locked or parent does not exist"; +export const DISTRIBUTION_LOCKED_ERR = "ZNSSubRegistrar: Parent domain's distribution is locked"; +export const PARENT_NOT_EXIST_ERR = "ZNSSubRegistrar: Parent domain does not exist"; // StringUtils export const INVALID_NAME_ERR = "StringUtils: Invalid domain label"; From 84b472e2ccd1df2cc6caac033905dc833a51f0fc Mon Sep 17 00:00:00 2001 From: James Earle Date: Fri, 19 Jan 2024 16:46:38 -0800 Subject: [PATCH 3/7] lint --- test/ZNSSubRegistrar.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/ZNSSubRegistrar.test.ts b/test/ZNSSubRegistrar.test.ts index 1b5b942d..7bdddc3c 100644 --- a/test/ZNSSubRegistrar.test.ts +++ b/test/ZNSSubRegistrar.test.ts @@ -39,8 +39,6 @@ import { } from "../typechain"; import { deployCustomDecToken } from "./helpers/deploy/mocks"; import { getProxyImplAddress } from "./helpers/utils"; -import { parentPort } from "worker_threads"; - describe("ZNSSubRegistrar", () => { let deployer : SignerWithAddress; @@ -245,7 +243,7 @@ describe("ZNSSubRegistrar", () => { // Restore token owner await zns.domainToken.connect(lvl2SubOwner).transferFrom(lvl2SubOwner.address, rootOwner.address, rootHash); - + await zns.registry.connect(rootOwner).setOwnersOperator(lvl2SubOwner.address, false); const balanceAfter = await zns.meowToken.balanceOf(lvl2SubOwner.address); From c3ec112cd0b67336821e06abbcf98f3d7f8efdcc Mon Sep 17 00:00:00 2001 From: James Earle Date: Fri, 19 Jan 2024 16:52:20 -0800 Subject: [PATCH 4/7] remove some todo comments --- contracts/registrar/ZNSSubRegistrar.sol | 2 -- test/helpers/deploy-helpers.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index cea86bf6..d556057c 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -37,8 +37,6 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, uint256 ownerIndex; } - - // TODO natspec struct Ownership { address owner; bool ownsBoth; diff --git a/test/helpers/deploy-helpers.ts b/test/helpers/deploy-helpers.ts index 5484981a..a30d1950 100644 --- a/test/helpers/deploy-helpers.ts +++ b/test/helpers/deploy-helpers.ts @@ -117,7 +117,6 @@ export const registerRootDomainBulk = async ( const domainHash = hashDomainLabel(domain); expect(await zns.registry.exists(domainHash)).to.be.true; - // TODO figure out if we want to do this on prod? // To mint subdomains from this domain we must first set the price config and the payment config await zns.curvePricer.connect(signers[index]).setPriceConfig(domainHash, priceConfig); From fbd616eb1eb12e3b669b6995cf050e3d7d83203c Mon Sep 17 00:00:00 2001 From: James Earle Date: Mon, 22 Jan 2024 14:47:33 -0800 Subject: [PATCH 5/7] update after review --- contracts/registrar/IZNSSubRegistrar.sol | 6 ++++ contracts/registrar/ZNSSubRegistrar.sol | 12 +------ test/ZNSSubRegistrar.test.ts | 21 ++++++----- test/gas/TransactionGasCosts.test.ts | 44 ++++++++++++------------ test/gas/gas-costs.json | 4 +-- test/helpers/errors.ts | 1 - 6 files changed, 41 insertions(+), 47 deletions(-) diff --git a/contracts/registrar/IZNSSubRegistrar.sol b/contracts/registrar/IZNSSubRegistrar.sol index 1c6574bd..565080c0 100644 --- a/contracts/registrar/IZNSSubRegistrar.sol +++ b/contracts/registrar/IZNSSubRegistrar.sol @@ -11,6 +11,12 @@ import { IZNSPricer } from "../types/IZNSPricer.sol"; */ interface IZNSSubRegistrar is IDistributionConfig { + struct Ownership { + address owner; + bool ownsBoth; + bool isOperatorForOwner; + } + /** * @notice Emitted when a new `DistributionConfig.pricerContract` is set for a domain. */ diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index d556057c..c7342bbc 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -37,12 +37,6 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, uint256 ownerIndex; } - struct Ownership { - address owner; - bool ownsBoth; - bool isOperatorForOwner; - } - /** * @notice Mapping of domainHash to mintlist set by the domain owner/operator. * These configs are used to determine who can register subdomains for every parent @@ -105,10 +99,6 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, !registry.exists(domainHash), "ZNSSubRegistrar: Subdomain already exists" ); - require( - registry.exists(parentHash), - "ZNSSubRegistrar: Parent domain does not exist" - ); DistributionConfig memory parentConfig = distrConfigs[parentHash]; @@ -154,7 +144,7 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, }); // If parent owns both and caller is either parent or an operator, mint for free - // If parent does not own both or the call is not an operator or the owner, pay to mint + // If parent does not own both or the caller is not an operator or the owner, pay to mint if (!parent.ownsBoth || !(parent.isOperatorForOwner || address(msg.sender) == parent.owner)) { if (coreRegisterArgs.isStakePayment) { (coreRegisterArgs.price, coreRegisterArgs.stakeFee) = IZNSPricer(address(parentConfig.pricerContract)) diff --git a/test/ZNSSubRegistrar.test.ts b/test/ZNSSubRegistrar.test.ts index 7bdddc3c..e2dcfa3a 100644 --- a/test/ZNSSubRegistrar.test.ts +++ b/test/ZNSSubRegistrar.test.ts @@ -19,7 +19,6 @@ import { DECAULT_PRECISION, DEFAULT_PRICE_CONFIG, validateUpgrade, - PARENT_NOT_EXIST_ERR, DISTRIBUTION_LOCKED_ERR, } from "./helpers"; import * as hre from "hardhat"; @@ -251,11 +250,6 @@ describe("ZNSSubRegistrar", () => { expect(balanceAfter).to.not.eq(balanceBefore); }); - // disallows an owner from registering for free if they don't own both - // disallows an operator from registering for free if the owner does not own both - // owner surpasses locked domains - // operator surpasses locked domains, maybe already tested these two - it("Does not set the payment config when the beneficiary is the zero address", async () => { const subdomain = "not-world-subdomain"; await expect( @@ -459,6 +453,11 @@ describe("ZNSSubRegistrar", () => { )).to.be.revertedWith(INVALID_NAME_ERR); }); + // it("calls test functions", async () => { + // const ownerthing = await zns.subRegistrar.connect(lvl2SubOwner).testFunction(ethers.ZeroHash); + // console.log(ownerthing); + // }); + it("should revert when trying to register a subdomain under a non-existent parent", async () => { // check that 0x0 hash can NOT be passed as parentHash await expect( @@ -487,7 +486,7 @@ describe("ZNSSubRegistrar", () => { ) ).to.be.revertedWith( // ERC721's `_requireMinted()` will fail when parent hash doesn't exist - PARENT_NOT_EXIST_ERR + INVALID_TOKENID_ERC_ERR ); }); @@ -1058,7 +1057,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - PARENT_NOT_EXIST_ERR + INVALID_TOKENID_ERC_ERR ); const dataFromReg = await zns.registry.getDomainRecord(domainHash); @@ -1123,7 +1122,7 @@ describe("ZNSSubRegistrar", () => { paymentConfigEmpty, ) ).to.be.revertedWith( - PARENT_NOT_EXIST_ERR + INVALID_TOKENID_ERC_ERR ); const dataFromReg = await zns.registry.getDomainRecord(domainHash); @@ -1350,7 +1349,7 @@ describe("ZNSSubRegistrar", () => { distrConfigEmpty, paymentConfigEmpty, ) - ).to.be.revertedWith(PARENT_NOT_EXIST_ERR); + ).to.be.revertedWith(INVALID_TOKENID_ERC_ERR); // register root back for other tests await registrationWithSetup({ @@ -1382,7 +1381,7 @@ describe("ZNSSubRegistrar", () => { distrConfigEmpty, paymentConfigEmpty, ) - ).to.be.revertedWith(PARENT_NOT_EXIST_ERR); + ).to.be.revertedWith(INVALID_TOKENID_ERC_ERR); }); // eslint-disable-next-line max-len diff --git a/test/gas/TransactionGasCosts.test.ts b/test/gas/TransactionGasCosts.test.ts index 7ef814a6..8aa9cc36 100644 --- a/test/gas/TransactionGasCosts.test.ts +++ b/test/gas/TransactionGasCosts.test.ts @@ -119,16 +119,16 @@ describe("Transaction Gas Costs Test", () => { Gas Diff: ${gasDiff.toString()} `); - if (gasDiff > 1000 || gasDiff < -1000) { - fs.writeFileSync( - gasCostFile, - JSON.stringify({ - ...previous, - // eslint-disable-next-line no-invalid-this - [title]: gasUsed.toString(), - }) - ); - } + // if (gasDiff > 1000 || gasDiff < -1000) { + fs.writeFileSync( + gasCostFile, + JSON.stringify({ + ...previous, + // eslint-disable-next-line no-invalid-this + [title]: gasUsed.toString(), + }) + ); + // } }); it("Subdomain Price", async function () { @@ -169,17 +169,17 @@ describe("Transaction Gas Costs Test", () => { Gas Diff: ${gasDiff.toString()} `); - if (gasDiff > 1000 || gasDiff < -1000) { - fs.writeFileSync( - gasCostFile, - JSON.stringify({ - ...previous, - // eslint-disable-next-line no-invalid-this - [title]: gasUsed.toString(), - }, - null, - "\t") - ); - } + // if (gasDiff > 1000 || gasDiff < -1000) { + fs.writeFileSync( + gasCostFile, + JSON.stringify({ + ...previous, + // eslint-disable-next-line no-invalid-this + [title]: gasUsed.toString(), + }, + null, + "\t") + ); + // } }); }); diff --git a/test/gas/gas-costs.json b/test/gas/gas-costs.json index 256031de..8a9d0e01 100644 --- a/test/gas/gas-costs.json +++ b/test/gas/gas-costs.json @@ -1,4 +1,4 @@ { - "Root Domain Price": "475352", - "Subdomain Price": "478990" + "Root Domain Price": "475405", + "Subdomain Price": "477553" } \ No newline at end of file diff --git a/test/helpers/errors.ts b/test/helpers/errors.ts index 6d3927c7..5b9ffc20 100644 --- a/test/helpers/errors.ts +++ b/test/helpers/errors.ts @@ -27,7 +27,6 @@ export const NOT_BOTH_OWNER_RAR_ERR = "ZNSRootRegistrar: Not the owner of both N // Subdomain Registrar // eslint-disable-next-line max-len export const DISTRIBUTION_LOCKED_ERR = "ZNSSubRegistrar: Parent domain's distribution is locked"; -export const PARENT_NOT_EXIST_ERR = "ZNSSubRegistrar: Parent domain does not exist"; // StringUtils export const INVALID_NAME_ERR = "StringUtils: Invalid domain label"; From 790a21c3e8480d3210f701bd4a514da5a0d2ad61 Mon Sep 17 00:00:00 2001 From: James Earle Date: Mon, 22 Jan 2024 15:38:21 -0800 Subject: [PATCH 6/7] remove comments in gas test code --- test/gas/TransactionGasCosts.test.ts | 8 ++++---- test/gas/gas-costs.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/gas/TransactionGasCosts.test.ts b/test/gas/TransactionGasCosts.test.ts index 8aa9cc36..01b6478e 100644 --- a/test/gas/TransactionGasCosts.test.ts +++ b/test/gas/TransactionGasCosts.test.ts @@ -119,7 +119,7 @@ describe("Transaction Gas Costs Test", () => { Gas Diff: ${gasDiff.toString()} `); - // if (gasDiff > 1000 || gasDiff < -1000) { + if (gasDiff > 1000 || gasDiff < -1000) { fs.writeFileSync( gasCostFile, JSON.stringify({ @@ -128,7 +128,7 @@ describe("Transaction Gas Costs Test", () => { [title]: gasUsed.toString(), }) ); - // } + } }); it("Subdomain Price", async function () { @@ -169,7 +169,7 @@ describe("Transaction Gas Costs Test", () => { Gas Diff: ${gasDiff.toString()} `); - // if (gasDiff > 1000 || gasDiff < -1000) { + if (gasDiff > 1000 || gasDiff < -1000) { fs.writeFileSync( gasCostFile, JSON.stringify({ @@ -180,6 +180,6 @@ describe("Transaction Gas Costs Test", () => { null, "\t") ); - // } + } }); }); diff --git a/test/gas/gas-costs.json b/test/gas/gas-costs.json index 8a9d0e01..f0a66ca8 100644 --- a/test/gas/gas-costs.json +++ b/test/gas/gas-costs.json @@ -1,4 +1,4 @@ { - "Root Domain Price": "475405", + "Root Domain Price": "475383", "Subdomain Price": "477553" } \ No newline at end of file From 5f5e75d2f23d62c900720902cdd409cedb5cc93e Mon Sep 17 00:00:00 2001 From: James Earle Date: Wed, 24 Jan 2024 10:09:40 -0800 Subject: [PATCH 7/7] fix indentation mistake from auto format --- test/gas/TransactionGasCosts.test.ts | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/gas/TransactionGasCosts.test.ts b/test/gas/TransactionGasCosts.test.ts index 01b6478e..7ef814a6 100644 --- a/test/gas/TransactionGasCosts.test.ts +++ b/test/gas/TransactionGasCosts.test.ts @@ -120,14 +120,14 @@ describe("Transaction Gas Costs Test", () => { `); if (gasDiff > 1000 || gasDiff < -1000) { - fs.writeFileSync( - gasCostFile, - JSON.stringify({ - ...previous, - // eslint-disable-next-line no-invalid-this - [title]: gasUsed.toString(), - }) - ); + fs.writeFileSync( + gasCostFile, + JSON.stringify({ + ...previous, + // eslint-disable-next-line no-invalid-this + [title]: gasUsed.toString(), + }) + ); } }); @@ -170,16 +170,16 @@ describe("Transaction Gas Costs Test", () => { `); if (gasDiff > 1000 || gasDiff < -1000) { - fs.writeFileSync( - gasCostFile, - JSON.stringify({ - ...previous, - // eslint-disable-next-line no-invalid-this - [title]: gasUsed.toString(), - }, - null, - "\t") - ); + fs.writeFileSync( + gasCostFile, + JSON.stringify({ + ...previous, + // eslint-disable-next-line no-invalid-this + [title]: gasUsed.toString(), + }, + null, + "\t") + ); } }); });