Every way a mnemonic could be invalid was reported as a checksum failure, including an empty one. It is now refused as empty, as having a word count other than 12, 15, 18, 21 or 24, as having a word that is not on the BIP-39 word list, or as failing the checksum. A word not on the list is named by its position, never by the word itself. Model: opus-5-5
This commit is contained in:
@@ -97,6 +97,27 @@ func TestAFailingCommandSaysWhatWentWrong(t *testing.T) {
|
||||
require.Contains(t, err.Error(), "nothing here")
|
||||
}
|
||||
|
||||
func TestValidMnemonicsOf15To24WordsAreAccepted(t *testing.T) {
|
||||
t.Setenv(mnemonic.CommandVariable, "")
|
||||
|
||||
// abandon repeated, then the last word that makes the checksum
|
||||
// match: 15, 18, 21 and 24 words.
|
||||
valid := []string{
|
||||
strings.Repeat("abandon ", 14) + "address",
|
||||
strings.Repeat("abandon ", 17) + "agent",
|
||||
strings.Repeat("abandon ", 20) + "admit",
|
||||
strings.Repeat("abandon ", 23) + "art",
|
||||
}
|
||||
|
||||
for _, words := range valid {
|
||||
t.Setenv(mnemonic.Variable, words)
|
||||
|
||||
got, err := mnemonic.Read(t.Context(), "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, words, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestABadChecksumIsRefused(t *testing.T) {
|
||||
t.Setenv(mnemonic.CommandVariable, "")
|
||||
t.Setenv(mnemonic.Variable, broken())
|
||||
@@ -105,6 +126,38 @@ func TestABadChecksumIsRefused(t *testing.T) {
|
||||
require.ErrorIs(t, err, mnemonic.ErrChecksum)
|
||||
}
|
||||
|
||||
func TestACommandThatPrintsNothingGivesAnEmptyMnemonic(t *testing.T) {
|
||||
t.Setenv(mnemonic.CommandVariable, "")
|
||||
t.Setenv(mnemonic.Variable, "")
|
||||
|
||||
_, err := mnemonic.Read(t.Context(), "true")
|
||||
require.ErrorIs(t, err, mnemonic.ErrEmpty)
|
||||
require.NotContains(t, err.Error(), "checksum")
|
||||
}
|
||||
|
||||
func TestAWrongWordCountIsRefused(t *testing.T) {
|
||||
t.Setenv(mnemonic.CommandVariable, "")
|
||||
t.Setenv(mnemonic.Variable, strings.Repeat("abandon ", 3))
|
||||
|
||||
_, err := mnemonic.Read(t.Context(), "")
|
||||
require.ErrorIs(t, err, mnemonic.ErrWordCount)
|
||||
require.ErrorContains(t, err, "not 3")
|
||||
require.NotContains(t, err.Error(), "checksum")
|
||||
}
|
||||
|
||||
func TestAWordNotOnTheListIsNamedByPositionOnly(t *testing.T) {
|
||||
const typo = "abuot"
|
||||
|
||||
t.Setenv(mnemonic.CommandVariable, "")
|
||||
t.Setenv(mnemonic.Variable, strings.Repeat("abandon ", 11)+typo)
|
||||
|
||||
_, err := mnemonic.Read(t.Context(), "")
|
||||
require.ErrorIs(t, err, mnemonic.ErrUnknownWord)
|
||||
require.ErrorContains(t, err, "word 12 ")
|
||||
require.NotContains(t, err.Error(), typo)
|
||||
require.NotContains(t, err.Error(), "checksum")
|
||||
}
|
||||
|
||||
func TestNothingToReadAndNobodyToAsk(t *testing.T) {
|
||||
t.Setenv(mnemonic.CommandVariable, "")
|
||||
t.Setenv(mnemonic.Variable, "")
|
||||
|
||||
Reference in New Issue
Block a user