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) } 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) } }