add test for Mnemonic.WordList func
This commit is contained in:
parent
eb112b89f9
commit
1b747bcbc7
|
@ -240,7 +240,7 @@ func (m *Mnemonic) ValidMnemonic(mnemonic string, language Language) bool {
|
||||||
|
|
||||||
// WordList returns list of words for a given language
|
// WordList returns list of words for a given language
|
||||||
func (m *Mnemonic) WordList(language Language) (*WordList, error) {
|
func (m *Mnemonic) WordList(language Language) (*WordList, error) {
|
||||||
if m.wordLists[language] == nil {
|
if int(language) < 0 || int(language) > len(m.wordLists)-1 || m.wordLists[language] == nil {
|
||||||
return nil, fmt.Errorf("language word list is missing (language id: %d)", language)
|
return nil, fmt.Errorf("language word list is missing (language id: %d)", language)
|
||||||
}
|
}
|
||||||
return m.wordLists[language], nil
|
return m.wordLists[language], nil
|
||||||
|
|
|
@ -29,6 +29,22 @@ func TestNewMnemonic(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMnemonic_WordList(t *testing.T) {
|
||||||
|
m := NewMnemonic("")
|
||||||
|
_, err := m.WordList(EnglishLanguage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected WordList to return WordList without errors, got: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
indexes := []Language{-1, Language(len(m.wordLists))}
|
||||||
|
for _, index := range indexes {
|
||||||
|
_, err := m.WordList(index)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("expected WordList to return an error with index %d", index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestMnemonicPhrase
|
// TestMnemonicPhrase
|
||||||
func TestMnemonicPhrase(t *testing.T) {
|
func TestMnemonicPhrase(t *testing.T) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue