diff options
author | Paul Shapiro <paulshapiro@users.noreply.github.com> | 2019-01-11 13:46:20 -0600 |
---|---|---|
committer | Paul Shapiro <paulshapiro@users.noreply.github.com> | 2019-01-11 13:46:20 -0600 |
commit | 5ecc5cc790df101f22d223c6825380d6b5387e4d (patch) | |
tree | a446a9118eccc7c95126017c0e58befb6da83b14 /tests | |
parent | Merge pull request #4699 (diff) | |
download | monero-5ecc5cc790df101f22d223c6825380d6b5387e4d.tar.xz |
added two tests for partial word and case tolerance in mnemonics
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_tests/mnemonics.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp index 0b74a6b94..59642828d 100644 --- a/tests/unit_tests/mnemonics.cpp +++ b/tests/unit_tests/mnemonics.cpp @@ -51,6 +51,7 @@ #include "mnemonics/english_old.h" #include "mnemonics/language_base.h" #include "mnemonics/singleton.h" +#include <boost/algorithm/string.hpp> namespace { @@ -75,7 +76,6 @@ namespace */ void test_language(const Language::Base &language) { - const std::vector<std::string> &word_list = language.get_word_list(); epee::wipeable_string w_seed = "", w_return_seed = ""; std::string seed, return_seed; // Generate a random seed without checksum @@ -222,3 +222,38 @@ TEST(mnemonics, utf8prefix) ASSERT_TRUE(Language::utf8prefix(epee::wipeable_string("æon"), 3) == "æon"); ASSERT_TRUE(Language::utf8prefix(epee::wipeable_string("æon"), 4) == "æon"); } + +TEST(mnemonics, case_tolerance) +{ + bool res; + // + crypto::secret_key key_1; + std::string language_name_1; + const std::string seed_1 = "Neubau umarmen Abart umarmen Turban feilen Brett Bargeld Episode Milchkuh Substanz Jahr Armband Maibaum Tand Grünalge Tabak erziehen Federboa Lobrede Tenor Leuchter Curry Diskurs Tenor"; + res = crypto::ElectrumWords::words_to_bytes(seed_1, key_1, language_name_1); + ASSERT_EQ(true, res); + ASSERT_STREQ(language_name_1.c_str(), "Deutsch"); + // + crypto::secret_key key_2; + std::string language_name_2; + // neubau is capitalized in the word list, but the language detection code should be able to detect it as Deutsch + std::string seed_2 = "neubau umarmen Abart umarmen Turban feilen Brett Bargeld Episode Milchkuh Substanz Jahr Armband Maibaum Tand Grünalge Tabak erziehen Federboa Lobrede Tenor Leuchter Curry Diskurs tenor"; + boost::algorithm::to_lower(seed_2); + res = crypto::ElectrumWords::words_to_bytes(seed_2, key_2, language_name_2); + ASSERT_EQ(true, res); + ASSERT_STREQ(language_name_2.c_str(), "Deutsch"); + // + ASSERT_TRUE(key_1 == key_2); +} + +TEST(mnemonics, partial_word_tolerance) +{ + bool res; + // + crypto::secret_key key_1; + std::string language_name_1; + const std::string seed_1 = "crim bam scamp gna limi woma wron tuit birth mundane donuts square cohesive dolphin titans narrate fue saved wrap aloof magic mirr toget upda wra"; + res = crypto::ElectrumWords::words_to_bytes(seed_1, key_1, language_name_1); + ASSERT_EQ(true, res); + ASSERT_STREQ(language_name_1.c_str(), "English"); +}
\ No newline at end of file |