Electroneum
Loading...
Searching...
No Matches
trezor_tests.cpp File Reference
Include dependency graph for trezor_tests.cpp:

Go to the source code of this file.

Macros

#define HW_TREZOR_NAME   "Trezor"
#define TREZOR_ACCOUNT_ORDERING   &m_miner_account, &m_alice_account, &m_bob_account, &m_eve_account
#define TREZOR_COMMON_TEST_CASE(genclass, CORE, BASE)
#define TREZOR_SETUP_CHAIN(NAME)
#define TREZOR_TEST_PREFIX()
#define TREZOR_TEST_SUFFIX()
#define TREZOR_SKIP_IF_VERSION_LEQ(x)
#define TREZOR_TEST_PAYMENT_ID   "\xde\xad\xc0\xde\xde\xad\xc0\xde"
#define TREZOR_TEST_PAYMENT_ID_LONG   "\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde"

Functions

int main (int argc, char *argv[])
bool get_short_payment_id (crypto::hash8 &payment_id8, const tools::wallet2::pending_tx &ptx, hw::device &hwdev)

Macro Definition Documentation

◆ HW_TREZOR_NAME

#define HW_TREZOR_NAME   "Trezor"

Definition at line 61 of file trezor_tests.cpp.

◆ TREZOR_ACCOUNT_ORDERING

#define TREZOR_ACCOUNT_ORDERING   &m_miner_account, &m_alice_account, &m_bob_account, &m_eve_account

Definition at line 62 of file trezor_tests.cpp.

◆ TREZOR_COMMON_TEST_CASE

#define TREZOR_COMMON_TEST_CASE ( genclass,
CORE,
BASE )
Value:
do { \
rollback_chain(CORE, BASE.head_block()); \
{ \
genclass ctest; \
BASE.fork(ctest); \
GENERATE_AND_PLAY_INSTANCE(genclass, ctest, *(CORE)); \
} \
} while(0)

Definition at line 63 of file trezor_tests.cpp.

63#define TREZOR_COMMON_TEST_CASE(genclass, CORE, BASE) do { \
64 rollback_chain(CORE, BASE.head_block()); \
65 { \
66 genclass ctest; \
67 BASE.fork(ctest); \
68 GENERATE_AND_PLAY_INSTANCE(genclass, ctest, *(CORE)); \
69 } \
70} while(0)

◆ TREZOR_SETUP_CHAIN

