From 1114e7eed778b4957561bca4da5c7631f8c60133 Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Thu, 20 Oct 2022 17:23:28 +0200 Subject: [PATCH] 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 --- src/wallet/api/wallet.h | 2 ++ tests/core_tests/wallet_tools.h | 8 ++++++++ tests/trezor/daemon.cpp | 2 +- tests/trezor/trezor_tests.cpp | 19 +++++++++++++++---- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index ec2d7e9b3..4ac672287 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -39,6 +39,7 @@ #include #include +class WalletApiAccessorTest; namespace Monero { class TransactionHistoryImpl; @@ -248,6 +249,7 @@ private: friend class AddressBookImpl; friend class SubaddressImpl; friend class SubaddressAccountImpl; + friend class ::WalletApiAccessorTest; std::unique_ptr m_wallet; mutable boost::mutex m_statusMutex; diff --git a/tests/core_tests/wallet_tools.h b/tests/core_tests/wallet_tools.h index 982862d45..20cd2c4d9 100644 --- a/tests/core_tests/wallet_tools.h +++ b/tests/core_tests/wallet_tools.h @@ -32,6 +32,7 @@ #include "chaingen.h" #include "wallet/wallet2.h" +#include "wallet/api/wallet.h" typedef struct { 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 &blocks, const std::vector &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 { public: diff --git a/tests/trezor/daemon.cpp b/tests/trezor/daemon.cpp index 546a8a180..be13f6d19 100644 --- a/tests/trezor/daemon.cpp +++ b/tests/trezor/daemon.cpp @@ -313,7 +313,7 @@ void mock_daemon::mine_blocks(size_t num_blocks, const std::string &miner_addres { bool blocks_mined = false; 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); start_mining(miner_address); diff --git a/tests/trezor/trezor_tests.cpp b/tests/trezor/trezor_tests.cpp index 0d61610be..cf85ffb30 100644 --- a/tests/trezor/trezor_tests.cpp +++ b/tests/trezor/trezor_tests.cpp @@ -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 // Bootstrapping common chain & accounts - const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", HF_VERSION_CLSAG); - const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_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_BULLETPROOF_PLUS); auto sync_test = get_env_long("TEST_KI_SYNC", 1); MINFO("Test versions " << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"); 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& events, std: for(auto &ptx : ptxs) { 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); 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& events, std: CHECK_AND_ASSERT_THROW_MES(resy, "Trezor tx_1 Nonsemantics failed"); 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 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); @@ -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) { + CHECK_AND_ASSERT_THROW_MES(m_destinations_orig.size() > idx, "Destination size not big enough to set integrated flag"); m_integrated.insert(idx); + m_destinations_orig[idx].is_integrated = true; 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; 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(), 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"); // Selected transfers permutation @@ -1927,6 +1933,11 @@ bool wallet_api_tests::generate(std::vector& events) Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager(); std::unique_ptr 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"); + + auto walletImpl = dynamic_cast(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"); uint64_t balance = w->balance(0); MDEBUG("Balance: " << balance);