32 #include "gtest/gtest.h" 39 #include <boost/chrono/chrono.hpp> 40 #include <boost/filesystem.hpp> 41 #include <boost/algorithm/string.hpp> 42 #include <boost/asio.hpp> 43 #include <boost/date_time/posix_time/posix_time.hpp> 44 #include <boost/thread/condition_variable.hpp> 45 #include <boost/thread/mutex.hpp> 46 #include <boost/thread/thread.hpp> 105 std::cout <<
"** deleting wallet: " << walletname << std::endl;
106 boost::filesystem::remove(walletname);
107 boost::filesystem::remove(walletname +
".address.txt");
108 boost::filesystem::remove(walletname +
".keys");
113 std::cout <<
"** removing dir recursively: " << path << std::endl;
114 boost::filesystem::remove_all(path);
122 <<
", pe: " << (t->
isPending() ?
"true" :
"false")
126 <<
", h: " << t->
hash()
149 std::cout << __FUNCTION__ << std::endl;
159 std::cout << __FUNCTION__ << std::endl;
172 std::cout << __FUNCTION__ << std::endl;
180 std::cout << __FUNCTION__ << std::endl;
215 std::vector<std::string> words;
217 boost::split(words, seed, boost::is_any_of(
" "), boost::token_compress_on);
219 std::cout <<
"** seed: " << wallet->
seed() << std::endl;
221 std::cout <<
"** address: " << wallet->
mainAddress() << std::endl;
235 std::cout <<
"** seed: " << wallet2->seed() << std::endl;
264 LOG_PRINT_L3(
"opening wallet in thread: " << boost::this_thread::get_id());
266 LOG_PRINT_L3(
"wallet address: " << (*wallet)->mainAddress());
268 LOG_PRINT_L3(
"closing wallet in thread: " << boost::this_thread::get_id());
349 ASSERT_TRUE(wallet2->filename() == WALLET_NAME_MOVED);
350 ASSERT_TRUE(wallet2->keysFilename() == WALLET_NAME_MOVED +
".keys");
474 std::cout <<
"Found wallets: " << std::endl;
475 for (
auto wallet_path: wallets) {
476 std::cout << wallet_path << std::endl;
510 std::cout <<
"wallet balance: " << wallet2->balance(0) << std::endl;
511 ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0));
512 std::cout <<
"wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl;
520 wmgr->closeWallet(wallet1);
531 wmgr->closeWallet(wallet1);
538 wmgr->closeWallet(wallet1);
578 const int MIXIN_COUNT = 4;
587 std::set<uint32_t>{});
603 std::vector<int> mixins;
605 mixins.push_back(2); mixins.push_back(3); mixins.push_back(4); mixins.push_back(5); mixins.push_back(6);
606 mixins.push_back(7); mixins.push_back(8); mixins.push_back(9); mixins.push_back(10); mixins.push_back(15);
607 mixins.push_back(20); mixins.push_back(25);
622 for (
auto mixin : mixins) {
623 std::cerr <<
"Transaction mixin count: " << mixin << std::endl;
628 std::cerr <<
"Transaction status: " << transaction->
status() << std::endl;
630 std::cerr <<
"Transaction error: " << transaction->
errorString() << std::endl;
658 std::vector<Electroneum::PendingTransaction::Priority> priorities = {
664 for (
auto it = priorities.begin(); it != priorities.end(); ++it) {
665 std::cerr <<
"Transaction priority: " << *it << std::endl;
668 recepient_address, payment_id,
AMOUNT_5ETN, mixin, *it, 0, std::set<uint32_t>{});
669 std::cerr <<
"Transaction status: " << transaction->
status() << std::endl;
671 std::cerr <<
"Transaction error: " << transaction->
errorString() << std::endl;
674 fee = transaction->
fee();
695 for (
auto t: history->getAll()) {
711 size_t count1 = history->count();
713 std::cout <<
"**** Transactions before transfer (" << count1 <<
")" << std::endl;
714 for (
auto t: history->getAll()) {
728 history = wallet_src->
history();
732 std::cout <<
"**** Transactions after transfer (" << history->count() <<
")" << std::endl;
733 for (
auto t: history->getAll()) {
750 size_t count1 = history->count();
752 std::cout <<
"**** Transactions before transfer (" << count1 <<
")" << std::endl;
753 for (
auto t: history->getAll()) {
770 history = wallet_src->
history();
774 bool payment_id_in_history =
false;
776 std::cout <<
"**** Transactions after transfer (" << history->count() <<
")" << std::endl;
777 for (
auto t: history->getAll()) {
780 if (t->paymentId() == payment_id) {
781 payment_id_in_history =
true;
810 : total_tx(0), total_rx(0)
814 this->wallet = wallet;
820 send_triggered = receive_triggered = newblock_triggered = update_triggered = refresh_triggered =
false;
825 std::cerr <<
"wallet: " << wallet->
mainAddress() <<
"**** just spent ETN (" 826 << txId <<
", " << wallet->
displayAmount(amount) <<
")" << std::endl;
828 send_triggered =
true;
829 cv_send.notify_one();
834 std::cout <<
"wallet: " << wallet->
mainAddress() <<
"**** just received ETN (" 835 << txId <<
", " << wallet->
displayAmount(amount) <<
")" << std::endl;
837 receive_triggered =
true;
838 cv_receive.notify_one();
843 std::cout <<
"wallet: " << wallet->
mainAddress() <<
"**** just received unconfirmed ETN (" 844 << txId <<
", " << wallet->
displayAmount(amount) <<
")" << std::endl;
857 <<
" / " << bc_height
859 newblock_triggered =
true;
860 cv_newblock.notify_one();
865 std::cout << __FUNCTION__ <<
"Wallet updated";
866 update_triggered =
true;
867 cv_update.notify_one();
872 std::cout << __FUNCTION__ <<
"Wallet refreshed";
873 refresh_triggered =
true;
874 cv_refresh.notify_one();
890 boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
891 boost::unique_lock<boost::mutex> lock (wallet_src_listener->
mutex);
892 wallet_src_listener->
cv_refresh.wait_for(lock, wait_for);
893 wmgr->closeWallet(wallet_src);
905 boost::chrono::seconds wait_for = boost::chrono::seconds(20);
906 boost::unique_lock<boost::mutex> lock (wallet_src_listener->
mutex);
909 std::cerr <<
"TEST: waiting on refresh lock...\n";
910 wallet_src_listener->
cv_refresh.wait_for(lock, wait_for);
911 std::cerr <<
"TEST: refresh lock acquired...\n";
914 std::cerr <<
"TEST: closing wallet...\n";
915 wmgr->closeWallet(wallet_src);
946 boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
947 boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
948 std::cerr <<
"TEST: waiting on send lock...\n";
949 wallet_src_listener->cv_send.wait_for(lock, wait_for);
950 std::cerr <<
"TEST: send lock acquired...\n";
952 ASSERT_TRUE(wallet_src_listener->update_triggered);
955 wmgr->closeWallet(wallet_src);
956 wmgr->closeWallet(wallet_dst);
967 std::cout <<
"** Balance src1: " << wallet_src->
displayAmount(wallet_src->
balance(0)) << std::endl;
973 std::cout <<
"** Balance dst1: " << wallet_dst->
displayAmount(wallet_dst->
balance(0)) << std::endl;
974 std::unique_ptr<MyWalletListener> wallet_dst_listener (
new MyWalletListener(wallet_dst));
988 boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
989 boost::unique_lock<boost::mutex> lock (wallet_dst_listener->
mutex);
990 std::cerr <<
"TEST: waiting on receive lock...\n";
991 wallet_dst_listener->
cv_receive.wait_for(lock, wait_for);
992 std::cerr <<
"TEST: receive lock acquired...\n";
996 std::cout <<
"** Balance src2: " << wallet_dst->
displayAmount(wallet_src->
balance(0)) << std::endl;
997 std::cout <<
"** Balance dst2: " << wallet_dst->
displayAmount(wallet_dst->
balance(0)) << std::endl;
1001 wmgr->closeWallet(wallet_src);
1002 wmgr->closeWallet(wallet_dst);
1015 std::cout <<
"** Block height: " << bc1 << std::endl;
1018 std::unique_ptr<MyWalletListener> wallet_listener (
new MyWalletListener(wallet_src));
1021 boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
1022 boost::unique_lock<boost::mutex> lock (wallet_listener->
mutex);
1023 std::cerr <<
"TEST: waiting on newblock lock...\n";
1024 wallet_listener->
cv_newblock.wait_for(lock, wait_for);
1025 std::cerr <<
"TEST: newblock lock acquired...\n";
1028 std::cout <<
"** Block height: " << bc2 << std::endl;
1030 wmgr->closeWallet(wallet_src);
1038 std::unique_ptr<MyWalletListener> wallet_listener (
new MyWalletListener(wallet));
1040 std::cerr <<
"TEST: waiting on refresh lock...\n";
1042 std::cerr <<
"TEST: refresh lock acquired...\n";
1046 std::cerr <<
"TEST: closing wallet...\n";
1047 wmgr->closeWallet(wallet);
1054 int SECONDS_TO_REFRESH = 120;
1057 std::unique_ptr<MyWalletListener> wallet_listener (
new MyWalletListener(wallet));
1059 boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
1060 boost::unique_lock<boost::mutex> lock (wallet_listener->
mutex);
1063 std::cerr <<
"TEST: waiting on refresh lock...\n";
1064 wallet_listener->
cv_refresh.wait_for(lock, wait_for);
1065 std::cerr <<
"TEST: refresh lock acquired...\n";
1070 std::cerr <<
"TEST: closing wallet...\n";
1071 wmgr->closeWallet(wallet);
1078 int SECONDS_TO_REFRESH = 120;
1080 wmgr->closeWallet(wallet);
1083 std::unique_ptr<MyWalletListener> wallet_listener (
new MyWalletListener(wallet));
1085 boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
1086 boost::unique_lock<boost::mutex> lock (wallet_listener->
mutex);
1089 std::cerr <<
"TEST: waiting on refresh lock...\n";
1090 wallet_listener->
cv_refresh.wait_for(lock, wait_for);
1091 std::cerr <<
"TEST: refresh lock acquired...\n";
1096 std::cerr <<
"TEST: closing wallet...\n";
1097 wmgr->closeWallet(wallet);
1105 int SECONDS_TO_REFRESH = 120;
1109 wmgr->closeWallet(wallet);
1118 std::unique_ptr<MyWalletListener> wallet_listener (
new MyWalletListener(wallet));
1119 boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
1120 boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
1123 std::cerr <<
"TEST: waiting on refresh lock...\n";
1128 wallet_listener->cv_refresh.wait_for(lock, wait_for);
1133 std::cerr <<
"TEST: closing wallet...\n";
1134 wmgr->closeWallet(wallet);
1135 std::cerr <<
"TEST: wallet closed\n";
1148 const char * testnet_daemon_addr = std::getenv(
"TESTNET_DAEMON_ADDRESS");
1149 if (testnet_daemon_addr) {
1153 const char * mainnet_daemon_addr = std::getenv(
"MAINNET_DAEMON_ADDRESS");
1154 if (mainnet_daemon_addr) {
1160 const char * wallets_root_dir = std::getenv(
"WALLETS_ROOT_DIR");
1161 if (wallets_root_dir) {
boost::condition_variable cv_refresh
virtual void updated()
updated - generic callback, called when any event (sent/received/block reveived/etc) happened with th...
static void setLogLevel(int level)
virtual std::string hash() const =0
transaction_id
Electroneum::Wallet * wallet
std::string TESTNET_WALLET2_NAME
static void deleteDir(const std::string &path)
The TransactionHistory - interface for displaying transaction history.
int main(int argc, char *argv[])
virtual int status() const =0
virtual std::string errorString() const =0
virtual uint64_t unlockedBalance(uint32_t accountIndex=0, bool public_blockchain=false) const =0
virtual std::string errorString() const =0
in case error status, returns error string
std::string CURRENT_DST_WALLET
Electroneum::WalletManager * wmgr
virtual bool store(const std::string &path)=0
store - stores wallet to file.
WalletManagerMainnetTest()
virtual bool closeWallet(Wallet *wallet, bool store=true)=0
Closes wallet. In case operation succeeded, wallet object deleted. in case operation failed...
virtual void disposeTransaction(PendingTransaction *t)=0
disposeTransaction - destroys transaction object
std::string TESTNET_WALLET3_NAME
std::string MAINNET_DAEMON_ADDRESS
const uint64_t AMOUNT_5ETN
virtual bool commit(const std::string &filename="", bool overwrite=false)=0
Electroneum::WalletManager * wmgr
virtual uint64_t amount() const =0
virtual Wallet * openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds=1, WalletListener *listener=nullptr)=0
Opens existing wallet.
boost::condition_variable cv_receive
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit=0, const std::string &daemon_username="", const std::string &daemon_password="", bool use_ssl=false, bool lightWallet=false)=0
init - initializes wallet with daemon connection params. if daemon_address is local address...
boost::condition_variable cv_send
std::string TESTNET_WALLET1_NAME
std::string TESTNET_DAEMON_ADDRESS
virtual uint64_t fee() const =0
virtual uint64_t blockChainHeight() const =0
blockChainHeight - returns current blockchain height
static std::string get_wallet_address(const std::string &filename, const std::string &password)
virtual uint64_t amount() const =0
MyWalletListener(Electroneum::Wallet *wallet)
std::string TESTNET_WALLET6_NAME
virtual uint64_t fee() const =0
virtual bool setPassword(const std::string &password)=0
static uint64_t maximumAllowedAmount()
std::string TESTNET_WALLET4_NAME
WalletManager - provides functions to manage wallets.
const char * WALLET_PASS2
#define ASSERT_FALSE(condition)
std::string CURRENT_SRC_WALLET
virtual PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id, optional< uint64_t > amount, uint32_t mixin_count, PendingTransaction::Priority=PendingTransaction::Priority_Low, uint32_t subaddr_account=0, std::set< uint32_t > subaddr_indices={})=0
createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored ...
virtual int direction() const =0
static void print_transaction(Electroneum::TransactionInfo *t)
virtual void setListener(WalletListener *)=0
static WalletManager * getWalletManager()
virtual int status() const =0
returns wallet status (Status_Ok | Status_Error)
virtual std::string integratedAddress(const std::string &payment_id) const =0
integratedAddress - returns integrated address for current wallet address and given payment_id...
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
boost::condition_variable cv_newblock
static std::string genPaymentId()
Electroneum::WalletManager * wmgr
virtual bool isPending() const =0
const char * WALLET_NAME_WITH_DIR_NON_WRITABLE
unsigned __int64 uint64_t
virtual void etnReceived(const string &txId, uint64_t amount)
etnReceived - called when etn received
Transaction-like interface for sending etn.
static std::string displayAmount(uint64_t amount)
virtual TransactionHistory * history()=0
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
static uint64_t amountFromDouble(double amount)
Electroneum::WalletManager * wmgr
virtual uint64_t blockHeight() const =0
std::string WALLETS_ROOT_DIR
virtual void etnSpent(const string &txId, uint64_t amount)
etnSpent - called when etn spent
virtual ConnectionStatus connected() const =0
connected - checks if the wallet connected to the daemon
~WalletManagerMainnetTest()
const char * WALLET_NAME_COPY
void open_wallet_helper(Electroneum::WalletManager *wmgr, Electroneum::Wallet **wallet, const std::string &pass, boost::mutex *mutex)
virtual std::string seed() const =0
#define ASSERT_TRUE(condition)
const char * WALLET_NAME_WITH_DIR
static void deleteWallet(const std::string &walletname)
virtual void refreshed()
refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "ref...
static uint64_t amountFromString(const std::string &amount)
const uint64_t AMOUNT_10ETN
const char * TESTNET_WALLET_PASS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
virtual uint64_t balance(uint32_t accountIndex=0, bool public_blockchain=false) const =0
virtual uint64_t daemonBlockChainHeight() const =0
daemonBlockChainHeight - returns daemon blockchain height
virtual std::string paymentId() const =0
const char * WALLET_NAME_MAINNET
const uint64_t AMOUNT_1ETN
const std::string PAYMENT_ID_EMPTY
boost::condition_variable cv_update
std::string mainAddress() const
virtual void startRefresh()=0
StartRefresh - Start/resume refresh thread (refresh every 10 seconds)
virtual bool refresh()=0
refresh - refreshes the wallet, updating transactions from daemon
#define CATCH_ENTRY_L0(lacation, return_val)
std::string TESTNET_WALLET5_NAME
virtual void newBlock(uint64_t height)
newBlock - called when new block received
virtual void unconfirmedETNReceived(const string &txId, uint64_t amount)
unconfirmedETNReceived - called when payment arrived in tx pool
The TransactionInfo - interface for displaying transaction information.
Interface for wallet operations. TODO: check if /include/IWallet.h is still actual.