diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-09-03 15:32:35 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-02-01 20:47:03 +0000 |
commit | 098dcf28858f244bae53d63f9d58f1d00d100808 (patch) | |
tree | 865d714eab57aeb54bfb5a185934faf591c29d0c /tests/unit_tests/mnemonics.cpp | |
parent | Merge pull request #636 (diff) | |
download | monero-098dcf28858f244bae53d63f9d58f1d00d100808.tar.xz |
unit_tests: fix mnemonics unit test testing invalid seeds
Some word triplets, such as "mugged names nail", are not valid
results from any 32 bit value. If used to decode a 32 bit value,
the result will therefore encode to a different word triplet.
Fix this by using random words converted from an actual random
bitstring, ensuring we always get valid triplets.
Diffstat (limited to 'tests/unit_tests/mnemonics.cpp')
-rw-r--r-- | tests/unit_tests/mnemonics.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp index 92a4c57f9..3dc5db7d4 100644 --- a/tests/unit_tests/mnemonics.cpp +++ b/tests/unit_tests/mnemonics.cpp @@ -45,16 +45,6 @@ namespace { /*! - * \brief Returns random index from 0 to max-1 - * \param max Range maximum - * \return required random index - */ - uint32_t get_random_index(int max) - { - return rand() % max; - } - - /*! * \brief Compares vectors for equality * \param expected expected vector * \param present current vector @@ -78,11 +68,17 @@ namespace const std::vector<std::string> &word_list = language.get_word_list(); std::string seed = "", return_seed = ""; // Generate a random seed without checksum - for (int ii = 0; ii < crypto::ElectrumWords::seed_length; ii++) + crypto::secret_key randkey; + for (size_t ii = 0; ii < sizeof(randkey); ++ii) { - seed += (word_list[get_random_index(word_list.size())] + ' '); + randkey.data[ii] = rand(); } - seed.pop_back(); + crypto::ElectrumWords::bytes_to_words(randkey, seed, language.get_language_name()); + // remove the checksum word + const char *space = strrchr(seed.c_str(), ' '); + ASSERT_TRUE(space != NULL); + seed = std::string(seed.c_str(), space-seed.c_str()); + std::cout << "Test seed without checksum:\n"; std::cout << seed << std::endl; |