chore!: Refactor x/bank CLI Tests (#12706)

This commit is contained in:
Aleksandr Bezobchuk
2022-08-03 12:08:41 -04:00
committed by GitHub
parent 71035879e4
commit ccc8003a80
21 changed files with 758 additions and 32 deletions
+12 -5
View File
@@ -20,14 +20,11 @@ import (
func Execute(rootCmd *cobra.Command, envPrefix string, defaultHome string) error {
// Create and set a client.Context on the command's Context. During the pre-run
// of the root command, a default initialized client.Context is provided to
// seed child command execution with values such as AccountRetriver, Keyring,
// seed child command execution with values such as AccountRetriever, Keyring,
// and a Tendermint RPC. This requires the use of a pointer reference when
// getting and setting the client.Context. Ideally, we utilize
// https://github.com/spf13/cobra/pull/1118.
srvCtx := server.NewDefaultContext()
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
ctx = context.WithValue(ctx, server.ServerContextKey, srvCtx)
ctx := CreateExecuteContext(context.Background())
rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic)")
rootCmd.PersistentFlags().String(flags.FlagLogFormat, tmlog.LogFormatPlain, "The logging format (json|plain)")
@@ -35,3 +32,13 @@ func Execute(rootCmd *cobra.Command, envPrefix string, defaultHome string) error
executor := tmcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome)
return executor.ExecuteContext(ctx)
}
// CreateExecuteContext returns a base Context with server and client context
// values initialized.
func CreateExecuteContext(ctx context.Context) context.Context {
srvCtx := server.NewDefaultContext()
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
ctx = context.WithValue(ctx, server.ServerContextKey, srvCtx)
return ctx
}