diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-07-06 18:11:04 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-07-06 18:11:04 +0200 |
commit | fc58069731074c07fb1e37f5cb7f5154d7f7097b (patch) | |
tree | f60b803315a789d3674e393ffca2f5b4397bd0a5 /tests | |
parent | Merge pull request #870 (diff) | |
parent | CMake: GPL 'libutils' script removed (diff) | |
download | monero-fc58069731074c07fb1e37f5cb7f5154d7f7097b.tar.xz |
Merge pull request #872
beb6d92 CMake: GPL 'libutils' script removed (Ilya Kitaev)
4e5521d PendingTransactionImpl: pointer->reference (Ilya Kitaev)
7b7cf21 commented regex (Ilya Kitaev)
eec0f57 Typo fixed (Ilya Kitaev)
f1c4a37 Wallet::createTransaction: added mixin_count param (Ilya Kitaev)
3318add double/string to monero integer convertion methods (Ilya Kitaev)
3ac20a4 wallet::default_mixin exposed to public interface as Wallet::setDefaultMixin, Wallet::defaultMixin; wallet::create_transaction_2 used in Wallet::createTransaction (Ilya Kitaev)
c554055 Wallet::filename, Wallet::keysFilename, tests for move wallet (Ilya Kitaev)
8f9d98b removed unused "using" (Ilya Kitaev)
2facbe7 Wallet API : WalletManager::findWallets() added (Ilya Kitaev)
ec949c3 scripts for faster test wallets generation (Ilya Kitaev)
7f3d28f regenerated test wallets, basic functions got broken (Ilya Kitaev)
4327548 installing wallet_api header (Ilya Kitaev)
7ac1342 cmake: BUILD_TESTS as option explicitly; added missed dependency (Ilya Kitaev)
1f0d016 cmake libutils dependency added (Ilya Kitaev)
d43ad22 all wallet dependencies merged to single static lib (Ilya Kitaev)
9ae4e87 WalletListener::moneyReceived test (Ilya Kitaev)
40087a7 WalletListener::moneySpent test (Ilya Kitaev)
27d86b7 WalletListener::moneySpent(), WalletListener::moneyReceived() (Ilya Kitaev)
ff52c67 i_wallet_callback: virtual dtor (Ilya Kitaev)
5dbd2b8 started WalletListener (Ilya Kitaev)
71131a8 TransactionHistory continued (Ilya Kitaev)
9311934 TransactionHistory continued (Ilya Kitaev)
566166a merged with upstream (Ilya Kitaev)
53a97bd Wallet API: transaction history in progress (Ilya Kitaev)
02c9df5 Wallet API : transaction history in progress (Ilya Kitaev)
a213887 transaction history api in progress (Ilya Kitaev)
b6aaf53 transaction history api in progress (Ilya Kitaev)
f83f3cb api implementation splitted over separate files (Ilya Kitaev)
4e1c2dc TransactionInfo / TransactionHistory APIs design (Ilya Kitaev)
1774d95 TODOs for Transaction/Transfer interface (Ilya Kitaev)
d97e9ef Transaction API continued (Ilya Kitaev)
079fbd3 Wallet::createTransaction API introduced (Ilya Kitaev)
ee5bb17 Wallet::transfer() continued (Ilya Kitaev)
c37c856 Wallet::transfer in progress (Ilya Kitaev)
830c19c Wallet::refresh + tests (Ilya Kitaev)
1ae9cdc "testnet" is default parameter (Ilya Kitaev)
2157a9a testnet option, Wallet::balance(), Wallet::unlockedBalance() (Ilya Kitaev)
8790904 - testnet option added to api; (Ilya Kitaev)
2cce329 wallet2::store() implemented within wallet2::store_to (Ilya Kitaev)
d608647 WalletManager::findWallets: searching by "keys" files instead of "address.txt" files (Ilya Kitaev)
ca61153 Wallet: payment id and integrated address (Ilya Kitaev)
23cbf6f PendingTransactionImpl: pointer->reference (Ilya Kitaev)
c1d9e7c commented regex (Ilya Kitaev)
563baf1 Typo fixed (Ilya Kitaev)
2efec04 Wallet::createTransaction: added mixin_count param (Ilya Kitaev)
85a6322 double/string to monero integer convertion methods (Ilya Kitaev)
e7d8f2a wallet::default_mixin exposed to public interface as Wallet::setDefaultMixin, Wallet::defaultMixin; wallet::create_transaction_2 used in Wallet::createTransaction (Ilya Kitaev)
a537489 Wallet::filename, Wallet::keysFilename, tests for move wallet (Ilya Kitaev)
a1eddcd removed unused "using" (Ilya Kitaev)
8390bfa Wallet API : WalletManager::findWallets() added (Ilya Kitaev)
44cc0ef scripts for faster test wallets generation (Ilya Kitaev)
2060bfe regenerated test wallets, basic functions got broken (Ilya Kitaev)
dbc0b03 installing wallet_api header (Ilya Kitaev)
653c7e3 cmake: BUILD_TESTS as option explicitly; added missed dependency (Ilya Kitaev)
ef9a74c cmake libutils dependency added (Ilya Kitaev)
191cb59 all wallet dependencies merged to single static lib (Ilya Kitaev)
91eeeb8 WalletListener::moneyReceived test (Ilya Kitaev)
64348a2 WalletListener::moneySpent test (Ilya Kitaev)
060bb62 WalletListener::moneySpent(), WalletListener::moneyReceived() (Ilya Kitaev)
214014c i_wallet_callback: virtual dtor (Ilya Kitaev)
3745770 started WalletListener (Ilya Kitaev)
e6fdd5d TransactionHistory continued (Ilya Kitaev)
3dd4b4c merged with upstream (Ilya Kitaev)
d500272 Wallet API : transaction history in progress (Ilya Kitaev)
663ed04 transaction history api in progress (Ilya Kitaev)
12345d3 api implementation splitted over separate files (Ilya Kitaev)
60508e6 TransactionInfo / TransactionHistory APIs design (Ilya Kitaev)
951f3b5 Wallet::createTransaction API introduced (Ilya Kitaev)
7c51227 Wallet::transfer in progress (Ilya Kitaev)
e04c67a Wallet::refresh + tests (Ilya Kitaev)
9cdf0b7 "testnet" is default parameter (Ilya Kitaev)
caf0e02 testnet option, Wallet::balance(), Wallet::unlockedBalance() (Ilya Kitaev)
8df820b - testnet option added to api; (Ilya Kitaev)
94eaeb5 wallet2::store() implemented within wallet2::store_to (Ilya Kitaev)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libwallet_api_tests/main.cpp | 513 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/create_wallets.sh | 20 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/mining_start.sh | 4 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/mining_stop.sh | 4 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/open_wallet_1.sh | 5 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/open_wallet_2.sh | 5 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/open_wallet_3.sh | 4 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/open_wallet_4.sh | 4 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/open_wallet_5.sh | 4 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/open_wallet_miner.sh | 4 | ||||
-rwxr-xr-x | tests/libwallet_api_tests/scripts/send_funds.sh | 22 |
11 files changed, 569 insertions, 20 deletions
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 9701c300c..f6f1b0832 100644 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -29,37 +29,116 @@ // 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> #include <iostream> #include <vector> +#include <mutex> +#include <thread> using namespace std; //unsigned int epee::g_test_dbg_lock_sleep = 0; +namespace Consts +{ + + +// TODO: get rid of hardcoded paths + +const char * WALLET_NAME = "testwallet"; +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"; + +// change this according your environment + +const std::string WALLETS_ROOT_DIR = "/home/mbg033/dev/monero/testnet/"; + +const std::string TESTNET_WALLET1_NAME = WALLETS_ROOT_DIR + "wallet_01.bin"; +const std::string TESTNET_WALLET2_NAME = WALLETS_ROOT_DIR + "wallet_02.bin"; +const std::string TESTNET_WALLET3_NAME = WALLETS_ROOT_DIR + "wallet_03.bin"; +const std::string TESTNET_WALLET4_NAME = WALLETS_ROOT_DIR + "wallet_04.bin"; +const std::string TESTNET_WALLET5_NAME = WALLETS_ROOT_DIR + "wallet_05.bin"; +const std::string TESTNET_WALLET6_NAME = WALLETS_ROOT_DIR + "wallet_06.bin"; + +const char * TESTNET_WALLET_PASS = ""; + +const std::string CURRENT_SRC_WALLET = TESTNET_WALLET1_NAME; +const std::string CURRENT_DST_WALLET = TESTNET_WALLET6_NAME; + +const char * TESTNET_DAEMON_ADDRESS = "localhost:38081"; +const uint64_t AMOUNT_10XMR = 10000000000000L; +const uint64_t AMOUNT_5XMR = 5000000000000L; +const uint64_t AMOUNT_1XMR = 1000000000000L; + +const std::string PAYMENT_ID_EMPTY = ""; + +} + + + +using namespace Consts; + +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); + } + + static void print_transaction(Bitmonero::TransactionInfo * t) + { + + std::cout << "d: " + << (t->direction() == Bitmonero::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()) + << ", h: " << t->hash() + << ", pid: " << t->paymentId() + << std::endl; + } + + 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); + std::string result = w->address(); + wmgr->closeWallet(w); + return result; + } +}; struct WalletManagerTest : public testing::Test { Bitmonero::WalletManager * wmgr; - const char * WALLET_NAME = "testwallet"; - 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"; 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()); } @@ -69,21 +148,32 @@ struct WalletManagerTest : public testing::Test //deleteWallet(WALLET_NAME); } +}; + - void deleteWallet(const std::string & walletname) +struct WalletTest1 : public testing::Test +{ + Bitmonero::WalletManager * wmgr; + + WalletTest1() { - std::cout << "** deleting wallet: " << walletname << std::endl; - boost::filesystem::remove(walletname); - boost::filesystem::remove(walletname + ".address.txt"); - boost::filesystem::remove(walletname + ".keys"); + wmgr = Bitmonero::WalletManagerFactory::getWalletManager(); } - void deleteDir(const std::string &path) + +}; + + +struct WalletTest2 : public testing::Test +{ + Bitmonero::WalletManager * wmgr; + + WalletTest2() { - std::cout << "** removing dir recursively: " << path << std::endl; - boost::filesystem::remove_all(path); + wmgr = Bitmonero::WalletManagerFactory::getWalletManager(); } + }; @@ -116,7 +206,36 @@ TEST_F(WalletManagerTest, WalletManagerOpensWallet) std::cout << "** seed: " << wallet2->seed() << std::endl; } +TEST_F(WalletManagerTest, WalletManagerStoresWallet) +{ + Bitmonero::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); + ASSERT_TRUE(wallet2->seed() == seed1); +} + + +TEST_F(WalletManagerTest, WalletManagerMovesWallet) +{ + + Bitmonero::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); + 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->seed() == seed1); +} + + +/* TEST_F(WalletManagerTest, WalletManagerChangesPassword) { Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG); @@ -124,7 +243,7 @@ TEST_F(WalletManagerTest, WalletManagerChangesPassword) 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); + ASSERT_TRUE(wallet2->status() == Bitmonero::Wallet::Status_Ok);quint64 ASSERT_TRUE(wallet2->seed() == seed1); ASSERT_TRUE(wmgr->closeWallet(wallet2)); Bitmonero::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS); @@ -140,7 +259,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 +284,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 +323,363 @@ 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, 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; + } +} + + +TEST_F(WalletManagerTest, WalletGeneratesPaymentId) +{ + std::string payment_id = Bitmonero::Wallet::genPaymentId(); + ASSERT_TRUE(payment_id.length() == 16); +} + + +TEST_F(WalletManagerTest, WalletGeneratesIntegratedAddress) +{ + std::string payment_id = Bitmonero::Wallet::genPaymentId(); + + Bitmonero::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); +} + + +TEST_F(WalletTest1, WalletShowsBalance) +{ + // TODO: temporary disabled; + return; + Bitmonero::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); + + 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(WalletTest1, WalletRefresh) +{ + Bitmonero::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()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + + +TEST_F(WalletTest1, WalletConvertsToString) +{ + std::string strAmount = Bitmonero::Wallet::displayAmount(AMOUNT_5XMR); + ASSERT_TRUE(AMOUNT_5XMR == Bitmonero::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)); + +} + + +/* +TEST_F(WalletTest1, WalletTransaction) +{ + Bitmonero::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); + + std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); + wallet1->setDefaultMixin(1); + ASSERT_TRUE(wallet1->defaultMixin() == 1); + + Bitmonero::PendingTransaction * transaction = wallet1->createTransaction( + recepient_address, AMOUNT_10XMR); + ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok); + wallet1->refresh(); + + 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(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); + + + std::string payment_id = ""; + + Bitmonero::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); + + 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( + 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 error: " << transaction->errorString() << std::endl; + ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok); + wallet1->disposeTransaction(transaction); + } + + wallet1->refresh(); + + ASSERT_TRUE(wallet1->balance() == balance); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + +TEST_F(WalletTest1, WalletHistory) +{ + Bitmonero::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(); + history->refresh(); + ASSERT_TRUE(history->count() > 0); + + + for (auto t: history->getAll()) { + ASSERT_TRUE(t != nullptr); + Utils::print_transaction(t); + } +} + +TEST_F(WalletTest1, WalletTransactionAndHistory) +{ + return; + Bitmonero::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(); + 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); + + + Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, + PAYMENT_ID_EMPTY, + AMOUNT_10XMR * 5, 0); + + ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok); + 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); + } +} + + +TEST_F(WalletTest1, WalletTransactionWithPaymentId) +{ + + Bitmonero::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(); + 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); + + std::string payment_id = Bitmonero::Wallet::genPaymentId(); + ASSERT_TRUE(payment_id.length() == 16); + + + Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, + payment_id, + AMOUNT_1XMR, 1); + + ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok); + ASSERT_TRUE(tx->commit()); + history = wallet_src->history(); + history->refresh(); + ASSERT_TRUE(count1 != history->count()); + + bool payment_id_in_history = false; + + std::cout << "**** Transactions after transfer (" << history->count() << ")" << std::endl; + for (auto t: history->getAll()) { + ASSERT_TRUE(t != nullptr); + Utils::print_transaction(t); + if (t->paymentId() == payment_id) { + payment_id_in_history = true; + } + } + + ASSERT_TRUE(payment_id_in_history); +} + +struct MyWalletListener : public Bitmonero::WalletListener +{ + + Bitmonero::Wallet * wallet; + uint64_t total_tx; + uint64_t total_rx; + std::timed_mutex guard; + + MyWalletListener(Bitmonero::Wallet * wallet) + : total_tx(0), total_rx(0) + { + this->wallet = wallet; + this->wallet->setListener(this); + } + + virtual void moneySpent(const string &txId, uint64_t amount) + { + std::cout << "wallet: " << wallet->address() << " just spent money (" + << txId << ", " << wallet->displayAmount(amount) << ")" << std::endl; + total_tx += amount; + guard.unlock(); + } + + virtual void moneyReceived(const string &txId, uint64_t amount) + { + std::cout << "wallet: " << wallet->address() << " just received money (" + << txId << ", " << wallet->displayAmount(amount) << ")" << std::endl; + total_rx += amount; + guard.unlock(); + } +}; + +/* +TEST_F(WalletTest2, WalletCallbackSent) +{ + + Bitmonero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET3_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()); + MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); + std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl; + + + uint64_t amount = AMOUNT_10XMR * 5; + std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << TESTNET_WALLET4_ADDRESS; + Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(TESTNET_WALLET4_ADDRESS, AMOUNT_1XMR * 5); + ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok); + ASSERT_TRUE(tx->commit()); + + std::chrono::seconds wait_for = std::chrono::seconds(60*3); + + wallet_src_listener->guard.lock(); + wallet_src_listener->guard.try_lock_for(wait_for); + + ASSERT_TRUE(wallet_src_listener->total_tx != 0); +} +*/ + +/* +TEST_F(WalletTest2, WalletCallbackReceived) +{ + + Bitmonero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET3_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()); + std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl; + + Bitmonero::Wallet * wallet_dst = wmgr->openWallet(TESTNET_WALLET4_NAME, TESTNET_WALLET_PASS, true); + ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(wallet_dst->refresh()); + MyWalletListener * wallet_dst_listener = new MyWalletListener(wallet_dst); + + + uint64_t amount = AMOUNT_1XMR * 5; + std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << TESTNET_WALLET4_ADDRESS; + Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(TESTNET_WALLET4_ADDRESS, AMOUNT_1XMR * 5); + ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok); + ASSERT_TRUE(tx->commit()); + + std::chrono::seconds wait_for = std::chrono::seconds(60*4); + + wallet_dst_listener->guard.lock(); + wallet_dst_listener->guard.try_lock_for(wait_for); + + ASSERT_TRUE(wallet_dst_listener->total_tx != 0); + +} +*/ int main(int argc, char** argv) { - //epee::debug::get_set_enable_assert(true, false); + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/tests/libwallet_api_tests/scripts/create_wallets.sh b/tests/libwallet_api_tests/scripts/create_wallets.sh new file mode 100755 index 000000000..6abad84f9 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/create_wallets.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +function create_wallet { + wallet_name=$1 + echo 0 | simplewallet --testnet --trusted-daemon --daemon-address localhost:38081 --generate-new-wallet $wallet_name --password "" --restore-height=1 +} + + + +create_wallet wallet_01.bin +create_wallet wallet_02.bin +create_wallet wallet_03.bin +create_wallet wallet_04.bin +create_wallet wallet_05.bin +create_wallet wallet_06.bin + + +#create_wallet wallet_m + + diff --git a/tests/libwallet_api_tests/scripts/mining_start.sh b/tests/libwallet_api_tests/scripts/mining_start.sh new file mode 100755 index 000000000..76eabfc55 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/mining_start.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rlwrap simplewallet --wallet-file wallet_m --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_m.log start_mining + diff --git a/tests/libwallet_api_tests/scripts/mining_stop.sh b/tests/libwallet_api_tests/scripts/mining_stop.sh new file mode 100755 index 000000000..640e56943 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/mining_stop.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rlwrap simplewallet --wallet-file wallet_m --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_miner.log stop_mining + diff --git a/tests/libwallet_api_tests/scripts/open_wallet_1.sh b/tests/libwallet_api_tests/scripts/open_wallet_1.sh new file mode 100755 index 000000000..08f4e28ab --- /dev/null +++ b/tests/libwallet_api_tests/scripts/open_wallet_1.sh @@ -0,0 +1,5 @@ +#!/bin/bash + + +rlwrap simplewallet --wallet-file wallet_01.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_01.log + diff --git a/tests/libwallet_api_tests/scripts/open_wallet_2.sh b/tests/libwallet_api_tests/scripts/open_wallet_2.sh new file mode 100755 index 000000000..8a16a6647 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/open_wallet_2.sh @@ -0,0 +1,5 @@ +#!/bin/bash + + +rlwrap simplewallet --wallet-file wallet_02.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_01.log + diff --git a/tests/libwallet_api_tests/scripts/open_wallet_3.sh b/tests/libwallet_api_tests/scripts/open_wallet_3.sh new file mode 100755 index 000000000..64a04b3c4 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/open_wallet_3.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rlwrap simplewallet --wallet-file wallet_03.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_03.log + diff --git a/tests/libwallet_api_tests/scripts/open_wallet_4.sh b/tests/libwallet_api_tests/scripts/open_wallet_4.sh new file mode 100755 index 000000000..8ebf0a4c7 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/open_wallet_4.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rlwrap simplewallet --wallet-file wallet_04.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_04.log + diff --git a/tests/libwallet_api_tests/scripts/open_wallet_5.sh b/tests/libwallet_api_tests/scripts/open_wallet_5.sh new file mode 100755 index 000000000..bbeb702c0 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/open_wallet_5.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rlwrap simplewallet --wallet-file wallet_05.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_05.log + diff --git a/tests/libwallet_api_tests/scripts/open_wallet_miner.sh b/tests/libwallet_api_tests/scripts/open_wallet_miner.sh new file mode 100755 index 000000000..07a4e58ea --- /dev/null +++ b/tests/libwallet_api_tests/scripts/open_wallet_miner.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rlwrap simplewallet --wallet-file wallet_m --password "" --testnet --trusted-daemon --daemon-address 127.0.0.1:38081 --log-file wallet_m.log + diff --git a/tests/libwallet_api_tests/scripts/send_funds.sh b/tests/libwallet_api_tests/scripts/send_funds.sh new file mode 100755 index 000000000..306b06a40 --- /dev/null +++ b/tests/libwallet_api_tests/scripts/send_funds.sh @@ -0,0 +1,22 @@ +#!/bin/bash + + + +function send_funds { + local amount=$1 + local dest=$(cat "$2.address.txt") + + simplewallet --wallet-file wallet_m --password "" \ + --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_m.log \ + --command transfer $dest $amount +} + + +send_funds 100 wallet_01.bin +send_funds 100 wallet_02.bin +send_funds 100 wallet_03.bin +send_funds 100 wallet_04.bin +send_funds 100 wallet_05.bin +send_funds 100 wallet_06.bin + + |