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

fix(app): exit with error code and use regen env prefix #285

Merged
merged 6 commits into from
Aug 5, 2022

Conversation

clevinson
Copy link
Member

@clevinson clevinson commented Mar 5, 2021

When working on #277 I kept having local tests fail despite CI working fine. Turns out that TestInitCmd() was looking into the default node home directory (~/.regen) for testing out the root command. This is fixed now (we should probably also fix this upstream on the SDK in the simapp tests?).

While investigating, there were a few other updates in usages of server.Execute()that I found in the SDK which I wanted to port over here to regen ledger, as it seems this is how we should be interfacing w/ the root command now.

Those PRs were cosmos/cosmos-sdk#8144, and cosmos/cosmos-sdk#7480

rootCmd, _ := cmd.NewRootCmd()
rootCmd.SetArgs([]string{
"init", // Test the init cmd
"regenapp-test", // Moniker
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists
Copy link
Member Author

Choose a reason for hiding this comment

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

I dropped this as it seemed unnecessary. If folks think there is a good reason to keep this flag, I can add it back in.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm I don't think it hurts. There could be edge cases where is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

What edge cases are you thinking of? Ideally this should be run as a self contained test with full teardown of any artifacts right? The home directory is created from scratch on each test run, so I don't see how we could expect there to already be a genesis.json here.

Previously this line was there because it always looked at your default home directory for running (or created one if it didnt exist). This PR changes that so it creates a temp home dir, which should render the --overwrite=true flag unnecessary. Lmk if i'm missing something

@@ -69,26 +66,6 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return rootCmd, encodingConfig
}

// Execute executes the root command.
func Execute(rootCmd *cobra.Command) error {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this deleted?

Copy link
Member Author

@clevinson clevinson Mar 5, 2021

Choose a reason for hiding this comment

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

In Cosmos SDK simapp we're now using sdk's server.Execute(), i figured this was what we should update to as well. There's no need to have this function defined in regen-ledger if its exposed on the SDK right? (see cosmos/cosmos-sdk#8144)

Copy link
Contributor

@anilcse anilcse Mar 8, 2021

Choose a reason for hiding this comment

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

@clevinson Only issue I see is, we may not be able to use prefix based ENV variables. iirc, PrepareBaseCmd takes an argument (in our case it was REGEN) through which it maps ENV variables to flags. I didn't test if it works with empty prefix, if not, that might create some UX issues

Copy link
Member Author

Choose a reason for hiding this comment

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

@anilcse Hmm... Yeah you're 100% right here. Seems strange then that server.Execute() is exposed at all if it doesn't provide a mechanism for chains to add their own prefix... Do you think this should be addressed upstream?

Maybe best to revert this part of my PR for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we can fix this upstream to take an extra argument for this ENV prefix.

Copy link
Member

Choose a reason for hiding this comment

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

Opened a pull request in the sdk: cosmos/cosmos-sdk#10950

@codecov
Copy link

codecov bot commented Mar 5, 2021

Codecov Report

Merging #285 (b69c246) into master (682e4de) will decrease coverage by 9.14%.
The diff coverage is n/a.

❗ Current head b69c246 differs from pull request most recent head d29448f. Consider uploading reports for the commit d29448f to get more accurate results

@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
- Coverage   77.45%   68.31%   -9.15%     
==========================================
  Files         221      107     -114     
  Lines       16120    16029      -91     
==========================================
- Hits        12486    10950    -1536     
- Misses       2620     4291    +1671     
+ Partials     1014      788     -226     
Flag Coverage Δ
experimental-codecov ?
stable-codecov 68.31% <ø> (-8.92%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@aaronc
Copy link
Member

aaronc commented Mar 8, 2021

@anilcse could you possibly take a look at this? I don't have very good context.

@amaury1093
Copy link
Contributor

Is this PR still relevant? Anyone working on it or should have a look?

@ryanchristo ryanchristo changed the title Make TestInitCmd self contained, update to latest server.Execute() usage fix(app): self-contained TestInitCmd, update server.Execute() Jan 13, 2022
@robert-zaremba
Copy link
Collaborator

This PR will need to wait for 0.46 release (see #285 (comment))

@ryanchristo ryanchristo marked this pull request as ready for review August 5, 2022 19:10
@ryanchristo ryanchristo changed the title fix(app): self-contained TestInitCmd, update server.Execute() fix(app): exit with error code and use regen env prefix Aug 5, 2022
@ryanchristo ryanchristo merged commit 3952f66 into master Aug 5, 2022
@ryanchristo ryanchristo deleted the clevinson/isolated-cmd-test branch August 5, 2022 19:11
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.

6 participants