-
Notifications
You must be signed in to change notification settings - Fork 293
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
refactor: remove unnecessary config.Seal()
#3786
Conversation
WalkthroughWalkthroughThe recent changes introduce a new configuration setup for the Cosmos SDK, enhancing the application's interaction with the Cosmos blockchain. A new file, Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant SDK
participant Config
App->>SDK: Initialize
SDK->>Config: GetConfig()
Config->>Config: Set Address Prefixes
Config->>Config: Seal Configuration
App->>SDK: Use Configuration
sequenceDiagram
participant App
participant SDK
participant Config
App->>SDK: Initialize
SDK->>Config: GetConfig()
Config->>Config: Set Address Prefixes
Config-->>App: Configuration Ready
App->>SDK: Use Configuration
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
I may expose a method on the config to check if it's sealed or not and then conditionally seal it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
func setCosmosSDKConfig() { | ||
config := sdk.GetConfig() | ||
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) | ||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) | ||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) | ||
config.Seal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider configuration flexibility.
The setCosmosSDKConfig
function hardcodes Bech32 prefixes. Consider parameterizing these values to allow for greater flexibility and reusability in different environments or tests.
func setCosmosSDKConfig(prefixes map[string]string) {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(prefixes["accAddr"], prefixes["accPub"])
config.SetBech32PrefixForValidator(prefixes["valAddr"], prefixes["valPub"])
config.SetBech32PrefixForConsensusNode(prefixes["consAddr"], prefixes["consPub"])
config.Seal()
}
func Test_setCosmosSDKConfig(t *testing.T) { | ||
config := sdk.GetConfig() | ||
assert.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix()) | ||
assert.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix()) | ||
assert.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix()) | ||
assert.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix()) | ||
assert.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix()) | ||
assert.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call setCosmosSDKConfig
in the test.
The test Test_setCosmosSDKConfig
does not call the setCosmosSDKConfig
function, which is necessary to verify its behavior. Add the function call to ensure the test is valid.
func Test_setCosmosSDKConfig(t *testing.T) {
setCosmosSDKConfig() // Ensure this function is called
config := sdk.GetConfig()
assert.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix())
assert.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix())
assert.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix())
assert.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix())
assert.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix())
assert.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix())
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rootulp I also agree with this comment, the setCosmosSDKConfig()
looks like missing, (or if not, adding some clarifying comments would be helpful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's invoked via init()
. In general I think init()
should be avoided because it makes it harder to unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Included some comments.
func Test_setCosmosSDKConfig(t *testing.T) { | ||
config := sdk.GetConfig() | ||
assert.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix()) | ||
assert.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix()) | ||
assert.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix()) | ||
assert.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix()) | ||
assert.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix()) | ||
assert.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rootulp I also agree with this comment, the setCosmosSDKConfig()
looks like missing, (or if not, adding some clarifying comments would be helpful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
- Add unit tests to cosmos SDK config set up - Remove an unnecessary `config.Seal` invocation that has been around for a [long time](5e4a1dc#diff-9e0425d31b7cf4072a746feb0c6bc1e0045b639e01dd0b5ac2f08e8c2952c886R120) but isn't necessary because the `init()` command always sets and seals the config. (cherry picked from commit 9c9e77a) # Conflicts: # cmd/celestia-appd/cmd/root.go
- Add unit tests to cosmos SDK config set up - Remove an unnecessary `config.Seal` invocation that has been around for a [long time](5e4a1dc#diff-9e0425d31b7cf4072a746feb0c6bc1e0045b639e01dd0b5ac2f08e8c2952c886R120) but isn't necessary because the `init()` command always sets and seals the config.<hr>This is an automatic backport of pull request #3786 done by [Mergify](https://mergify.com). --------- Co-authored-by: Rootul P <rootulp@gmail.com>
config.Seal
invocation that has been around for a long time but isn't necessary because theinit()
command always sets and seals the config.