Skip to content
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

Merged
merged 19 commits into from
Sep 11, 2024
Merged

Conversation

MichaelKorchagin
Copy link
Collaborator

No description provided.

Copy link

openzeppelin-code bot commented May 7, 2024

[ZNS ZChain] String Resolver

Generated at commit: 898ac6067eaf1a47f790cc74fe72148170b23283

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
1
1
0
2
20
24
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector


interface IZNSStringResolver {
/**
* @param newString The new domain owner
Copy link
Collaborator

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),
Copy link
Collaborator

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.



describe("ZNSStringResolver", () => {
describe("One campaign for everybody", () => {
Copy link
Collaborator

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"

] = await hre.ethers.getSigners();

const campaignConfig = await getConfig({
deployer: deployer as unknown as SignerWithAddress,
Copy link
Collaborator

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

await mongoAdapter.dropDB();
});

it("Should not let initialize the contract", async () => {
Copy link
Collaborator

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"

distrConfigEmpty,
paymentConfigEmpty,
);
await stringResolver.connect(user).setString(domainNameHash, "hippopotamus");
Copy link
Collaborator

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

expect(
await stringResolver.resolveDomainString(domainNameHash)
).to.eq(
"hippopotamus"
Copy link
Collaborator

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);
Copy link
Collaborator

@Whytecrowe Whytecrowe May 7, 2024

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 () => {
Copy link
Collaborator

@Whytecrowe Whytecrowe May 7, 2024

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?

Copy link
Collaborator Author

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)
Copy link
Collaborator

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.

});

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 () => {
Copy link
Collaborator

@Whytecrowe Whytecrowe May 7, 2024

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()

Copy link
Collaborator

@Whytecrowe Whytecrowe left a 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!

@Whytecrowe Whytecrowe changed the title Feat/zns string resolver [WIP] String Resolver May 7, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.81%. Comparing base (449e121) to head (898ac60).
Report is 20 commits behind head on zns-zchain-final.

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;
Copy link
Collaborator

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

Copy link
Collaborator Author

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(
Copy link
Collaborator

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 = {
Copy link
Collaborator

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
}

Copy link
Collaborator

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".
Copy link
Collaborator

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

@Whytecrowe Whytecrowe changed the title [WIP] String Resolver String Resolver Jul 2, 2024
@Whytecrowe Whytecrowe changed the base branch from development to rc/zns-meowchain July 2, 2024 21:25
@Whytecrowe Whytecrowe changed the title String Resolver [RC Meowchain] String Resolver Jul 17, 2024
@Whytecrowe Whytecrowe changed the title [RC Meowchain] String Resolver [RC ZChain] String Resolver Sep 11, 2024
@Whytecrowe Whytecrowe changed the title [RC ZChain] String Resolver [ZNS ZChain] String Resolver Sep 11, 2024
@Whytecrowe Whytecrowe changed the base branch from rc/zns-meowchain to zns-zchain-final September 11, 2024 22:23
@Whytecrowe Whytecrowe merged commit 1b7cf47 into zns-zchain-final Sep 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants