Merge pull request #978
99dd572
libwallet_api: tests: checking for result while opening wallet (Ilya Kitaev)bcf7b67
libwallet_api: Wallet::amountFromString fixed (Ilya Kitaev)32bc7b4
libwallet_api: helper method to return maximumAllowedAmount (Ilya Kitaev)cbe534d
libwallet_api: tests: removed logged passwords (Ilya Kitaev)b1a5a93
libwallet_api: do not store wallet on close if status is not ok (Ilya Kitaev)
This commit is contained in:
commit
9308b4e8b9
|
@ -129,7 +129,7 @@ string Wallet::displayAmount(uint64_t amount)
|
||||||
|
|
||||||
uint64_t Wallet::amountFromString(const string &amount)
|
uint64_t Wallet::amountFromString(const string &amount)
|
||||||
{
|
{
|
||||||
uint64_t result;
|
uint64_t result = 0;
|
||||||
cryptonote::parse_amount(result, amount);
|
cryptonote::parse_amount(result, amount);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,11 @@ bool Wallet::paymentIdValid(const string &paiment_id)
|
||||||
return tools::wallet2::parse_short_payment_id(paiment_id, pid);
|
return tools::wallet2::parse_short_payment_id(paiment_id, pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t Wallet::maximumAllowedAmount()
|
||||||
|
{
|
||||||
|
return std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////// WalletImpl implementation ////////////////////////
|
///////////////////////// WalletImpl implementation ////////////////////////
|
||||||
WalletImpl::WalletImpl(bool testnet)
|
WalletImpl::WalletImpl(bool testnet)
|
||||||
|
@ -267,16 +272,18 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed)
|
||||||
|
|
||||||
bool WalletImpl::close()
|
bool WalletImpl::close()
|
||||||
{
|
{
|
||||||
clearStatus();
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
try {
|
try {
|
||||||
// LOG_PRINT_L0("Calling wallet::store...");
|
// do not store wallet with invalid status
|
||||||
m_wallet->store();
|
if (status() == Status_Ok)
|
||||||
|
m_wallet->store();
|
||||||
// LOG_PRINT_L0("wallet::store done");
|
// LOG_PRINT_L0("wallet::store done");
|
||||||
// LOG_PRINT_L0("Calling wallet::stop...");
|
// LOG_PRINT_L0("Calling wallet::stop...");
|
||||||
m_wallet->stop();
|
m_wallet->stop();
|
||||||
// LOG_PRINT_L0("wallet::stop done");
|
// LOG_PRINT_L0("wallet::stop done");
|
||||||
result = true;
|
result = true;
|
||||||
|
clearStatus();
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
m_status = Status_Error;
|
m_status = Status_Error;
|
||||||
m_errorString = e.what();
|
m_errorString = e.what();
|
||||||
|
|
|
@ -216,6 +216,7 @@ struct Wallet
|
||||||
static uint64_t amountFromDouble(double amount);
|
static uint64_t amountFromDouble(double amount);
|
||||||
static std::string genPaymentId();
|
static std::string genPaymentId();
|
||||||
static bool paymentIdValid(const std::string &paiment_id);
|
static bool paymentIdValid(const std::string &paiment_id);
|
||||||
|
static uint64_t maximumAllowedAmount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief refresh - refreshes the wallet, updating transactions from daemon
|
* @brief refresh - refreshes the wallet, updating transactions from daemon
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include "wallet/wallet2_api.h"
|
#include "wallet/wallet2_api.h"
|
||||||
|
#include "wallet/wallet2.h"
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
@ -41,6 +42,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,6 +212,94 @@ TEST_F(WalletManagerTest, WalletManagerOpensWallet)
|
||||||
std::cout << "** seed: " << wallet2->seed() << std::endl;
|
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)
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -239,7 +329,6 @@ TEST_F(WalletManagerTest, WalletManagerMovesWallet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
|
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
|
||||||
{
|
{
|
||||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue