diff --git a/app/prefix.go b/app/prefix.go index ab215987f2..2e97fc9519 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -1,8 +1,6 @@ package app import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -11,6 +9,7 @@ const ( AccountAddressPrefixTestNet = "tp" CoinTypeMainNet = 505 CoinTypeTestNet = 1 + Purpose = 44 ) var ( @@ -26,7 +25,7 @@ var ( ) // SetConfig sets the configuration for the network using mainnet or testnet -func SetConfig(testnet bool) { +func SetConfig(testnet bool, seal bool) { // not the default (mainnet) so reset with testnet config if testnet { AccountAddressPrefix = AccountAddressPrefixTestNet @@ -40,9 +39,11 @@ func SetConfig(testnet bool) { config := sdk.GetConfig() config.SetCoinType(uint32(CoinType)) - config.SetFullFundraiserPath(fmt.Sprintf("m/44'/%d'/0'/0/0", CoinType)) + config.SetPurpose(Purpose) config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix) config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix) config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix) - config.Seal() + if seal { + config.Seal() + } } diff --git a/app/prefix_test.go b/app/prefix_test.go new file mode 100644 index 0000000000..9071cb693d --- /dev/null +++ b/app/prefix_test.go @@ -0,0 +1,59 @@ +package app + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestFullBIP44PathForTestnet(t *testing.T) { + cases := []struct { + name string + expected string + isTestnet bool + seal bool + shouldPanic bool + panicMessage string + }{ + { + "has correct bip44th path for testnet", + "m/44'/118'/0'/0/0", + true, + false, + false, + "", + }, + { + "has correct bip44th path for mainnet", + "m/44'/118'/0'/0/0", + true, + true, + false, + "", + }, + { + "cannot double seal", + "m/44'/118'/0'/0/0", + true, + true, + true, + "Config is sealed", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + config := sdk.NewConfig() + if tc.shouldPanic { + require.Panics(t, func() { + SetConfig(tc.isTestnet, tc.seal) + }, tc.name) + } else { + SetConfig(tc.isTestnet, tc.seal) + require.Equal(t, tc.expected, config.GetFullBIP44Path(), tc.name) + } + + }) + } +} diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index f343518395..56050e6a78 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -90,7 +90,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { // set app context based on initialized EnvTypeFlag testnet := server.GetServerContextFromCmd(cmd).Viper.GetBool(EnvTypeFlag) - app.SetConfig(testnet) + app.SetConfig(testnet, true) overwriteFlagDefaults(cmd, map[string]string{ // Override default value for coin-type to match our mainnet or testnet value. CoinTypeFlag: fmt.Sprint(app.CoinType),