Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix: enable fixIssue172 flag for test #1447

Merged
merged 12 commits into from
Nov 23, 2022
18 changes: 13 additions & 5 deletions crypto/hd/algorithm_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hd

import (
"os"
"strings"
"testing"

Expand All @@ -10,7 +11,6 @@ import (

hdwallet "github.com/miguelmota/go-ethereum-hdwallet"

"github.com/cosmos/cosmos-sdk/codec"
amino "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -20,23 +20,29 @@ import (
ethermint "github.com/evmos/ethermint/types"
)

var TestCodec codec.Codec
var TestCodec amino.Codec

func init() {
cdc := codec.NewLegacyAmino()
cdc := amino.NewLegacyAmino()
cryptocodec.RegisterCrypto(cdc)

interfaceRegistry := types.NewInterfaceRegistry()
TestCodec = amino.NewProtoCodec(interfaceRegistry)
enccodec.RegisterInterfaces(interfaceRegistry)
}

const mnemonic = "picnic rent average infant boat squirrel federal assault mercy purity very motor fossil wheel verify upset box fresh horse vivid copy predict square regret"
const (
mnemonic = "picnic rent average infant boat squirrel federal assault mercy purity very motor fossil wheel verify upset box fresh horse vivid copy predict square regret"

// hdWalletFixEnv defines whether the standard (correct) bip39
// derivation path was used, or if derivation was affected by
// https://github.com/btcsuite/btcutil/issues/172
hdWalletFixEnv = "GO_ETHEREUM_HDWALLET_FIX_ISSUE_179"
)

func TestKeyring(t *testing.T) {
dir := t.TempDir()
mockIn := strings.NewReader("")

kr, err := keyring.New("ethermint", keyring.BackendTest, dir, mockIn, TestCodec, EthSecp256k1Option())
require.NoError(t, err)

Expand Down Expand Up @@ -68,7 +74,9 @@ func TestKeyring(t *testing.T) {
privkey := EthSecp256k1.Generate()(bz)
addr := common.BytesToAddress(privkey.PubKey().Address().Bytes())

os.Setenv(hdWalletFixEnv, "true")
wallet, err := hdwallet.NewFromMnemonic(mnemonic)
os.Setenv(hdWalletFixEnv, "")
require.NoError(t, err)

path := hdwallet.MustParseDerivationPath(hdPath)
Expand Down