#define TREZOR_SETUP_CHAIN ( NAME)
Value:
do { \
++tests_count; \
try { \
setup_chain(core, trezor_base, chain_path, fix_chain, vm_core); \
} catch (const std::exception& ex) { \
failed_tests.emplace_back("gen_trezor_base " #NAME); \
} \
} while(0)
handles core cryptonote functionality
#define NAME(s)

Definition at line 72 of file trezor_tests.cpp.

72#define TREZOR_SETUP_CHAIN(NAME) do { \
73 ++tests_count; \
74 try { \
75 setup_chain(core, trezor_base, chain_path, fix_chain, vm_core); \
76 } catch (const std::exception& ex) { \
77 failed_tests.emplace_back("gen_trezor_base " #NAME); \
78 } \
79} while(0)

◆ TREZOR_SKIP_IF_VERSION_LEQ

#define TREZOR_SKIP_IF_VERSION_LEQ ( x)
Value:
if (m_trezor->get_version() <= x) { MDEBUG("Test skipped"); return true; }
#define MDEBUG(x)
Definition misc_log_ex.h:76

Definition at line 1282 of file trezor_tests.cpp.

◆ TREZOR_TEST_PAYMENT_ID

#define TREZOR_TEST_PAYMENT_ID   "\xde\xad\xc0\xde\xde\xad\xc0\xde"

Definition at line 1283 of file trezor_tests.cpp.

◆ TREZOR_TEST_PAYMENT_ID_LONG

#define TREZOR_TEST_PAYMENT_ID_LONG   "\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde"

Definition at line 1284 of file trezor_tests.cpp.

◆ TREZOR_TEST_PREFIX

#define TREZOR_TEST_PREFIX ( )
Value:
test_generator generator(m_generator); \
test_setup(events); \
tsx_builder t_builder_o(this); \
tsx_builder * t_builder = &t_builder_o

Definition at line 1270 of file trezor_tests.cpp.

1270#define TREZOR_TEST_PREFIX() \
1271 test_generator generator(m_generator); \
1272 test_setup(events); \
1273 tsx_builder t_builder_o(this); \
1274 tsx_builder * t_builder = &t_builder_o

◆ TREZOR_TEST_SUFFIX

#define TREZOR_TEST_SUFFIX ( )
Value:
auto _dsts = t_builder->build(); \
auto _dsts_info = t_builder->dest_info(); \
test_trezor_tx(events, _dsts, _dsts_info, generator, vct_wallets(m_wl_alice.get(), m_wl_bob.get(), m_wl_eve.get())); \
return true

Definition at line 1276 of file trezor_tests.cpp.

1276#define TREZOR_TEST_SUFFIX() \
1277 auto _dsts = t_builder->build(); \
1278 auto _dsts_info = t_builder->dest_info(); \
1279 test_trezor_tx(events, _dsts, _dsts_info, generator, vct_wallets(m_wl_alice.get(), m_wl_bob.get(), m_wl_eve.get())); \
1280 return true

Function Documentation

◆ get_short_payment_id()

bool get_short_payment_id ( crypto::hash8 & payment_id8,
const tools::wallet2::pending_tx & ptx,
hw::device & hwdev )

Definition at line 430 of file trezor_tests.cpp.

431{
432 std::vector<tx_extra_field> tx_extra_fields;
433 parse_tx_extra(ptx.tx.extra, tx_extra_fields); // ok if partially parsed
434 cryptonote::tx_extra_nonce extra_nonce;
435 if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
436 {
437 if(get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
438 {
439 if (ptx.dests.empty())
440 {
441 MWARNING("Encrypted payment id found, but no destinations public key, cannot decrypt");
442 return false;
443 }
444 return hwdev.decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key);
445 }
446 }
447 return false;
448}
bool decrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key)
Definition device.hpp:210
#define MWARNING(x)
Definition misc_log_ex.h:74
bool get_encrypted_payment_id_from_tx_extra_nonce(const blobdata &extra_nonce, crypto::hash8 &payment_id)
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
crypto::secret_key tx_key
Definition wallet2.h:472
std::vector< cryptonote::tx_destination_entry > dests
Definition wallet2.h:474
cryptonote::transaction tx
Definition wallet2.h:466
Here is the call graph for this function:

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 92 of file trezor_tests.cpp.

93{
94 TRY_ENTRY();
97
98 //set up logging options
99 mlog_configure(mlog_get_default_log_path("trezor_tests.log"), true);
101
102 po::options_description desc_options("Allowed options");
104 command_line::add_arg(desc_options, arg_filter);
105 command_line::add_arg(desc_options, arg_trezor_path);
106 command_line::add_arg(desc_options, arg_heavy_tests);
107 command_line::add_arg(desc_options, arg_chain_path);
108 command_line::add_arg(desc_options, arg_fix_chain);
109
110 po::variables_map vm;
111 bool r = command_line::handle_error_helper(desc_options, [&]()
112 {
113 po::store(po::parse_command_line(argc, argv, desc_options), vm);
114 po::notify(vm);
115 return true;
116 });
117 if (!r)
118 return 1;
119
121 {
122 std::cout << desc_options << std::endl;
123 return 0;
124 }
125
126 const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter));
127 boost::smatch match;
128
129 size_t tests_count = 0;
130 std::vector<std::string> failed_tests;
131 std::string trezor_path = command_line::get_arg(vm, arg_trezor_path);
132 std::string chain_path = command_line::get_arg(vm, arg_chain_path);
133 const bool heavy_tests = command_line::get_arg(vm, arg_heavy_tests);
134 const bool fix_chain = command_line::get_arg(vm, arg_fix_chain);
135
136 hw::register_device(HW_TREZOR_NAME, ensure_trezor_test_device()); // shim device for call tracking
137
138 // Bootstrapping common chain & accounts
139 const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", 11);
140 const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_HF", 11);
141 MINFO("Test versions " << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")");
142 MINFO("Testing hardforks [" << (int)initial_hf << ", " << (int)max_hf << "]");
143
144 cryptonote::core core_obj(nullptr);
145 cryptonote::core * const core = &core_obj;
146 std::shared_ptr<mock_daemon> daemon = nullptr;
147
148 gen_trezor_base trezor_base;
149 trezor_base.setup_args(trezor_path, heavy_tests);
150 trezor_base.set_hard_fork(initial_hf);
151
152 // Arguments for core & daemon
153 po::variables_map vm_core;
154 po::options_description desc_params_core("Core");
155 mock_daemon::init_options(desc_params_core);
156 tools::options::build_options(vm_core, desc_params_core);
158
159 // Transaction tests
160 for(uint8_t hf=initial_hf; hf <= max_hf + 1; ++hf)
161 {
162 if (hf > initial_hf || hf > max_hf)
163 {
164 daemon->stop_and_deinit();
165 daemon = nullptr;
166 trezor_base.daemon(nullptr);
167 if (hf > max_hf)
168 {
169 break;
170 }
171 }
172
173 MDEBUG("Transaction tests for HF " << (int)hf);
174 trezor_base.set_hard_fork(hf);
175 TREZOR_SETUP_CHAIN(std::string("HF") + std::to_string((int)hf));
176
177 daemon = std::make_shared<mock_daemon>(core, vm_core);
178 CHECK_AND_ASSERT_THROW_MES(daemon->nettype() == trezor_base.nettype(), "Serialized chain network type does not match");
179
180 daemon->try_init_and_run();
181 trezor_base.daemon(daemon);
182
183 // Hard-fork independent tests
184 if (hf == initial_hf)
185 {
189 }
190
203 }
204
205 if (trezor_base.heavy_tests())
206 {
208 }
209
210 core->deinit();
211 el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
212 MLOG(level, "\nREPORT:");
213 MLOG(level, " Test run: " << tests_count);
214 MLOG(level, " Failures: " << failed_tests.size());
215 if (!failed_tests.empty())
216 {
217 MLOG(level, "FAILED TESTS:");
218 BOOST_FOREACH(auto test_name, failed_tests)
219 {
220 MLOG(level, " " << test_name);
221 }
222 }
223
224 return failed_tests.empty() ? 0 : 1;
225
226 CATCH_ENTRY_L0("main", 1);
227}
bool deinit()
performs safe shutdown steps for core and core components
std::shared_ptr< mock_daemon > daemon() const
virtual void set_hard_fork(uint8_t hf)
virtual void setup_args(const std::string &trezor_path, bool heavy_tests=false)
bool heavy_tests() const
cryptonote::network_type nettype() const
static void default_options(boost::program_options::variables_map &vm)
Definition daemon.cpp:53
static void init_options(boost::program_options::options_description &option_spec)
Definition daemon.cpp:43
static void build_options(boost::program_options::variables_map &vm, const boost::program_options::options_description &desc_params)
Definition tools.cpp:48
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition mlog.cpp:148
std::string mlog_get_default_log_path(const char *default_filename)
Definition mlog.cpp:72
void mlog_set_log_level(int level)
Definition mlog.cpp:282
#define MLOG(level, x)
Definition misc_log_ex.h:78
#define CATCH_ENTRY_L0(lacation, return_val)
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
#define MINFO(x)
Definition misc_log_ex.h:75
#define TRY_ENTRY()
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const arg_descriptor< bool > arg_help
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Level
Represents enumeration for severity level used to determine level of logging.
@ Info
Mainly useful to represent current progress of application.
@ Error
Information representing errors in application but application will keep running.
bool set_module_name_and_folder(const std::string &path_to_process_)
bool register_device(const std::string &device_name, device *hw_device)
Definition device.cpp:100
std::string glob_to_regex(const std::string &val)
Definition util.cpp:1012
bool on_startup()
Definition util.cpp:778
unsigned char uint8_t
Definition stdint.h:124
#define TREZOR_COMMON_TEST_CASE(genclass, CORE, BASE)
#define TREZOR_SETUP_CHAIN(NAME)
#define HW_TREZOR_NAME
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL
Here is the call graph for this function: