Skip to content

Commit

Permalink
refactor: remove unnecessary config.Seal() (#3786)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
rootulp authored and mergify[bot] committed Aug 20, 2024
1 parent 2b5d3d9 commit 351f36d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
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()
}
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())
}
36 changes: 36 additions & 0 deletions cmd/celestia-appd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import (
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
<<<<<<< HEAD

Check failure on line 26 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 26 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

missing import path (typecheck)

Check failure on line 26 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / test / test

missing import path

Check failure on line 26 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / test / test-short

missing import path

Check failure on line 26 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

missing import path

Check failure on line 26 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / test / test-race

missing import path
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/snapshots"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
=======

Check failure on line 33 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 33 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

missing import path (typecheck)
simdcmd "github.com/cosmos/cosmos-sdk/simapp/simd/cmd"
>>>>>>> 9c9e77a2 (refactor: remove unnecessary `config.Seal()` (#3786))

Check failure on line 35 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 35 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

invalid character U+0023 '#'

Check failure on line 35 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

missing import path (typecheck)
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
Expand Down Expand Up @@ -109,7 +113,39 @@ func NewRootCmd() *cobra.Command {
rootCmd.PersistentFlags().String(FlagLogToFile, "", "Write logs directly to a file. If empty, logs are written to stderr")
initRootCmd(rootCmd, encodingConfig)

<<<<<<< HEAD

Check failure on line 116 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: unexpected <<, expected }
return rootCmd
=======
return rootCommand
}

// initRootCommand performs a bunch of side-effects on the root command.
func initRootCommand(rootCommand *cobra.Command, encodingConfig encoding.Config) {
rootCommand.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
simdcmd.AddGenesisAccountCmd(app.DefaultNodeHome),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
tmcli.NewCompletionCmd(rootCommand, true),
debug.Cmd(),
clientconfig.Cmd(),
commands.CompactGoLevelDBCmd,
addrbookCommand(),
downloadGenesisCommand(),
addrConversionCmd(),
rpc.StatusCommand(),
queryCommand(),
txCommand(),
keys.Commands(app.DefaultNodeHome),
blobstreamclient.VerifyCmd(),
snapshot.Cmd(NewAppServer),
)

// Add the following commands to the rootCommand: start, tendermint, export, version, and rollback.
server.AddCommands(rootCommand, app.DefaultNodeHome, NewAppServer, appExporter, addModuleInitFlags)
>>>>>>> 9c9e77a2 (refactor: remove unnecessary `config.Seal()` (#3786))

Check failure on line 148 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: unexpected >>, expected }

Check failure on line 148 in cmd/celestia-appd/cmd/root.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

invalid character U+0023 '#' (typecheck)
}

// setDefaultConsensusParams sets the default consensus parameters for the
Expand Down

0 comments on commit 351f36d

Please sign in to comment.