aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/libwallet_api_tests/main.cpp150
1 files changed, 130 insertions, 20 deletions
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index 9701c300c..51c0a3ca3 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -29,7 +29,9 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "gtest/gtest.h"
+
#include "wallet/wallet2_api.h"
+
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
@@ -41,6 +43,23 @@ using namespace std;
//unsigned int epee::g_test_dbg_lock_sleep = 0;
+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);
+ }
+};
+
struct WalletManagerTest : public testing::Test
{
@@ -54,12 +73,22 @@ struct WalletManagerTest : public testing::Test
const char * WALLET_PASS2 = "password22";
const char * WALLET_LANG = "English";
+
+ // TODO: add test wallets to the source tree (as they have some balance mined)?
+ const char * TESTNET_WALLET_NAME = "/home/mbg033/dev/monero/testnet/wallet_01.bin";
+ const char * TESTNET_WALLET_PASS = "";
+
+ const char * TESTNET_DAEMON_ADDRESS = "localhost:38081";
+ const uint64_t AMOUNT_10XMR = 10000000000000L;
+ const uint64_t AMOUNT_5XMR = 50000000000000L;
+ const char * RECIPIENT_WALLET_ADDRESS = "9uekQVGj7NjSAREnZ8cUsRagWDdjvdhpwUKhsL95oXngBnZXZ1RzH8R6UJbU1R7wim9yKbSjxuoQ22ERRkEochGECj66oP3";
+
WalletManagerTest()
{
std::cout << __FUNCTION__ << std::endl;
wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
- deleteWallet(WALLET_NAME);
- deleteDir(boost::filesystem::path(WALLET_NAME_WITH_DIR).parent_path().string());
+ Utils::deleteWallet(WALLET_NAME);
+ Utils::deleteDir(boost::filesystem::path(WALLET_NAME_WITH_DIR).parent_path().string());
}
@@ -68,22 +97,6 @@ struct WalletManagerTest : public testing::Test
std::cout << __FUNCTION__ << std::endl;
//deleteWallet(WALLET_NAME);
}
-
-
- 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");
- }
-
- void deleteDir(const std::string &path)
- {
- std::cout << "** removing dir recursively: " << path << std::endl;
- boost::filesystem::remove_all(path);
- }
-
};
@@ -140,7 +153,7 @@ TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
std::string address1 = wallet1->address();
ASSERT_FALSE(address1.empty());
ASSERT_TRUE(wmgr->closeWallet(wallet1));
- deleteWallet(WALLET_NAME);
+ Utils::deleteWallet(WALLET_NAME);
Bitmonero::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME, seed1);
ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
@@ -165,6 +178,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
ASSERT_TRUE(wmgr->closeWallet(wallet2));
}
+
TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
{
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
@@ -203,10 +217,106 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
}
+TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
+{
+ Bitmonero::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->store(""));
+ ASSERT_TRUE(wallet1->status() == Bitmonero::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->seed() == seed1);
+ ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+}
+
+
+TEST_F(WalletManagerTest, WalletShowsBalance)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->openWallet(TESTNET_WALLET_NAME, 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(TESTNET_WALLET_NAME, TESTNET_WALLET_PASS, true);
+
+ ASSERT_TRUE(balance1 == wallet2->balance());
+ std::cout << "wallet balance: " << wallet2->balance() << std::endl;
+ ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance());
+ std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance() << std::endl;
+ ASSERT_TRUE(wmgr->closeWallet(wallet2));
+}
+
+TEST_F(WalletManagerTest, WalletRefresh)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->openWallet(TESTNET_WALLET_NAME, TESTNET_WALLET_PASS, true);
+ // make sure testnet daemon is running
+ ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
+ ASSERT_TRUE(wallet1->refresh());
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+}
+
+TEST_F(WalletManagerTest, WalletTransaction)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->openWallet(TESTNET_WALLET_NAME, 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);
+
+ Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(
+ RECIPIENT_WALLET_ADDRESS, AMOUNT_10XMR);
+ ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
+
+ ASSERT_TRUE(wallet1->balance() == balance);
+ ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR);
+ ASSERT_TRUE(transaction->commit());
+ ASSERT_FALSE(wallet1->balance() == balance);
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+}
+
+TEST_F(WalletManagerTest, WalletHistory)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->openWallet(TESTNET_WALLET_NAME, 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();
+ history->refresh();
+ ASSERT_TRUE(history->count() > 0);
+ auto transaction_print = [=] (Bitmonero::TransactionInfo * t) {
+ std::cout << "d: "
+ << (t->direction() == Bitmonero::TransactionInfo::Direction_In ? "in" : "out")
+ << ", bh: " << t->blockHeight()
+ << ", a: " << Bitmonero::Wallet::displayAmount(t->amount())
+ << ", f: " << Bitmonero::Wallet::displayAmount(t->fee())
+ << ", h: " << t->hash()
+ << ", pid: " << t->paymentId()
+ << std::endl;
+ };
+
+ for (auto t: history->getAll()) {
+ ASSERT_TRUE(t != nullptr);
+ transaction_print(t);
+ }
+}
+
+
int main(int argc, char** argv)
{
- //epee::debug::get_set_enable_assert(true, false);
+
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}