add test for Mnemonic.WordList func

This commit is contained in:
Andrea Franz 2018-03-14 11:21:20 +01:00
parent eb112b89f9
commit 1b747bcbc7
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 17 additions and 1 deletions

View File

@ -240,7 +240,7 @@ func (m *Mnemonic) ValidMnemonic(mnemonic string, language Language) bool {
// WordList returns list of words for a given language
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 m.wordLists[language], nil

View File

@ -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
func TestMnemonicPhrase(t *testing.T) {