-
Notifications
You must be signed in to change notification settings - Fork 3
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
[ZNS ZChain] String Resolver #106
Conversation
[ZNS ZChain] String Resolver
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
|
||
interface IZNSStringResolver { | ||
/** | ||
* @param newString The new domain owner |
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.
change the order of these.
also, newString
comment is not correct. it's not the owner, it's the string that owner assigns which a domain will resolve to
require( | ||
registry.isOwnerOrOperator(domainHash, msg.sender) || | ||
// TODO: decide, whether the registrar can set a string | ||
accessController.isRegistrar(msg.sender), |
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.
please, remove the comment and L63. Registrar will not be able to set a string. only owner or operator can.
test/ZNSStringResolver.test.ts
Outdated
|
||
|
||
describe("ZNSStringResolver", () => { | ||
describe("One campaign for everybody", () => { |
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.
rename to "Single State Tests"
test/ZNSStringResolver.test.ts
Outdated
] = await hre.ethers.getSigners(); | ||
|
||
const campaignConfig = await getConfig({ | ||
deployer: deployer as unknown as SignerWithAddress, |
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.
this probably doesn't need cast to unknown
. can just cast as SignerWithAddress
right away, without unknown
test/ZNSStringResolver.test.ts
Outdated
await mongoAdapter.dropDB(); | ||
}); | ||
|
||
it("Should not let initialize the contract", async () => { |
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.
add "twice" to the test name.
"Should not let initialize the contract twice"
test/ZNSStringResolver.test.ts
Outdated
distrConfigEmpty, | ||
paymentConfigEmpty, | ||
); | ||
await stringResolver.connect(user).setString(domainNameHash, "hippopotamus"); |
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.
put "hippopotamus" into a var and then compare to this var in expect
. don't hardcode stuff
test/ZNSStringResolver.test.ts
Outdated
expect( | ||
await stringResolver.resolveDomainString(domainNameHash) | ||
).to.eq( | ||
"hippopotamus" |
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.
put the var here
.to.emit(stringResolver, "RegistrySet") | ||
.withArgs(admin.address); | ||
|
||
expect(await stringResolver.registry()).to.equal(admin.address); |
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.
since you have a single state (a single deployment of ZNS), reset the Registry here to the proper address after all the checks are done, otherwise other tests would fail. registry needs to be correct in order for next tests to work properly
await mongoAdapter.dropDB(); | ||
}); | ||
|
||
it("Should not allow non-owner address to setString (similar domain and string)", async () => { |
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.
what does "(similar domain and string)" mean? is there a reason you made the parent and child domain the same string?
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.
Just different test params to cover more scenarios
}); | ||
|
||
await expect( | ||
stringResolver.connect(user).setString(hashDomainLabel(curStringDomain), curStringDomain) |
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.
I don't understand what this does and why.
test/ZNSStringResolver.test.ts
Outdated
}); | ||
|
||
it.skip("Should allow REGISTRAR_ROLE to setString and emit event." + | ||
"TODO: decide, whether the registrar can set a string (different domain and string)", async () => { |
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.
don't add "TODOs" to the test name. always add them as comments.
and no, Registrar will not be able to set a string through registration. so you can delete this test altogether AFTER you deleted the registrar line from the Solidity code that checks registrar role in setString()
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.
Please, address the comments and fix other failing tests in the repo.
Good start!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## zns-zchain-final #106 +/- ##
=================================================
Coverage 99.80% 99.81%
=================================================
Files 11 12 +1
Lines 525 547 +22
Branches 117 122 +5
=================================================
+ Hits 524 546 +22
Misses 1 1 |
ERC165, | ||
IZNSStringResolver { | ||
|
||
mapping(bytes32 domainHash => string resolvedString) internal domainStrings; |
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.
the name domainStrings
could be a bit misleading in that it implies the resolved strings are the domains themselves, not what they resolve to, maybe resolvedStrings
similar to the name you already are using in the mapping key/value pair
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.
Called them resolvedString and resolvedStrings, which I dont like, to be honest. Tell me, if I'm wrong and have to find another name)
string calldata newString | ||
) external override { | ||
// only owner or operator of the current domain can set the string | ||
require( |
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.
Using custom errors is more gas efficient. I know they aren't used in the other contracts but they have already been deployed, so maybe we can update that at some point but for now use them instead of require
and do the opposite logic of what you're checking here
if (!registry.IsOwnerOrOperator(domainHash, msg.sender)) {
revert CustomErrorName();
}
@@ -28,4 +28,7 @@ export const EXECUTOR_ROLE = ethers.solidityPackedKeccak256( | |||
|
|||
export const ResolverTypes = { |
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.
this would be better as an enum, then it would resolve the "TODO" comment you have below as these are just given values 0
, 1
, 2
etc. unless you specifically assign them something.
export enum ResolverTypes {
ADDRESS,
STRING
}
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.
that would require a Registry contract upgrade...
); | ||
}); | ||
|
||
// TODO: Falls on the role. I think, cannot give a REGISTRAR_ROLE to mock "deployAdmin". |
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.
Make sure you take care of any existing TODO comments. If they are already fixed, remove them
No description provided.