fix(trezor-tests): fix trezor tests build, fix integrated addr test

- fix integrated address test, it was not testing integrated address suport
- fix trezor test build as dependent classes were changed
- add a friend test class for Monero::WalletImpl to support wallet api tests
When using wallet_api in tests, synthetic chain is used. Without being able to set `allow_mismatched_daemon_version` in the underlying wallet, we are not able to use a synthetic chain with the tests
This commit is contained in:
Dusan Klinec 2022-10-20 17:23:28 +02:00
parent fc907a9570
commit 1114e7eed7
No known key found for this signature in database
GPG Key ID: 6337E118CCBCE103
4 changed files with 26 additions and 5 deletions

View File

@ -39,6 +39,7 @@
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
#include <boost/thread/condition_variable.hpp> #include <boost/thread/condition_variable.hpp>
class WalletApiAccessorTest;
namespace Monero { namespace Monero {
class TransactionHistoryImpl; class TransactionHistoryImpl;
@ -248,6 +249,7 @@ private:
friend class AddressBookImpl; friend class AddressBookImpl;
friend class SubaddressImpl; friend class SubaddressImpl;
friend class SubaddressAccountImpl; friend class SubaddressAccountImpl;
friend class ::WalletApiAccessorTest;
std::unique_ptr<tools::wallet2> m_wallet; std::unique_ptr<tools::wallet2> m_wallet;
mutable boost::mutex m_statusMutex; mutable boost::mutex m_statusMutex;

View File

@ -32,6 +32,7 @@
#include "chaingen.h" #include "chaingen.h"
#include "wallet/wallet2.h" #include "wallet/wallet2.h"
#include "wallet/api/wallet.h"
typedef struct { typedef struct {
tools::wallet2::transfer_details * td; tools::wallet2::transfer_details * td;
@ -57,6 +58,13 @@ public:
static void process_parsed_blocks(tools::wallet2 * wallet, uint64_t start_height, const std::vector<cryptonote::block_complete_entry> &blocks, const std::vector<tools::wallet2::parsed_block> &parsed_blocks, uint64_t& blocks_added); static void process_parsed_blocks(tools::wallet2 * wallet, uint64_t start_height, const std::vector<cryptonote::block_complete_entry> &blocks, const std::vector<tools::wallet2::parsed_block> &parsed_blocks, uint64_t& blocks_added);
}; };
// Wallet API friend, direct access to required fields and private methods
class WalletApiAccessorTest
{
public:
static void allow_mismatched_daemon_version(Monero::WalletImpl * wallet, bool allow_mismatch) { wallet->m_wallet->allow_mismatched_daemon_version(allow_mismatch); }
};
class wallet_tools class wallet_tools
{ {
public: public:

View File

@ -313,7 +313,7 @@ void mock_daemon::mine_blocks(size_t num_blocks, const std::string &miner_addres
{ {
bool blocks_mined = false; bool blocks_mined = false;
const uint64_t start_height = get_height(); const uint64_t start_height = get_height();
const auto mining_timeout = std::chrono::seconds(120); const auto mining_timeout = std::chrono::seconds(360);
MDEBUG("Current height before mining: " << start_height); MDEBUG("Current height before mining: " << start_height);
start_mining(miner_address); start_mining(miner_address);

View File

@ -137,8 +137,8 @@ int main(int argc, char* argv[])
hw::register_device(HW_TREZOR_NAME, ensure_trezor_test_device()); // shim device for call tracking hw::register_device(HW_TREZOR_NAME, ensure_trezor_test_device()); // shim device for call tracking
// Bootstrapping common chain & accounts // Bootstrapping common chain & accounts
const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", HF_VERSION_CLSAG); const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", HF_VERSION_BULLETPROOF_PLUS);
const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_HF", HF_VERSION_CLSAG); const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_HF", HF_VERSION_BULLETPROOF_PLUS);
auto sync_test = get_env_long("TEST_KI_SYNC", 1); auto sync_test = get_env_long("TEST_KI_SYNC", 1);
MINFO("Test versions " << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"); MINFO("Test versions " << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
MINFO("Testing hardforks [" << (int)initial_hf << ", " << (int)max_hf << "], sync-test: " << sync_test); MINFO("Testing hardforks [" << (int)initial_hf << ", " << (int)max_hf << "], sync-test: " << sync_test);
@ -1025,7 +1025,8 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
for(auto &ptx : ptxs) { for(auto &ptx : ptxs) {
txs.txes.push_back(get_construction_data_with_decrypted_short_payment_id(ptx, *m_trezor)); txs.txes.push_back(get_construction_data_with_decrypted_short_payment_id(ptx, *m_trezor));
} }
txs.transfers = std::make_pair(0, wallet_accessor_test::get_transfers(m_wl_alice.get())); const auto transfers = wallet_accessor_test::get_transfers(m_wl_alice.get());
txs.transfers = std::make_tuple(0, transfers.size(), transfers);
auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor); auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor);
CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface"); CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface");
@ -1055,7 +1056,10 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
CHECK_AND_ASSERT_THROW_MES(resy, "Trezor tx_1 Nonsemantics failed"); CHECK_AND_ASSERT_THROW_MES(resy, "Trezor tx_1 Nonsemantics failed");
tx_list.push_back(c_ptx.tx); tx_list.push_back(c_ptx.tx);
const crypto::hash txhash = cryptonote::get_transaction_hash(c_ptx.tx);
MDEBUG("Transaction: " << dump_data(c_ptx.tx)); MDEBUG("Transaction: " << dump_data(c_ptx.tx));
MDEBUG("Transaction hash: " << epee::string_tools::pod_to_hex(txhash));
MDEBUG("Serialized transaction: " << epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(c_ptx.tx)));
} }
add_transactions_to_events(events, generator, tx_list); add_transactions_to_events(events, generator, tx_list);
@ -1384,7 +1388,9 @@ tsx_builder * tsx_builder::add_destination(const tools::wallet2 * wallet, bool i
tsx_builder * tsx_builder::set_integrated(size_t idx) tsx_builder * tsx_builder::set_integrated(size_t idx)
{ {
CHECK_AND_ASSERT_THROW_MES(m_destinations_orig.size() > idx, "Destination size not big enough to set integrated flag");
m_integrated.insert(idx); m_integrated.insert(idx);
m_destinations_orig[idx].is_integrated = true;
return this; return this;
} }
@ -1451,7 +1457,7 @@ tsx_builder * tsx_builder::construct_pending_tx(tools::wallet2::pending_tx &ptx,
auto change_addr = m_from->get_account().get_keys().m_account_address; auto change_addr = m_from->get_account().get_keys().m_account_address;
bool r = construct_tx_and_get_tx_key(m_from->get_account().get_keys(), subaddresses, m_sources, destinations_copy, bool r = construct_tx_and_get_tx_key(m_from->get_account().get_keys(), subaddresses, m_sources, destinations_copy,
change_addr, extra ? extra.get() : std::vector<uint8_t>(), tx, 0, tx_key, change_addr, extra ? extra.get() : std::vector<uint8_t>(), tx, 0, tx_key,
additional_tx_keys, true, m_rct_config, nullptr); additional_tx_keys, true, m_rct_config, this->m_tester->cur_hf() >= HF_VERSION_VIEW_TAGS);
CHECK_AND_ASSERT_THROW_MES(r, "Transaction construction failed"); CHECK_AND_ASSERT_THROW_MES(r, "Transaction construction failed");
// Selected transfers permutation // Selected transfers permutation
@ -1927,6 +1933,11 @@ bool wallet_api_tests::generate(std::vector<test_event_entry>& events)
Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager(); Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager();
std::unique_ptr<Monero::Wallet> w{wmgr->createWalletFromDevice(wallet_path, "", api_net_type, m_trezor_path, 1)}; std::unique_ptr<Monero::Wallet> w{wmgr->createWalletFromDevice(wallet_path, "", api_net_type, m_trezor_path, 1)};
CHECK_AND_ASSERT_THROW_MES(w->init(daemon()->rpc_addr(), 0), "Wallet init fail"); CHECK_AND_ASSERT_THROW_MES(w->init(daemon()->rpc_addr(), 0), "Wallet init fail");
auto walletImpl = dynamic_cast<Monero::WalletImpl *>(w.get());
CHECK_AND_ASSERT_THROW_MES(walletImpl, "Dynamic wallet cast failed");
WalletApiAccessorTest::allow_mismatched_daemon_version(walletImpl, true);
CHECK_AND_ASSERT_THROW_MES(w->refresh(), "Refresh fail"); CHECK_AND_ASSERT_THROW_MES(w->refresh(), "Refresh fail");
uint64_t balance = w->balance(0); uint64_t balance = w->balance(0);
MDEBUG("Balance: " << balance); MDEBUG("Balance: " << balance);