From 9c9e77a2853f4f90c9fa3808ad2f3401fd5bd989 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Tue, 20 Aug 2024 14:32:28 -0400 Subject: [PATCH] refactor: remove unnecessary `config.Seal()` (#3786) - Add unit tests to cosmos SDK config set up - Remove an unnecessary `config.Seal` invocation that has been around for a [long time](https://github.com/celestiaorg/celestia-app/commit/5e4a1dc56e42e7341b6da9526430b12dcc7a6691#diff-9e0425d31b7cf4072a746feb0c6bc1e0045b639e01dd0b5ac2f08e8c2952c886R120) but isn't necessary because the `init()` command always sets and seals the config. --- app/config.go | 13 ------------- app/sdk_config.go | 15 +++++++++++++++ app/sdk_config_test.go | 18 ++++++++++++++++++ cmd/celestia-appd/cmd/root.go | 4 ---- 4 files changed, 33 insertions(+), 17 deletions(-) delete mode 100644 app/config.go create mode 100644 app/sdk_config.go create mode 100644 app/sdk_config_test.go diff --git a/app/config.go b/app/config.go deleted file mode 100644 index c6cd322e3b..0000000000 --- a/app/config.go +++ /dev/null @@ -1,13 +0,0 @@ -package app - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func init() { - cfg := sdk.GetConfig() - cfg.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) - cfg.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) - cfg.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) - cfg.Seal() -} diff --git a/app/sdk_config.go b/app/sdk_config.go new file mode 100644 index 0000000000..dd74de158d --- /dev/null +++ b/app/sdk_config.go @@ -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() +} diff --git a/app/sdk_config_test.go b/app/sdk_config_test.go new file mode 100644 index 0000000000..f3179096df --- /dev/null +++ b/app/sdk_config_test.go @@ -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()) +} diff --git a/cmd/celestia-appd/cmd/root.go b/cmd/celestia-appd/cmd/root.go index bfb052fc8a..a1fef093ad 100644 --- a/cmd/celestia-appd/cmd/root.go +++ b/cmd/celestia-appd/cmd/root.go @@ -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" @@ -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() - config.Seal() - rootCommand.AddCommand( genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),