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

test: added more tests #9

Merged
merged 1 commit into from
Mar 16, 2022
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
30 changes: 19 additions & 11 deletions cmd/melt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,35 @@ func completeColor(truecolor, ansi256, ansi string) string {

// setLanguage sets the language of the big39 mnemonic seed.
func setLanguage(language string) error {
list := getWordlist(language)
if list == nil {
return fmt.Errorf("this language is not supported")
}
bip39.SetWordList(list)
return nil
}

func getWordlist(language string) []string {
switch strings.ToLower(language) {
case "chinese-simplified", "zh", "zh_hans":
bip39.SetWordList(wordlists.ChineseSimplified)
return wordlists.ChineseSimplified
case "chinese-traditional", "zh_hant":
bip39.SetWordList(wordlists.ChineseTraditional)
return wordlists.ChineseTraditional
case "czech", "cs":
bip39.SetWordList(wordlists.Czech)
return wordlists.Czech
case "english", "en":
bip39.SetWordList(wordlists.English)
return wordlists.English
case "french", "fr":
bip39.SetWordList(wordlists.French)
return wordlists.French
case "italian", "it":
bip39.SetWordList(wordlists.Italian)
return wordlists.Italian
case "japanese", "ja":
bip39.SetWordList(wordlists.Japanese)
return wordlists.Japanese
case "korean", "ko":
bip39.SetWordList(wordlists.Korean)
return wordlists.Korean
case "spanish", "es":
bip39.SetWordList(wordlists.Spanish)
return wordlists.Spanish
default:
return fmt.Errorf("this language is not supported")
return nil
}
return nil
}
38 changes: 35 additions & 3 deletions cmd/melt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/matryer/is"
"github.com/tyler-smith/go-bip39/wordlists"
"golang.org/x/crypto/ssh"
)

Expand Down Expand Up @@ -76,11 +77,42 @@ func TestBackupRestoreKnownKey(t *testing.T) {
})
}

func TestGetWordlist(t *testing.T) {
for lang, wordlist := range map[string][]string{
"cHinese-simplified": wordlists.ChineseSimplified,
"zH": wordlists.ChineseSimplified,
"zH_haNs": wordlists.ChineseSimplified,
"cHinese-tradITIONAL": wordlists.ChineseTraditional,
"zH_hanT": wordlists.ChineseTraditional,
"cZech": wordlists.Czech,
"cS": wordlists.Czech,
"eN": wordlists.English,
"eNglish": wordlists.English,
"fRench": wordlists.French,
"fR": wordlists.French,
"iTaliaN": wordlists.Italian,
"iT": wordlists.Italian,
"jApanesE": wordlists.Japanese,
"jA": wordlists.Japanese,
"kORean": wordlists.Korean,
"kO": wordlists.Korean,
"sPanish": wordlists.Spanish,
"eS": wordlists.Spanish,
"ES": wordlists.Spanish,
"sOmething": nil,
} {
t.Run(lang, func(t *testing.T) {
is := is.New(t)
is.Equal(wordlist, getWordlist(lang))
})
}
}

func TestBackupRestoreKnownKeyInJapanse(t *testing.T) {
const expectedMnemonic = `
いきおい ざるそば えもの せんめんじょ てあみ ていねい はったつ
ろこつ すあし のぞく かまう ほくろ らくご けぶかい たおす よゆう
ひめじし くたびれる ぐんたい なわばり にかい えほん せなか
いきおい ざるそば えもの せんめんじょ てあみ ていねい はったつ
ろこつ すあし のぞく かまう ほくろ らくご けぶかい たおす よゆう
ひめじし くたびれる ぐんたい なわばり にかい えほん せなか
そいとげる
`
const expectedSum = "ba34175ef608633b29f046b40cce596dd221347b77abba40763eef2e7ae51fe9"
Expand Down