From 8fe938ea344fd40196d2c7259fd394b8e5978e23 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Tue, 23 Aug 2022 15:45:23 -0400 Subject: [PATCH 1/2] Removed SetFullFundraiserPath and replaced it with SetCoinType and SetPurpose. --- app/prefix.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/prefix.go b/app/prefix.go index ab215987f2..97585de08e 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 ( @@ -40,7 +39,7 @@ 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) From fc9df2acebbd9bc62f1c1fc2c2b10e48e7f963a1 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Wed, 24 Aug 2022 09:28:47 -0400 Subject: [PATCH 2/2] Added prefix_test and updated SetConfig to have a configurable seal param. This was mainly to help with testing. --- app/prefix.go | 6 ++-- app/prefix_test.go | 59 +++++++++++++++++++++++++++++++++++++ cmd/provenanced/cmd/root.go | 2 +- 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 app/prefix_test.go diff --git a/app/prefix.go b/app/prefix.go index 97585de08e..2e97fc9519 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -25,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 @@ -43,5 +43,7 @@ func SetConfig(testnet bool) { 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),