From cabd3a9b4f76e7a88cc33c14a02ee73856accd0d Mon Sep 17 00:00:00 2001 From: atheeshp <59333759+atheeshp@users.noreply.github.com> Date: Tue, 31 May 2022 18:57:52 +0530 Subject: [PATCH] fix: tx commands are no need to specify --chain-id (#12092) ## Description Closes: #12085 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- client/config/config.go | 4 ++++ client/config/config_test.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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) } }