aboutsummaryrefslogtreecommitdiff
path: root/tests/libwallet_api_tests/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libwallet_api_tests/main.cpp')
-rw-r--r--tests/libwallet_api_tests/main.cpp475
1 files changed, 314 insertions, 161 deletions
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index 87e0cc935..bf0483b0f 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2016, The Monero Project
+// Copyright (c) 2014-2017, The Monero Project
//
// All rights reserved.
//
@@ -34,18 +34,19 @@
#include "wallet/wallet2.h"
#include "include_base_utils.h"
+#include <boost/chrono/chrono.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/thread/condition_variable.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
#include <iostream>
#include <vector>
-#include <mutex>
-#include <thread>
#include <atomic>
#include <functional>
-#include <condition_variable>
using namespace std;
@@ -58,6 +59,7 @@ namespace Consts
// TODO: get rid of hardcoded paths
const char * WALLET_NAME = "testwallet";
+const char * WALLET_NAME_MAINNET = "testwallet_mainnet";
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";
@@ -85,6 +87,7 @@ const uint64_t AMOUNT_1XMR = 1000000000000L;
const std::string PAYMENT_ID_EMPTY = "";
std::string TESTNET_DAEMON_ADDRESS = "localhost:38081";
+std::string MAINNET_DAEMON_ADDRESS = "localhost:18081";
}
@@ -109,15 +112,15 @@ struct Utils
boost::filesystem::remove_all(path);
}
- static void print_transaction(Bitmonero::TransactionInfo * t)
+ static void print_transaction(Monero::TransactionInfo * t)
{
std::cout << "d: "
- << (t->direction() == Bitmonero::TransactionInfo::Direction_In ? "in" : "out")
+ << (t->direction() == Monero::TransactionInfo::Direction_In ? "in" : "out")
<< ", pe: " << (t->isPending() ? "true" : "false")
<< ", bh: " << t->blockHeight()
- << ", a: " << Bitmonero::Wallet::displayAmount(t->amount())
- << ", f: " << Bitmonero::Wallet::displayAmount(t->fee())
+ << ", a: " << Monero::Wallet::displayAmount(t->amount())
+ << ", f: " << Monero::Wallet::displayAmount(t->fee())
<< ", h: " << t->hash()
<< ", pid: " << t->paymentId()
<< std::endl;
@@ -125,8 +128,8 @@ struct Utils
static std::string get_wallet_address(const std::string &filename, const std::string &password)
{
- Bitmonero::WalletManager *wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
- Bitmonero::Wallet * w = wmgr->openWallet(filename, password, true);
+ Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager();
+ Monero::Wallet * w = wmgr->openWallet(filename, password, true);
std::string result = w->address();
wmgr->closeWallet(w);
return result;
@@ -136,14 +139,14 @@ struct Utils
struct WalletManagerTest : public testing::Test
{
- Bitmonero::WalletManager * wmgr;
+ Monero::WalletManager * wmgr;
WalletManagerTest()
{
std::cout << __FUNCTION__ << std::endl;
- wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
- // Bitmonero::WalletManagerFactory::setLogLevel(Bitmonero::WalletManagerFactory::LogLevel_4);
+ wmgr = Monero::WalletManagerFactory::getWalletManager();
+ // Monero::WalletManagerFactory::setLogLevel(Monero::WalletManagerFactory::LogLevel_4);
Utils::deleteWallet(WALLET_NAME);
Utils::deleteDir(boost::filesystem::path(WALLET_NAME_WITH_DIR).parent_path().string());
}
@@ -157,14 +160,33 @@ struct WalletManagerTest : public testing::Test
};
+struct WalletManagerMainnetTest : public testing::Test
+{
+ Monero::WalletManager * wmgr;
+
+
+ WalletManagerMainnetTest()
+ {
+ std::cout << __FUNCTION__ << std::endl;
+ wmgr = Monero::WalletManagerFactory::getWalletManager();
+ Utils::deleteWallet(WALLET_NAME_MAINNET);
+ }
+
+
+ ~WalletManagerMainnetTest()
+ {
+ std::cout << __FUNCTION__ << std::endl;
+ }
+
+};
struct WalletTest1 : public testing::Test
{
- Bitmonero::WalletManager * wmgr;
+ Monero::WalletManager * wmgr;
WalletTest1()
{
- wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
+ wmgr = Monero::WalletManagerFactory::getWalletManager();
}
@@ -173,11 +195,11 @@ struct WalletTest1 : public testing::Test
struct WalletTest2 : public testing::Test
{
- Bitmonero::WalletManager * wmgr;
+ Monero::WalletManager * wmgr;
WalletTest2()
{
- wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
+ wmgr = Monero::WalletManagerFactory::getWalletManager();
}
};
@@ -185,8 +207,8 @@ struct WalletTest2 : public testing::Test
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
{
- Bitmonero::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
- ASSERT_TRUE(wallet->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(!wallet->seed().empty());
std::vector<std::string> words;
std::string seed = wallet->seed();
@@ -202,11 +224,11 @@ TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
TEST_F(WalletManagerTest, WalletManagerOpensWallet)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
ASSERT_TRUE(wmgr->closeWallet(wallet1));
- Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
- ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
+ ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
std::cout << "** seed: " << wallet2->seed() << std::endl;
}
@@ -214,34 +236,34 @@ TEST_F(WalletManagerTest, WalletManagerOpensWallet)
TEST_F(WalletManagerTest, WalletMaxAmountAsString)
{
- LOG_PRINT_L3("max amount: " << Bitmonero::Wallet::displayAmount(
- Bitmonero::Wallet::maximumAllowedAmount()));
+ LOG_PRINT_L3("max amount: " << Monero::Wallet::displayAmount(
+ Monero::Wallet::maximumAllowedAmount()));
}
TEST_F(WalletManagerTest, WalletAmountFromString)
{
- uint64_t amount = Bitmonero::Wallet::amountFromString("18446740");
+ uint64_t amount = Monero::Wallet::amountFromString("18446740");
ASSERT_TRUE(amount > 0);
- amount = Bitmonero::Wallet::amountFromString("11000000000000");
+ amount = Monero::Wallet::amountFromString("11000000000000");
ASSERT_FALSE(amount > 0);
- amount = Bitmonero::Wallet::amountFromString("0.0");
+ amount = Monero::Wallet::amountFromString("0.0");
ASSERT_FALSE(amount > 0);
- amount = Bitmonero::Wallet::amountFromString("10.1");
+ amount = Monero::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)
+void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, const std::string &pass, boost::mutex *mutex)
{
if (mutex)
mutex->lock();
- LOG_PRINT_L3("opening wallet in thread: " << std::this_thread::get_id());
+ LOG_PRINT_L3("opening wallet in thread: " << boost::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());
+ LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id());
if (mutex)
mutex->unlock();
}
@@ -254,23 +276,23 @@ void open_wallet_helper(Bitmonero::WalletManager *wmgr, Bitmonero::Wallet **wall
// // 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);
+// Monero::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;
+// Monero::Wallet *wallet2 = nullptr;
+// Monero::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(wallet2->status() != Monero::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(wallet3->status() == Monero::Wallet::Status_Ok);
// ASSERT_TRUE(wmgr->closeWallet(wallet3));
//}
@@ -280,22 +302,22 @@ 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);
+ Monero::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;
+ Monero::Wallet *wallet2 = nullptr;
+ Monero::Wallet *wallet3 = nullptr;
+ boost::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(wallet2->status() != Monero::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(wallet3->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wmgr->closeWallet(wallet3));
}
@@ -303,12 +325,12 @@ TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen)
TEST_F(WalletManagerTest, WalletManagerStoresWallet)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
wallet1->store("");
ASSERT_TRUE(wmgr->closeWallet(wallet1));
- Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
- ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
+ ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
}
@@ -316,45 +338,45 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet)
TEST_F(WalletManagerTest, WalletManagerMovesWallet)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string WALLET_NAME_MOVED = std::string("/tmp/") + WALLET_NAME + ".moved";
std::string seed1 = wallet1->seed();
ASSERT_TRUE(wallet1->store(WALLET_NAME_MOVED));
- Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_MOVED, WALLET_PASS);
+ Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_MOVED, WALLET_PASS);
ASSERT_TRUE(wallet2->filename() == WALLET_NAME_MOVED);
ASSERT_TRUE(wallet2->keysFilename() == WALLET_NAME_MOVED + ".keys");
- ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
}
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
ASSERT_TRUE(wallet1->setPassword(WALLET_PASS2));
ASSERT_TRUE(wmgr->closeWallet(wallet1));
- Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS2);
- ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS2);
+ ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
ASSERT_TRUE(wmgr->closeWallet(wallet2));
- Bitmonero::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
- ASSERT_FALSE(wallet3->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
+ ASSERT_FALSE(wallet3->status() == Monero::Wallet::Status_Ok);
}
TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
std::string address1 = wallet1->address();
ASSERT_FALSE(address1.empty());
ASSERT_TRUE(wmgr->closeWallet(wallet1));
Utils::deleteWallet(WALLET_NAME);
- Bitmonero::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME, seed1);
- ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME, seed1);
+ ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
ASSERT_TRUE(wallet2->address() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet2));
@@ -363,15 +385,15 @@ TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
std::string address1 = wallet1->address();
ASSERT_TRUE(wallet1->store(""));
ASSERT_TRUE(wallet1->store(WALLET_NAME_COPY));
ASSERT_TRUE(wmgr->closeWallet(wallet1));
- Bitmonero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS);
- ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
+ Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS);
+ ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
ASSERT_TRUE(wallet2->address() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet2));
@@ -380,7 +402,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
std::string address1 = wallet1->address();
@@ -388,7 +410,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
ASSERT_TRUE(wmgr->closeWallet(wallet1));
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR, WALLET_PASS);
- ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->seed() == seed1);
ASSERT_TRUE(wallet1->address() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
@@ -397,7 +419,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
std::string address1 = wallet1->address();
@@ -405,13 +427,13 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
ASSERT_TRUE(wmgr->closeWallet(wallet1));
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
- ASSERT_FALSE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_FALSE(wallet1->status() == Monero::Wallet::Status_Ok);
// "close" always returns true;
ASSERT_TRUE(wmgr->closeWallet(wallet1));
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
- ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->seed() == seed1);
ASSERT_TRUE(wallet1->address() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
@@ -421,20 +443,20 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
{
- Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
std::string address1 = wallet1->address();
ASSERT_TRUE(wallet1->store(""));
- ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->store(""));
- ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
- ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->seed() == seed1);
ASSERT_TRUE(wallet1->address() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
@@ -456,16 +478,16 @@ TEST_F(WalletManagerTest, WalletManagerFindsWallet)
TEST_F(WalletTest1, WalletGeneratesPaymentId)
{
- std::string payment_id = Bitmonero::Wallet::genPaymentId();
+ std::string payment_id = Monero::Wallet::genPaymentId();
ASSERT_TRUE(payment_id.length() == 16);
}
TEST_F(WalletTest1, WalletGeneratesIntegratedAddress)
{
- std::string payment_id = Bitmonero::Wallet::genPaymentId();
+ std::string payment_id = Monero::Wallet::genPaymentId();
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
std::string integrated_address = wallet1->integratedAddress(payment_id);
ASSERT_TRUE(integrated_address.length() == 106);
}
@@ -473,14 +495,14 @@ TEST_F(WalletTest1, WalletGeneratesIntegratedAddress)
TEST_F(WalletTest1, WalletShowsBalance)
{
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
ASSERT_TRUE(wallet1->balance() > 0);
ASSERT_TRUE(wallet1->unlockedBalance() > 0);
uint64_t balance1 = wallet1->balance();
uint64_t unlockedBalance1 = wallet1->unlockedBalance();
ASSERT_TRUE(wmgr->closeWallet(wallet1));
- Bitmonero::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
ASSERT_TRUE(balance1 == wallet2->balance());
std::cout << "wallet balance: " << wallet2->balance() << std::endl;
@@ -491,7 +513,7 @@ TEST_F(WalletTest1, WalletShowsBalance)
TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight)
{
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
ASSERT_TRUE(wallet1->blockChainHeight() > 0);
wmgr->closeWallet(wallet1);
}
@@ -499,10 +521,10 @@ TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight)
TEST_F(WalletTest1, WalletReturnsDaemonBlockHeight)
{
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// wallet not connected to daemon
ASSERT_TRUE(wallet1->daemonBlockChainHeight() == 0);
- ASSERT_TRUE(wallet1->status() != Bitmonero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet1->status() != Monero::Wallet::Status_Ok);
ASSERT_FALSE(wallet1->errorString().empty());
wmgr->closeWallet(wallet1);
@@ -518,8 +540,10 @@ TEST_F(WalletTest1, WalletReturnsDaemonBlockHeight)
TEST_F(WalletTest1, WalletRefresh)
{
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ std::cout << "Opening wallet: " << CURRENT_SRC_WALLET << std::endl;
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
+ std::cout << "connecting to daemon: " << TESTNET_DAEMON_ADDRESS << std::endl;
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
ASSERT_TRUE(wmgr->closeWallet(wallet1));
@@ -527,12 +551,12 @@ TEST_F(WalletTest1, WalletRefresh)
TEST_F(WalletTest1, WalletConvertsToString)
{
- std::string strAmount = Bitmonero::Wallet::displayAmount(AMOUNT_5XMR);
- ASSERT_TRUE(AMOUNT_5XMR == Bitmonero::Wallet::amountFromString(strAmount));
+ std::string strAmount = Monero::Wallet::displayAmount(AMOUNT_5XMR);
+ ASSERT_TRUE(AMOUNT_5XMR == Monero::Wallet::amountFromString(strAmount));
- ASSERT_TRUE(AMOUNT_5XMR == Bitmonero::Wallet::amountFromDouble(5.0));
- ASSERT_TRUE(AMOUNT_10XMR == Bitmonero::Wallet::amountFromDouble(10.0));
- ASSERT_TRUE(AMOUNT_1XMR == Bitmonero::Wallet::amountFromDouble(1.0));
+ 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));
}
@@ -541,22 +565,23 @@ TEST_F(WalletTest1, WalletConvertsToString)
TEST_F(WalletTest1, WalletTransaction)
{
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
uint64_t balance = wallet1->balance();
- ASSERT_TRUE(wallet1->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
- wallet1->setDefaultMixin(1);
- ASSERT_TRUE(wallet1->defaultMixin() == 1);
+ const int MIXIN_COUNT = 4;
+
- Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(recepient_address,
+ Monero::PendingTransaction * transaction = wallet1->createTransaction(recepient_address,
PAYMENT_ID_EMPTY,
AMOUNT_10XMR,
- 1);
- ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
+ MIXIN_COUNT,
+ Monero::PendingTransaction::Priority_Medium);
+ ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
wallet1->refresh();
ASSERT_TRUE(wallet1->balance() == balance);
@@ -580,25 +605,25 @@ TEST_F(WalletTest1, WalletTransactionWithMixin)
std::string payment_id = "";
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
uint64_t balance = wallet1->balance();
- ASSERT_TRUE(wallet1->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
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;
- Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(
+ Monero::PendingTransaction * transaction = wallet1->createTransaction(
recepient_address, payment_id, AMOUNT_5XMR, mixin);
std::cerr << "Transaction status: " << transaction->status() << std::endl;
- std::cerr << "Transaction fee: " << Bitmonero::Wallet::displayAmount(transaction->fee()) << std::endl;
+ std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
std::cerr << "Transaction error: " << transaction->errorString() << std::endl;
- ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
wallet1->disposeTransaction(transaction);
}
@@ -613,33 +638,33 @@ TEST_F(WalletTest1, WalletTransactionWithPriority)
std::string payment_id = "";
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
uint64_t balance = wallet1->balance();
- ASSERT_TRUE(wallet1->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
uint32_t mixin = 2;
uint64_t fee = 0;
- std::vector<Bitmonero::PendingTransaction::Priority> priorities = {
- Bitmonero::PendingTransaction::Priority_Low,
- Bitmonero::PendingTransaction::Priority_Medium,
- Bitmonero::PendingTransaction::Priority_High
+ std::vector<Monero::PendingTransaction::Priority> priorities = {
+ Monero::PendingTransaction::Priority_Low,
+ Monero::PendingTransaction::Priority_Medium,
+ Monero::PendingTransaction::Priority_High
};
for (auto it = priorities.begin(); it != priorities.end(); ++it) {
std::cerr << "Transaction priority: " << *it << std::endl;
- Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(
+ Monero::PendingTransaction * transaction = wallet1->createTransaction(
recepient_address, payment_id, AMOUNT_5XMR, mixin, *it);
std::cerr << "Transaction status: " << transaction->status() << std::endl;
- std::cerr << "Transaction fee: " << Bitmonero::Wallet::displayAmount(transaction->fee()) << std::endl;
+ std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
std::cerr << "Transaction error: " << transaction->errorString() << std::endl;
ASSERT_TRUE(transaction->fee() > fee);
- ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
fee = transaction->fee();
wallet1->disposeTransaction(transaction);
}
@@ -652,11 +677,11 @@ TEST_F(WalletTest1, WalletTransactionWithPriority)
TEST_F(WalletTest1, WalletHistory)
{
- Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
- Bitmonero::TransactionHistory * history = wallet1->history();
+ Monero::TransactionHistory * history = wallet1->history();
history->refresh();
ASSERT_TRUE(history->count() > 0);
@@ -670,11 +695,11 @@ TEST_F(WalletTest1, WalletHistory)
TEST_F(WalletTest1, WalletTransactionAndHistory)
{
return;
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src->refresh());
- Bitmonero::TransactionHistory * history = wallet_src->history();
+ Monero::TransactionHistory * history = wallet_src->history();
history->refresh();
ASSERT_TRUE(history->count() > 0);
size_t count1 = history->count();
@@ -688,11 +713,11 @@ TEST_F(WalletTest1, WalletTransactionAndHistory)
std::string wallet4_addr = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
- Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
+ Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
PAYMENT_ID_EMPTY,
AMOUNT_10XMR * 5, 1);
- ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
history = wallet_src->history();
history->refresh();
@@ -709,11 +734,11 @@ TEST_F(WalletTest1, WalletTransactionAndHistory)
TEST_F(WalletTest1, WalletTransactionWithPaymentId)
{
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src->refresh());
- Bitmonero::TransactionHistory * history = wallet_src->history();
+ Monero::TransactionHistory * history = wallet_src->history();
history->refresh();
ASSERT_TRUE(history->count() > 0);
size_t count1 = history->count();
@@ -726,15 +751,15 @@ TEST_F(WalletTest1, WalletTransactionWithPaymentId)
std::string wallet4_addr = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
- std::string payment_id = Bitmonero::Wallet::genPaymentId();
+ std::string payment_id = Monero::Wallet::genPaymentId();
ASSERT_TRUE(payment_id.length() == 16);
- Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
+ Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
payment_id,
AMOUNT_1XMR, 1);
- ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
history = wallet_src->history();
history->refresh();
@@ -755,18 +780,18 @@ TEST_F(WalletTest1, WalletTransactionWithPaymentId)
}
-struct MyWalletListener : public Bitmonero::WalletListener
+struct MyWalletListener : public Monero::WalletListener
{
- Bitmonero::Wallet * wallet;
+ Monero::Wallet * wallet;
uint64_t total_tx;
uint64_t total_rx;
- std::mutex mutex;
- std::condition_variable cv_send;
- std::condition_variable cv_receive;
- std::condition_variable cv_update;
- std::condition_variable cv_refresh;
- std::condition_variable cv_newblock;
+ 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;
bool send_triggered;
bool receive_triggered;
bool newblock_triggered;
@@ -775,7 +800,7 @@ struct MyWalletListener : public Bitmonero::WalletListener
- MyWalletListener(Bitmonero::Wallet * wallet)
+ MyWalletListener(Monero::Wallet * wallet)
: total_tx(0), total_rx(0)
{
reset();
@@ -807,10 +832,24 @@ struct MyWalletListener : public Bitmonero::WalletListener
cv_receive.notify_one();
}
+ virtual void unconfirmedMoneyReceived(const string &txId, uint64_t amount)
+ {
+ std::cout << "wallet: " << wallet->address() << "**** just received unconfirmed money ("
+ << txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
+ // Don't trigger recieve until tx is mined
+ // total_rx += amount;
+ // receive_triggered = true;
+ // cv_receive.notify_one();
+ }
+
virtual void newBlock(uint64_t height)
{
- std::cout << "wallet: " << wallet->address()
- <<", new block received, blockHeight: " << height << std::endl;
+// std::cout << "wallet: " << wallet->address()
+// <<", new block received, blockHeight: " << height << std::endl;
+ static int bc_height = wallet->daemonBlockChainHeight();
+ std::cout << height
+ << " / " << bc_height/* 0*/
+ << std::endl;
newblock_triggered = true;
cv_newblock.notify_one();
}
@@ -837,13 +876,13 @@ struct MyWalletListener : public Bitmonero::WalletListener
TEST_F(WalletTest2, WalletCallBackRefreshedSync)
{
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
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());
- std::chrono::seconds wait_for = std::chrono::seconds(60*3);
- std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
+ boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
+ boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
wmgr->closeWallet(wallet_src);
}
@@ -854,12 +893,13 @@ TEST_F(WalletTest2, WalletCallBackRefreshedSync)
TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
{
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
- std::chrono::seconds wait_for = std::chrono::seconds(20);
- std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
- wallet_src->initAsync(TESTNET_DAEMON_ADDRESS, 0);
+ boost::chrono::seconds wait_for = boost::chrono::seconds(20);
+ boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
+ wallet_src->init(MAINNET_DAEMON_ADDRESS, 0);
+ wallet_src->startRefresh();
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";
@@ -871,33 +911,34 @@ TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
+
TEST_F(WalletTest2, WalletCallbackSent)
{
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// 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);
uint64_t balance = wallet_src->balance();
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
- Bitmonero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
uint64_t amount = AMOUNT_1XMR * 5;
- std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
+ std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
- Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
+ Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
PAYMENT_ID_EMPTY,
amount, 1);
- std::cout << "** Committing transaction: " << Bitmonero::Wallet::displayAmount(tx->amount())
- << " with fee: " << Bitmonero::Wallet::displayAmount(tx->fee());
+ std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
+ << " with fee: " << Monero::Wallet::displayAmount(tx->fee());
- ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
- std::chrono::seconds wait_for = std::chrono::seconds(60*3);
- std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
+ boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
+ boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
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";
@@ -913,33 +954,33 @@ TEST_F(WalletTest2, WalletCallbackSent)
TEST_F(WalletTest2, WalletCallbackReceived)
{
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src->refresh());
std::cout << "** Balance src1: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
- Bitmonero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_dst->refresh());
uint64_t balance = wallet_dst->balance();
std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance()) << std::endl;
- MyWalletListener * wallet_dst_listener = new MyWalletListener(wallet_dst);
+ std::unique_ptr<MyWalletListener> wallet_dst_listener (new MyWalletListener(wallet_dst));
uint64_t amount = AMOUNT_1XMR * 5;
- std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
- Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
+ std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
+ Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
PAYMENT_ID_EMPTY,
amount, 1);
- std::cout << "** Committing transaction: " << Bitmonero::Wallet::displayAmount(tx->amount())
- << " with fee: " << Bitmonero::Wallet::displayAmount(tx->fee());
+ std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
+ << " with fee: " << Monero::Wallet::displayAmount(tx->fee());
- ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
+ ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
- std::chrono::seconds wait_for = std::chrono::seconds(60*4);
- std::unique_lock<std::mutex> lock (wallet_dst_listener->mutex);
+ boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
+ boost::unique_lock<boost::mutex> lock (wallet_dst_listener->mutex);
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";
@@ -960,7 +1001,7 @@ TEST_F(WalletTest2, WalletCallbackReceived)
TEST_F(WalletTest2, WalletCallbackNewBlock)
{
- Bitmonero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET5_NAME, TESTNET_WALLET_PASS, true);
+ Monero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET5_NAME, TESTNET_WALLET_PASS, true);
// make sure testnet daemon is running
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src->refresh());
@@ -968,11 +1009,11 @@ TEST_F(WalletTest2, WalletCallbackNewBlock)
std::cout << "** Block height: " << bc1 << std::endl;
- MyWalletListener * wallet_listener = new MyWalletListener(wallet_src);
+ std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet_src));
// wait max 4 min for new block
- std::chrono::seconds wait_for = std::chrono::seconds(60*4);
- std::unique_lock<std::mutex> lock (wallet_listener->mutex);
+ boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
+ boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
std::cerr << "TEST: waiting on newblock lock...\n";
wallet_listener->cv_newblock.wait_for(lock, wait_for);
std::cerr << "TEST: newblock lock acquired...\n";
@@ -984,17 +1025,129 @@ TEST_F(WalletTest2, WalletCallbackNewBlock)
}
+TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetSync)
+{
+
+ Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
+ std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
+ 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);
+}
+
+
+TEST_F(WalletManagerMainnetTest, CreateAndRefreshWalletMainNetAsync)
+{
+ // supposing 120 seconds should be enough for fast refresh
+ int SECONDS_TO_REFRESH = 120;
+
+ Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
+ std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
+
+ boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
+ boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
+ wallet->init(MAINNET_DAEMON_ADDRESS, 0);
+ wallet->startRefresh();
+ 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->status() == Monero::Wallet::Status_Ok);
+ 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);
+}
+
+TEST_F(WalletManagerMainnetTest, OpenAndRefreshWalletMainNetAsync)
+{
+
+ // supposing 120 seconds should be enough for fast refresh
+ int SECONDS_TO_REFRESH = 120;
+ Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
+ wmgr->closeWallet(wallet);
+ wallet = wmgr->openWallet(WALLET_NAME_MAINNET, "");
+
+ std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
+
+ boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
+ boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
+ wallet->init(MAINNET_DAEMON_ADDRESS, 0);
+ wallet->startRefresh();
+ 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->status() == Monero::Wallet::Status_Ok);
+ 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);
+
+}
+
+TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync)
+{
+
+ // supposing 120 seconds should be enough for fast refresh
+ int SECONDS_TO_REFRESH = 120;
+ Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
+ std::string seed = wallet->seed();
+ std::string address = wallet->address();
+ wmgr->closeWallet(wallet);
+
+ // deleting wallet files
+ Utils::deleteWallet(WALLET_NAME_MAINNET);
+ // ..and recovering wallet from seed
+
+ wallet = wmgr->recoveryWallet(WALLET_NAME_MAINNET, seed);
+ ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
+ ASSERT_TRUE(wallet->address() == address);
+ std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
+ boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
+ boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
+ wallet->init(MAINNET_DAEMON_ADDRESS, 0);
+ wallet->startRefresh();
+ 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);
+ ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
+ 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";
+
+}
+
int main(int argc, char** argv)
{
// we can override default values for "TESTNET_DAEMON_ADDRESS" and "WALLETS_ROOT_DIR"
- const char * monero_daemon_addr = std::getenv("TESTNET_DAEMON_ADDRESS");
- if (monero_daemon_addr) {
- TESTNET_DAEMON_ADDRESS = monero_daemon_addr;
+ const char * testnet_daemon_addr = std::getenv("TESTNET_DAEMON_ADDRESS");
+ if (testnet_daemon_addr) {
+ TESTNET_DAEMON_ADDRESS = testnet_daemon_addr;
}
+ const char * mainnet_daemon_addr = std::getenv("MAINNET_DAEMON_ADDRESS");
+ if (mainnet_daemon_addr) {
+ MAINNET_DAEMON_ADDRESS = mainnet_daemon_addr;
+ }
+
+
+
const char * wallets_root_dir = std::getenv("WALLETS_ROOT_DIR");
if (wallets_root_dir) {
WALLETS_ROOT_DIR = wallets_root_dir;
@@ -1008,10 +1161,10 @@ int main(int argc, char** argv)
TESTNET_WALLET5_NAME = WALLETS_ROOT_DIR + "/wallet_05.bin";
TESTNET_WALLET6_NAME = WALLETS_ROOT_DIR + "/wallet_06.bin";
- CURRENT_SRC_WALLET = TESTNET_WALLET6_NAME;
- CURRENT_DST_WALLET = TESTNET_WALLET5_NAME;
+ CURRENT_SRC_WALLET = TESTNET_WALLET5_NAME;
+ CURRENT_DST_WALLET = TESTNET_WALLET1_NAME;
::testing::InitGoogleTest(&argc, argv);
- // Bitmonero::WalletManagerFactory::setLogLevel(Bitmonero::WalletManagerFactory::LogLevel_Max);
+ Monero::WalletManagerFactory::setLogLevel(Monero::WalletManagerFactory::LogLevel_Max);
return RUN_ALL_TESTS();
}