Skip to content
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

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions app/config.go

This file was deleted.

15 changes: 15 additions & 0 deletions app/sdk_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import sdk "github.com/cosmos/cosmos-sdk/types"

func init() {
setCosmosSDKConfig()
}

func setCosmosSDKConfig() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
config.Seal()
Comment on lines +9 to +14
Copy link
Contributor

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

}
18 changes: 18 additions & 0 deletions app/sdk_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package app

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
)

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())
Comment on lines +10 to +17
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Collaborator Author

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.

}
4 changes: 0 additions & 4 deletions cmd/celestia-appd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
simdcmd "github.com/cosmos/cosmos-sdk/simapp/simd/cmd"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -100,9 +99,6 @@ func NewRootCmd() *cobra.Command {

// initRootCommand performs a bunch of side-effects on the root command.
func initRootCommand(rootCommand *cobra.Command, encodingConfig encoding.Config) {
config := sdk.GetConfig()
staheri14 marked this conversation as resolved.
Show resolved Hide resolved
config.Seal()

rootCommand.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
Expand Down
Loading