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: tx commands are no need to specify --chain-id (backport #12092) #12096

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
return ctx, fmt.Errorf("couldn't make client config: %v", err)
}

if ctx.ChainID != "" {
conf.ChainID = ctx.ChainID // chain-id will be written to the client.toml while initiating the chain.
}

if err := writeConfigToFile(configFilePath, conf); err != nil {
return ctx, fmt.Errorf("could not write client config to the file: %v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ const (
// initClientContext initiates client Context for tests
func initClientContext(t *testing.T, envVar string) (client.Context, func()) {
home := t.TempDir()
chainId := "test-chain"
clientCtx := client.Context{}.
WithHomeDir(home).
WithViper("").
WithCodec(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()))
WithCodec(codec.NewProtoCodec(codectypes.NewInterfaceRegistry())).
WithChainID(chainId)

require.NoError(t, clientCtx.Viper.BindEnv(nodeEnv))
if envVar != "" {
Expand All @@ -38,6 +40,7 @@ func initClientContext(t *testing.T, envVar string) (client.Context, func()) {

clientCtx, err := config.ReadFromClientConfig(clientCtx)
require.NoError(t, err)
require.Equal(t, clientCtx.ChainID, chainId)

return clientCtx, func() { _ = os.RemoveAll(home) }
}
Expand Down