aboutsummaryrefslogtreecommitdiff
path: root/tests/libwallet_api_tests/main.cpp
diff options
context:
space:
mode:
authorIlya Kitaev <mbg033@gmail.com>2016-03-15 23:11:38 +0300
committerIlya Kitaev <mbg033@gmail.com>2016-03-16 14:29:06 +0300
commit62606f11f50b4c68446d3f581c96d5505a0ad6ef (patch)
treec258047ddcbf349f853f82eb71ef74c5af7111bf /tests/libwallet_api_tests/main.cpp
parentWallet::address implemented (diff)
downloadmonero-62606f11f50b4c68446d3f581c96d5505a0ad6ef.tar.xz
Wallet::store_to(path, password) implemented;
Diffstat (limited to 'tests/libwallet_api_tests/main.cpp')
-rw-r--r--tests/libwallet_api_tests/main.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index 8f4aba6bd..9701c300c 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -47,6 +47,9 @@ 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";
@@ -56,6 +59,7 @@ struct WalletManagerTest : public testing::Test
std::cout << __FUNCTION__ << std::endl;
wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
deleteWallet(WALLET_NAME);
+ deleteDir(boost::filesystem::path(WALLET_NAME_WITH_DIR).parent_path().string());
}
@@ -68,12 +72,18 @@ struct WalletManagerTest : public testing::Test
void deleteWallet(const std::string & walletname)
{
- std::cout << "** deleting wallet " << std::endl;
+ 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);
+ }
+
};
@@ -139,6 +149,59 @@ TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
}
+TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
+{
+ 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->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);
+ ASSERT_TRUE(wallet2->seed() == seed1);
+ ASSERT_TRUE(wallet2->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet2));
+}
+
+TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
+{
+ 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(WALLET_NAME_WITH_DIR));
+ 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->seed() == seed1);
+ ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+}
+
+TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
+{
+ Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
+ std::string seed1 = wallet1->seed();
+ std::string address1 = wallet1->address();
+
+ ASSERT_FALSE(wallet1->store(WALLET_NAME_WITH_DIR_NON_WRITABLE));
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
+
+ wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
+ ASSERT_FALSE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
+
+ ASSERT_FALSE(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));
+
+}
int main(int argc, char** argv)