diff options
-rw-r--r-- | src/wallet/api/wallet.cpp | 9 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 2 | ||||
-rw-r--r-- | tests/libwallet_api_tests/main.cpp | 26 |
3 files changed, 30 insertions, 7 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 55b13ba7e..9bb7f0569 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -175,7 +175,7 @@ WalletImpl::WalletImpl(bool testnet) m_wallet->callback(m_wallet2Callback); m_refreshThreadDone = false; m_refreshEnabled = false; - m_newWallet = true; + m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS; @@ -196,7 +196,6 @@ WalletImpl::~WalletImpl() bool WalletImpl::create(const std::string &path, const std::string &password, const std::string &language) { - m_newWallet = true; clearStatus(); bool keys_file_exists; @@ -234,7 +233,6 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co bool WalletImpl::open(const std::string &path, const std::string &password) { - m_newWallet = false; clearStatus(); try { // TODO: handle "deprecated" @@ -746,7 +744,10 @@ void WalletImpl::pauseRefresh() bool WalletImpl::isNewWallet() const { - return m_newWallet; + // in case wallet created without daemon connection, closed and opened again, + // it's the same case as if it created from scratch, i.e. we need "fast sync" + // with the daemon (pull hashes instead of pull blocks) + return !(blockChainHeight() > 1); } void WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit) diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index e2eb05167..09db05d08 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -128,8 +128,6 @@ private: boost::mutex m_refreshMutex2; boost::condition_variable m_refreshCV; boost::thread m_refreshThread; - bool m_newWallet; - }; diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 42445d53a..a4b881407 100644 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -1030,7 +1030,7 @@ TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetSync) } -TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetAsync) +TEST_F(WalletManagerMainnetTest, CreateAndRefreshWalletMainNetAsync) { Bitmonero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG); @@ -1049,6 +1049,30 @@ TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetAsync) wmgr->closeWallet(wallet); } +TEST_F(WalletManagerMainnetTest, OpenAndRefreshWalletMainNetAsync) +{ + + Bitmonero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG); + + wmgr->closeWallet(wallet); + wallet = wmgr->openWallet(WALLET_NAME_MAINNET, ""); + + MyWalletListener * wallet_listener = new MyWalletListener(wallet); + std::chrono::seconds wait_for = std::chrono::seconds(30); + std::unique_lock<std::mutex> lock (wallet_listener->mutex); + wallet->initAsync(MAINNET_DAEMON_ADDRESS, 0); + // wallet->init(MAINNET_DAEMON_ADDRESS, 0); + std::cerr << "TEST: waiting on refresh lock...\n"; + wallet_listener->cv_refresh.wait_for(lock, wait_for); + std::cerr << "TEST: refresh lock acquired...\n"; + ASSERT_TRUE(wallet_listener->refresh_triggered); + ASSERT_TRUE(wallet->connected()); + ASSERT_TRUE(wallet->blockChainHeight() == wallet->daemonBlockChainHeight()); + std::cerr << "TEST: closing wallet...\n"; + wmgr->closeWallet(wallet); +} + + int main(int argc, char** argv) |