From 60c043d4dd06229152a4017315a1e21db7dd2c98 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Thu, 12 Dec 2024 12:34:18 -0800 Subject: [PATCH] refactor: unify cosmos sdk configurations remove address format verifier --- app/app.go | 39 +------------------ app/prefix.go | 17 -------- cmd/cosmos.go | 36 ----------------- cmd/zetaclientd/main.go | 4 +- cmd/zetacored/config/config.go | 14 ------- cmd/zetacored/main.go | 1 + cmd/zetacored/parse_genesis_test.go | 16 +------- cmd/zetacored/parsers_test.go | 3 +- cmd/zetacored/root.go | 7 ---- cmd/zetae2e/balances.go | 4 -- cmd/zetae2e/bitcoin_address.go | 4 -- cmd/zetae2e/local/get_zetaclient_bootstrap.go | 2 - cmd/zetae2e/local/local.go | 3 -- cmd/zetae2e/main.go | 2 + cmd/zetae2e/run.go | 4 -- cmd/zetae2e/setup_bitcoin.go | 4 -- cmd/zetae2e/show_tss.go | 4 -- cmd/zetae2e/stress.go | 7 ---- contrib/rpcimportable/rpcimportable_test.go | 18 +++++++++ pkg/sdkconfig/default/default.go | 11 ++++++ pkg/sdkconfig/sdkconfig.go | 8 +--- testutil/keeper/emissions.go | 3 +- x/emissions/abci_test.go | 2 - zetaclient/keys/keys_test.go | 24 +++--------- zetaclient/testutils/mocks/tss.go | 6 +-- zetaclient/tss/config.go | 6 --- 26 files changed, 46 insertions(+), 203 deletions(-) delete mode 100644 app/prefix.go delete mode 100644 cmd/cosmos.go create mode 100644 pkg/sdkconfig/default/default.go diff --git a/app/app.go b/app/app.go index c79552bc74..1132e89cb3 100644 --- a/app/app.go +++ b/app/app.go @@ -8,7 +8,6 @@ import ( "runtime/debug" "time" - cosmoserrors "cosmossdk.io/errors" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" @@ -26,7 +25,6 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" @@ -145,26 +143,8 @@ func init() { } var ( - AccountAddressPrefix = "zeta" - NodeDir = ".zetacored" - DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir - - // AddrLen is the allowed length (in bytes) for an address. - // NOTE: In the SDK, the default value is 255. - AddrLen = 20 - - // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address - Bech32PrefixAccAddr = AccountAddressPrefix - // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key - Bech32PrefixAccPub = AccountAddressPrefix + sdk.PrefixPublic - // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address - Bech32PrefixValAddr = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixOperator - // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key - Bech32PrefixValPub = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic - // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address - Bech32PrefixConsAddr = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixConsensus - // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key - Bech32PrefixConsPub = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic + NodeDir = ".zetacored" + DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir ) func getGovProposalHandlers() []govclient.ProposalHandler { @@ -1037,21 +1017,6 @@ func initParamsKeeper( return paramsKeeper } -// VerifyAddressFormat verifies the address is compatible with ethereum -func VerifyAddressFormat(bz []byte) error { - if len(bz) == 0 { - return cosmoserrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty") - } - if len(bz) != AddrLen { - return cosmoserrors.Wrapf( - sdkerrors.ErrUnknownAddress, - "invalid address length; got: %d, expect: %d", len(bz), AddrLen, - ) - } - - return nil -} - // SimulationManager implements the SimulationApp interface func (app *App) SimulationManager() *module.SimulationManager { return app.sm diff --git a/app/prefix.go b/app/prefix.go deleted file mode 100644 index 34e0274a4e..0000000000 --- a/app/prefix.go +++ /dev/null @@ -1,17 +0,0 @@ -package app - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - ethcfg "github.com/zeta-chain/ethermint/cmd/config" - - cmdcfg "github.com/zeta-chain/node/cmd/zetacored/config" -) - -func SetConfig() { - config := sdk.GetConfig() - cmdcfg.SetBech32Prefixes(config) - ethcfg.SetBip44CoinType(config) - // Make sure address is compatible with ethereum - config.SetAddressVerifier(VerifyAddressFormat) - config.Seal() -} diff --git a/cmd/cosmos.go b/cmd/cosmos.go deleted file mode 100644 index 9c0b3b8e3d..0000000000 --- a/cmd/cosmos.go +++ /dev/null @@ -1,36 +0,0 @@ -// Package cmd provides cosmos constants for ZetaClient. -package cmd - -import ( - "sync" - - cosmos "github.com/cosmos/cosmos-sdk/types" -) - -const ( - Bech32PrefixAccAddr = "zeta" - Bech32PrefixAccPub = "zetapub" - Bech32PrefixValAddr = "zetav" - Bech32PrefixValPub = "zetavpub" - Bech32PrefixConsAddr = "zetac" - Bech32PrefixConsPub = "zetacpub" - DenomRegex = `[a-zA-Z][a-zA-Z0-9:\\/\\\-\\_\\.]{2,127}` - ZetaChainHDPath string = `m/44'/60'/0'/0/0` -) - -var setupConfig sync.Once - -// SetupCosmosConfig configures basic Cosmos parameters. -// This function is required because some parts of ZetaClient rely on these constants. -func SetupCosmosConfig() { - setupConfig.Do(setupCosmosConfig) -} - -func setupCosmosConfig() { - config := cosmos.GetConfig() - config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) - config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) - config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) - config.SetFullFundraiserPath(ZetaChainHDPath) - cosmos.SetCoinDenomRegex(func() string { return DenomRegex }) -} diff --git a/cmd/zetaclientd/main.go b/cmd/zetaclientd/main.go index b3113f4035..a5f8187699 100644 --- a/cmd/zetaclientd/main.go +++ b/cmd/zetaclientd/main.go @@ -9,8 +9,8 @@ import ( "github.com/spf13/cobra" "github.com/zeta-chain/node/app" - "github.com/zeta-chain/node/cmd" "github.com/zeta-chain/node/pkg/constant" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" ) var ( @@ -85,8 +85,6 @@ func setupGlobalOptions() { } func init() { - cmd.SetupCosmosConfig() - // Setup options setupGlobalOptions() setupInitializeConfigOptions() diff --git a/cmd/zetacored/config/config.go b/cmd/zetacored/config/config.go index 09c62182da..a989d260b1 100644 --- a/cmd/zetacored/config/config.go +++ b/cmd/zetacored/config/config.go @@ -5,13 +5,6 @@ import ( ethermint "github.com/zeta-chain/ethermint/types" ) -// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. -func SetBech32Prefixes(config *sdk.Config) { - config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) - config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) - config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) -} - const ( DisplayDenom = "zeta" BaseDenom = "azeta" @@ -28,10 +21,3 @@ func RegisterDenoms() { panic(err) } } - -// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets. -func SetBip44CoinType(config *sdk.Config) { - config.SetCoinType(ethermint.Bip44CoinType) - config.SetPurpose(sdk.Purpose) // Shared - config.SetFullFundraiserPath(ethermint.BIP44HDPath) // nolint: staticcheck -} diff --git a/cmd/zetacored/main.go b/cmd/zetacored/main.go index 4ec6c36631..0c798b0212 100644 --- a/cmd/zetacored/main.go +++ b/cmd/zetacored/main.go @@ -10,6 +10,7 @@ import ( "github.com/zeta-chain/node/app" cmdcfg "github.com/zeta-chain/node/cmd/zetacored/config" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" ) func main() { diff --git a/cmd/zetacored/parse_genesis_test.go b/cmd/zetacored/parse_genesis_test.go index 864a701fa8..43ceed95da 100644 --- a/cmd/zetacored/parse_genesis_test.go +++ b/cmd/zetacored/parse_genesis_test.go @@ -15,8 +15,8 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/stretchr/testify/require" - "github.com/zeta-chain/node/app" zetacored "github.com/zeta-chain/node/cmd/zetacored" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" keepertest "github.com/zeta-chain/node/testutil/keeper" "github.com/zeta-chain/node/testutil/sample" crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" @@ -24,18 +24,7 @@ import ( observertypes "github.com/zeta-chain/node/x/observer/types" ) -func setConfig(t *testing.T) { - defer func(t *testing.T) { - if r := recover(); r != nil { - t.Log("config is already sealed", r) - } - }(t) - cfg := sdk.GetConfig() - cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub) - cfg.Seal() -} func Test_ModifyCrossChainState(t *testing.T) { - setConfig(t) t.Run("successfully modify cross chain state to reduce data", func(t *testing.T) { cdc := keepertest.NewCodec() appState := sample.AppState(t) @@ -64,7 +53,6 @@ func Test_ModifyCrossChainState(t *testing.T) { } func Test_ModifyObserverState(t *testing.T) { - setConfig(t) t.Run("successfully modify observer state to reduce data", func(t *testing.T) { cdc := keepertest.NewCodec() appState := sample.AppState(t) @@ -93,7 +81,6 @@ func Test_ModifyObserverState(t *testing.T) { func Test_ImportDataIntoFile(t *testing.T) { t.Run("successfully import data into file and modify data", func(t *testing.T) { - setConfig(t) cdc := keepertest.NewCodec() genDoc := sample.GenDoc(t) importGenDoc := ImportGenDoc(t, cdc, 100) @@ -133,7 +120,6 @@ func Test_ImportDataIntoFile(t *testing.T) { }) t.Run("successfully import data into file without modifying data", func(t *testing.T) { - setConfig(t) cdc := keepertest.NewCodec() genDoc := sample.GenDoc(t) importGenDoc := ImportGenDoc(t, cdc, 8) diff --git a/cmd/zetacored/parsers_test.go b/cmd/zetacored/parsers_test.go index 3dc47952da..a547b04956 100644 --- a/cmd/zetacored/parsers_test.go +++ b/cmd/zetacored/parsers_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/zeta-chain/node/app" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" "github.com/zeta-chain/node/testutil/sample" ) @@ -18,7 +18,6 @@ func TestParsefileToObserverMapper(t *testing.T) { err := os.RemoveAll(fp) require.NoError(t, err) }(t, file) - app.SetConfig() observerAddress := sample.AccAddress() commonGrantAddress := sample.AccAddress() diff --git a/cmd/zetacored/root.go b/cmd/zetacored/root.go index 1f7115e57a..24f8d5f631 100644 --- a/cmd/zetacored/root.go +++ b/cmd/zetacored/root.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/snapshot" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -47,12 +46,6 @@ const EnvPrefix = "zetacore" func NewRootCmd() (*cobra.Command, types.EncodingConfig) { encodingConfig := app.MakeEncodingConfig() - cfg := sdk.GetConfig() - cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub) - cfg.SetBech32PrefixForValidator(app.Bech32PrefixValAddr, app.Bech32PrefixValPub) - cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub) - cfg.Seal() - initClientCtx := client.Context{}. WithCodec(encodingConfig.Codec). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index e8fa290065..5e6e07ab6d 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -6,7 +6,6 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/e2e/config" "github.com/zeta-chain/node/e2e/runner" @@ -46,9 +45,6 @@ func runBalances(cmd *cobra.Command, args []string) error { // initialize logger logger := runner.NewLogger(false, color.FgHiCyan, "") - // set config - app.SetConfig() - // initialize context ctx, cancel := context.WithCancel(context.Background()) diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index be1251d1d2..b4288ff788 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -6,7 +6,6 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/e2e/config" "github.com/zeta-chain/node/e2e/runner" @@ -46,9 +45,6 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { // initialize logger logger := runner.NewLogger(false, color.FgHiYellow, "") - // set config - app.SetConfig() - // initialize context ctx, cancel := context.WithCancel(context.Background()) diff --git a/cmd/zetae2e/local/get_zetaclient_bootstrap.go b/cmd/zetae2e/local/get_zetaclient_bootstrap.go index 16cbdcf10c..a5ca2dffee 100644 --- a/cmd/zetae2e/local/get_zetaclient_bootstrap.go +++ b/cmd/zetae2e/local/get_zetaclient_bootstrap.go @@ -13,7 +13,6 @@ import ( "google.golang.org/grpc/credentials/insecure" "github.com/zeta-chain/node/pkg/rpc" - "github.com/zeta-chain/node/pkg/sdkconfig" observertypes "github.com/zeta-chain/node/x/observer/types" ) @@ -33,7 +32,6 @@ func NewGetZetaclientBootstrap() *cobra.Command { } func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error { - sdkconfig.SetDefault(true) grpcURL, _ := cmd.Flags().GetString(grpcURLFlag) rpcClient, err := rpc.NewGRPCClients( grpcURL, diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index e625b4174a..0df7153980 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -11,7 +11,6 @@ import ( "github.com/spf13/cobra" "golang.org/x/sync/errgroup" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/e2e/config" "github.com/zeta-chain/node/e2e/e2etests" @@ -154,8 +153,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) { noError(utils.WaitForBlockHeight(ctx, waitForHeight, conf.RPCs.ZetaCoreRPC, logger)) } - app.SetConfig() - zetaTxServer, err := txserver.NewZetaTxServer( conf.RPCs.ZetaCoreRPC, []string{ diff --git a/cmd/zetae2e/main.go b/cmd/zetae2e/main.go index 7b8038709c..8466227db4 100644 --- a/cmd/zetae2e/main.go +++ b/cmd/zetae2e/main.go @@ -5,6 +5,8 @@ import ( "os" "github.com/fatih/color" + + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" ) func main() { diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index 91116f234c..a33dae5022 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -11,7 +11,6 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/e2e/config" "github.com/zeta-chain/node/e2e/e2etests" @@ -99,9 +98,6 @@ func runE2ETest(cmd *cobra.Command, args []string) error { conf.Contracts.ZEVM.ERC20ZRC20Addr = config.DoubleQuotedString(zrc20ContractAddress) } - // set config - app.SetConfig() - // initialize context ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index a51d8880b0..d248dddb26 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -6,7 +6,6 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/e2e/config" "github.com/zeta-chain/node/e2e/runner" @@ -34,9 +33,6 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { // initialize logger logger := runner.NewLogger(false, color.FgHiYellow, "") - // set config - app.SetConfig() - // initialize context ctx, cancel := context.WithCancel(context.Background()) diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 22ba0b2ae7..d1ada5184c 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -6,7 +6,6 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/e2e/config" "github.com/zeta-chain/node/e2e/runner" @@ -34,9 +33,6 @@ func runShowTSS(_ *cobra.Command, args []string) error { // initialize logger logger := runner.NewLogger(true, color.FgHiCyan, "") - // set config - app.SetConfig() - // initialize context ctx, cancel := context.WithCancel(context.Background()) diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index d2167ec466..d38cbd1283 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -10,7 +10,6 @@ import ( "sync" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/ethclient" "github.com/fatih/color" @@ -18,7 +17,6 @@ import ( "github.com/zeta-chain/protocol-contracts/v2/pkg/zrc20.sol" "google.golang.org/grpc" - "github.com/zeta-chain/node/app" zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config" "github.com/zeta-chain/node/cmd/zetae2e/local" "github.com/zeta-chain/node/e2e/runner" @@ -77,11 +75,6 @@ func StressTest(cmd *cobra.Command, _ []string) { os.Exit(1) }() - // set account prefix to zeta - cosmosConf := sdk.GetConfig() - cosmosConf.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub) - cosmosConf.Seal() - // initialize E2E tests config conf := must(local.GetConfig(cmd)) diff --git a/contrib/rpcimportable/rpcimportable_test.go b/contrib/rpcimportable/rpcimportable_test.go index b2bc8959a5..5aa28fc977 100644 --- a/contrib/rpcimportable/rpcimportable_test.go +++ b/contrib/rpcimportable/rpcimportable_test.go @@ -3,9 +3,27 @@ package rpcimportable import ( "testing" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/zeta-chain/node/pkg/rpc" + "github.com/zeta-chain/node/pkg/sdkconfig" ) func TestRPCImportable(t *testing.T) { _ = rpc.Clients{} } + +func TestCosmosSdkConfigUntouched(t *testing.T) { + zetaCfg := sdk.NewConfig() + sdkconfig.Set(zetaCfg, true) + if zetaCfg.GetBech32AccountAddrPrefix() != sdkconfig.AccountAddressPrefix { + t.Logf("zetaCfg account prefix is not %s", sdkconfig.AccountAddressPrefix) + t.FailNow() + } + + // ensure that importing/using zeta sdkconfig does not mutate the global config + globalConfig := sdk.GetConfig() + if globalConfig.GetBech32AccountAddrPrefix() != sdk.Bech32MainPrefix { + t.Logf("globalConfig account prefix is not %s", sdk.Bech32MainPrefix) + t.FailNow() + } +} diff --git a/pkg/sdkconfig/default/default.go b/pkg/sdkconfig/default/default.go new file mode 100644 index 0000000000..a14ea36c72 --- /dev/null +++ b/pkg/sdkconfig/default/default.go @@ -0,0 +1,11 @@ +// Set the global default cosmos sdk config on import +// +// this should ONLY be imported in test and internal packages +// as we do not want to set the defaults for external importers +package sdkconfigdefault + +import "github.com/zeta-chain/node/pkg/sdkconfig" + +func init() { + sdkconfig.SetDefault(true) +} diff --git a/pkg/sdkconfig/sdkconfig.go b/pkg/sdkconfig/sdkconfig.go index 37149496f0..6f2c02a53d 100644 --- a/pkg/sdkconfig/sdkconfig.go +++ b/pkg/sdkconfig/sdkconfig.go @@ -9,6 +9,7 @@ const ( ) var ( + AddrLen = 20 AccountPubKeyPrefix = AccountAddressPrefix + "pub" ValidatorAddressPrefix = AccountAddressPrefix + "valoper" ValidatorPubKeyPrefix = AccountAddressPrefix + "valoperpub" @@ -18,12 +19,7 @@ var ( func SetDefault(seal bool) { config := sdk.GetConfig() - config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix) - config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix) - config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix) - if seal { - config.Seal() - } + Set(config, seal) } func Set(config *sdk.Config, seal bool) { diff --git a/testutil/keeper/emissions.go b/testutil/keeper/emissions.go index bfbe2813d9..05f14b918f 100644 --- a/testutil/keeper/emissions.go +++ b/testutil/keeper/emissions.go @@ -12,7 +12,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/stretchr/testify/require" - "github.com/zeta-chain/node/pkg/sdkconfig" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" //nolint:blank-imports this is a test package emissionsmocks "github.com/zeta-chain/node/testutil/keeper/mocks/emissions" "github.com/zeta-chain/node/x/emissions/keeper" "github.com/zeta-chain/node/x/emissions/types" @@ -33,7 +33,6 @@ func EmissionKeeperWithMockOptions( t testing.TB, mockOptions EmissionMockOptions, ) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) { - sdkconfig.SetDefault(false) storeKey := sdk.NewKVStoreKey(types.StoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) diff --git a/x/emissions/abci_test.go b/x/emissions/abci_test.go index 681a8b1247..b29698c398 100644 --- a/x/emissions/abci_test.go +++ b/x/emissions/abci_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "github.com/zeta-chain/node/cmd/zetacored/config" - "github.com/zeta-chain/node/pkg/sdkconfig" keepertest "github.com/zeta-chain/node/testutil/keeper" "github.com/zeta-chain/node/testutil/sample" "github.com/zeta-chain/node/x/emissions" @@ -313,7 +312,6 @@ func TestBeginBlocker(t *testing.T) { } func TestDistributeObserverRewards(t *testing.T) { - sdkconfig.SetDefault(false) observerSet := sample.ObserverSet(4) tt := []struct { diff --git a/zetaclient/keys/keys_test.go b/zetaclient/keys/keys_test.go index 0812c727f6..f8fdad0780 100644 --- a/zetaclient/keys/keys_test.go +++ b/zetaclient/keys/keys_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/require" . "gopkg.in/check.v1" - "github.com/zeta-chain/node/cmd" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" "github.com/zeta-chain/node/zetaclient/config" "github.com/zeta-chain/node/zetaclient/testutils/mocks" ) @@ -35,25 +35,11 @@ var ( ) const ( - signerNameForTest = `jack` - signerPasswordForTest = `password` + signerNameForTest = `jack` + signerPasswordForTest = `password` + zetaChainHDPath string = `m/44'/60'/0'/0/0` ) -func setupConfig() { - testConfig := sdk.GetConfig() - testConfig.SetBech32PrefixForAccount(cmd.Bech32PrefixAccAddr, cmd.Bech32PrefixAccPub) - testConfig.SetBech32PrefixForValidator(cmd.Bech32PrefixValAddr, cmd.Bech32PrefixValPub) - testConfig.SetBech32PrefixForConsensusNode(cmd.Bech32PrefixConsAddr, cmd.Bech32PrefixConsPub) - testConfig.SetFullFundraiserPath(cmd.ZetaChainHDPath) - sdk.SetCoinDenomRegex(func() string { - return cmd.DenomRegex - }) -} - -func (*KeysSuite) SetUpSuite(_ *C) { - setupConfig() -} - func (*KeysSuite) setupKeysForTest(c *C) string { ns := strconv.Itoa(time.Now().Nanosecond()) metaCliDir := filepath.Join(os.TempDir(), ns, ".metacli") @@ -72,7 +58,7 @@ func (*KeysSuite) setupKeysForTest(c *C) string { _, _, err = kb.NewMnemonic( GetGranteeKeyName(signerNameForTest), cKeys.English, - cmd.ZetaChainHDPath, + zetaChainHDPath, password, hd.Secp256k1, ) diff --git a/zetaclient/testutils/mocks/tss.go b/zetaclient/testutils/mocks/tss.go index 65ca954e55..f9c1024ab9 100644 --- a/zetaclient/testutils/mocks/tss.go +++ b/zetaclient/testutils/mocks/tss.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" - "github.com/zeta-chain/node/cmd" + _ "github.com/zeta-chain/node/pkg/sdkconfig/default" //nolint:blank-imports this is a test package zetatss "github.com/zeta-chain/node/zetaclient/tss" ) @@ -121,7 +121,3 @@ func (tss *TSS) Pause() { func (tss *TSS) Unpause() { tss.paused = false } - -func init() { - cmd.SetupCosmosConfig() -} diff --git a/zetaclient/tss/config.go b/zetaclient/tss/config.go index 06a24e87ed..fcf89ce7cf 100644 --- a/zetaclient/tss/config.go +++ b/zetaclient/tss/config.go @@ -11,8 +11,6 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" tsscommon "gitlab.com/thorchain/tss/go-tss/common" - - "github.com/zeta-chain/node/cmd" ) const ( @@ -22,10 +20,6 @@ const ( Algo = tsscommon.ECDSA ) -func init() { - cmd.SetupCosmosConfig() -} - // MultiAddressFromString parses a string into a slice of addresses (for convenience). func MultiAddressFromString(peer string) ([]multiaddr.Multiaddr, error) { if peer == "" {