Skip to content

Commit

Permalink
fix: tx commands are no need to specify --chain-id (#12092) (#12096)
Browse files Browse the repository at this point in the history
## 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)

(cherry picked from commit cabd3a9)

Co-authored-by: atheeshp <[email protected]>
  • Loading branch information
mergify[bot] and atheeshp authored May 31, 2022
1 parent b480d56 commit d278ad1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit d278ad1

Please sign in to comment.