2020-07-21 02:05:23 +00:00
|
|
|
package derived
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
2020-07-21 02:05:23 +00:00
|
|
|
"github.com/tyler-smith/go-bip39"
|
2022-10-26 21:04:00 +00:00
|
|
|
"github.com/tyler-smith/go-bip39/wordlists"
|
2020-07-21 02:05:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMnemonic_Generate_CanRecover(t *testing.T) {
|
2022-10-26 21:04:00 +00:00
|
|
|
generator := &MnemonicGenerator{}
|
2020-07-21 02:05:23 +00:00
|
|
|
data := make([]byte, 32)
|
2020-07-22 19:42:43 +00:00
|
|
|
copy(data, "hello-world")
|
2020-07-21 02:05:23 +00:00
|
|
|
phrase, err := generator.Generate(data)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-07-21 02:05:23 +00:00
|
|
|
entropy, err := bip39.EntropyFromMnemonic(phrase)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.DeepEqual(t, data, entropy, "Expected to recover original data")
|
2020-07-21 02:05:23 +00:00
|
|
|
}
|
2022-10-26 21:04:00 +00:00
|
|
|
|
|
|
|
func Test_setBip39Lang(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
lang string
|
|
|
|
expectedWordlist []string
|
|
|
|
}{
|
|
|
|
{lang: "english", expectedWordlist: wordlists.English},
|
|
|
|
{lang: "chinese_traditional", expectedWordlist: wordlists.ChineseTraditional},
|
|
|
|
{lang: "chinese_simplified", expectedWordlist: wordlists.ChineseSimplified},
|
|
|
|
{lang: "czech", expectedWordlist: wordlists.Czech},
|
|
|
|
{lang: "french", expectedWordlist: wordlists.French},
|
|
|
|
{lang: "japanese", expectedWordlist: wordlists.Japanese},
|
|
|
|
{lang: "korean", expectedWordlist: wordlists.Korean},
|
|
|
|
{lang: "italian", expectedWordlist: wordlists.Italian},
|
|
|
|
{lang: "spanish", expectedWordlist: wordlists.Spanish},
|
|
|
|
{lang: "undefined", expectedWordlist: wordlists.English},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.lang, func(t *testing.T) {
|
|
|
|
setBip39Lang(tt.lang)
|
|
|
|
wordlist := bip39.GetWordList()
|
|
|
|
assert.DeepEqual(t, tt.expectedWordlist, wordlist, "Expected wordlist to match")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|