decred.org/dcrdex@v1.0.3/client/mnemonic/seed_test.go (about) 1 package mnemonic 2 3 import ( 4 "bytes" 5 "testing" 6 "time" 7 ) 8 9 func TestFindWordIndex(t *testing.T) { 10 for i := range wordList { 11 j, err := wordIndex(wordList[i]) 12 if err != nil { 13 t.Fatal(err) 14 } 15 if i != int(j) { 16 t.Fatalf("wrong index %d returned for %q. expected %d", j, wordList[i], i) 17 } 18 } 19 20 if _, err := wordIndex("blah"); err == nil { 21 t.Fatal("no error for blah") 22 } 23 24 if _, err := wordIndex("aaa"); err == nil { 25 t.Fatal("no error for aaa") 26 } 27 28 if _, err := wordIndex("zzz"); err == nil { 29 t.Fatal("no error for zzz") 30 } 31 } 32 33 func TestEncodeDecode(t *testing.T) { 34 for i := 0; i < 1000; i++ { 35 ogEntropy, mnemonic := New() 36 reEntropy, stamp, err := DecodeMnemonic(mnemonic) 37 if err != nil { 38 t.Fatal(err) 39 } 40 if !bytes.Equal(reEntropy, ogEntropy) { 41 t.Fatal("failed to recover entropy") 42 } 43 if stamp.Unix()/secondsPerDay != time.Now().Unix()/secondsPerDay { 44 t.Fatalf("time not recovered") 45 } 46 } 47 }