Electroneum
mnemonics.cpp File Reference
#include "gtest/gtest.h"
#include "wipeable_string.h"
#include "mnemonics/language_base.h"
#include "mnemonics/electrum-words.h"
#include "crypto/crypto.h"
#include <stdlib.h>
#include <vector>
#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/german.h"
#include "mnemonics/italian.h"
#include "mnemonics/russian.h"
#include "mnemonics/french.h"
#include "mnemonics/dutch.h"
#include "mnemonics/esperanto.h"
#include "mnemonics/lojban.h"
#include "mnemonics/english_old.h"
#include "mnemonics/singleton.h"
Include dependency graph for mnemonics.cpp:

Go to the source code of this file.

Functions

 TEST (mnemonics, consistency)
 
 TEST (mnemonics, all_languages)
 
 TEST (mnemonics, language_detection_with_bad_checksum)
 
 TEST (mnemonics, utf8prefix)
 
 TEST (mnemonics, case_tolerance)
 
 TEST (mnemonics, partial_word_tolerance)
 

Function Documentation

◆ TEST() [1/6]

TEST ( mnemonics  ,
consistency   
)

Definition at line 151 of file mnemonics.cpp.

152 {
153  try {
154  std::vector<std::string> language_list;
156  }
157  catch(const std::exception &e)
158  {
159  std::cout << "Error initializing mnemonics: " << e.what() << std::endl;
160  ASSERT_TRUE(false);
161  }
162 }
std::vector< const Language::Base * > get_language_list()
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
Here is the call graph for this function:

◆ TEST() [2/6]

TEST ( mnemonics  ,
all_languages   
)

Definition at line 164 of file mnemonics.cpp.

165 {
166  srand(time(NULL));
167  std::vector<Language::Base*> languages({
180  });
181 
182  for (std::vector<Language::Base*>::iterator it = languages.begin(); it != languages.end(); it++)
183  {
184  try {
185  test_language(*(*it));
186  }
187  catch (const std::exception &e) {
188  std::cout << "Error testing " << (*it)->get_language_name() << " language: " << e.what() << std::endl;
189  ASSERT_TRUE(false);
190  }
191  }
192 }
static T * instance()
Definition: singleton.h:57
time_t time
Definition: blockchain.cpp:93
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
Here is the call graph for this function:

◆ TEST() [3/6]

TEST ( mnemonics  ,
language_detection_with_bad_checksum   
)

Definition at line 194 of file mnemonics.cpp.

195 {
197  std::string language_name;
198  bool res;
199 
200  // This Portuguese (4-prefix) seed has all its words with 3-prefix that's also present in English
201  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";
202  const std::string real_checksum = "gnostico";
203 
204  res = crypto::ElectrumWords::words_to_bytes(base_seed, key, language_name);
205  ASSERT_EQ(true, res);
206  ASSERT_STREQ(language_name.c_str(), "Português");
207 
208  res = crypto::ElectrumWords::words_to_bytes(base_seed + " " + real_checksum, key, language_name);
209  ASSERT_EQ(true, res);
210  ASSERT_STREQ(language_name.c_str(), "Português");
211 }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
const char * key
Definition: hmac_keccak.cpp:39
bool words_to_bytes(const epee::wipeable_string &words, epee::wipeable_string &dst, size_t len, bool duplicate, std::string &language_name)
Converts seed words to bytes (secret key).
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_STREQ(s1, s2)
Definition: gtest.h:2004
Here is the call graph for this function:

◆ TEST() [4/6]

TEST ( mnemonics  ,
utf8prefix   
)

Definition at line 213 of file mnemonics.cpp.

214 {
225 }
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
T utf8prefix(const T &s, size_t count)
Returns a string made of (at most) the first count characters in s. Assumes well formedness. No check is made for this.
Definition: language_base.h:60
Here is the call graph for this function:

◆ TEST() [5/6]

TEST ( mnemonics  ,
case_tolerance   
)

Definition at line 227 of file mnemonics.cpp.

228 {
229  bool res;
230  //
231  crypto::secret_key key_1;
232  std::string language_name_1;
233  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";
234  res = crypto::ElectrumWords::words_to_bytes(seed_1, key_1, language_name_1);
235  ASSERT_EQ(true, res);
236  ASSERT_STREQ(language_name_1.c_str(), "Deutsch");
237  //
238  crypto::secret_key key_2;
239  std::string language_name_2;
240  // neubau is capitalized in the word list, but the language detection code should be able to detect it as Deutsch
241  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";
242  boost::algorithm::to_lower(seed_2);
243  res = crypto::ElectrumWords::words_to_bytes(seed_2, key_2, language_name_2);
244  ASSERT_EQ(true, res);
245  ASSERT_STREQ(language_name_2.c_str(), "Deutsch");
246  //
247  ASSERT_TRUE(key_1 == key_2);
248 }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
bool words_to_bytes(const epee::wipeable_string &words, epee::wipeable_string &dst, size_t len, bool duplicate, std::string &language_name)
Converts seed words to bytes (secret key).
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_STREQ(s1, s2)
Definition: gtest.h:2004
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
Here is the call graph for this function:

◆ TEST() [6/6]

TEST ( mnemonics  ,
partial_word_tolerance   
)

Definition at line 250 of file mnemonics.cpp.

251 {
252  bool res;
253  //
254  crypto::secret_key key_1;
255  std::string language_name_1;
256  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";
257  res = crypto::ElectrumWords::words_to_bytes(seed_1, key_1, language_name_1);
258  ASSERT_EQ(true, res);
259  ASSERT_STREQ(language_name_1.c_str(), "English");
260 }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
bool words_to_bytes(const epee::wipeable_string &words, epee::wipeable_string &dst, size_t len, bool duplicate, std::string &language_name)
Converts seed words to bytes (secret key).
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_STREQ(s1, s2)
Definition: gtest.h:2004
Here is the call graph for this function: