Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Refactor console-child.js to make the network settings more robust #5245

Merged
merged 6 commits into from
Jul 1, 2022

Conversation

sukanyaparashar
Copy link
Contributor

@sukanyaparashar sukanyaparashar commented Jun 29, 2022

ISSUE

PR #5087 broke truffle console --network because it hardcoded the network name to be develop

This was because console-child.js had logic exclusively used by the truffle develop command. When truffle console --network <network_name> is used, it adds the develop network into config which is not required. This behaviour doesn't make sense after PR #5087 because console-child.js has to satisfy more code paths such as:

  • truffle console --network
  • truffle console --url
  • truffle develop

SOLUTION

This PR makes console-child.js more robust to handle the above cases. And also adds an integration test for the truffle console --network option.

NOTE: It needs to be merged before the next release so that it doesn't break the use of --network options with the truffle console command.

@sukanyaparashar sukanyaparashar marked this pull request as draft June 29, 2022 18:05
@sukanyaparashar sukanyaparashar marked this pull request as ready for review June 29, 2022 18:31
Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

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

Looks good @sukanyaparashar. A few tests should be added for better coverage.

packages/core/lib/console-child.js Show resolved Hide resolved
packages/core/lib/console-child.js Outdated Show resolved Hide resolved
packages/core/lib/console-child.js Show resolved Hide resolved
packages/core/lib/console-child.js Show resolved Hide resolved
describe("when run with options", () => {
it("displays the url hostname in the prompt", async () => {
const url = "http://localhost:8545";
const parsedUrl = new URL(url);
Copy link
Member

Choose a reason for hiding this comment

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

These tests should cover the cases

  • url
    • runs in folder with a truffle-config
    • runs in folder without a truffle-config
  • network
    • runs in folder with a truffle-config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks for the suggestions @amal. I will add the tests to cover the mentioned cases.

sandlot = tmp.dirSync({ unsafeCleanup: true });
config = { working_directory: sandlot.name };
config.logger = logger;
config.mocha = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure you need to configure config.mocha. Do the tests work with setting this value? I ask because I recently removed a bunch of these as the whole Reporter thing was unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah! I just checked that it works without config.mocha. I will remove those.

};
});
after(() => {
sandlot.removeCallback();
Copy link
Contributor

@eggplantzzz eggplantzzz Jun 29, 2022

Choose a reason for hiding this comment

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

You probably copied this from another test as well but you don't really need this as tmp cleans up after itself. Check out the "Synchronous file creation" section of this.

Copy link
Contributor Author

@sukanyaparashar sukanyaparashar Jun 29, 2022

Choose a reason for hiding this comment

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

Thanks for the link @eggplantzzz . It is clearly written that it will clean itself after. You are correct! Its not needed.

config.logger = logger;
config.mocha = {
reporter: new Reporter(logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

You might not need to set this property for all these tests. In other tests I've found this doesn't do anything and I was able to get rid of

config.mocha = {
  reporter: new Reporter(logger)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure. I also checked removing those. And it seems that it doesn't do anything. I will get rid of these.

@sukanyaparashar sukanyaparashar force-pushed the fix-url-to-console branch 2 times, most recently from d7d3836 to d9da056 Compare June 30, 2022 21:12
@sukanyaparashar sukanyaparashar marked this pull request as ready for review June 30, 2022 22:59
Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

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

Looks good to me, though @eggplantzzz may have more comments.

network_id: "*",
url
};
} else {
// Otherwise derive network settings
const customConfig = detectedConfig.networks.develop || {};
const customConfig = detectedConfig.networks[network] || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use develop as a fallback? Because the settings in config.networks.develop are meant for the develop console. Or do we pass the name "develop" as a network in the case when it is the development console? Like maybe it should be

detectedConfig.networks[network] || detectedConfig.develop || {};

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We pass "develop" as a network in the console when using truffle develop.

Copy link
Contributor

@eggplantzzz eggplantzzz left a comment

Choose a reason for hiding this comment

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

I like it

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.

3 participants