diff options
Diffstat (limited to 'tests/unit_tests/mnemonics.cpp')
-rw-r--r-- | tests/unit_tests/mnemonics.cpp | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp index 3dc5db7d4..956c5e1b2 100644 --- a/tests/unit_tests/mnemonics.cpp +++ b/tests/unit_tests/mnemonics.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2016, The Monero Project +// Copyright (c) 2014-2017, The Monero Project // // All rights reserved. // @@ -34,11 +34,17 @@ #include <time.h> #include <iostream> #include <boost/algorithm/string.hpp> +#include "mnemonics/chinese_simplified.h" #include "mnemonics/english.h" #include "mnemonics/spanish.h" #include "mnemonics/portuguese.h" #include "mnemonics/japanese.h" -#include "mnemonics/old_english.h" +#include "mnemonics/german.h" +#include "mnemonics/italian.h" +#include "mnemonics/russian.h" +#include "mnemonics/french.h" +#include "mnemonics/dutch.h" +#include "mnemonics/english_old.h" #include "mnemonics/language_base.h" #include "mnemonics/singleton.h" @@ -133,18 +139,62 @@ namespace } } +TEST(mnemonics, consistency) +{ + try { + std::vector<std::string> language_list; + crypto::ElectrumWords::get_language_list(language_list); + } + catch(const std::exception &e) + { + std::cout << "Error initializing mnemonics: " << e.what() << std::endl; + ASSERT_TRUE(false); + } +} + TEST(mnemonics, all_languages) { srand(time(NULL)); std::vector<Language::Base*> languages({ + Language::Singleton<Language::Chinese_Simplified>::instance(), Language::Singleton<Language::English>::instance(), Language::Singleton<Language::Spanish>::instance(), Language::Singleton<Language::Portuguese>::instance(), Language::Singleton<Language::Japanese>::instance(), + Language::Singleton<Language::German>::instance(), + Language::Singleton<Language::Italian>::instance(), + Language::Singleton<Language::Russian>::instance(), + Language::Singleton<Language::French>::instance(), + Language::Singleton<Language::Dutch>::instance() }); for (std::vector<Language::Base*>::iterator it = languages.begin(); it != languages.end(); it++) { - test_language(*(*it)); + try { + test_language(*(*it)); + } + catch (const std::exception &e) { + std::cout << "Error testing " << (*it)->get_language_name() << " language: " << e.what() << std::endl; + ASSERT_TRUE(false); + } } } + +TEST(mnemonics, language_detection_with_bad_checksum) +{ + crypto::secret_key key; + std::string language_name; + bool res; + + // This Portuguese (4-prefix) seed has all its words with 3-prefix that's also present in English + const std::string base_seed = "cinzento luxuriante leonardo gnostico digressao cupula fifa broxar iniquo louvor ovario dorsal ideologo besuntar decurso rosto susto lemure unheiro pagodeiro nitroglicerina eclusa mazurca bigorna"; + const std::string real_checksum = "gnostico"; + + res = crypto::ElectrumWords::words_to_bytes(base_seed, key, language_name); + ASSERT_EQ(true, res); + ASSERT_STREQ(language_name.c_str(), "Portuguese"); + + res = crypto::ElectrumWords::words_to_bytes(base_seed + " " + real_checksum, key, language_name); + ASSERT_EQ(true, res); + ASSERT_STREQ(language_name.c_str(), "Portuguese"); +} |