Move to Go 1.26, embed the wordlist from english.txt, add ValidateWordlist, NormalizeWordlist, and GenerateMnemonic with tests, and remove the old root-level CLI that used the previous module path.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package bip39wordlist_test
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/tyler-smith/go-bip39/wordlists"
|
|
|
|
"sneak.berlin/go/x/pkg/bip39wordlist"
|
|
)
|
|
|
|
func TestWordlistEnglishShape(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
wordlist := bip39wordlist.WordlistEnglish
|
|
|
|
assert.Len(t, wordlist, bip39wordlist.WordlistSize)
|
|
assert.Equal(t, "abandon", wordlist[0])
|
|
assert.Equal(t, "zoo", wordlist[len(wordlist)-1])
|
|
assert.True(t, slices.IsSorted(wordlist), "wordlist must be sorted")
|
|
}
|
|
|
|
func TestWordlistEnglishMatchesReferenceImplementation(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.Equal(t, wordlists.English, bip39wordlist.WordlistEnglish)
|
|
}
|
|
|
|
func TestWordlistIsEnglish(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.Equal(t, bip39wordlist.WordlistEnglish, bip39wordlist.Wordlist)
|
|
}
|
|
|
|
func TestContains(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.True(t, bip39wordlist.Contains("abandon"))
|
|
assert.True(t, bip39wordlist.Contains("zoo"))
|
|
assert.True(t, bip39wordlist.Contains("legal"))
|
|
assert.False(t, bip39wordlist.Contains("Abandon"), "lookup is case sensitive")
|
|
assert.False(t, bip39wordlist.Contains("notaword"))
|
|
assert.False(t, bip39wordlist.Contains(""))
|
|
}
|