From baf479bff6558571224dca65f5cfca558a15bb8a Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 31 May 2022 14:57:15 +0530 Subject: [PATCH 1/2] fix: tx commands are no need to specify --chain-id --- client/config/config.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/config/config.go b/client/config/config.go index 6297cf2c26b1..f9e48c989d88 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -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) } From 6e30e307c85e0dcd5dc161e9385291d46cca32b8 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 31 May 2022 17:22:17 +0530 Subject: [PATCH 2/2] add test --- client/config/config_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/config/config_test.go b/client/config/config_test.go index 3f5c5902820b..287a976d3970 100644 --- a/client/config/config_test.go +++ b/client/config/config_test.go @@ -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 != "" { @@ -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) } }