From 3477c35869f74b6a7bd4491197b358ae4557fe62 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Mon, 10 Jun 2024 14:19:31 -0400 Subject: [PATCH 1/2] chore: write gentx info to cmd.ErrOrStderr The "init" and "collect-gentxs" subcommands were hardcoded to write directly to os.Stderr. This made it impossible to write tests against the output. Instead, write to cmd.ErrOrStderr, which will still default to os.Stderr, but will also allow tests to intercept the cobra Command's stderr value in case there is a need to assert against that output. --- x/genutil/client/cli/collect.go | 2 +- x/genutil/client/cli/init.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index 3b0354c1073b..f8e59533f10c 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -52,7 +52,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator ty toPrint.AppMessage = appMessage - return displayInfo(toPrint) + return displayInfo(cmd.ErrOrStderr(), toPrint) }, } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 920dfcec260f..db9491df5997 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "os" "path/filepath" @@ -58,13 +59,13 @@ func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.Ra } } -func displayInfo(info printInfo) error { +func displayInfo(dst io.Writer, info printInfo) error { out, err := json.MarshalIndent(info, "", " ") if err != nil { return err } - _, err = fmt.Fprintf(os.Stderr, "%s\n", out) + _, err = fmt.Fprintf(dst, "%s\n", out) return err } @@ -175,7 +176,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState) cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config) - return displayInfo(toPrint) + return displayInfo(cmd.ErrOrStderr(), toPrint) }, } From 792b6ac7081227c6d5e26c1546d91716bf8f425d Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Mon, 10 Jun 2024 16:20:29 -0400 Subject: [PATCH 2/2] chore: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21784defaa04..e5d1ce7be6b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,6 +186,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (server) [#20140](https://github.com/cosmos/cosmos-sdk/pull/20140) Remove embedded grpc-web proxy in favor of standalone grpc-web proxy. [Envoy Proxy](https://www.envoyproxy.io/docs/envoy/latest/start/start) * (client) [#20255](https://github.com/cosmos/cosmos-sdk/pull/20255) Use comet proofOp proto type instead of sdk version to avoid needing to translate to later be proven in the merkle proof runtime. * (all) [#19726](https://github.com/cosmos/cosmos-sdk/pull/19726) Integrate comet v1 +* (client) [#20616](https://github.com/cosmos/cosmos-sdk/pull/20616) gentx subcommand output goes to `cmd.ErrOrStderr()` instead of being hardcoded to `os.Stderr` ### Client Breaking Changes