-
Notifications
You must be signed in to change notification settings - Fork 2
SubRegistrar tests improvement (Domain helper class) #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
…ister them using Domain class.
… statement to signer var.
…r optimization according to registration and revocation.
…s. Adjusted distrConfig setter for Domain class. WIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Improves test coverage and refactors the Domain test helper to use object parameter patterns while adding new helper methods; introduces a comprehensive ZNSSubRegistrar unit test suite and adjusts existing tests to the new Domain API. Key changes include: refactoring Domain helper method signatures, adding retrieval and state mutation helpers, and expanding sub-registrar test scenarios (bulk + nested registration, config mutation, and access control behaviors).
- Refactored Domain helper methods to accept single object params and added config/query utilities.
- Added extensive ZNSSubRegistrar.unit.test.ts covering bulk registration, nested domains, and state mutation paths.
- Updated existing tests (RootRegistrar, AddressResolver) to new Domain helper API and added minor type simplifications.
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| test/helpers/types.ts | Narrowed pricerContract type; potential API restriction. |
| test/helpers/register-setup.ts | Simplified approval flow; removed conditional allowance check. |
| test/helpers/domain/domain.ts | Major refactor: new helper methods, object param signatures, pricing logic changes; introduced several logic issues. |
| test/helpers/deploy/deploy-zns.ts | Removed unused import. |
| test/helpers/ac.ts | Added file containing only commented-out (inactive) test scaffold. |
| test/ZNSSubRegistrar.unit.test.ts | New comprehensive unit tests; contains a loop logic bug. |
| test/ZNSRootRegistrar.test.ts | Updated calls to new Domain helper signatures; switched to helper getters. |
| test/ZNSAddressResolver.test.ts | Updated operator-setting call to new object-style API. |
| test/DeployCampaignInt.test.ts | Removed unused git tagging utility invocation/import. |
Comments suppressed due to low confidence (1)
test/helpers/ac.ts:1
- New file consists only of commented-out code; keeping inactive scaffolding increases noise and can confuse contributors. Remove the file or add active tests; if kept for future work, add a brief comment explaining its intentional placeholder status.
// import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
test/helpers/domain/domain.ts
Outdated
| if (priceConfig || | ||
| this.priceConfig !== undefined || | ||
| Object.keys(this.priceConfig).length === 0 | ||
| ) { | ||
| const args = [this.hash]; |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logical condition is flawed: (a) Object.keys(this.priceConfig) is accessed when this.priceConfig may be undefined (runtime TypeError), (b) using ORs makes the branch almost always true, and (c) when priceConfig is undefined you still cast and encode it at line 301 (likely undefined -> error). Replace with a guarded condition such as: if (priceConfig) { ... } else if (this.priceConfig) { reuse existing } else { throw error } and only call Object.keys after confirming existence.
test/helpers/domain/domain.ts
Outdated
| this.priceConfig = decodePriceConfig(priceConfig); | ||
|
|
||
| } else { | ||
| args.push(encodePriceConfig(priceConfig as ICurvePriceConfig | IFixedPriceConfig)); |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logical condition is flawed: (a) Object.keys(this.priceConfig) is accessed when this.priceConfig may be undefined (runtime TypeError), (b) using ORs makes the branch almost always true, and (c) when priceConfig is undefined you still cast and encode it at line 301 (likely undefined -> error). Replace with a guarded condition such as: if (priceConfig) { ... } else if (this.priceConfig) { reuse existing } else { throw error } and only call Object.keys after confirming existence.
| async setPricerDataForDomain ({ | ||
| priceConfig, | ||
| pricerContract, | ||
| executor, | ||
| } : { | ||
| priceConfig ?: ICurvePriceConfig | IFixedPriceConfig | string; | ||
| pricerContract ?: string; | ||
| executor ?: SignerWithAddress; | ||
| }) { | ||
| if (priceConfig || | ||
| this.priceConfig !== undefined || | ||
| Object.keys(this.priceConfig).length === 0 | ||
| ) { | ||
| const args = [this.hash]; | ||
|
|
||
| if (typeof priceConfig === "string") { | ||
| args.push(priceConfig); | ||
|
|
||
| this.priceConfig = decodePriceConfig(priceConfig); | ||
|
|
||
| } else { | ||
| args.push(encodePriceConfig(priceConfig as ICurvePriceConfig | IFixedPriceConfig)); | ||
|
|
||
| this.priceConfig = priceConfig as ICurvePriceConfig | IFixedPriceConfig; | ||
| } | ||
|
|
||
| args.push(pricerContract ? pricerContract : this.distrConfig.pricerContract); | ||
|
|
||
| await this.zns.subRegistrar.connect(executor ? executor : this.owner).setPricerDataForDomain( | ||
| this.hash, | ||
| priceConfig ? encodePriceConfig(priceConfig) : encodePriceConfig(this.priceConfig), | ||
| pricerContract ? pricerContract : this.distrConfig.pricerContract | ||
| ...args | ||
| ); | ||
| } else { | ||
| throw new Error("Domain Helper: priceConfig is not specified"); | ||
| } | ||
|
|
||
| // updating local var | ||
| if (priceConfig) { | ||
| this.priceConfig = priceConfig; | ||
| } | ||
| } | ||
|
|
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Allowing priceConfig to be either a structured config object or a pre-encoded string mixes responsibilities and weakens type safety. Consider splitting into two distinct methods (setPricerDataWithConfig vs setPricerDataWithBytes) or using a discriminated union to avoid ambiguous runtime branching.
| }); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/prefer-for-of | ||
| for (let i = logs.length - 1; i === 0; i--) { |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop condition uses i === 0, so it only executes when logs.length - 1 == 0 (single log); for multiple logs the body never runs. Replace condition with i >= 0 to iterate all logs in reverse.
| for (let i = logs.length - 1; i === 0; i--) { | |
| for (let i = logs.length - 1; i >= 0; i--) { |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #161 +/- ##
=============================================
Coverage 100.00% 100.00%
=============================================
Files 13 13
Lines 596 596
Branches 137 137
=============================================
Hits 596 596 🚀 New features to boost your workflow:
|
No description provided.