Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced deprecated SetFullFundraiserPath with SetCoinType and SetPurpose #1037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/prefix.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package app

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -11,6 +9,7 @@ const (
AccountAddressPrefixTestNet = "tp"
CoinTypeMainNet = 505
CoinTypeTestNet = 1
Purpose = 44
)

var (
Expand All @@ -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
Expand All @@ -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)
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)
config.Seal()
if seal {
config.Seal()
}
}
59 changes: 59 additions & 0 deletions app/prefix_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

})
}
}
2 changes: 1 addition & 1 deletion cmd/provenanced/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down