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

Hardhat network configuration should not contain url property #1118

Merged
merged 2 commits into from
Dec 29, 2020

Conversation

sisco0
Copy link
Contributor

@sisco0 sisco0 commented Dec 20, 2020

Closes #1051.

This PR modified the configuration validator code in order to disallow url property of the hardhat object. This issue was caused because the modified conditional clause was testing url against undefined, which is a falsy value, but the property could be present after all. In order not to tackle with validations against this property in a subsequent step of the execution (which indeed is the purpose of the configuration validator) this conditional clause now uses .hasOwnProperty instead of comparing the value with undefined, where this property could be present with an undefined value.

Test cases have been added as well for the case of hardhat object containing an url property with value equal or not equal to undefined.

I am happy to bring my efforts to this project by this first contribution and want to thank @alcuadrado for his accompaniment through this task accomplishment.

Modified conditional clause for disallowing undefined url property of Hardhat network at the networks configuration object
@@ -225,7 +225,7 @@ export function getValidationErrors(config: any): string[] {
if (config !== undefined && typeof config.networks === "object") {
const hardhatNetwork = config.networks[HARDHAT_NETWORK_NAME];
if (hardhatNetwork !== undefined) {
if (hardhatNetwork.url !== undefined) {
if (hardhatNetwork.hasOwnProperty("url")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use "url" in hardhatNetwork for this. I know there's a subtle difference between the two things in javascript, but I would do it that way just for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand @fvictorio , from what you specify it should be valid to have a url property under the hardhat network object with value equal to undefined. Would it be correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no, it wouldn't. But (AFAIK) the only difference between the idiom I suggested and the one you used is that hasOwnProperty doesn't check the prototype chain, but that doesn't really matter in this scenario, that's why I think consistency is more important here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What any other clause could be used instead to check if url property is present or not? (Even if it is set to a value or as undefined).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm not explaining myself correctly 😅 All I'm saying is that I'd rather do

if ("url" in hardhatNetwork) {

instead of

if (hardhatNetwork.hasOwnProperty("url")) {

They are very similar, and in many cases the latter one is the one you want. Since in this case they are pretty much the same, I'd use the first one since it's the one we use in the rest of the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now, thank you for your efforts on this PR review as I want to be an active contributor of this repository. I would do the changes adding a new commit to this PR and would ensure that new tests continue passing.

In this way, url parameter could not be a property under hardhat object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2cents to avoid future confusion:

In this case we do want to use in. If we were to use hasOwnProperty to validate the absence of a property, all the consumers of the config should be aware of this, and use the config's own properties instead of just doing config.value.

Comments have been taken into account
@sisco0
Copy link
Contributor Author

sisco0 commented Dec 22, 2020

I uploaded the changes requested in order to comply with coding standards for this project. Even more, a validation conditional clause has been added as well in order to ensure validity of the hardhat network object.

@alcuadrado
Copy link
Member

Thanks for submitting this PR, @sisco0. It looks good now.

@alcuadrado alcuadrado merged commit fa1267e into NomicFoundation:master Dec 29, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hardhat network can contain an url field, confusing the provider initialization
3 participants