mnemonic_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package crypto
  17. import (
  18. "testing"
  19. )
  20. func TestMnDecode(t *testing.T) {
  21. words := []string{
  22. "ink",
  23. "balance",
  24. "gain",
  25. "fear",
  26. "happen",
  27. "melt",
  28. "mom",
  29. "surface",
  30. "stir",
  31. "bottle",
  32. "unseen",
  33. "expression",
  34. "important",
  35. "curl",
  36. "grant",
  37. "fairy",
  38. "across",
  39. "back",
  40. "figure",
  41. "breast",
  42. "nobody",
  43. "scratch",
  44. "worry",
  45. "yesterday",
  46. }
  47. encode := "c61d43dc5bb7a4e754d111dae8105b6f25356492df5e50ecb33b858d94f8c338"
  48. result := MnemonicDecode(words)
  49. if encode != result {
  50. t.Error("We expected", encode, "got", result, "instead")
  51. }
  52. }
  53. func TestMnEncode(t *testing.T) {
  54. encode := "c61d43dc5bb7a4e754d111dae8105b6f25356492df5e50ecb33b858d94f8c338"
  55. result := []string{
  56. "ink",
  57. "balance",
  58. "gain",
  59. "fear",
  60. "happen",
  61. "melt",
  62. "mom",
  63. "surface",
  64. "stir",
  65. "bottle",
  66. "unseen",
  67. "expression",
  68. "important",
  69. "curl",
  70. "grant",
  71. "fairy",
  72. "across",
  73. "back",
  74. "figure",
  75. "breast",
  76. "nobody",
  77. "scratch",
  78. "worry",
  79. "yesterday",
  80. }
  81. words := MnemonicEncode(encode)
  82. for i, word := range words {
  83. if word != result[i] {
  84. t.Error("Mnenonic does not match:", words, result)
  85. }
  86. }
  87. }