2017-02-21 12:38:18 -05:00
|
|
|
// Copyright (c) 2014-2017, The Monero Project
|
2016-02-20 11:04:56 -05:00
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
2016-04-22 06:21:08 -04:00
|
|
|
|
2016-02-20 11:04:56 -05:00
|
|
|
#include "wallet/wallet2_api.h"
|
2016-08-22 08:53:07 -04:00
|
|
|
#include "wallet/wallet2.h"
|
2016-07-14 05:47:01 -04:00
|
|
|
#include "include_base_utils.h"
|
2017-10-21 05:09:51 -04:00
|
|
|
#include "common/util.h"
|
2016-04-22 06:21:08 -04:00
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
#include <boost/chrono/chrono.hpp>
|
2016-02-21 13:18:16 -05:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2016-09-20 13:40:58 -04:00
|
|
|
#include <boost/asio.hpp>
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
2017-02-12 17:53:13 -05:00
|
|
|
#include <boost/thread/condition_variable.hpp>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
#include <boost/thread/thread.hpp>
|
2016-02-20 11:04:56 -05:00
|
|
|
|
2016-02-21 13:18:16 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2016-07-10 10:17:23 -04:00
|
|
|
#include <atomic>
|
2016-08-22 08:53:07 -04:00
|
|
|
#include <functional>
|
2016-02-21 13:18:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
2016-02-20 11:04:56 -05:00
|
|
|
//unsigned int epee::g_test_dbg_lock_sleep = 0;
|
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
namespace Consts
|
|
|
|
{
|
|
|
|
|
2016-06-01 10:06:10 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
// TODO: get rid of hardcoded paths
|
|
|
|
|
|
|
|
const char * WALLET_NAME = "testwallet";
|
2016-09-27 18:36:49 -04:00
|
|
|
const char * WALLET_NAME_MAINNET = "testwallet_mainnet";
|
2016-05-16 06:11:44 -04:00
|
|
|
const char * WALLET_NAME_COPY = "testwallet_copy";
|
|
|
|
const char * WALLET_NAME_WITH_DIR = "walletdir/testwallet_test";
|
|
|
|
const char * WALLET_NAME_WITH_DIR_NON_WRITABLE = "/var/walletdir/testwallet_test";
|
|
|
|
const char * WALLET_PASS = "password";
|
|
|
|
const char * WALLET_PASS2 = "password22";
|
|
|
|
const char * WALLET_LANG = "English";
|
|
|
|
|
2016-09-22 13:32:57 -04:00
|
|
|
std::string WALLETS_ROOT_DIR = "/var/monero/testnet_pvt";
|
|
|
|
std::string TESTNET_WALLET1_NAME;
|
|
|
|
std::string TESTNET_WALLET2_NAME;
|
|
|
|
std::string TESTNET_WALLET3_NAME;
|
|
|
|
std::string TESTNET_WALLET4_NAME;
|
|
|
|
std::string TESTNET_WALLET5_NAME;
|
|
|
|
std::string TESTNET_WALLET6_NAME;
|
2016-06-01 10:06:10 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
const char * TESTNET_WALLET_PASS = "";
|
|
|
|
|
2016-09-22 13:32:57 -04:00
|
|
|
std::string CURRENT_SRC_WALLET;
|
|
|
|
std::string CURRENT_DST_WALLET;
|
2016-09-22 12:07:12 -04:00
|
|
|
|
2016-06-01 10:06:10 -04:00
|
|
|
const uint64_t AMOUNT_10XMR = 10000000000000L;
|
2016-05-17 05:16:11 -04:00
|
|
|
const uint64_t AMOUNT_5XMR = 5000000000000L;
|
|
|
|
const uint64_t AMOUNT_1XMR = 1000000000000L;
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-06-23 07:38:22 -04:00
|
|
|
const std::string PAYMENT_ID_EMPTY = "";
|
|
|
|
|
2016-09-22 13:32:57 -04:00
|
|
|
std::string TESTNET_DAEMON_ADDRESS = "localhost:38081";
|
2016-09-27 18:36:49 -04:00
|
|
|
std::string MAINNET_DAEMON_ADDRESS = "localhost:18081";
|
2016-09-22 13:32:57 -04:00
|
|
|
|
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 05:16:11 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
using namespace Consts;
|
|
|
|
|
2016-03-25 10:06:30 -04:00
|
|
|
struct Utils
|
|
|
|
{
|
|
|
|
static void deleteWallet(const std::string & walletname)
|
|
|
|
{
|
|
|
|
std::cout << "** deleting wallet: " << walletname << std::endl;
|
|
|
|
boost::filesystem::remove(walletname);
|
|
|
|
boost::filesystem::remove(walletname + ".address.txt");
|
|
|
|
boost::filesystem::remove(walletname + ".keys");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deleteDir(const std::string &path)
|
|
|
|
{
|
|
|
|
std::cout << "** removing dir recursively: " << path << std::endl;
|
|
|
|
boost::filesystem::remove_all(path);
|
|
|
|
}
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
static void print_transaction(Monero::TransactionInfo * t)
|
2016-05-16 06:11:44 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
std::cout << "d: "
|
2016-12-13 10:21:38 -05:00
|
|
|
<< (t->direction() == Monero::TransactionInfo::Direction_In ? "in" : "out")
|
2016-05-16 06:11:44 -04:00
|
|
|
<< ", pe: " << (t->isPending() ? "true" : "false")
|
|
|
|
<< ", bh: " << t->blockHeight()
|
2016-12-13 10:21:38 -05:00
|
|
|
<< ", a: " << Monero::Wallet::displayAmount(t->amount())
|
|
|
|
<< ", f: " << Monero::Wallet::displayAmount(t->fee())
|
2016-05-16 06:11:44 -04:00
|
|
|
<< ", h: " << t->hash()
|
|
|
|
<< ", pid: " << t->paymentId()
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2016-06-01 10:06:10 -04:00
|
|
|
|
|
|
|
static std::string get_wallet_address(const std::string &filename, const std::string &password)
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager();
|
|
|
|
Monero::Wallet * w = wmgr->openWallet(filename, password, true);
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string result = w->mainAddress();
|
2016-06-01 10:06:10 -04:00
|
|
|
wmgr->closeWallet(w);
|
|
|
|
return result;
|
|
|
|
}
|
2016-03-25 10:06:30 -04:00
|
|
|
};
|
|
|
|
|
2016-02-20 11:04:56 -05:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
struct WalletManagerTest : public testing::Test
|
2016-02-20 11:04:56 -05:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::WalletManager * wmgr;
|
2016-02-20 11:04:56 -05:00
|
|
|
|
2016-03-25 10:06:30 -04:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
WalletManagerTest()
|
2016-02-20 11:04:56 -05:00
|
|
|
{
|
2016-03-10 11:43:10 -05:00
|
|
|
std::cout << __FUNCTION__ << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
wmgr = Monero::WalletManagerFactory::getWalletManager();
|
|
|
|
// Monero::WalletManagerFactory::setLogLevel(Monero::WalletManagerFactory::LogLevel_4);
|
2016-03-25 10:06:30 -04:00
|
|
|
Utils::deleteWallet(WALLET_NAME);
|
|
|
|
Utils::deleteDir(boost::filesystem::path(WALLET_NAME_WITH_DIR).parent_path().string());
|
2016-02-20 11:04:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
~WalletManagerTest()
|
2016-02-21 13:18:16 -05:00
|
|
|
{
|
2016-03-10 11:43:10 -05:00
|
|
|
std::cout << __FUNCTION__ << std::endl;
|
2016-03-12 09:41:11 -05:00
|
|
|
//deleteWallet(WALLET_NAME);
|
2016-02-21 13:18:16 -05:00
|
|
|
}
|
2016-04-29 09:26:14 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
};
|
|
|
|
|
2016-09-27 18:36:49 -04:00
|
|
|
struct WalletManagerMainnetTest : public testing::Test
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::WalletManager * wmgr;
|
2016-09-27 18:36:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
WalletManagerMainnetTest()
|
|
|
|
{
|
|
|
|
std::cout << __FUNCTION__ << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
wmgr = Monero::WalletManagerFactory::getWalletManager();
|
2016-09-27 18:36:49 -04:00
|
|
|
Utils::deleteWallet(WALLET_NAME_MAINNET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~WalletManagerMainnetTest()
|
|
|
|
{
|
|
|
|
std::cout << __FUNCTION__ << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
struct WalletTest1 : public testing::Test
|
2016-05-16 06:11:44 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::WalletManager * wmgr;
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
WalletTest1()
|
2016-04-29 09:26:14 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
wmgr = Monero::WalletManagerFactory::getWalletManager();
|
2016-05-16 06:11:44 -04:00
|
|
|
}
|
2016-04-29 09:26:14 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct WalletTest2 : public testing::Test
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::WalletManager * wmgr;
|
2016-05-16 06:11:44 -04:00
|
|
|
|
|
|
|
WalletTest2()
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
wmgr = Monero::WalletManagerFactory::getWalletManager();
|
2016-04-29 09:26:14 -04:00
|
|
|
}
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-02-21 13:18:16 -05:00
|
|
|
};
|
2016-02-20 11:04:56 -05:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
2016-02-20 11:04:56 -05:00
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
|
|
|
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
2016-03-10 11:43:10 -05:00
|
|
|
ASSERT_TRUE(!wallet->seed().empty());
|
2016-02-21 13:18:16 -05:00
|
|
|
std::vector<std::string> words;
|
|
|
|
std::string seed = wallet->seed();
|
|
|
|
boost::split(words, seed, boost::is_any_of(" "), boost::token_compress_on);
|
2016-03-10 11:43:10 -05:00
|
|
|
ASSERT_TRUE(words.size() == 25);
|
2016-02-21 13:18:16 -05:00
|
|
|
std::cout << "** seed: " << wallet->seed() << std::endl;
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_FALSE(wallet->mainAddress().empty());
|
|
|
|
std::cout << "** address: " << wallet->mainAddress() << std::endl;
|
2016-03-10 11:43:10 -05:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet));
|
2016-03-12 09:52:58 -05:00
|
|
|
|
2016-03-10 11:43:10 -05:00
|
|
|
}
|
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerOpensWallet)
|
2016-03-10 11:43:10 -05:00
|
|
|
{
|
2016-03-11 09:05:36 -05:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-10 11:43:10 -05:00
|
|
|
std::string seed1 = wallet1->seed();
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
|
|
|
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
|
2016-03-10 11:43:10 -05:00
|
|
|
ASSERT_TRUE(wallet2->seed() == seed1);
|
|
|
|
std::cout << "** seed: " << wallet2->seed() << std::endl;
|
2016-02-20 11:04:56 -05:00
|
|
|
}
|
|
|
|
|
2016-08-22 08:53:07 -04:00
|
|
|
|
2016-08-23 06:46:51 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletMaxAmountAsString)
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
LOG_PRINT_L3("max amount: " << Monero::Wallet::displayAmount(
|
|
|
|
Monero::Wallet::maximumAllowedAmount()));
|
2016-08-23 06:46:51 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-22 12:07:12 -04:00
|
|
|
|
2016-08-23 06:46:51 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletAmountFromString)
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
uint64_t amount = Monero::Wallet::amountFromString("18446740");
|
2016-08-23 06:46:51 -04:00
|
|
|
ASSERT_TRUE(amount > 0);
|
2016-12-13 10:21:38 -05:00
|
|
|
amount = Monero::Wallet::amountFromString("11000000000000");
|
2016-08-23 06:46:51 -04:00
|
|
|
ASSERT_FALSE(amount > 0);
|
2016-12-13 10:21:38 -05:00
|
|
|
amount = Monero::Wallet::amountFromString("0.0");
|
2016-08-23 06:46:51 -04:00
|
|
|
ASSERT_FALSE(amount > 0);
|
2016-12-13 10:21:38 -05:00
|
|
|
amount = Monero::Wallet::amountFromString("10.1");
|
2016-08-23 06:46:51 -04:00
|
|
|
ASSERT_TRUE(amount > 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, const std::string &pass, boost::mutex *mutex)
|
2016-08-22 08:53:07 -04:00
|
|
|
{
|
|
|
|
if (mutex)
|
|
|
|
mutex->lock();
|
2017-02-12 17:53:13 -05:00
|
|
|
LOG_PRINT_L3("opening wallet in thread: " << boost::this_thread::get_id());
|
2016-08-22 08:53:07 -04:00
|
|
|
*wallet = wmgr->openWallet(WALLET_NAME, pass, true);
|
2017-02-18 21:42:10 -05:00
|
|
|
LOG_PRINT_L3("wallet address: " << (*wallet)->mainAddress());
|
2016-08-22 08:53:07 -04:00
|
|
|
LOG_PRINT_L3("wallet status: " << (*wallet)->status());
|
2017-02-12 17:53:13 -05:00
|
|
|
LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id());
|
2016-08-22 08:53:07 -04:00
|
|
|
if (mutex)
|
|
|
|
mutex->unlock();
|
|
|
|
}
|
|
|
|
|
2016-08-23 06:46:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-22 08:53:07 -04:00
|
|
|
//TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopenMultiThreaded)
|
|
|
|
//{
|
|
|
|
// // create password protected wallet
|
|
|
|
// std::string wallet_pass = "password";
|
|
|
|
// std::string wrong_wallet_pass = "1111";
|
2016-12-13 10:21:38 -05:00
|
|
|
// Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, wallet_pass, WALLET_LANG, true);
|
2016-08-22 08:53:07 -04:00
|
|
|
// std::string seed1 = wallet1->seed();
|
|
|
|
// ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
// Monero::Wallet *wallet2 = nullptr;
|
|
|
|
// Monero::Wallet *wallet3 = nullptr;
|
2016-08-22 08:53:07 -04:00
|
|
|
|
|
|
|
// std::mutex mutex;
|
|
|
|
// std::thread thread1(open_wallet, wmgr, &wallet2, wrong_wallet_pass, &mutex);
|
|
|
|
// thread1.join();
|
2016-12-13 10:21:38 -05:00
|
|
|
// ASSERT_TRUE(wallet2->status() != Monero::Wallet::Status_Ok);
|
2016-08-22 08:53:07 -04:00
|
|
|
// ASSERT_TRUE(wmgr->closeWallet(wallet2));
|
|
|
|
|
|
|
|
// std::thread thread2(open_wallet, wmgr, &wallet3, wallet_pass, &mutex);
|
|
|
|
// thread2.join();
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
// ASSERT_TRUE(wallet3->status() == Monero::Wallet::Status_Ok);
|
2016-08-22 08:53:07 -04:00
|
|
|
// ASSERT_TRUE(wmgr->closeWallet(wallet3));
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen)
|
|
|
|
{
|
|
|
|
// create password protected wallet
|
|
|
|
std::string wallet_pass = "password";
|
|
|
|
std::string wrong_wallet_pass = "1111";
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, wallet_pass, WALLET_LANG, true);
|
2016-08-22 08:53:07 -04:00
|
|
|
std::string seed1 = wallet1->seed();
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet *wallet2 = nullptr;
|
|
|
|
Monero::Wallet *wallet3 = nullptr;
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::mutex mutex;
|
2016-08-22 08:53:07 -04:00
|
|
|
|
2016-08-23 07:13:30 -04:00
|
|
|
open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr);
|
|
|
|
ASSERT_TRUE(wallet2 != nullptr);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet2->status() != Monero::Wallet::Status_Ok);
|
2016-08-22 08:53:07 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet2));
|
|
|
|
|
2016-08-23 07:13:30 -04:00
|
|
|
open_wallet_helper(wmgr, &wallet3, wallet_pass, nullptr);
|
|
|
|
ASSERT_TRUE(wallet3 != nullptr);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet3->status() == Monero::Wallet::Status_Ok);
|
2016-08-22 08:53:07 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet3));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-10 05:51:09 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-06-10 05:51:09 -04:00
|
|
|
std::string seed1 = wallet1->seed();
|
|
|
|
wallet1->store("");
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
|
|
|
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
|
2016-06-10 05:51:09 -04:00
|
|
|
ASSERT_TRUE(wallet2->seed() == seed1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WalletManagerTest, WalletManagerMovesWallet)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-06-10 05:51:09 -04:00
|
|
|
std::string WALLET_NAME_MOVED = std::string("/tmp/") + WALLET_NAME + ".moved";
|
|
|
|
std::string seed1 = wallet1->seed();
|
|
|
|
ASSERT_TRUE(wallet1->store(WALLET_NAME_MOVED));
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_MOVED, WALLET_PASS);
|
2016-06-10 05:51:09 -04:00
|
|
|
ASSERT_TRUE(wallet2->filename() == WALLET_NAME_MOVED);
|
|
|
|
ASSERT_TRUE(wallet2->keysFilename() == WALLET_NAME_MOVED + ".keys");
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
|
2016-06-10 05:51:09 -04:00
|
|
|
ASSERT_TRUE(wallet2->seed() == seed1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
|
2016-03-11 09:05:36 -05:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-11 09:05:36 -05:00
|
|
|
std::string seed1 = wallet1->seed();
|
|
|
|
ASSERT_TRUE(wallet1->setPassword(WALLET_PASS2));
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS2);
|
|
|
|
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
|
2016-03-11 09:05:36 -05:00
|
|
|
ASSERT_TRUE(wallet2->seed() == seed1);
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet2));
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
|
|
|
ASSERT_FALSE(wallet3->status() == Monero::Wallet::Status_Ok);
|
2016-03-11 09:05:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
|
2016-03-12 09:41:11 -05:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-12 09:41:11 -05:00
|
|
|
std::string seed1 = wallet1->seed();
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string address1 = wallet1->mainAddress();
|
2016-03-12 09:52:58 -05:00
|
|
|
ASSERT_FALSE(address1.empty());
|
2016-03-12 09:41:11 -05:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-03-31 05:48:41 -04:00
|
|
|
Utils::deleteWallet(WALLET_NAME);
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME, seed1);
|
|
|
|
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
|
2016-03-12 09:41:11 -05:00
|
|
|
ASSERT_TRUE(wallet2->seed() == seed1);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet2->mainAddress() == address1);
|
2016-03-12 09:41:11 -05:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet2));
|
|
|
|
}
|
|
|
|
|
2016-03-11 09:05:36 -05:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
|
2016-03-15 16:11:38 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-15 16:11:38 -04:00
|
|
|
std::string seed1 = wallet1->seed();
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string address1 = wallet1->mainAddress();
|
2016-03-15 16:11:38 -04:00
|
|
|
|
|
|
|
ASSERT_TRUE(wallet1->store(""));
|
|
|
|
ASSERT_TRUE(wallet1->store(WALLET_NAME_COPY));
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS);
|
|
|
|
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
|
2016-03-15 16:11:38 -04:00
|
|
|
ASSERT_TRUE(wallet2->seed() == seed1);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet2->mainAddress() == address1);
|
2016-03-15 16:11:38 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet2));
|
|
|
|
}
|
|
|
|
|
2016-03-21 09:17:03 -04:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
|
2016-03-15 16:11:38 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-15 16:11:38 -04:00
|
|
|
std::string seed1 = wallet1->seed();
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string address1 = wallet1->mainAddress();
|
2016-03-15 16:11:38 -04:00
|
|
|
|
|
|
|
ASSERT_TRUE(wallet1->store(WALLET_NAME_WITH_DIR));
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
|
|
|
|
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR, WALLET_PASS);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
|
2016-03-15 16:11:38 -04:00
|
|
|
ASSERT_TRUE(wallet1->seed() == seed1);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->mainAddress() == address1);
|
2016-03-15 16:11:38 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
}
|
|
|
|
|
2016-09-20 13:40:58 -04:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
|
2016-03-15 16:11:38 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-15 16:11:38 -04:00
|
|
|
std::string seed1 = wallet1->seed();
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string address1 = wallet1->mainAddress();
|
2016-03-15 16:11:38 -04:00
|
|
|
|
|
|
|
ASSERT_FALSE(wallet1->store(WALLET_NAME_WITH_DIR_NON_WRITABLE));
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
|
|
|
|
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_FALSE(wallet1->status() == Monero::Wallet::Status_Ok);
|
2016-03-15 16:11:38 -04:00
|
|
|
|
2016-09-20 13:40:58 -04:00
|
|
|
// "close" always returns true;
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-03-15 16:11:38 -04:00
|
|
|
|
|
|
|
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
|
2016-03-15 16:11:38 -04:00
|
|
|
ASSERT_TRUE(wallet1->seed() == seed1);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->mainAddress() == address1);
|
2016-03-15 16:11:38 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
|
|
|
|
}
|
2016-03-12 09:52:58 -05:00
|
|
|
|
2016-09-20 13:40:58 -04:00
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
|
2016-03-21 09:17:03 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
2016-03-21 09:17:03 -04:00
|
|
|
std::string seed1 = wallet1->seed();
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string address1 = wallet1->mainAddress();
|
2016-03-21 09:17:03 -04:00
|
|
|
|
|
|
|
ASSERT_TRUE(wallet1->store(""));
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
|
2016-03-21 09:17:03 -04:00
|
|
|
|
|
|
|
ASSERT_TRUE(wallet1->store(""));
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
|
2016-03-21 09:17:03 -04:00
|
|
|
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
|
|
|
|
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
|
2016-03-21 09:17:03 -04:00
|
|
|
ASSERT_TRUE(wallet1->seed() == seed1);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->mainAddress() == address1);
|
2016-03-21 09:17:03 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-03-25 10:06:30 -04:00
|
|
|
}
|
2016-03-31 05:48:41 -04:00
|
|
|
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-07-14 05:47:01 -04:00
|
|
|
|
|
|
|
|
2016-06-03 07:52:58 -04:00
|
|
|
TEST_F(WalletManagerTest, WalletManagerFindsWallet)
|
|
|
|
{
|
|
|
|
std::vector<std::string> wallets = wmgr->findWallets(WALLETS_ROOT_DIR);
|
|
|
|
ASSERT_FALSE(wallets.empty());
|
|
|
|
std::cout << "Found wallets: " << std::endl;
|
|
|
|
for (auto wallet_path: wallets) {
|
|
|
|
std::cout << wallet_path << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2016-03-25 10:06:30 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-09-22 12:07:12 -04:00
|
|
|
TEST_F(WalletTest1, WalletGeneratesPaymentId)
|
2016-06-23 07:38:22 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
std::string payment_id = Monero::Wallet::genPaymentId();
|
2016-06-23 07:38:22 -04:00
|
|
|
ASSERT_TRUE(payment_id.length() == 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-22 12:07:12 -04:00
|
|
|
TEST_F(WalletTest1, WalletGeneratesIntegratedAddress)
|
2016-06-23 07:38:22 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
std::string payment_id = Monero::Wallet::genPaymentId();
|
2016-06-23 07:38:22 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-06-23 07:38:22 -04:00
|
|
|
std::string integrated_address = wallet1->integratedAddress(payment_id);
|
|
|
|
ASSERT_TRUE(integrated_address.length() == 106);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletShowsBalance)
|
2016-03-25 10:06:30 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->balance(0) > 0);
|
|
|
|
ASSERT_TRUE(wallet1->unlockedBalance(0) > 0);
|
2016-03-25 10:06:30 -04:00
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
uint64_t balance1 = wallet1->balance(0);
|
|
|
|
uint64_t unlockedBalance1 = wallet1->unlockedBalance(0);
|
2016-03-25 10:06:30 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-03-31 05:48:41 -04:00
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(balance1 == wallet2->balance(0));
|
|
|
|
std::cout << "wallet balance: " << wallet2->balance(0) << std::endl;
|
|
|
|
ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0));
|
|
|
|
std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl;
|
2016-03-25 10:06:30 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet2));
|
2016-03-21 09:17:03 -04:00
|
|
|
}
|
|
|
|
|
2016-09-26 14:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight)
|
2016-09-23 15:36:37 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-09-23 15:36:37 -04:00
|
|
|
ASSERT_TRUE(wallet1->blockChainHeight() > 0);
|
|
|
|
wmgr->closeWallet(wallet1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 14:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletReturnsDaemonBlockHeight)
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-09-26 14:35:00 -04:00
|
|
|
// wallet not connected to daemon
|
|
|
|
ASSERT_TRUE(wallet1->daemonBlockChainHeight() == 0);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() != Monero::Wallet::Status_Ok);
|
2016-09-26 14:35:00 -04:00
|
|
|
ASSERT_FALSE(wallet1->errorString().empty());
|
|
|
|
wmgr->closeWallet(wallet1);
|
|
|
|
|
|
|
|
wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
|
|
|
// wallet connected to daemon
|
|
|
|
wallet1->init(TESTNET_DAEMON_ADDRESS, 0);
|
|
|
|
ASSERT_TRUE(wallet1->daemonBlockChainHeight() > 0);
|
|
|
|
std::cout << "daemonBlockChainHeight: " << wallet1->daemonBlockChainHeight() << std::endl;
|
|
|
|
wmgr->closeWallet(wallet1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletRefresh)
|
2016-03-31 09:38:57 -04:00
|
|
|
{
|
2016-09-22 13:32:57 -04:00
|
|
|
|
2016-10-06 08:45:43 -04:00
|
|
|
std::cout << "Opening wallet: " << CURRENT_SRC_WALLET << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-03-31 09:38:57 -04:00
|
|
|
// make sure testnet daemon is running
|
2016-10-06 08:45:43 -04:00
|
|
|
std::cout << "connecting to daemon: " << TESTNET_DAEMON_ADDRESS << std::endl;
|
2016-03-31 09:38:57 -04:00
|
|
|
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet1->refresh());
|
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
}
|
|
|
|
|
2016-06-16 09:42:33 -04:00
|
|
|
TEST_F(WalletTest1, WalletConvertsToString)
|
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
std::string strAmount = Monero::Wallet::displayAmount(AMOUNT_5XMR);
|
|
|
|
ASSERT_TRUE(AMOUNT_5XMR == Monero::Wallet::amountFromString(strAmount));
|
2016-06-16 09:42:33 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(AMOUNT_5XMR == Monero::Wallet::amountFromDouble(5.0));
|
|
|
|
ASSERT_TRUE(AMOUNT_10XMR == Monero::Wallet::amountFromDouble(10.0));
|
|
|
|
ASSERT_TRUE(AMOUNT_1XMR == Monero::Wallet::amountFromDouble(1.0));
|
2016-06-16 09:42:33 -04:00
|
|
|
|
|
|
|
}
|
2016-06-03 07:52:58 -04:00
|
|
|
|
2016-06-16 09:42:33 -04:00
|
|
|
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletTransaction)
|
2016-09-22 12:07:12 -04:00
|
|
|
|
2016-04-03 07:34:38 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-04-03 07:34:38 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet1->refresh());
|
2017-02-18 21:42:10 -05:00
|
|
|
uint64_t balance = wallet1->balance(0);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
|
2016-04-05 08:24:44 -04:00
|
|
|
|
2016-06-01 10:06:10 -04:00
|
|
|
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
|
2016-10-06 09:35:03 -04:00
|
|
|
const int MIXIN_COUNT = 4;
|
|
|
|
|
2016-06-01 10:06:10 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::PendingTransaction * transaction = wallet1->createTransaction(recepient_address,
|
2016-07-10 10:17:23 -04:00
|
|
|
PAYMENT_ID_EMPTY,
|
|
|
|
AMOUNT_10XMR,
|
2016-10-06 09:35:03 -04:00
|
|
|
MIXIN_COUNT,
|
2017-10-29 10:25:32 -04:00
|
|
|
Monero::PendingTransaction::Priority_Medium,
|
2017-02-18 21:42:10 -05:00
|
|
|
0,
|
2017-10-29 10:25:32 -04:00
|
|
|
std::set<uint32_t>{});
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
|
2016-06-01 10:06:10 -04:00
|
|
|
wallet1->refresh();
|
2016-04-29 09:26:14 -04:00
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->balance(0) == balance);
|
2016-04-05 08:24:44 -04:00
|
|
|
ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR);
|
|
|
|
ASSERT_TRUE(transaction->commit());
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_FALSE(wallet1->balance(0) == balance);
|
2016-04-03 07:34:38 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
}
|
2016-06-20 15:56:30 -04:00
|
|
|
|
2016-09-22 12:07:12 -04:00
|
|
|
|
|
|
|
|
2016-06-20 15:56:30 -04:00
|
|
|
TEST_F(WalletTest1, WalletTransactionWithMixin)
|
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<int> mixins;
|
|
|
|
// 2,3,4,5,6,7,8,9,10,15,20,25 can we do it like that?
|
|
|
|
mixins.push_back(2); mixins.push_back(3); mixins.push_back(4); mixins.push_back(5); mixins.push_back(6);
|
|
|
|
mixins.push_back(7); mixins.push_back(8); mixins.push_back(9); mixins.push_back(10); mixins.push_back(15);
|
|
|
|
mixins.push_back(20); mixins.push_back(25);
|
|
|
|
|
2016-06-23 07:38:22 -04:00
|
|
|
|
2016-06-23 09:23:09 -04:00
|
|
|
std::string payment_id = "";
|
2016-06-20 15:56:30 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-06-20 15:56:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet1->refresh());
|
2017-02-18 21:42:10 -05:00
|
|
|
uint64_t balance = wallet1->balance(0);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
|
2016-06-20 15:56:30 -04:00
|
|
|
|
|
|
|
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
|
|
|
|
for (auto mixin : mixins) {
|
|
|
|
std::cerr << "Transaction mixin count: " << mixin << std::endl;
|
2017-02-18 21:42:10 -05:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::PendingTransaction * transaction = wallet1->createTransaction(
|
2017-10-29 10:25:32 -04:00
|
|
|
recepient_address, payment_id, AMOUNT_5XMR, mixin, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
|
2016-06-20 15:56:30 -04:00
|
|
|
|
|
|
|
std::cerr << "Transaction status: " << transaction->status() << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
|
2016-06-20 15:56:30 -04:00
|
|
|
std::cerr << "Transaction error: " << transaction->errorString() << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
|
2016-06-20 15:56:30 -04:00
|
|
|
wallet1->disposeTransaction(transaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
wallet1->refresh();
|
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->balance(0) == balance);
|
2016-06-20 15:56:30 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
}
|
|
|
|
|
2016-06-27 07:55:13 -04:00
|
|
|
TEST_F(WalletTest1, WalletTransactionWithPriority)
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string payment_id = "";
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-06-27 07:55:13 -04:00
|
|
|
|
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet1->refresh());
|
2017-02-18 21:42:10 -05:00
|
|
|
uint64_t balance = wallet1->balance(0);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
|
2016-06-27 07:55:13 -04:00
|
|
|
|
|
|
|
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
|
|
|
|
uint32_t mixin = 2;
|
|
|
|
uint64_t fee = 0;
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
std::vector<Monero::PendingTransaction::Priority> priorities = {
|
|
|
|
Monero::PendingTransaction::Priority_Low,
|
|
|
|
Monero::PendingTransaction::Priority_Medium,
|
|
|
|
Monero::PendingTransaction::Priority_High
|
2016-06-27 07:55:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto it = priorities.begin(); it != priorities.end(); ++it) {
|
|
|
|
std::cerr << "Transaction priority: " << *it << std::endl;
|
2017-02-18 21:42:10 -05:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::PendingTransaction * transaction = wallet1->createTransaction(
|
2017-10-29 10:25:32 -04:00
|
|
|
recepient_address, payment_id, AMOUNT_5XMR, mixin, *it, 0, std::set<uint32_t>{});
|
2016-06-27 07:55:13 -04:00
|
|
|
std::cerr << "Transaction status: " << transaction->status() << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
|
2016-06-27 07:55:13 -04:00
|
|
|
std::cerr << "Transaction error: " << transaction->errorString() << std::endl;
|
|
|
|
ASSERT_TRUE(transaction->fee() > fee);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
|
2016-06-27 07:55:13 -04:00
|
|
|
fee = transaction->fee();
|
|
|
|
wallet1->disposeTransaction(transaction);
|
|
|
|
}
|
|
|
|
wallet1->refresh();
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet1->balance(0) == balance);
|
2016-06-27 07:55:13 -04:00
|
|
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletHistory)
|
2016-04-22 06:21:08 -04:00
|
|
|
{
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-04-22 06:21:08 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet1->refresh());
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::TransactionHistory * history = wallet1->history();
|
2016-04-22 06:21:08 -04:00
|
|
|
history->refresh();
|
|
|
|
ASSERT_TRUE(history->count() > 0);
|
|
|
|
|
2016-04-29 09:26:14 -04:00
|
|
|
|
|
|
|
for (auto t: history->getAll()) {
|
|
|
|
ASSERT_TRUE(t != nullptr);
|
2016-05-16 06:11:44 -04:00
|
|
|
Utils::print_transaction(t);
|
2016-04-29 09:26:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 06:35:00 -04:00
|
|
|
TEST_F(WalletTest1, WalletTransactionAndHistory)
|
2016-04-29 09:26:14 -04:00
|
|
|
{
|
2016-06-01 10:06:10 -04:00
|
|
|
return;
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-04-29 09:26:14 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_src->refresh());
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::TransactionHistory * history = wallet_src->history();
|
2016-04-29 09:26:14 -04:00
|
|
|
history->refresh();
|
|
|
|
ASSERT_TRUE(history->count() > 0);
|
|
|
|
size_t count1 = history->count();
|
|
|
|
|
|
|
|
std::cout << "**** Transactions before transfer (" << count1 << ")" << std::endl;
|
|
|
|
for (auto t: history->getAll()) {
|
|
|
|
ASSERT_TRUE(t != nullptr);
|
2016-05-16 06:11:44 -04:00
|
|
|
Utils::print_transaction(t);
|
2016-04-29 09:26:14 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 10:06:10 -04:00
|
|
|
std::string wallet4_addr = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
|
|
|
|
|
2016-06-23 09:23:09 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
|
2016-06-23 07:38:22 -04:00
|
|
|
PAYMENT_ID_EMPTY,
|
2017-10-29 10:25:32 -04:00
|
|
|
AMOUNT_10XMR * 5, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
|
2016-06-23 09:23:09 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
2016-06-23 07:38:22 -04:00
|
|
|
ASSERT_TRUE(tx->commit());
|
|
|
|
history = wallet_src->history();
|
|
|
|
history->refresh();
|
|
|
|
ASSERT_TRUE(count1 != history->count());
|
|
|
|
|
|
|
|
std::cout << "**** Transactions after transfer (" << history->count() << ")" << std::endl;
|
|
|
|
for (auto t: history->getAll()) {
|
|
|
|
ASSERT_TRUE(t != nullptr);
|
|
|
|
Utils::print_transaction(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 09:23:09 -04:00
|
|
|
|
2016-06-23 07:38:22 -04:00
|
|
|
TEST_F(WalletTest1, WalletTransactionWithPaymentId)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-06-23 07:38:22 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_src->refresh());
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::TransactionHistory * history = wallet_src->history();
|
2016-06-23 07:38:22 -04:00
|
|
|
history->refresh();
|
|
|
|
ASSERT_TRUE(history->count() > 0);
|
|
|
|
size_t count1 = history->count();
|
|
|
|
|
|
|
|
std::cout << "**** Transactions before transfer (" << count1 << ")" << std::endl;
|
|
|
|
for (auto t: history->getAll()) {
|
|
|
|
ASSERT_TRUE(t != nullptr);
|
|
|
|
Utils::print_transaction(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string wallet4_addr = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
std::string payment_id = Monero::Wallet::genPaymentId();
|
2016-06-23 07:38:22 -04:00
|
|
|
ASSERT_TRUE(payment_id.length() == 16);
|
|
|
|
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
|
2016-06-23 07:38:22 -04:00
|
|
|
payment_id,
|
2017-10-29 10:25:32 -04:00
|
|
|
AMOUNT_1XMR, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
|
2016-06-23 07:38:22 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
2016-04-29 09:26:14 -04:00
|
|
|
ASSERT_TRUE(tx->commit());
|
|
|
|
history = wallet_src->history();
|
|
|
|
history->refresh();
|
|
|
|
ASSERT_TRUE(count1 != history->count());
|
|
|
|
|
2016-06-23 07:38:22 -04:00
|
|
|
bool payment_id_in_history = false;
|
|
|
|
|
2016-04-29 09:26:14 -04:00
|
|
|
std::cout << "**** Transactions after transfer (" << history->count() << ")" << std::endl;
|
2016-04-22 06:21:08 -04:00
|
|
|
for (auto t: history->getAll()) {
|
|
|
|
ASSERT_TRUE(t != nullptr);
|
2016-05-16 06:11:44 -04:00
|
|
|
Utils::print_transaction(t);
|
2016-06-23 07:38:22 -04:00
|
|
|
if (t->paymentId() == payment_id) {
|
|
|
|
payment_id_in_history = true;
|
|
|
|
}
|
2016-04-22 06:21:08 -04:00
|
|
|
}
|
2016-06-23 07:38:22 -04:00
|
|
|
|
|
|
|
ASSERT_TRUE(payment_id_in_history);
|
2016-04-22 06:21:08 -04:00
|
|
|
}
|
2016-07-14 05:47:01 -04:00
|
|
|
|
2016-04-22 06:21:08 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
struct MyWalletListener : public Monero::WalletListener
|
2016-05-16 06:11:44 -04:00
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet;
|
2016-05-16 06:11:44 -04:00
|
|
|
uint64_t total_tx;
|
|
|
|
uint64_t total_rx;
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::mutex mutex;
|
|
|
|
boost::condition_variable cv_send;
|
|
|
|
boost::condition_variable cv_receive;
|
|
|
|
boost::condition_variable cv_update;
|
|
|
|
boost::condition_variable cv_refresh;
|
|
|
|
boost::condition_variable cv_newblock;
|
2016-07-14 05:47:01 -04:00
|
|
|
bool send_triggered;
|
|
|
|
bool receive_triggered;
|
2016-09-23 15:36:37 -04:00
|
|
|
bool newblock_triggered;
|
2016-07-14 05:47:01 -04:00
|
|
|
bool update_triggered;
|
|
|
|
bool refresh_triggered;
|
|
|
|
|
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
MyWalletListener(Monero::Wallet * wallet)
|
2016-05-16 06:11:44 -04:00
|
|
|
: total_tx(0), total_rx(0)
|
|
|
|
{
|
2016-07-14 05:47:01 -04:00
|
|
|
reset();
|
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
this->wallet = wallet;
|
|
|
|
this->wallet->setListener(this);
|
|
|
|
}
|
|
|
|
|
2016-07-14 05:47:01 -04:00
|
|
|
void reset()
|
|
|
|
{
|
2017-09-09 07:13:26 -04:00
|
|
|
send_triggered = receive_triggered = newblock_triggered = update_triggered = refresh_triggered = false;
|
2016-07-14 05:47:01 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
virtual void moneySpent(const string &txId, uint64_t amount)
|
|
|
|
{
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cerr << "wallet: " << wallet->mainAddress() << "**** just spent money ("
|
2016-05-16 06:11:44 -04:00
|
|
|
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
|
|
|
total_tx += amount;
|
2016-07-14 05:47:01 -04:00
|
|
|
send_triggered = true;
|
|
|
|
cv_send.notify_one();
|
2016-05-16 06:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void moneyReceived(const string &txId, uint64_t amount)
|
|
|
|
{
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "wallet: " << wallet->mainAddress() << "**** just received money ("
|
2016-05-16 06:11:44 -04:00
|
|
|
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
|
|
|
total_rx += amount;
|
2016-07-14 05:47:01 -04:00
|
|
|
receive_triggered = true;
|
|
|
|
cv_receive.notify_one();
|
2016-05-16 06:11:44 -04:00
|
|
|
}
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2017-01-12 12:23:23 -05:00
|
|
|
virtual void unconfirmedMoneyReceived(const string &txId, uint64_t amount)
|
|
|
|
{
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "wallet: " << wallet->mainAddress() << "**** just received unconfirmed money ("
|
2017-01-12 12:23:23 -05:00
|
|
|
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
|
|
|
// Don't trigger recieve until tx is mined
|
|
|
|
// total_rx += amount;
|
|
|
|
// receive_triggered = true;
|
|
|
|
// cv_receive.notify_one();
|
|
|
|
}
|
|
|
|
|
2016-09-23 15:36:37 -04:00
|
|
|
virtual void newBlock(uint64_t height)
|
|
|
|
{
|
2017-02-18 21:42:10 -05:00
|
|
|
// std::cout << "wallet: " << wallet->mainAddress()
|
2016-09-29 19:11:28 -04:00
|
|
|
// <<", new block received, blockHeight: " << height << std::endl;
|
|
|
|
static int bc_height = wallet->daemonBlockChainHeight();
|
|
|
|
std::cout << height
|
|
|
|
<< " / " << bc_height/* 0*/
|
|
|
|
<< std::endl;
|
2016-09-23 15:36:37 -04:00
|
|
|
newblock_triggered = true;
|
|
|
|
cv_newblock.notify_one();
|
|
|
|
}
|
|
|
|
|
2016-07-10 10:17:23 -04:00
|
|
|
virtual void updated()
|
|
|
|
{
|
2016-07-14 05:47:01 -04:00
|
|
|
std::cout << __FUNCTION__ << "Wallet updated";
|
|
|
|
update_triggered = true;
|
|
|
|
cv_update.notify_one();
|
2016-07-10 10:17:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void refreshed()
|
|
|
|
{
|
2016-07-14 05:47:01 -04:00
|
|
|
std::cout << __FUNCTION__ << "Wallet refreshed";
|
|
|
|
refresh_triggered = true;
|
|
|
|
cv_refresh.notify_one();
|
2016-07-10 10:17:23 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
};
|
|
|
|
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-09-22 12:07:12 -04:00
|
|
|
|
|
|
|
|
2016-07-14 05:47:01 -04:00
|
|
|
TEST_F(WalletTest2, WalletCallBackRefreshedSync)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-07-14 05:47:01 -04:00
|
|
|
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
|
|
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
|
|
|
|
ASSERT_TRUE(wallet_src->connected());
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
|
2016-09-20 13:40:58 -04:00
|
|
|
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
2016-07-14 05:47:01 -04:00
|
|
|
wmgr->closeWallet(wallet_src);
|
|
|
|
}
|
2016-09-22 12:07:12 -04:00
|
|
|
|
|
|
|
|
2016-07-14 05:47:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-07-14 05:47:01 -04:00
|
|
|
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(20);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
|
2017-01-30 14:31:19 -05:00
|
|
|
wallet_src->init(MAINNET_DAEMON_ADDRESS, 0);
|
|
|
|
wallet_src->startRefresh();
|
2016-07-14 05:47:01 -04:00
|
|
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
|
|
|
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
|
|
|
std::cerr << "TEST: refresh lock acquired...\n";
|
|
|
|
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
|
|
|
|
ASSERT_TRUE(wallet_src->connected());
|
|
|
|
std::cerr << "TEST: closing wallet...\n";
|
|
|
|
wmgr->closeWallet(wallet_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-09-27 18:36:49 -04:00
|
|
|
|
2016-05-16 06:11:44 -04:00
|
|
|
TEST_F(WalletTest2, WalletCallbackSent)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-05-16 06:11:44 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_src->refresh());
|
|
|
|
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
2017-02-18 21:42:10 -05:00
|
|
|
uint64_t balance = wallet_src->balance(0);
|
|
|
|
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl;
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
|
2016-07-10 10:17:23 -04:00
|
|
|
|
|
|
|
uint64_t amount = AMOUNT_1XMR * 5;
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress();
|
2016-05-16 06:11:44 -04:00
|
|
|
|
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(),
|
2016-07-10 10:17:23 -04:00
|
|
|
PAYMENT_ID_EMPTY,
|
2017-10-29 10:25:32 -04:00
|
|
|
amount, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
|
2016-12-13 10:21:38 -05:00
|
|
|
std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
|
|
|
|
<< " with fee: " << Monero::Wallet::displayAmount(tx->fee());
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
2016-05-16 06:11:44 -04:00
|
|
|
ASSERT_TRUE(tx->commit());
|
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
|
2016-07-14 05:47:01 -04:00
|
|
|
std::cerr << "TEST: waiting on send lock...\n";
|
|
|
|
wallet_src_listener->cv_send.wait_for(lock, wait_for);
|
|
|
|
std::cerr << "TEST: send lock acquired...\n";
|
|
|
|
ASSERT_TRUE(wallet_src_listener->send_triggered);
|
|
|
|
ASSERT_TRUE(wallet_src_listener->update_triggered);
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl;
|
|
|
|
ASSERT_TRUE(wallet_src->balance(0) < balance);
|
2016-07-10 10:17:23 -04:00
|
|
|
wmgr->closeWallet(wallet_src);
|
|
|
|
wmgr->closeWallet(wallet_dst);
|
2016-05-17 05:16:11 -04:00
|
|
|
}
|
|
|
|
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-05-17 05:16:11 -04:00
|
|
|
TEST_F(WalletTest2, WalletCallbackReceived)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
2016-05-17 05:16:11 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_src->refresh());
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "** Balance src1: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl;
|
2016-05-17 05:16:11 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
|
2016-05-17 05:16:11 -04:00
|
|
|
ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_dst->refresh());
|
2017-02-18 21:42:10 -05:00
|
|
|
uint64_t balance = wallet_dst->balance(0);
|
|
|
|
std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl;
|
2016-10-01 14:04:49 -04:00
|
|
|
std::unique_ptr<MyWalletListener> wallet_dst_listener (new MyWalletListener(wallet_dst));
|
2016-05-17 05:16:11 -04:00
|
|
|
|
|
|
|
uint64_t amount = AMOUNT_1XMR * 5;
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress();
|
|
|
|
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(),
|
2016-07-10 10:17:23 -04:00
|
|
|
PAYMENT_ID_EMPTY,
|
2017-10-29 10:25:32 -04:00
|
|
|
amount, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
|
|
|
|
<< " with fee: " << Monero::Wallet::displayAmount(tx->fee());
|
2016-07-10 10:17:23 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
2016-05-17 05:16:11 -04:00
|
|
|
ASSERT_TRUE(tx->commit());
|
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_dst_listener->mutex);
|
2016-07-14 05:47:01 -04:00
|
|
|
std::cerr << "TEST: waiting on receive lock...\n";
|
|
|
|
wallet_dst_listener->cv_receive.wait_for(lock, wait_for);
|
|
|
|
std::cerr << "TEST: receive lock acquired...\n";
|
|
|
|
ASSERT_TRUE(wallet_dst_listener->receive_triggered);
|
|
|
|
ASSERT_TRUE(wallet_dst_listener->update_triggered);
|
2016-09-27 17:02:35 -04:00
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
std::cout << "** Balance src2: " << wallet_dst->displayAmount(wallet_src->balance(0)) << std::endl;
|
|
|
|
std::cout << "** Balance dst2: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl;
|
2016-09-27 17:02:35 -04:00
|
|
|
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet_dst->balance(0) > balance);
|
2016-07-10 10:17:23 -04:00
|
|
|
|
|
|
|
wmgr->closeWallet(wallet_src);
|
|
|
|
wmgr->closeWallet(wallet_dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-23 15:36:37 -04:00
|
|
|
|
|
|
|
TEST_F(WalletTest2, WalletCallbackNewBlock)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET5_NAME, TESTNET_WALLET_PASS, true);
|
2016-09-23 15:36:37 -04:00
|
|
|
// make sure testnet daemon is running
|
|
|
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
|
|
|
ASSERT_TRUE(wallet_src->refresh());
|
2016-09-27 16:45:03 -04:00
|
|
|
uint64_t bc1 = wallet_src->blockChainHeight();
|
2016-09-23 15:36:37 -04:00
|
|
|
std::cout << "** Block height: " << bc1 << std::endl;
|
|
|
|
|
|
|
|
|
2016-10-01 14:04:49 -04:00
|
|
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet_src));
|
2016-09-23 15:36:37 -04:00
|
|
|
|
|
|
|
// wait max 4 min for new block
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
2016-09-23 15:36:37 -04:00
|
|
|
std::cerr << "TEST: waiting on newblock lock...\n";
|
|
|
|
wallet_listener->cv_newblock.wait_for(lock, wait_for);
|
|
|
|
std::cerr << "TEST: newblock lock acquired...\n";
|
|
|
|
ASSERT_TRUE(wallet_listener->newblock_triggered);
|
2016-09-27 16:45:03 -04:00
|
|
|
uint64_t bc2 = wallet_src->blockChainHeight();
|
2016-09-23 15:36:37 -04:00
|
|
|
std::cout << "** Block height: " << bc2 << std::endl;
|
|
|
|
ASSERT_TRUE(bc2 > bc1);
|
|
|
|
wmgr->closeWallet(wallet_src);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:11:28 -04:00
|
|
|
TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetSync)
|
|
|
|
{
|
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
|
2016-10-01 14:04:49 -04:00
|
|
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
2016-09-29 19:11:28 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 15:42:15 -04:00
|
|
|
TEST_F(WalletManagerMainnetTest, CreateAndRefreshWalletMainNetAsync)
|
2016-09-27 18:36:49 -04:00
|
|
|
{
|
2016-10-01 14:04:49 -04:00
|
|
|
// supposing 120 seconds should be enough for fast refresh
|
|
|
|
int SECONDS_TO_REFRESH = 120;
|
2016-09-27 18:36:49 -04:00
|
|
|
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
|
2016-10-01 14:04:49 -04:00
|
|
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
2017-01-30 14:31:19 -05:00
|
|
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
|
|
|
wallet->startRefresh();
|
2016-09-27 18:36:49 -04:00
|
|
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
|
|
|
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
|
|
|
std::cerr << "TEST: refresh lock acquired...\n";
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
2016-09-27 18:36:49 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:42:15 -04:00
|
|
|
TEST_F(WalletManagerMainnetTest, OpenAndRefreshWalletMainNetAsync)
|
|
|
|
{
|
|
|
|
|
2016-10-01 14:04:49 -04:00
|
|
|
// supposing 120 seconds should be enough for fast refresh
|
|
|
|
int SECONDS_TO_REFRESH = 120;
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
|
2016-09-30 15:42:15 -04:00
|
|
|
wmgr->closeWallet(wallet);
|
|
|
|
wallet = wmgr->openWallet(WALLET_NAME_MAINNET, "");
|
|
|
|
|
2016-10-01 14:04:49 -04:00
|
|
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
|
|
|
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
2017-01-30 14:31:19 -05:00
|
|
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
|
|
|
wallet->startRefresh();
|
2016-09-30 15:42:15 -04:00
|
|
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
|
|
|
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
|
|
|
std::cerr << "TEST: refresh lock acquired...\n";
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
2016-09-30 15:42:15 -04:00
|
|
|
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);
|
2016-10-01 14:04:49 -04:00
|
|
|
|
2016-09-30 15:42:15 -04:00
|
|
|
}
|
|
|
|
|
2016-10-01 14:04:49 -04:00
|
|
|
TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync)
|
|
|
|
{
|
|
|
|
|
|
|
|
// supposing 120 seconds should be enough for fast refresh
|
|
|
|
int SECONDS_TO_REFRESH = 120;
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
|
2016-10-01 14:04:49 -04:00
|
|
|
std::string seed = wallet->seed();
|
2017-02-18 21:42:10 -05:00
|
|
|
std::string address = wallet->mainAddress();
|
2016-10-01 14:04:49 -04:00
|
|
|
wmgr->closeWallet(wallet);
|
|
|
|
|
|
|
|
// deleting wallet files
|
|
|
|
Utils::deleteWallet(WALLET_NAME_MAINNET);
|
|
|
|
// ..and recovering wallet from seed
|
|
|
|
|
|
|
|
wallet = wmgr->recoveryWallet(WALLET_NAME_MAINNET, seed);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
2017-02-18 21:42:10 -05:00
|
|
|
ASSERT_TRUE(wallet->mainAddress() == address);
|
2016-10-01 14:04:49 -04:00
|
|
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
2017-02-12 17:53:13 -05:00
|
|
|
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
|
|
|
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
2017-01-30 14:31:19 -05:00
|
|
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
|
|
|
wallet->startRefresh();
|
2016-10-01 14:04:49 -04:00
|
|
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
|
|
|
|
|
|
|
// here we wait for 120 seconds and test if wallet doesn't syncrnonize blockchain completely,
|
|
|
|
// as it needs much more than 120 seconds for mainnet
|
|
|
|
|
|
|
|
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
2016-12-13 10:21:38 -05:00
|
|
|
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
2016-10-01 14:04:49 -04:00
|
|
|
ASSERT_FALSE(wallet_listener->refresh_triggered);
|
|
|
|
ASSERT_TRUE(wallet->connected());
|
|
|
|
ASSERT_FALSE(wallet->blockChainHeight() == wallet->daemonBlockChainHeight());
|
|
|
|
std::cerr << "TEST: closing wallet...\n";
|
|
|
|
wmgr->closeWallet(wallet);
|
|
|
|
std::cerr << "TEST: wallet closed\n";
|
|
|
|
|
|
|
|
}
|
2016-09-30 15:42:15 -04:00
|
|
|
|
2016-09-23 15:36:37 -04:00
|
|
|
|
|
|
|
|
2016-02-20 11:04:56 -05:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2017-10-21 05:09:51 -04:00
|
|
|
tools::on_startup();
|
2016-09-22 13:32:57 -04:00
|
|
|
// we can override default values for "TESTNET_DAEMON_ADDRESS" and "WALLETS_ROOT_DIR"
|
|
|
|
|
2016-09-27 18:36:49 -04:00
|
|
|
const char * testnet_daemon_addr = std::getenv("TESTNET_DAEMON_ADDRESS");
|
|
|
|
if (testnet_daemon_addr) {
|
|
|
|
TESTNET_DAEMON_ADDRESS = testnet_daemon_addr;
|
2016-09-22 13:32:57 -04:00
|
|
|
}
|
|
|
|
|
2016-09-27 18:36:49 -04:00
|
|
|
const char * mainnet_daemon_addr = std::getenv("MAINNET_DAEMON_ADDRESS");
|
|
|
|
if (mainnet_daemon_addr) {
|
|
|
|
MAINNET_DAEMON_ADDRESS = mainnet_daemon_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-09-22 13:32:57 -04:00
|
|
|
const char * wallets_root_dir = std::getenv("WALLETS_ROOT_DIR");
|
|
|
|
if (wallets_root_dir) {
|
|
|
|
WALLETS_ROOT_DIR = wallets_root_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TESTNET_WALLET1_NAME = WALLETS_ROOT_DIR + "/wallet_01.bin";
|
|
|
|
TESTNET_WALLET2_NAME = WALLETS_ROOT_DIR + "/wallet_02.bin";
|
|
|
|
TESTNET_WALLET3_NAME = WALLETS_ROOT_DIR + "/wallet_03.bin";
|
|
|
|
TESTNET_WALLET4_NAME = WALLETS_ROOT_DIR + "/wallet_04.bin";
|
|
|
|
TESTNET_WALLET5_NAME = WALLETS_ROOT_DIR + "/wallet_05.bin";
|
|
|
|
TESTNET_WALLET6_NAME = WALLETS_ROOT_DIR + "/wallet_06.bin";
|
|
|
|
|
2016-10-06 08:45:43 -04:00
|
|
|
CURRENT_SRC_WALLET = TESTNET_WALLET5_NAME;
|
|
|
|
CURRENT_DST_WALLET = TESTNET_WALLET1_NAME;
|
2016-09-22 13:32:57 -04:00
|
|
|
|
2016-07-14 05:47:01 -04:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
2016-12-13 10:21:38 -05:00
|
|
|
Monero::WalletManagerFactory::setLogLevel(Monero::WalletManagerFactory::LogLevel_Max);
|
2016-07-14 05:47:01 -04:00
|
|
|
return RUN_ALL_TESTS();
|
2016-02-20 11:04:56 -05:00
|
|
|
}
|