Electroneum
Loading...
Searching...
No Matches
trezor_tests.h
Go to the documentation of this file.
1// Copyright (c) 2014-2018, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31#pragma once
32
35#include "daemon.h"
38
39#define TREZOR_TEST_FEE 90000000000
40#define TREZOR_TEST_MIXIN 11
41
42/************************************************************************/
43/* */
44/************************************************************************/
45class tsx_builder;
47{
48public:
49 friend class tsx_builder;
50
52 gen_trezor_base(const gen_trezor_base &other);
53 virtual ~gen_trezor_base() {};
54
55 virtual void setup_args(const std::string & trezor_path, bool heavy_tests=false);
56 virtual bool generate(std::vector<test_event_entry>& events);
57 virtual void load(std::vector<test_event_entry>& events); // load events, init test obj
58 virtual void fix_hf(std::vector<test_event_entry>& events);
59 virtual void update_trackers(std::vector<test_event_entry>& events);
60
61 virtual void fork(gen_trezor_base & other); // fork generated chain to another test
62 virtual void clear(); // clears m_events, bt, generator, hforks
63 virtual void add_shared_events(std::vector<test_event_entry>& events); // m_events -> events
64 virtual void test_setup(std::vector<test_event_entry>& events); // init setup env, wallets
65
66 virtual void add_transactions_to_events(
67 std::vector<test_event_entry>& events,
68 test_generator &generator,
69 const std::vector<cryptonote::transaction> &txs);
70
71 virtual void test_trezor_tx(
72 std::vector<test_event_entry>& events,
73 std::vector<tools::wallet2::pending_tx>& ptxs,
74 std::vector<cryptonote::address_parse_info>& dsts_info,
75 test_generator &generator,
76 std::vector<tools::wallet2*> wallets,
77 bool is_sweep=false);
78
79 virtual void test_get_tx(
80 std::vector<test_event_entry>& events,
81 std::vector<tools::wallet2*> wallets,
82 const std::vector<tools::wallet2::pending_tx> &ptxs,
83 const std::vector<std::string> &aux_tx_info);
84
85 virtual void mine_and_test(std::vector<test_event_entry>& events);
86
87 virtual void rewind_blocks(std::vector<test_event_entry>& events, size_t rewind_n, uint8_t hf);
88
89 virtual void set_hard_fork(uint8_t hf);
90
93 bool heavy_tests() const { return m_heavy_tests; }
95 uint8_t cur_hf() const { return m_hard_forks.size() > 0 ? m_hard_forks.back().first : 0; }
97 std::shared_ptr<mock_daemon> daemon() const { return m_daemon; }
98 void daemon(std::shared_ptr<mock_daemon> daemon){ m_daemon = std::move(daemon); }
99
100 // Static configuration
101 static const uint64_t m_ts_start;
102 static const uint64_t m_wallet_ts;
103 static const std::string m_device_name;
104 static const std::string m_master_seed_str;
105 static const std::string m_device_seed;
106 static const std::string m_alice_spend_private;
107 static const std::string m_alice_view_private;
108
109protected:
110 virtual void setup_trezor();
111 virtual void init_fields();
112 virtual void update_client_settings();
113 virtual bool verify_tx_key(const ::crypto::secret_key & tx_priv, const ::crypto::public_key & tx_pub, const subaddresses_t & subs);
114
118 std::shared_ptr<mock_daemon> m_daemon;
119
123 std::vector<test_event_entry> m_events;
124
125 std::string m_trezor_path;
130
135 hw::trezor::device_trezor * m_trezor;
136 std::unique_ptr<tools::wallet2> m_wl_alice;
137 std::unique_ptr<tools::wallet2> m_wl_bob;
138 std::unique_ptr<tools::wallet2> m_wl_eve;
139
141
142 template<class Archive>
143 void serialize(Archive & ar, const unsigned int /*version*/)
144 {
145 ar & m_generator;
146 ar & m_network_type;
147 }
148};
149
151public:
154
158
160 tsx_builder * mixin(size_t mixin=TREZOR_TEST_MIXIN) { m_mixin = mixin; return this; }
162 tsx_builder * payment_id(const std::string & payment_id) { m_payment_id = payment_id; return this; }
163 tsx_builder * from(tools::wallet2 *from, uint32_t account=0) { m_from = from; m_account=account; return this; }
164 tsx_builder * sources(std::vector<cryptonote::tx_source_entry> & sources, std::vector<size_t> & selected_transfers);
165 tsx_builder * compute_sources(boost::optional<size_t> num_utxo=boost::none, boost::optional<uint64_t> min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional<fnc_accept_tx_source_t> fnc_accept=boost::none);
166 tsx_builder * compute_sources_to_sub(boost::optional<size_t> num_utxo=boost::none, boost::optional<uint64_t> min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional<fnc_accept_tx_source_t> fnc_accept=boost::none);
167 tsx_builder * compute_sources_to_sub_acc(boost::optional<size_t> num_utxo=boost::none, boost::optional<uint64_t> min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional<fnc_accept_tx_source_t> fnc_accept=boost::none);
168
169 tsx_builder * destinations(std::vector<cryptonote::tx_destination_entry> &dsts);
171 tsx_builder * add_destination(const tools::wallet2 * wallet, bool is_subaddr=false, uint64_t amount=1000);
172 tsx_builder * add_destination(const var_addr_t addr, bool is_subaddr=false, uint64_t amount=1000);
173 tsx_builder * set_integrated(size_t idx);
175
177 tsx_builder * construct_pending_tx(tools::wallet2::pending_tx &ptx, boost::optional<std::vector<uint8_t>> extra = boost::none);
179 std::vector<tools::wallet2::pending_tx> build();
180 std::vector<cryptonote::address_parse_info> dest_info(){ return m_dsts_info; }
181
182protected:
185 std::vector<tools::wallet2::pending_tx> m_ptxs; // all transactions
186
187 // current transaction
188 size_t m_mixin;
193 std::vector<size_t> m_selected_transfers;
194 std::vector<cryptonote::tx_source_entry> m_sources;
195 std::vector<cryptonote::tx_destination_entry> m_destinations;
196 std::vector<cryptonote::tx_destination_entry> m_destinations_orig;
197 std::vector<cryptonote::address_parse_info> m_dsts_info;
198 std::unordered_set<size_t> m_integrated;
199 std::string m_payment_id;
201};
202
203// Trezor device ship to track actual method calls.
204class device_trezor_test : public hw::trezor::device_trezor {
205public:
208
210
211 void clear_test_counters();
212 void setup_for_tests(const std::string & trezor_path, const std::string & seed, cryptonote::network_type network_type);
213
214 bool compute_key_image(const ::cryptonote::account_keys &ack, const ::crypto::public_key &out_key,
215 const ::crypto::key_derivation &recv_derivation, size_t real_output_index,
216 const ::cryptonote::subaddress_index &received_index, ::cryptonote::keypair &in_ephemeral,
217 ::crypto::key_image &ki) override;
218
219protected:
220 void tx_sign(hw::wallet_shim *wallet, const ::tools::wallet2::unsigned_tx_set &unsigned_tx, size_t idx,
221 hw::tx_aux_data &aux_data, std::shared_ptr<hw::trezor::protocol::tx::Signer> &signer) override;
222};
223
224// Tests
226{
227public:
228 bool generate(std::vector<test_event_entry>& events) override;
229};
230
232{
233public:
234 bool generate(std::vector<test_event_entry>& events) override;
235};
236
238{
239public:
240 bool generate(std::vector<test_event_entry>& events) override;
241};
242
244{
245public:
246 bool generate(std::vector<test_event_entry>& events) override;
247};
248
250{
251public:
252 bool generate(std::vector<test_event_entry>& events) override;
253};
254
256{
257public:
258 bool generate(std::vector<test_event_entry>& events) override;
259};
260
262{
263public:
264 bool generate(std::vector<test_event_entry>& events) override;
265};
266
268{
269public:
270 bool generate(std::vector<test_event_entry>& events) override;
271};
272
274{
275public:
276 bool generate(std::vector<test_event_entry>& events) override;
277};
278
280{
281public:
282 bool generate(std::vector<test_event_entry>& events) override;
283};
284
286{
287public:
288 bool generate(std::vector<test_event_entry>& events) override;
289};
290
292{
293public:
294 bool generate(std::vector<test_event_entry>& events) override;
295};
296
298{
299public:
300 bool generate(std::vector<test_event_entry>& events) override;
301};
302
304{
305public:
306 bool generate(std::vector<test_event_entry>& events) override;
307};
308
310{
311public:
312 bool generate(std::vector<test_event_entry>& events) override;
313};
314
316{
317public:
318 bool generate(std::vector<test_event_entry>& events) override;
319};
320
321// Wallet::API tests
323{
324public:
325 virtual ~wallet_api_tests();
326 void init();
327 bool generate(std::vector<test_event_entry>& events) override;
328
329protected:
330 boost::filesystem::path m_wallet_dir;
331};
std::vector< std::pair< uint8_t, uint64_t > > v_hardforks_t
Definition chaingen.h:137
std::unordered_map< crypto::public_key, cryptonote::subaddress_index > subaddresses_t
Definition chaingen.h:359
boost::variant< cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry > var_addr_t
Definition chaingen.h:362
size_t m_compute_key_image_ctr
bool compute_key_image(const ::cryptonote::account_keys &ack, const ::crypto::public_key &out_key, const ::crypto::key_derivation &recv_derivation, size_t real_output_index, const ::cryptonote::subaddress_index &received_index, ::cryptonote::keypair &in_ephemeral, ::crypto::key_image &ki) override
void setup_for_tests(const std::string &trezor_path, const std::string &seed, cryptonote::network_type network_type)
void tx_sign(hw::wallet_shim *wallet, const ::tools::wallet2::unsigned_tx_set &unsigned_tx, size_t idx, hw::tx_aux_data &aux_data, std::shared_ptr< hw::trezor::protocol::tx::Signer > &signer) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
std::vector< test_event_entry > m_events
cryptonote::account_base m_bob_account
virtual void setup_trezor()
virtual void update_client_settings()
std::shared_ptr< mock_daemon > daemon() const
std::string m_trezor_path
virtual void update_trackers(std::vector< test_event_entry > &events)
cryptonote::network_type m_network_type
block_tracker m_bt
void daemon(std::shared_ptr< mock_daemon > daemon)
uint8_t m_top_hard_fork
static const uint64_t m_wallet_ts
virtual ~gen_trezor_base()
static const std::string m_alice_view_private
cryptonote::account_base m_alice_account
bool m_live_refresh_enabled
virtual void clear()
cryptonote::block m_head
virtual void load(std::vector< test_event_entry > &events)
static const std::string m_device_seed
test_generator m_generator
friend class tsx_builder
virtual void test_trezor_tx(std::vector< test_event_entry > &events, std::vector< tools::wallet2::pending_tx > &ptxs, std::vector< cryptonote::address_parse_info > &dsts_info, test_generator &generator, std::vector< tools::wallet2 * > wallets, bool is_sweep=false)
virtual void add_transactions_to_events(std::vector< test_event_entry > &events, test_generator &generator, const std::vector< cryptonote::transaction > &txs)
virtual void set_hard_fork(uint8_t hf)
hw::trezor::device_trezor * m_trezor
v_hardforks_t m_hard_forks
cryptonote::account_base m_miner_account
virtual bool verify_tx_key(const ::crypto::secret_key &tx_priv, const ::crypto::public_key &tx_pub, const subaddresses_t &subs)
std::unique_ptr< tools::wallet2 > m_wl_bob
virtual void setup_args(const std::string &trezor_path, bool heavy_tests=false)
crypto::hash head_hash() const
void rct_config(rct::RCTConfig rct_config)
static const std::string m_alice_spend_private
virtual void mine_and_test(std::vector< test_event_entry > &events)
virtual void init_fields()
virtual void add_shared_events(std::vector< test_event_entry > &events)
cryptonote::account_base m_eve_account
virtual void rewind_blocks(std::vector< test_event_entry > &events, size_t rewind_n, uint8_t hf)
virtual bool generate(std::vector< test_event_entry > &events)
static const std::string m_master_seed_str
friend class boost::serialization::access
bool heavy_tests() const
std::unique_ptr< tools::wallet2 > m_wl_alice
virtual void test_setup(std::vector< test_event_entry > &events)
static const uint64_t m_ts_start
virtual void fork(gen_trezor_base &other)
rct::RCTConfig m_rct_config
std::shared_ptr< mock_daemon > m_daemon
cryptonote::network_type nettype() const
virtual void test_get_tx(std::vector< test_event_entry > &events, std::vector< tools::wallet2 * > wallets, const std::vector< tools::wallet2::pending_tx > &ptxs, const std::vector< std::string > &aux_tx_info)
static const std::string m_device_name
cryptonote::block head_block() const
std::unique_ptr< tools::wallet2 > m_wl_eve
void serialize(Archive &ar, const unsigned int)
uint8_t cur_hf() const
virtual void fix_hf(std::vector< test_event_entry > &events)
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
bool generate(std::vector< test_event_entry > &events) override
std::vector< cryptonote::address_parse_info > dest_info()
std::vector< cryptonote::tx_source_entry > m_sources
gen_trezor_base * m_tester
tsx_builder * mixin(size_t mixin=TREZOR_TEST_MIXIN)
std::vector< cryptonote::tx_destination_entry > m_destinations_orig
tsx_builder * clear_current()
tsx_builder * fee(uint64_t fee=TREZOR_TEST_FEE)
std::vector< tools::wallet2::pending_tx > build()
std::vector< tools::wallet2::pending_tx > m_ptxs
tsx_builder * destinations(std::vector< cryptonote::tx_destination_entry > &dsts)
std::vector< size_t > m_selected_transfers
tsx_builder * from(tools::wallet2 *from, uint32_t account=0)
tsx_builder * construct_pending_tx(tools::wallet2::pending_tx &ptx, boost::optional< std::vector< uint8_t > > extra=boost::none)
tsx_builder * build_tx()
tsx_builder * cur_height(uint64_t cur_height)
std::vector< cryptonote::address_parse_info > m_dsts_info
tsx_builder * sources(std::vector< cryptonote::tx_source_entry > &sources, std::vector< size_t > &selected_transfers)
tsx_builder(gen_trezor_base *tester)
tsx_builder * add_destination(const cryptonote::tx_destination_entry &dst)
tsx_builder * set_integrated(size_t idx)
tsx_builder * compute_sources_to_sub(boost::optional< size_t > num_utxo=boost::none, boost::optional< uint64_t > min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional< fnc_accept_tx_source_t > fnc_accept=boost::none)
uint64_t m_cur_height
tsx_builder * compute_sources_to_sub_acc(boost::optional< size_t > num_utxo=boost::none, boost::optional< uint64_t > min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional< fnc_accept_tx_source_t > fnc_accept=boost::none)
rct::RCTConfig m_rct_config
std::vector< cryptonote::tx_destination_entry > m_destinations
tsx_builder * rct_config(const rct::RCTConfig &rct_config)
uint32_t m_account
tsx_builder * compute_sources(boost::optional< size_t > num_utxo=boost::none, boost::optional< uint64_t > min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional< fnc_accept_tx_source_t > fnc_accept=boost::none)
cryptonote::transaction m_tx
tools::wallet2 * m_from
std::unordered_set< size_t > m_integrated
uint64_t m_fee
tsx_builder * payment_id(const std::string &payment_id)
std::string m_payment_id
boost::filesystem::path m_wallet_dir
virtual ~wallet_api_tests()
bool generate(std::vector< test_event_entry > &events) override
POD_CLASS key_image
Definition crypto.h:105
POD_CLASS hash
Definition hash.h:50
@ RangeProofPaddedBulletproof
Definition rctTypes.h:235
crypto::hash get_block_hash(uint64_t height)
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
#define TREZOR_TEST_FEE
#define TREZOR_TEST_MIXIN