aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.i18n2
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp5
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl2
-rw-r--r--src/simplewallet/simplewallet.cpp11
-rw-r--r--src/wallet/api/wallet.cpp15
-rw-r--r--src/wallet/wallet2_api.h1
-rw-r--r--tests/libwallet_api_tests/main.cpp92
7 files changed, 118 insertions, 10 deletions
diff --git a/README.i18n b/README.i18n
index 2b913f7d8..0c7a010ef 100644
--- a/README.i18n
+++ b/README.i18n
@@ -13,7 +13,7 @@ To update ts files after changing source code:
To add a new language, eg Spanish (ISO code es):
- cp transations/monero.ts transations/monero_es.ts
+ cp translations/monero.ts translations/monero_es.ts
To edit translations for Spanish:
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 25b750b1d..26748aceb 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -957,7 +957,10 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
void core::set_target_blockchain_height(uint64_t target_blockchain_height)
{
- m_target_blockchain_height = target_blockchain_height;
+ if (target_blockchain_height > m_target_blockchain_height)
+ {
+ m_target_blockchain_height = target_blockchain_height;
+ }
}
//-----------------------------------------------------------------------------------------------
uint64_t core::get_target_blockchain_height() const
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 9f0ea0e83..6f095a76f 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -263,7 +263,7 @@ namespace cryptonote
if(context.m_state == cryptonote_connection_context::state_synchronizing)
return true;
- if(m_core.have_block(hshd.top_id))
+ if(m_core.have_block(hshd.top_id) && !(hshd.current_height < m_core.get_target_blockchain_height()))
{
context.m_state = cryptonote_connection_context::state_normal;
if(is_inital)
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 36d1fa0a9..1840e54c9 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -76,6 +76,13 @@ typedef cryptonote::simple_wallet sw;
#define DEFAULT_MIX 4
+// workaround for a suspected bug in pthread/kernel on MacOS X
+#ifdef __APPLE__
+#define DEFAULT_MAX_CONCURRENCY 1
+#else
+#define DEFAULT_MAX_CONCURRENCY 0
+#endif
+
#define LOCK_IDLE_SCOPE() \
bool auto_refresh_enabled = m_auto_refresh_enabled.load(std::memory_order_relaxed); \
m_auto_refresh_enabled.store(false, std::memory_order_relaxed); \
@@ -95,7 +102,7 @@ typedef cryptonote::simple_wallet sw;
namespace
{
const command_line::arg_descriptor<std::string> arg_wallet_file = {"wallet-file", sw::tr("Use wallet <arg>"), ""};
- const command_line::arg_descriptor<std::string> arg_generate_new_wallet = {"generate-new-wallet", sw::tr("Generate new wallet and save it to <arg> or <address>.wallet by default"), ""};
+ const command_line::arg_descriptor<std::string> arg_generate_new_wallet = {"generate-new-wallet", sw::tr("Generate new wallet and save it to <arg>"), ""};
const command_line::arg_descriptor<std::string> arg_generate_from_view_key = {"generate-from-view-key", sw::tr("Generate incoming-only wallet from view key"), ""};
const command_line::arg_descriptor<std::string> arg_generate_from_keys = {"generate-from-keys", sw::tr("Generate wallet from private keys"), ""};
const command_line::arg_descriptor<std::string> arg_generate_from_json = {"generate-from-json", sw::tr("Generate wallet from JSON format file"), ""};
@@ -108,7 +115,7 @@ namespace
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false};
const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", sw::tr("Use daemon instance at port <arg> instead of 18081"), 0};
const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0};
- const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", "Max number of threads to use for a parallel job", 0};
+ const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", "Max number of threads to use for a parallel job", DEFAULT_MAX_CONCURRENCY};
const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", sw::tr("Specify log file"), ""};
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false};
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 4b97e2f1d..b3ee4112b 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -129,7 +129,7 @@ string Wallet::displayAmount(uint64_t amount)
uint64_t Wallet::amountFromString(const string &amount)
{
- uint64_t result;
+ uint64_t result = 0;
cryptonote::parse_amount(result, amount);
return result;
}
@@ -154,6 +154,11 @@ bool Wallet::paymentIdValid(const string &paiment_id)
return tools::wallet2::parse_short_payment_id(paiment_id, pid);
}
+uint64_t Wallet::maximumAllowedAmount()
+{
+ return std::numeric_limits<uint64_t>::max();
+}
+
///////////////////////// WalletImpl implementation ////////////////////////
WalletImpl::WalletImpl(bool testnet)
@@ -267,16 +272,18 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed)
bool WalletImpl::close()
{
- clearStatus();
+
bool result = false;
try {
- // LOG_PRINT_L0("Calling wallet::store...");
- m_wallet->store();
+ // do not store wallet with invalid status
+ if (status() == Status_Ok)
+ m_wallet->store();
// LOG_PRINT_L0("wallet::store done");
// LOG_PRINT_L0("Calling wallet::stop...");
m_wallet->stop();
// LOG_PRINT_L0("wallet::stop done");
result = true;
+ clearStatus();
} catch (const std::exception &e) {
m_status = Status_Error;
m_errorString = e.what();
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index 2c5836573..e880b1c68 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -216,6 +216,7 @@ struct Wallet
static uint64_t amountFromDouble(double amount);
static std::string genPaymentId();
static bool paymentIdValid(const std::string &paiment_id);
+ static uint64_t maximumAllowedAmount();
/**
* @brief refresh - refreshes the wallet, updating transactions from daemon
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index d642534b0..b4bc86f91 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -31,6 +31,7 @@
#include "gtest/gtest.h"
#include "wallet/wallet2_api.h"
+#include "wallet/wallet2.h"
#include "include_base_utils.h"
#include <boost/filesystem.hpp>
@@ -41,6 +42,7 @@
#include <mutex>
#include <thread>
#include <atomic>
+#include <functional>
#include <condition_variable>
@@ -210,6 +212,94 @@ TEST_F(WalletManagerTest, WalletManagerOpensWallet)
std::cout << "** seed: " << wallet2->seed() << std::endl;
}
+
+TEST_F(WalletManagerTest, WalletMaxAmountAsString)
+{
+ LOG_PRINT_L3("max amount: " << Bitmonero::Wallet::displayAmount(
+ Bitmonero::Wallet::maximumAllowedAmount()));
+
+}
+
+TEST_F(WalletManagerTest, WalletAmountFromString)
+{
+ uint64_t amount = Bitmonero::Wallet::amountFromString("18446740");
+ ASSERT_TRUE(amount > 0);
+ amount = Bitmonero::Wallet::amountFromString("11000000000000");
+ ASSERT_FALSE(amount > 0);
+ amount = Bitmonero::Wallet::amountFromString("0.0");
+ ASSERT_FALSE(amount > 0);
+ amount = Bitmonero::Wallet::amountFromString("10.1");
+ ASSERT_TRUE(amount > 0);
+
+}
+
+void open_wallet_helper(Bitmonero::WalletManager *wmgr, Bitmonero::Wallet **wallet, const std::string &pass, std::mutex *mutex)
+{
+ if (mutex)
+ mutex->lock();
+ LOG_PRINT_L3("opening wallet in thread: " << std::this_thread::get_id());
+ *wallet = wmgr->openWallet(WALLET_NAME, pass, true);
+ LOG_PRINT_L3("wallet address: " << (*wallet)->address());
+ LOG_PRINT_L3("wallet status: " << (*wallet)->status());
+ LOG_PRINT_L3("closing wallet in thread: " << std::this_thread::get_id());
+ if (mutex)
+ mutex->unlock();
+}
+
+
+
+
+//TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopenMultiThreaded)
+//{
+// // create password protected wallet
+// std::string wallet_pass = "password";
+// std::string wrong_wallet_pass = "1111";
+// Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, wallet_pass, WALLET_LANG, true);
+// std::string seed1 = wallet1->seed();
+// ASSERT_TRUE(wmgr->closeWallet(wallet1));
+
+// Bitmonero::Wallet *wallet2 = nullptr;
+// Bitmonero::Wallet *wallet3 = nullptr;
+
+// std::mutex mutex;
+// std::thread thread1(open_wallet, wmgr, &wallet2, wrong_wallet_pass, &mutex);
+// thread1.join();
+// ASSERT_TRUE(wallet2->status() != Bitmonero::Wallet::Status_Ok);
+// ASSERT_TRUE(wmgr->closeWallet(wallet2));
+
+// std::thread thread2(open_wallet, wmgr, &wallet3, wallet_pass, &mutex);
+// thread2.join();
+
+// ASSERT_TRUE(wallet3->status() == Bitmonero::Wallet::Status_Ok);
+// ASSERT_TRUE(wmgr->closeWallet(wallet3));
+//}
+
+
+TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen)
+{
+ // create password protected wallet
+ std::string wallet_pass = "password";
+ std::string wrong_wallet_pass = "1111";
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, wallet_pass, WALLET_LANG, true);
+ std::string seed1 = wallet1->seed();
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+
+ Bitmonero::Wallet *wallet2 = nullptr;
+ Bitmonero::Wallet *wallet3 = nullptr;
+ std::mutex mutex;
+
+ open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr);
+ ASSERT_TRUE(wallet2 != nullptr);
+ ASSERT_TRUE(wallet2->status() != Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wmgr->closeWallet(wallet2));
+
+ open_wallet_helper(wmgr, &wallet3, wallet_pass, nullptr);
+ ASSERT_TRUE(wallet3 != nullptr);
+ ASSERT_TRUE(wallet3->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wmgr->closeWallet(wallet3));
+}
+
+
TEST_F(WalletManagerTest, WalletManagerStoresWallet)
{
@@ -239,7 +329,6 @@ TEST_F(WalletManagerTest, WalletManagerMovesWallet)
}
-
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
{
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
@@ -819,6 +908,7 @@ TEST_F(WalletTest2, WalletCallbackReceived)
}
+
int main(int argc, char** argv)
{