From 3c6356946ebc12aa792c3461aaced8fbcf50e3bd Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Fri, 14 Jul 2023 22:47:00 +0530 Subject: [PATCH 01/23] Some of the testcases are disabled for bnstesting --- tests/libwallet_api_tests/main.cpp | 1346 ++++++++++++++-------------- 1 file changed, 664 insertions(+), 682 deletions(-) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index ff6b753b73..3db1267283 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -201,70 +201,65 @@ struct WalletTest2 : public testing::Test }; -TEST_F(WalletManagerTest, WalletManagerCreatesWallet) -{ - - Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet->good()); - std::cout <<"**good(): " << wallet->good()<< std::endl; - ASSERT_TRUE(!wallet->seed().empty()); - std::vector words; - std::string seed = wallet->seed(); - boost::split(words, seed, boost::is_any_of(" "), boost::token_compress_on); - ASSERT_TRUE(words.size() == 25); - std::cout << "** seed: " << wallet->seed() << std::endl; - ASSERT_FALSE(wallet->mainAddress().empty()); - std::cout << "** address: " << wallet->mainAddress() << std::endl; - ASSERT_TRUE(wmgr->closeWallet(wallet)); - -} - -TEST_F(WalletManagerTest, WalletManagerOpensWallet) -{ - - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet2->good()); - ASSERT_TRUE(wallet2->seed() == seed1); - std::cout << "** seed: " << wallet2->seed() << std::endl; -} - - -TEST_F(WalletManagerTest, WalletMaxAmountAsString) -{ - LOG_PRINT_L3("max amount: " << Wallet::Wallet::displayAmount( - Wallet::Wallet::maximumAllowedAmount())); - -} - - -TEST_F(WalletManagerTest, WalletAmountFromString) -{ - uint64_t amount = Wallet::Wallet::amountFromString("18446740"); - ASSERT_TRUE(amount > 0); - amount = Wallet::Wallet::amountFromString("11000000000000"); - ASSERT_TRUE(amount > 0); - amount = Wallet::Wallet::amountFromString("0.0"); - ASSERT_FALSE(amount > 0); - amount = Wallet::Wallet::amountFromString("10.1"); - ASSERT_TRUE(amount > 0); - -} - -void open_wallet_helper(Wallet::WalletManagerBase *wmgr, Wallet::Wallet **wallet, const std::string &pass, std::mutex *mutex) -{ - if (mutex) - mutex->lock(); - LOG_PRINT_L3("opening wallet in thread: " << boost::this_thread::get_id()); - *wallet = wmgr->openWallet(WALLET_NAME, pass, Wallet::NetworkType::TESTNET); - LOG_PRINT_L3("wallet address: " << (*wallet)->mainAddress()); - LOG_PRINT_L3("wallet status: " << (*wallet)->good()); - LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id()); - if (mutex) - mutex->unlock(); -} +// TEST_F(WalletManagerTest, WalletManagerCreatesWallet) +// { +// Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet->good()); +// std::cout <<"**good(): " << wallet->good()<< std::endl; +// ASSERT_TRUE(!wallet->seed().empty()); +// std::vector words; +// std::string seed = wallet->seed(); +// boost::split(words, seed, boost::is_any_of(" "), boost::token_compress_on); +// ASSERT_TRUE(words.size() == 25); +// std::cout << "** seed: " << wallet->seed() << std::endl; +// ASSERT_FALSE(wallet->mainAddress().empty()); +// std::cout << "** address: " << wallet->mainAddress() << std::endl; +// ASSERT_TRUE(wmgr->closeWallet(wallet)); +// } + +// TEST_F(WalletManagerTest, WalletManagerOpensWallet) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet2->good()); +// ASSERT_TRUE(wallet2->seed() == seed1); +// std::cout << "** seed: " << wallet2->seed() << std::endl; +// } + + +// TEST_F(WalletManagerTest, WalletMaxAmountAsString) +// { +// LOG_PRINT_L3("max amount: " << Wallet::Wallet::displayAmount( +// Wallet::Wallet::maximumAllowedAmount())); +// } + + +// TEST_F(WalletManagerTest, WalletAmountFromString) +// { +// uint64_t amount = Wallet::Wallet::amountFromString("18446740"); +// ASSERT_TRUE(amount > 0); +// amount = Wallet::Wallet::amountFromString("11000000000000"); +// ASSERT_TRUE(amount > 0); +// amount = Wallet::Wallet::amountFromString("0.0"); +// ASSERT_FALSE(amount > 0); +// amount = Wallet::Wallet::amountFromString("10.1"); +// ASSERT_TRUE(amount > 0); +// } + +// void open_wallet_helper(Wallet::WalletManagerBase *wmgr, Wallet::Wallet **wallet, const std::string &pass, std::mutex *mutex) +// { +// if (mutex) +// mutex->lock(); +// LOG_PRINT_L3("opening wallet in thread: " << boost::this_thread::get_id()); +// *wallet = wmgr->openWallet(WALLET_NAME, pass, Wallet::NetworkType::TESTNET); +// LOG_PRINT_L3("wallet address: " << (*wallet)->mainAddress()); +// LOG_PRINT_L3("wallet status: " << (*wallet)->good()); +// LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id()); +// if (mutex) +// mutex->unlock(); +// } @@ -295,173 +290,169 @@ void open_wallet_helper(Wallet::WalletManagerBase *wmgr, Wallet::Wallet **wallet //} -TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen) -{ - // create password protected wallet - std::string wallet_pass = "password"; - std::string wrong_wallet_pass = "1111"; - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, wallet_pass, WALLET_LANG, Wallet::NetworkType::TESTNET); - std::string seed1 = wallet1->seed(); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - - Wallet::Wallet *wallet2 = nullptr; - Wallet::Wallet *wallet3 = nullptr; - std::mutex mutex; - - open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr); - ASSERT_TRUE(wallet2 != nullptr); - ASSERT_FALSE(wallet2->good()); - ASSERT_TRUE(wmgr->closeWallet(wallet2)); - - open_wallet_helper(wmgr, &wallet3, wallet_pass, nullptr); - ASSERT_TRUE(wallet3 != nullptr); - ASSERT_TRUE(wallet3->good()); - ASSERT_TRUE(wmgr->closeWallet(wallet3)); -} - - -TEST_F(WalletManagerTest, WalletManagerStoresWallet) -{ - - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - wallet1->store(""); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet2->good()); - ASSERT_TRUE(wallet2->seed() == seed1); -} - - -TEST_F(WalletManagerTest, WalletManagerMovesWallet) -{ - - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string WALLET_NAME_MOVED = std::string("/tmp/") + WALLET_NAME + ".moved"; - std::string seed1 = wallet1->seed(); - std::cout << "** seed: " << seed1 << std::endl; - ASSERT_TRUE(wallet1->store(WALLET_NAME_MOVED)); - - Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_MOVED, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet2->filename() == WALLET_NAME_MOVED); - ASSERT_TRUE(wallet2->keysFilename() == WALLET_NAME_MOVED + ".keys"); - ASSERT_TRUE(wallet2->good()); - ASSERT_TRUE(wallet2->seed() == seed1); -} - - -TEST_F(WalletManagerTest, WalletManagerChangesPassword) -{ - std::cout <<"++++++++++++++++++++++ 9 ++++++++++++++++++++++\n"; - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - ASSERT_TRUE(wallet1->setPassword(WALLET_PASS2)); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS2, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet2->good()); - ASSERT_TRUE(wallet2->seed() == seed1); - ASSERT_TRUE(wmgr->closeWallet(wallet2)); - Wallet::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_FALSE(wallet3->good()); -} - - - -TEST_F(WalletManagerTest, WalletManagerRecoversWallet) -{ - std::cout <<"++++++++++++++++++++++ 10 ++++++++++++++++++++++\n"; - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - std::string address1 = wallet1->mainAddress(); - ASSERT_FALSE(address1.empty()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - Utils::deleteWallet(WALLET_NAME); - Wallet::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME,WALLET_PASS, seed1, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet2->good()); - ASSERT_TRUE(wallet2->seed() == seed1); - ASSERT_TRUE(wallet2->mainAddress() == address1); - ASSERT_TRUE(wmgr->closeWallet(wallet2)); -} - - -TEST_F(WalletManagerTest, WalletManagerStoresWallet1) -{ - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - std::string address1 = wallet1->mainAddress(); - - ASSERT_TRUE(wallet1->store("")); - ASSERT_TRUE(wallet1->store(WALLET_NAME_COPY)); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet2->good()); - ASSERT_TRUE(wallet2->seed() == seed1); - ASSERT_TRUE(wallet2->mainAddress() == address1); - ASSERT_TRUE(wmgr->closeWallet(wallet2)); -} - - -TEST_F(WalletManagerTest, WalletManagerStoresWallet2) -{ - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - std::string address1 = wallet1->mainAddress(); - - ASSERT_TRUE(wallet1->store(WALLET_NAME_WITH_DIR)); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - - wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet1->good()); - ASSERT_TRUE(wallet1->seed() == seed1); - ASSERT_TRUE(wallet1->mainAddress() == address1); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} - - -TEST_F(WalletManagerTest, WalletManagerStoresWallet3) -{ - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - std::string address1 = wallet1->mainAddress(); - - 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, Wallet::NetworkType::MAINNET); - ASSERT_FALSE(wallet1->good()); - - // "close" always returns true; - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - - wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet1->good()); - ASSERT_TRUE(wallet1->seed() == seed1); - ASSERT_TRUE(wallet1->mainAddress() == address1); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - -} - - -TEST_F(WalletManagerTest, WalletManagerStoresWallet4) -{ - Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed1 = wallet1->seed(); - std::string address1 = wallet1->mainAddress(); +// TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen) +// { +// // create password protected wallet +// std::string wallet_pass = "password"; +// std::string wrong_wallet_pass = "1111"; +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, wallet_pass, WALLET_LANG, Wallet::NetworkType::TESTNET); +// std::string seed1 = wallet1->seed(); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); + +// Wallet::Wallet *wallet2 = nullptr; +// Wallet::Wallet *wallet3 = nullptr; +// std::mutex mutex; + +// open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr); +// ASSERT_TRUE(wallet2 != nullptr); +// ASSERT_FALSE(wallet2->good()); +// ASSERT_TRUE(wmgr->closeWallet(wallet2)); + +// open_wallet_helper(wmgr, &wallet3, wallet_pass, nullptr); +// ASSERT_TRUE(wallet3 != nullptr); +// ASSERT_TRUE(wallet3->good()); +// ASSERT_TRUE(wmgr->closeWallet(wallet3)); +// } + + +// TEST_F(WalletManagerTest, WalletManagerStoresWallet) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// wallet1->store(""); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet2->good()); +// ASSERT_TRUE(wallet2->seed() == seed1); +// } + + +// TEST_F(WalletManagerTest, WalletManagerMovesWallet) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string WALLET_NAME_MOVED = std::string("/tmp/") + WALLET_NAME + ".moved"; +// std::string seed1 = wallet1->seed(); +// std::cout << "** seed: " << seed1 << std::endl; +// ASSERT_TRUE(wallet1->store(WALLET_NAME_MOVED)); + +// Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_MOVED, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet2->filename() == WALLET_NAME_MOVED); +// ASSERT_TRUE(wallet2->keysFilename() == WALLET_NAME_MOVED + ".keys"); +// ASSERT_TRUE(wallet2->good()); +// ASSERT_TRUE(wallet2->seed() == seed1); +// } + + +// TEST_F(WalletManagerTest, WalletManagerChangesPassword) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// ASSERT_TRUE(wallet1->setPassword(WALLET_PASS2)); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME, WALLET_PASS2, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet2->good()); +// ASSERT_TRUE(wallet2->seed() == seed1); +// ASSERT_TRUE(wmgr->closeWallet(wallet2)); +// Wallet::Wallet * wallet3 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_FALSE(wallet3->good()); +// } + + + +// TEST_F(WalletManagerTest, WalletManagerRecoversWallet) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// std::string address1 = wallet1->mainAddress(); +// ASSERT_FALSE(address1.empty()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// Utils::deleteWallet(WALLET_NAME); +// Wallet::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME,WALLET_PASS, seed1, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet2->good()); +// ASSERT_TRUE(wallet2->seed() == seed1); +// ASSERT_TRUE(wallet2->mainAddress() == address1); +// ASSERT_TRUE(wmgr->closeWallet(wallet2)); +// } + + +// TEST_F(WalletManagerTest, WalletManagerStoresWallet1) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// std::string address1 = wallet1->mainAddress(); + +// ASSERT_TRUE(wallet1->store("")); +// ASSERT_TRUE(wallet1->store(WALLET_NAME_COPY)); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// // Wallet::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS, Wallet::NetworkType::MAINNET); +// // ASSERT_TRUE(wallet2->good()); +// // ASSERT_TRUE(wallet2->seed() == seed1); +// // ASSERT_TRUE(wallet2->mainAddress() == address1); +// // ASSERT_TRUE(wmgr->closeWallet(wallet2)); +// } + + +// TEST_F(WalletManagerTest, WalletManagerStoresWallet2) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// std::string address1 = wallet1->mainAddress(); + +// ASSERT_TRUE(wallet1->store(WALLET_NAME_WITH_DIR)); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); + +// wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet1->good()); +// ASSERT_TRUE(wallet1->seed() == seed1); +// ASSERT_TRUE(wallet1->mainAddress() == address1); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } + + +// TEST_F(WalletManagerTest, WalletManagerStoresWallet3) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// std::string address1 = wallet1->mainAddress(); + +// 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, Wallet::NetworkType::MAINNET); +// ASSERT_FALSE(wallet1->good()); + +// // "close" always returns true; +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); + +// wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet1->good()); +// ASSERT_TRUE(wallet1->seed() == seed1); +// ASSERT_TRUE(wallet1->mainAddress() == address1); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); + +// } + + +// TEST_F(WalletManagerTest, WalletManagerStoresWallet4) +// { +// Wallet::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed1 = wallet1->seed(); +// std::string address1 = wallet1->mainAddress(); - ASSERT_TRUE(wallet1->store("")); - ASSERT_TRUE(wallet1->good()); +// ASSERT_TRUE(wallet1->store("")); +// ASSERT_TRUE(wallet1->good()); - ASSERT_TRUE(wallet1->store("")); - ASSERT_TRUE(wallet1->good()); +// ASSERT_TRUE(wallet1->store("")); +// ASSERT_TRUE(wallet1->good()); + +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - - wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet1->good()); - ASSERT_TRUE(wallet1->seed() == seed1); - ASSERT_TRUE(wallet1->mainAddress() == address1); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet1->good()); +// ASSERT_TRUE(wallet1->seed() == seed1); +// ASSERT_TRUE(wallet1->mainAddress() == address1); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } @@ -469,7 +460,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet4) TEST_F(WalletManagerTest, WalletManagerFindsWallet) { std::vector wallets = wmgr->findWallets(WALLETS_ROOT_DIR); - // Have to create by using create_wallet.sh + // wallet have to create by own ASSERT_FALSE(wallets.empty()); std::cout << "Found wallets: " << std::endl; for (auto wallet_path: wallets) { @@ -478,21 +469,21 @@ TEST_F(WalletManagerTest, WalletManagerFindsWallet) } -TEST_F(WalletTest1, WalletGeneratesPaymentId) -{ - std::string payment_id = Wallet::Wallet::genPaymentId(); - ASSERT_TRUE(payment_id.length() == 16); -} +// TEST_F(WalletTest1, WalletGeneratesPaymentId) +// { +// std::string payment_id = Wallet::Wallet::genPaymentId(); +// ASSERT_TRUE(payment_id.length() == 16); +// } -TEST_F(WalletTest1, WalletGeneratesIntegratedAddress) -{ - std::string payment_id = Wallet::Wallet::genPaymentId(); +// TEST_F(WalletTest1, WalletGeneratesIntegratedAddress) +// { +// std::string payment_id = Wallet::Wallet::genPaymentId(); - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - std::string integrated_address = wallet1->integratedAddress(payment_id); - ASSERT_TRUE(integrated_address.length() == 106); -} +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// std::string integrated_address = wallet1->integratedAddress(payment_id); +// ASSERT_TRUE(integrated_address.length() == 106); +// } TEST_F(WalletTest1, WalletShowsBalance) @@ -506,7 +497,7 @@ TEST_F(WalletTest1, WalletShowsBalance) uint64_t unlockedBalance1 = wallet1->unlockedBalance(0); ASSERT_TRUE(wmgr->closeWallet(wallet1)); Wallet::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - + ASSERT_TRUE(wallet2->init(TESTNET_DAEMON_ADDRESS, 0)); ASSERT_TRUE(balance1 == wallet2->balance(0)); std::cout << "wallet balance: " << wallet2->balance(0) << std::endl; ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0)); @@ -514,30 +505,30 @@ TEST_F(WalletTest1, WalletShowsBalance) ASSERT_TRUE(wmgr->closeWallet(wallet2)); } -TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight) -{ - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - ASSERT_TRUE(wallet1->blockChainHeight() > 0); - wmgr->closeWallet(wallet1); -} +// TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight) +// { +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// ASSERT_TRUE(wallet1->blockChainHeight() > 0); +// wmgr->closeWallet(wallet1); +// } -TEST_F(WalletTest1, WalletReturnsDaemonBlockHeight) -{ - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // wallet not connected to daemon - ASSERT_TRUE(wallet1->daemonBlockChainHeight() == 0); - ASSERT_TRUE(wallet1->good()); - ASSERT_FALSE(wmgr->errorString().empty()); - wmgr->closeWallet(wallet1); - - wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // wallet connected to daemon - wallet1->init(TESTNET_DAEMON_ADDRESS, 0); - ASSERT_TRUE(wallet1->daemonBlockChainHeight() > 0); - std::cout << "daemonBlockChainHeight: " << wallet1->daemonBlockChainHeight() << std::endl; - wmgr->closeWallet(wallet1); -} +// TEST_F(WalletTest1, WalletReturnsDaemonBlockHeight) +// { +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // wallet not connected to daemon +// ASSERT_TRUE(wallet1->daemonBlockChainHeight() == 0); +// ASSERT_TRUE(wallet1->good()); +// ASSERT_FALSE(wmgr->errorString().empty()); +// wmgr->closeWallet(wallet1); + +// wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // wallet connected to daemon +// wallet1->init(TESTNET_DAEMON_ADDRESS, 0); +// ASSERT_TRUE(wallet1->daemonBlockChainHeight() > 0); +// std::cout << "daemonBlockChainHeight: " << wallet1->daemonBlockChainHeight() << std::endl; +// wmgr->closeWallet(wallet1); +// } TEST_F(WalletTest1, WalletRefresh) @@ -552,27 +543,28 @@ TEST_F(WalletTest1, WalletRefresh) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } -TEST_F(WalletTest1, WalletConvertsToString) -{ - std::string strAmount = Wallet::Wallet::displayAmount(AMOUNT_5XMR); - ASSERT_TRUE(AMOUNT_5XMR == Wallet::Wallet::amountFromString(strAmount)); +// TEST_F(WalletTest1, WalletConvertsToString) +// { +// std::string strAmount = Wallet::Wallet::displayAmount(AMOUNT_5XMR); +// ASSERT_TRUE(AMOUNT_5XMR == Wallet::Wallet::amountFromString(strAmount)); - ASSERT_TRUE(AMOUNT_2BDX == Wallet::Wallet::amountFromDouble(2.0)); - ASSERT_TRUE(AMOUNT_4BDX == Wallet::Wallet::amountFromDouble(4.0)); - ASSERT_TRUE(AMOUNT_1XMR == Wallet::Wallet::amountFromDouble(1.0)); +// ASSERT_TRUE(AMOUNT_5XMR == Wallet::Wallet::amountFromDouble(0.5)); +// ASSERT_TRUE(AMOUNT_10XMR == Wallet::Wallet::amountFromDouble(1.0)); +// ASSERT_TRUE(AMOUNT_1XMR == Wallet::Wallet::amountFromDouble(0.1)); -} +// } TEST_F(WalletTest1, WalletTransaction) { - std::cout <<"++++++++++++++++++++++ 23 ++++++++++++++++++++++\n"; Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); // make sure testnet daemon is running ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; uint64_t balance = wallet1->balance(0); std::cout <<"**balance: " << balance << std::endl; ASSERT_TRUE(wallet1->good()); @@ -582,12 +574,13 @@ TEST_F(WalletTest1, WalletTransaction) Wallet::PendingTransaction * transaction = wallet1->createTransaction(recepient_address, - AMOUNT_4BDX); + AMOUNT_10XMR); ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; wallet1->refresh(); - + std::cout <<"refresh_end...\n"; ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(transaction->amount() == AMOUNT_4BDX); + ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR); ASSERT_TRUE(transaction->commit()); ASSERT_FALSE(wallet1->balance(0) == balance); ASSERT_TRUE(wmgr->closeWallet(wallet1)); @@ -595,191 +588,188 @@ TEST_F(WalletTest1, WalletTransaction) -TEST_F(WalletTest1, WalletTransactionWithMixin) -{ - std::cout <<"++++++++++++++++++++++ 24 ++++++++++++++++++++++\n"; - std::vector 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); +// TEST_F(WalletTest1, WalletTransactionWithMixin) +// { +// std::vector 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 = ""; +// std::string payment_id = ""; - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet1->refresh()); - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet1->refresh()); +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - 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; +// 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; - Wallet::PendingTransaction * transaction = wallet1->createTransaction( - recepient_address,AMOUNT_2BDX); - - std::cerr << "Transaction status: " << transaction->good()<< std::endl; - std::cerr << "Transaction fee: " << Wallet::Wallet::displayAmount(transaction->fee()) << std::endl; - std::cerr << "Transaction error: " << wmgr->errorString() << std::endl; - ASSERT_TRUE(transaction->good()); - wallet1->disposeTransaction(transaction); - } +// Wallet::PendingTransaction * transaction = wallet1->createTransaction( +// recepient_address,AMOUNT_5XMR); - wallet1->refresh(); +// std::cerr << "Transaction status: " << transaction->good()<< std::endl; +// std::cerr << "Transaction fee: " << Wallet::Wallet::displayAmount(transaction->fee()) << std::endl; +// std::cerr << "Transaction error: " << wmgr->errorString() << std::endl; +// ASSERT_TRUE(transaction->good()); +// wallet1->disposeTransaction(transaction); +// } - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// wallet1->refresh(); +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, WalletTransactionWithPriority) -{ - std::string payment_id = ""; +// TEST_F(WalletTest1, WalletTransactionWithPriority) +// { +// std::string payment_id = ""; - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet1->refresh()); - uint64_t balance = wallet1->balance(0); - ASSERT_TRUE(wallet1->good()); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet1->refresh()); +// uint64_t balance = wallet1->balance(0); +// ASSERT_TRUE(wallet1->good()); - std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); - uint32_t mixin = 2; - uint64_t fee = 0; +// std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); +// uint32_t mixin = 2; +// uint64_t fee = 0; - std::vector priorities = { - 1,2,3 - }; +// std::vector priorities = { +// 1,2,3 +// }; - for (auto it = priorities.begin(); it != priorities.end(); ++it) { - std::cerr << "Transaction priority: " << *it << std::endl; +// for (auto it = priorities.begin(); it != priorities.end(); ++it) { +// std::cerr << "Transaction priority: " << *it << std::endl; - Wallet::PendingTransaction * transaction = wallet1->createTransaction( - recepient_address, AMOUNT_2BDX, *it); - std::cerr << "Transaction status: " << transaction->good()<< std::endl; - std::cerr << "Transaction fee: " << Wallet::Wallet::displayAmount(transaction->fee()) << std::endl; - std::cerr << "Transaction error: " << wmgr->errorString() << std::endl; - ASSERT_TRUE(transaction->fee() > fee); - ASSERT_TRUE(transaction->good()); - fee = transaction->fee(); - wallet1->disposeTransaction(transaction); - } - wallet1->refresh(); - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} - - - -TEST_F(WalletTest1, WalletHistory) -{ - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet1->refresh()); - Wallet::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; - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet_src->refresh()); - Wallet::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); - - - Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, - AMOUNT_4BDX * 2); - - ASSERT_TRUE(tx->good()); - 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) -{ - - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet_src->refresh()); - Wallet::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 = Wallet::Wallet::genPaymentId(); - ASSERT_TRUE(payment_id.length() == 16); - - - Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, - AMOUNT_1XMR); - - ASSERT_TRUE(tx->good()); - 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); -} +// Wallet::PendingTransaction * transaction = wallet1->createTransaction( +// recepient_address, AMOUNT_5XMR, *it); +// std::cerr << "Transaction status: " << transaction->good()<< std::endl; +// std::cerr << "Transaction fee: " << Wallet::Wallet::displayAmount(transaction->fee()) << std::endl; +// std::cerr << "Transaction error: " << wmgr->errorString() << std::endl; +// ASSERT_TRUE(transaction->fee() > fee); +// ASSERT_TRUE(transaction->good()); +// fee = transaction->fee(); +// wallet1->disposeTransaction(transaction); +// } +// wallet1->refresh(); +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } + + + +// TEST_F(WalletTest1, WalletHistory) +// { +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet1->refresh()); +// Wallet::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; +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet_src->refresh()); +// Wallet::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); + + +// Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, +// AMOUNT_10XMR * 2); + +// ASSERT_TRUE(tx->good()); +// 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) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet_src->refresh()); +// Wallet::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 = Wallet::Wallet::genPaymentId(); +// ASSERT_TRUE(payment_id.length() == 16); + + +// Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, +// AMOUNT_1XMR); + +// ASSERT_TRUE(tx->good()); +// 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 Wallet::WalletListener @@ -875,253 +865,245 @@ struct MyWalletListener : public Wallet::WalletListener -TEST_F(WalletTest2, WalletCallBackRefreshedSync) -{ - - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - 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::unique_lock lock{wallet_src_listener->mutex}; - wallet_src_listener->cv_refresh.wait_for(lock, 3min); - wmgr->closeWallet(wallet_src); -} - - - - -TEST_F(WalletTest2, WalletCallBackRefreshedAsync) -{ - - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); - - std::unique_lock 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, 20s); - std::cerr << "TEST: refresh lock acquired...\n"; - ASSERT_TRUE(wallet_src_listener->refresh_triggered); - ASSERT_TRUE(wallet_src->connected()); - std::cerr << "TEST: closing wallet...\n"; - wmgr->closeWallet(wallet_src); -} - - - - -TEST_F(WalletTest2, WalletCallbackSent) -{ +// TEST_F(WalletTest2, WalletCallBackRefreshedSync) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// 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::unique_lock lock{wallet_src_listener->mutex}; +// wallet_src_listener->cv_refresh.wait_for(lock, 3min); +// wmgr->closeWallet(wallet_src); +// } + - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // 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(0); - std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl; - Wallet::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - - uint64_t amount = AMOUNT_1XMR * 5; - std::cout << "** Sending " << Wallet::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress(); - - - Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(), - amount); - std::cout << "** Committing transaction: " << Wallet::Wallet::displayAmount(tx->amount()) - << " with fee: " << Wallet::Wallet::displayAmount(tx->fee()); - - ASSERT_TRUE(tx->good()); - ASSERT_TRUE(tx->commit()); - - std::unique_lock lock{wallet_src_listener->mutex}; - std::cerr << "TEST: waiting on send lock...\n"; - wallet_src_listener->cv_send.wait_for(lock, 3min); - std::cerr << "TEST: send lock acquired...\n"; - ASSERT_TRUE(wallet_src_listener->send_triggered); - ASSERT_TRUE(wallet_src_listener->update_triggered); - std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl; - ASSERT_TRUE(wallet_src->balance(0) < balance); - wmgr->closeWallet(wallet_src); - wmgr->closeWallet(wallet_dst); -} -TEST_F(WalletTest2, WalletCallbackReceived) -{ +// TEST_F(WalletTest2, WalletCallBackRefreshedAsync) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // 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(0)) << std::endl; - - Wallet::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet_dst->refresh()); - uint64_t balance = wallet_dst->balance(0); - std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl; - std::unique_ptr wallet_dst_listener (new MyWalletListener(wallet_dst)); - - uint64_t amount = AMOUNT_1XMR * 5; - std::cout << "** Sending " << Wallet::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress(); - Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(), - amount); - - std::cout << "** Committing transaction: " << Wallet::Wallet::displayAmount(tx->amount()) - << " with fee: " << Wallet::Wallet::displayAmount(tx->fee()); - - ASSERT_TRUE(tx->good()); - ASSERT_TRUE(tx->commit()); - - std::unique_lock lock{wallet_dst_listener->mutex}; - std::cerr << "TEST: waiting on receive lock...\n"; - wallet_dst_listener->cv_receive.wait_for(lock, 4min); - std::cerr << "TEST: receive lock acquired...\n"; - ASSERT_TRUE(wallet_dst_listener->receive_triggered); - ASSERT_TRUE(wallet_dst_listener->update_triggered); - - std::cout << "** Balance src2: " << wallet_dst->displayAmount(wallet_src->balance(0)) << std::endl; - std::cout << "** Balance dst2: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl; - - ASSERT_TRUE(wallet_dst->balance(0) > balance); - - wmgr->closeWallet(wallet_src); - wmgr->closeWallet(wallet_dst); -} +// std::unique_lock 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, 20s); +// std::cerr << "TEST: refresh lock acquired...\n"; +// ASSERT_TRUE(wallet_src_listener->refresh_triggered); +// ASSERT_TRUE(wallet_src->connected()); +// std::cerr << "TEST: closing wallet...\n"; +// wmgr->closeWallet(wallet_src); +// } -TEST_F(WalletTest2, WalletCallbackNewBlock) -{ - Wallet::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET5_NAME, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet_src->refresh()); - uint64_t bc1 = wallet_src->blockChainHeight(); - std::cout << "** Block height: " << bc1 << std::endl; - - - std::unique_ptr wallet_listener (new MyWalletListener(wallet_src)); - - // wait max 4 min for new block - std::unique_lock lock{wallet_listener->mutex}; - std::cerr << "TEST: waiting on newblock lock...\n"; - wallet_listener->cv_newblock.wait_for(lock, 4min); - std::cerr << "TEST: newblock lock acquired...\n"; - ASSERT_TRUE(wallet_listener->newblock_triggered); - uint64_t bc2 = wallet_src->blockChainHeight(); - std::cout << "** Block height: " << bc2 << std::endl; - ASSERT_TRUE(bc2 > bc1); - wmgr->closeWallet(wallet_src); - -} - -TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetSync) -{ - - Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); - std::unique_ptr 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 2 minutes should be enough for fast refresh - constexpr auto wait_for = 2min; - - Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); - std::unique_ptr wallet_listener (new MyWalletListener(wallet)); - - std::unique_lock 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->good()); - 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 2 minutes should be enough for fast refresh - constexpr auto wait_for = 2min; - - Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); - wmgr->closeWallet(wallet); - wallet = wmgr->openWallet(WALLET_NAME_MAINNET, "", Wallet::NetworkType::MAINNET); - - std::unique_ptr wallet_listener (new MyWalletListener(wallet)); - - std::unique_lock 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->good()); - 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 2 minutes should be enough for fast refresh - constexpr auto wait_for = 2min; - Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); - std::string seed = wallet->seed(); - std::string address = wallet->mainAddress(); - wmgr->closeWallet(wallet); - - // deleting wallet files - Utils::deleteWallet(WALLET_NAME_MAINNET); - // ..and recovering wallet from seed - - wallet = wmgr->recoveryWallet(WALLET_NAME_MAINNET,"", seed, Wallet::NetworkType::MAINNET); - ASSERT_TRUE(wallet->good()); - ASSERT_TRUE(wallet->mainAddress() == address); - std::unique_ptr wallet_listener (new MyWalletListener(wallet)); - std::unique_lock 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->good()); - 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"; - -} +// TEST_F(WalletTest2, WalletCallbackSent) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // 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(0); +// std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl; +// Wallet::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + +// uint64_t amount = AMOUNT_1XMR * 5; +// std::cout << "** Sending " << Wallet::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress(); + + +// Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(), +// amount); +// std::cout << "** Committing transaction: " << Wallet::Wallet::displayAmount(tx->amount()) +// << " with fee: " << Wallet::Wallet::displayAmount(tx->fee()); + +// ASSERT_TRUE(tx->good()); +// ASSERT_TRUE(tx->commit()); + +// std::unique_lock lock{wallet_src_listener->mutex}; +// std::cerr << "TEST: waiting on send lock...\n"; +// wallet_src_listener->cv_send.wait_for(lock, 3min); +// std::cerr << "TEST: send lock acquired...\n"; +// ASSERT_TRUE(wallet_src_listener->send_triggered); +// ASSERT_TRUE(wallet_src_listener->update_triggered); +// std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl; +// ASSERT_TRUE(wallet_src->balance(0) < balance); +// wmgr->closeWallet(wallet_src); +// wmgr->closeWallet(wallet_dst); +// } + + +// TEST_F(WalletTest2, WalletCallbackReceived) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // 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(0)) << std::endl; + +// Wallet::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet_dst->refresh()); +// uint64_t balance = wallet_dst->balance(0); +// std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl; +// std::unique_ptr wallet_dst_listener (new MyWalletListener(wallet_dst)); + +// uint64_t amount = AMOUNT_1XMR * 5; +// std::cout << "** Sending " << Wallet::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress(); +// Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(), +// amount); + +// std::cout << "** Committing transaction: " << Wallet::Wallet::displayAmount(tx->amount()) +// << " with fee: " << Wallet::Wallet::displayAmount(tx->fee()); + +// ASSERT_TRUE(tx->good()); +// ASSERT_TRUE(tx->commit()); + +// std::unique_lock lock{wallet_dst_listener->mutex}; +// std::cerr << "TEST: waiting on receive lock...\n"; +// wallet_dst_listener->cv_receive.wait_for(lock, 4min); +// std::cerr << "TEST: receive lock acquired...\n"; +// ASSERT_TRUE(wallet_dst_listener->receive_triggered); +// ASSERT_TRUE(wallet_dst_listener->update_triggered); + +// std::cout << "** Balance src2: " << wallet_dst->displayAmount(wallet_src->balance(0)) << std::endl; +// std::cout << "** Balance dst2: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl; + +// ASSERT_TRUE(wallet_dst->balance(0) > balance); + +// wmgr->closeWallet(wallet_src); +// wmgr->closeWallet(wallet_dst); +// } + + + +// TEST_F(WalletTest2, WalletCallbackNewBlock) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET5_NAME, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet_src->refresh()); +// uint64_t bc1 = wallet_src->blockChainHeight(); +// std::cout << "** Block height: " << bc1 << std::endl; + + +// std::unique_ptr wallet_listener (new MyWalletListener(wallet_src)); + +// // wait max 4 min for new block +// std::unique_lock lock{wallet_listener->mutex}; +// std::cerr << "TEST: waiting on newblock lock...\n"; +// wallet_listener->cv_newblock.wait_for(lock, 4min); +// std::cerr << "TEST: newblock lock acquired...\n"; +// ASSERT_TRUE(wallet_listener->newblock_triggered); +// uint64_t bc2 = wallet_src->blockChainHeight(); +// std::cout << "** Block height: " << bc2 << std::endl; +// ASSERT_TRUE(bc2 > bc1); +// wmgr->closeWallet(wallet_src); + +// } + +// TEST_F(WalletManagerMainnetTest, CreateOpenAndRefreshWalletMainNetSync) +// { +// Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::unique_ptr 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 2 minutes should be enough for fast refresh +// constexpr auto wait_for = 2min; + +// Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::unique_ptr wallet_listener (new MyWalletListener(wallet)); + +// std::unique_lock 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->good()); +// 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 2 minutes should be enough for fast refresh +// constexpr auto wait_for = 2min; + +// Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); +// wmgr->closeWallet(wallet); +// wallet = wmgr->openWallet(WALLET_NAME_MAINNET, "", Wallet::NetworkType::MAINNET); + +// std::unique_ptr wallet_listener (new MyWalletListener(wallet)); + +// std::unique_lock 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->good()); +// 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 2 minutes should be enough for fast refresh +// constexpr auto wait_for = 2min; +// Wallet::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG, Wallet::NetworkType::MAINNET); +// std::string seed = wallet->seed(); +// std::string address = wallet->mainAddress(); +// wmgr->closeWallet(wallet); + +// // deleting wallet files +// Utils::deleteWallet(WALLET_NAME_MAINNET); +// // ..and recovering wallet from seed + +// wallet = wmgr->recoveryWallet(WALLET_NAME_MAINNET,"", seed, Wallet::NetworkType::MAINNET); +// ASSERT_TRUE(wallet->good()); +// ASSERT_TRUE(wallet->mainAddress() == address); +// std::unique_ptr wallet_listener (new MyWalletListener(wallet)); +// std::unique_lock 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->good()); +// 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"; + +// } From db8a58e145a9783f37d023ba41818326d3989f68 Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Fri, 14 Jul 2023 22:56:01 +0530 Subject: [PATCH 02/23] basic function for buy BNS from libwalletapi --- src/wallet/api/wallet.cpp | 146 +++++++++++++++++++++++++++++++++++ src/wallet/api/wallet.h | 8 ++ src/wallet/api/wallet2_api.h | 21 +++++ 3 files changed, 175 insertions(+) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 24adeb1050..ce13d96322 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1715,6 +1715,152 @@ PendingTransaction *WalletImpl::createTransaction(const std::string &dst_addr, s return createTransactionMultDest(std::vector {dst_addr}, amount ? (std::vector {*amount}) : (std::optional>()), priority, subaddr_account, subaddr_indices); } +EXPORT +bool WalletImpl::validate_bns_type(std::string mapping,bns::mapping_type *mapping_type) +{ + LOG_PRINT_L1(__FUNCTION__ << "Check bns type"); + std::optional mapping_type_; + + //TODO wallet bns type check have to add + if (tools::string_iequal(mapping, "bchat")) + mapping_type_ = bns::mapping_type::bchat; + else if (tools::string_iequal(mapping, "belnet")) + mapping_type_ = bns::mapping_type::belnet; + else if (tools::string_iequal_any(mapping, "belnet_1y", "belnet_1years")) // Can also specify "belnet" + mapping_type_ = bns::mapping_type::belnet; + else if (tools::string_iequal_any(mapping, "belnet_2y", "belnet_2years")) + mapping_type_ = bns::mapping_type::belnet_2years; + else if (tools::string_iequal_any(mapping, "belnet_5y", "belnet_5years")) + mapping_type_ = bns::mapping_type::belnet_5years; + else if (tools::string_iequal_any(mapping, "belnet_10y", "belnet_10years")) + mapping_type_ = bns::mapping_type::belnet_10years; + else + { + setStatusError(tr("Unsupported BNS type")); + return false; + } + + LOG_PRINT_L1(__FUNCTION__ << "Bnstype asigning..."); + *mapping_type = *mapping_type_; + return true; +} + +EXPORT +PendingTransaction *WalletImpl::createBnsTransaction(std::string& owner, std::string& backup_owner,std::string &value,std::string &name,std::string &bnstype, + uint32_t priority, uint32_t subaddr_account, std::set subaddr_indices) + +{ + clearStatus(); + // Pause refresh thread while creating transaction + pauseRefresh(); + + PendingTransactionImpl * transaction = new PendingTransactionImpl(*this); + + do { + auto w = wallet(); + bns::mapping_type mapping_type; + if(!validate_bns_type(bnstype, &mapping_type)) + break; + + // Getting subaddress for create a transaction from this subaddress + if (subaddr_indices.empty()) { + for (uint32_t index = 0; index < w->get_num_subaddresses(subaddr_account); ++index) + subaddr_indices.insert(index); + } + + std::string reason; + try { + LOG_PRINT_L1(__FUNCTION__ << "Create bns_buy is start..."); + transaction->m_pending_tx = w->bns_create_buy_mapping_tx(mapping_type, + owner.size() ? &owner : nullptr, + backup_owner.size() ? &backup_owner : nullptr, + name, + value, + &reason, + priority, + subaddr_account, + subaddr_indices); + + pendingTxPostProcess(transaction); + + }catch (const tools::error::daemon_busy&) { + // TODO: make it translatable with "tr"? + setStatusError(tr("daemon is busy. Please try again later.")); + } catch (const tools::error::no_connection_to_daemon&) { + setStatusError(tr("no connection to daemon. Please make sure daemon is running.")); + } catch (const tools::error::wallet_rpc_error& e) { + setStatusError(tr("RPC error: ") + e.to_string()); + } catch (const tools::error::get_outs_error &e) { + setStatusError((boost::format(tr("failed to get outputs to mix: %s")) % e.what()).str()); + } catch (const tools::error::not_enough_unlocked_money& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, available only %s, sent amount %s")) % + print_money(e.available()) % + print_money(e.tx_amount()); + setStatusError(writer.str()); + } catch (const tools::error::not_enough_money& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, overall balance only %s, sent amount %s")) % + print_money(e.available()) % + print_money(e.tx_amount()); + setStatusError(writer.str()); + } catch (const tools::error::tx_not_possible& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) % + print_money(e.available()) % + print_money(e.tx_amount() + e.fee()) % + print_money(e.tx_amount()) % + print_money(e.fee()); + setStatusError(writer.str()); + } catch (const tools::error::not_enough_outs_to_mix& e) { + std::ostringstream writer; + writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":"; + for (const std::pair outs_for_amount : e.scanty_outs()) { + writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second; + } + writer << "\n" << tr("Please sweep unmixable outputs."); + setStatusError(writer.str()); + } catch (const tools::error::tx_not_constructed&) { + setStatusError(tr("transaction was not constructed")); + } catch (const tools::error::tx_rejected& e) { + std::ostringstream writer; + writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status(); + setStatusError(writer.str()); + } catch (const tools::error::tx_sum_overflow& e) { + setStatusError(e.what()); + } catch (const tools::error::zero_destination&) { + setStatusError(tr("one of destinations is zero")); + } catch (const tools::error::tx_too_big& e) { + setStatusError(tr("failed to find a suitable way to split transactions")); + } catch (const tools::error::transfer_error& e) { + setStatusError(std::string(tr("unknown transfer error: ")) + e.what()); + } catch (const tools::error::wallet_internal_error& e) { + setStatusError(std::string(tr("internal error: ")) + e.what()); + } catch (const std::exception& e) { + setStatusError(std::string(tr("unexpected error: ")) + e.what()); + } catch (...) { + setStatusError(tr("unknown error")); + } + + if (transaction->m_pending_tx.empty()) + { + LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); + setStatusError(reason); + return transaction; + } + + }while(false); + + LOG_PRINT_L1(__FUNCTION__ << "Status given to transaction object"); + transaction->m_status = status(); + // Resume refresh thread + startRefresh(); + return transaction; +} + EXPORT PendingTransaction *WalletImpl::createSweepUnmixableTransaction() diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index e6a0ea7f57..a741d32916 100755 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -180,6 +180,14 @@ class WalletImpl : public Wallet uint32_t priority = 0, uint32_t subaddr_account = 0, std::set subaddr_indices = {}) override; + PendingTransaction* createBnsTransaction(std::string& owner, + std::string& backup_owner, + std::string &value, + std::string &name, + std::string &bnstype, + uint32_t priority = 0, + uint32_t subaddr_account = 0, + std::set subaddr_indices = {}) override; PendingTransaction* createSweepUnmixableTransaction() override; bool submitTransaction(std::string_view filename) override; UnsignedTransaction* loadUnsignedTx(std::string_view unsigned_filename) override; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 55f1994098..6417a989e1 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -860,6 +860,27 @@ struct Wallet uint32_t subaddr_account = 0, std::set subaddr_indices = {}) = 0; + /*! + * \brief createBnsTransaction creates bns transaction + * \param owner owner + * \param backup_owner backup_owner + * \param value bchatid or belnet or wallet address + * \param name bns name + * \param bnstype type(bchat,belnet,wallet) + * \param subaddr_account subaddress account from which the input funds are taken + * \param subaddr_indices set of subaddress indices to use for transfer or sweeping. if set empty, all are chosen when sweeping, and one or more are automatically chosen when transferring. after execution, returns the set of actually used indices + * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() + * after object returned + */ + virtual PendingTransaction *createBnsTransaction(std::string& owner, + std::string& backup_owner, + std::string &value, + std::string &name, + std::string &bnstype, + uint32_t priority = 0, + uint32_t subaddr_account = 0, + std::set subaddr_indices = {}) = 0; + /*! * \brief createSweepUnmixableTransaction creates transaction with unmixable outputs. * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() From aa49e37a1cce163a622f55e65cea32fbea504855 Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Fri, 14 Jul 2023 23:01:09 +0530 Subject: [PATCH 03/23] testcase for the bns_buy --- tests/libwallet_api_tests/main.cpp | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 3db1267283..928b0c6180 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -586,7 +586,39 @@ TEST_F(WalletTest1, WalletTransaction) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } +TEST_F(WalletTest1, BnsBuyTransaction) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; + std::string name ="blackpearl.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, + backup_owner, + value, + name, + type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_TRUE(transaction->commit()); + ASSERT_FALSE(wallet1->balance(0) == balance); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} // TEST_F(WalletTest1, WalletTransactionWithMixin) // { From a27c3beadc307e10a9a02d1bd6a04cc6381f233b Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Fri, 14 Jul 2023 23:11:30 +0530 Subject: [PATCH 04/23] typo fix in liwalletapi testcase --- tests/libwallet_api_tests/main.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 928b0c6180..5eb26f10c5 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -81,7 +81,7 @@ std::string CURRENT_DST_WALLET; const uint64_t AMOUNT_4BDX = 4000000000L; const uint64_t AMOUNT_2BDX = 2000000000L; -const uint64_t AMOUNT_1XMR = 1000000000L; +const uint64_t AMOUNT_1BDX = 1000000000L; const std::string PAYMENT_ID_EMPTY = ""; @@ -545,12 +545,12 @@ TEST_F(WalletTest1, WalletRefresh) // TEST_F(WalletTest1, WalletConvertsToString) // { -// std::string strAmount = Wallet::Wallet::displayAmount(AMOUNT_5XMR); -// ASSERT_TRUE(AMOUNT_5XMR == Wallet::Wallet::amountFromString(strAmount)); +// std::string strAmount = Wallet::Wallet::displayAmount(AMOUNT_2BDX); +// ASSERT_TRUE(AMOUNT_2BDX == Wallet::Wallet::amountFromString(strAmount)); -// ASSERT_TRUE(AMOUNT_5XMR == Wallet::Wallet::amountFromDouble(0.5)); -// ASSERT_TRUE(AMOUNT_10XMR == Wallet::Wallet::amountFromDouble(1.0)); -// ASSERT_TRUE(AMOUNT_1XMR == Wallet::Wallet::amountFromDouble(0.1)); +// ASSERT_TRUE(AMOUNT_2BDX == Wallet::Wallet::amountFromDouble(2.0)); +// ASSERT_TRUE(AMOUNT_4BDX == Wallet::Wallet::amountFromDouble(4.0)); +// ASSERT_TRUE(AMOUNT_1BDX == Wallet::Wallet::amountFromDouble(1.0)); // } @@ -574,13 +574,13 @@ TEST_F(WalletTest1, WalletTransaction) Wallet::PendingTransaction * transaction = wallet1->createTransaction(recepient_address, - AMOUNT_10XMR); + AMOUNT_4BDX); ASSERT_TRUE(transaction->good()); std::cout <<"refresh_started...\n"; wallet1->refresh(); std::cout <<"refresh_end...\n"; ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR); + ASSERT_TRUE(transaction->amount() == AMOUNT_4BDX); ASSERT_TRUE(transaction->commit()); ASSERT_FALSE(wallet1->balance(0) == balance); ASSERT_TRUE(wmgr->closeWallet(wallet1)); @@ -646,7 +646,7 @@ TEST_F(WalletTest1, BnsBuyTransaction) // std::cerr << "Transaction mixin count: " << mixin << std::endl; // Wallet::PendingTransaction * transaction = wallet1->createTransaction( -// recepient_address,AMOUNT_5XMR); +// recepient_address,AMOUNT_2BDX); // std::cerr << "Transaction status: " << transaction->good()<< std::endl; // std::cerr << "Transaction fee: " << Wallet::Wallet::displayAmount(transaction->fee()) << std::endl; @@ -686,7 +686,7 @@ TEST_F(WalletTest1, BnsBuyTransaction) // std::cerr << "Transaction priority: " << *it << std::endl; // Wallet::PendingTransaction * transaction = wallet1->createTransaction( -// recepient_address, AMOUNT_5XMR, *it); +// recepient_address, AMOUNT_2BDX, *it); // std::cerr << "Transaction status: " << transaction->good()<< std::endl; // std::cerr << "Transaction fee: " << Wallet::Wallet::displayAmount(transaction->fee()) << std::endl; // std::cerr << "Transaction error: " << wmgr->errorString() << std::endl; @@ -741,7 +741,7 @@ TEST_F(WalletTest1, BnsBuyTransaction) // Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, -// AMOUNT_10XMR * 2); +// AMOUNT_4BDX * 2); // ASSERT_TRUE(tx->good()); // ASSERT_TRUE(tx->commit()); @@ -781,7 +781,7 @@ TEST_F(WalletTest1, BnsBuyTransaction) // Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, -// AMOUNT_1XMR); +// AMOUNT_1BDX); // ASSERT_TRUE(tx->good()); // ASSERT_TRUE(tx->commit()); @@ -943,7 +943,7 @@ struct MyWalletListener : public Wallet::WalletListener // std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl; // Wallet::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// uint64_t amount = AMOUNT_1XMR * 5; +// uint64_t amount = AMOUNT_1BDX * 5; // std::cout << "** Sending " << Wallet::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress(); @@ -983,7 +983,7 @@ struct MyWalletListener : public Wallet::WalletListener // std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl; // std::unique_ptr wallet_dst_listener (new MyWalletListener(wallet_dst)); -// uint64_t amount = AMOUNT_1XMR * 5; +// uint64_t amount = AMOUNT_1BDX * 5; // std::cout << "** Sending " << Wallet::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress(); // Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(), // amount); From 75cccd45146f0754a9940eec1d4ad32367d0a163 Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Mon, 17 Jul 2023 10:54:51 +0530 Subject: [PATCH 05/23] validate_bns_type function declaration added in walletImpl struct --- src/wallet/api/wallet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index a741d32916..5e88098dde 100755 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -250,6 +250,7 @@ class WalletImpl : public Wallet bool isNewWallet() const; void pendingTxPostProcess(PendingTransactionImpl * pending); bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, bool ssl = false); + bool validate_bns_type(std::string mapping,bns::mapping_type *mapping_type); private: friend class PendingTransactionImpl; From 561fed7d0dd525eac70d8e3d7eda5dfb4ec7fd24 Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Mon, 17 Jul 2023 14:47:26 +0530 Subject: [PATCH 06/23] is_bns() function added in transaction_info --- src/wallet/api/transaction_history.cpp | 4 ++ src/wallet/api/transaction_info.cpp | 7 +++ src/wallet/api/transaction_info.h | 2 + src/wallet/api/wallet2_api.h | 1 + tests/libwallet_api_tests/main.cpp | 80 +++++++++++++------------- 5 files changed, 55 insertions(+), 39 deletions(-) diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index 762196547c..d18a9befd1 100755 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -145,6 +145,7 @@ void TransactionHistoryImpl::refresh() ti->m_hash = tools::type_to_hex(pd.m_tx_hash); ti->m_blockheight = pd.m_block_height; ti->m_is_stake = pd.m_type == wallet::pay_type::stake; + ti->m_is_bns = pd.m_type == wallet::pay_type::bns; ti->m_subaddrIndex = { pd.m_subaddr_index.minor }; ti->m_subaddrAccount = pd.m_subaddr_index.major; ti->m_label = w->get_subaddress_label(pd.m_subaddr_index); @@ -190,6 +191,7 @@ void TransactionHistoryImpl::refresh() ti->m_hash = tools::type_to_hex(hash); ti->m_blockheight = pd.m_block_height; ti->m_is_stake = pd.m_pay_type == wallet::pay_type::stake; + ti->m_is_bns = pd.m_pay_type == wallet::pay_type::bns; ti->m_subaddrIndex = pd.m_subaddr_indices; ti->m_subaddrAccount = pd.m_subaddr_account; ti->m_label = pd.m_subaddr_indices.size() == 1 ? w->get_subaddress_label({pd.m_subaddr_account, *pd.m_subaddr_indices.begin()}) : ""; @@ -222,6 +224,7 @@ void TransactionHistoryImpl::refresh() ti->m_fee = fee; ti->m_direction = TransactionInfo::Direction_Out; ti->m_is_stake = pd.m_pay_type == wallet::pay_type::stake; + ti->m_is_bns = pd.m_pay_type == wallet::pay_type::bns; ti->m_failed = is_failed; ti->m_pending = true; ti->m_hash = tools::type_to_hex(hash); @@ -249,6 +252,7 @@ void TransactionHistoryImpl::refresh() ti->m_hash = tools::type_to_hex(pd.m_tx_hash); ti->m_blockheight = pd.m_block_height; ti->m_is_stake = pd.m_type == wallet::pay_type::stake; + ti->m_is_bns = pd.m_type == wallet::pay_type::bns; ti->m_pending = true; ti->m_subaddrIndex = { pd.m_subaddr_index.minor }; ti->m_subaddrAccount = pd.m_subaddr_index.major; diff --git a/src/wallet/api/transaction_info.cpp b/src/wallet/api/transaction_info.cpp index 3064c6274e..aebae20b1e 100755 --- a/src/wallet/api/transaction_info.cpp +++ b/src/wallet/api/transaction_info.cpp @@ -46,6 +46,7 @@ EXPORT TransactionInfoImpl::TransactionInfoImpl() : m_direction(Direction_Out) , m_is_stake(false) + , m_is_bns(false) , m_pending(false) , m_failed(false) , m_reward_type(reward_type::unspecified) @@ -90,6 +91,12 @@ bool TransactionInfoImpl::isStake() const return m_is_stake; } +EXPORT +bool TransactionInfoImpl::isBns() const +{ + return m_is_bns; +} + EXPORT bool TransactionInfoImpl::isPending() const { diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h index 2b6f658045..d96114997f 100755 --- a/src/wallet/api/transaction_info.h +++ b/src/wallet/api/transaction_info.h @@ -66,11 +66,13 @@ class TransactionInfoImpl : public TransactionInfo virtual uint64_t unlockTime() const override; bool isMasterNodeReward() const override; bool isStake() const override; + bool isBns() const override; bool isMinerReward() const override; private: int m_direction; bool m_is_stake; + bool m_is_bns; bool m_pending; bool m_failed; reward_type m_reward_type; // may have a value rather than `unspecified` after hf 10 diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 6417a989e1..f578446726 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -178,6 +178,7 @@ struct TransactionInfo virtual bool isMasterNodeReward() const = 0; virtual bool isMinerReward() const = 0; virtual bool isStake() const =0; + virtual bool isBns() const =0; virtual int direction() const = 0; virtual bool isPending() const = 0; virtual bool isFailed() const = 0; diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 5eb26f10c5..43066826f2 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -120,6 +120,7 @@ struct Utils << ", f: " << Wallet::Wallet::displayAmount(t->fee()) << ", h: " << t->hash() << ", pid: " << t->paymentId() + << ", stake or Bns : " << (t->isStake() ? "STAKE" : t->isBns() ? "BNS" : "false") << std::endl; } @@ -556,35 +557,35 @@ TEST_F(WalletTest1, WalletRefresh) -TEST_F(WalletTest1, WalletTransaction) +// TEST_F(WalletTest1, WalletTransaction) -{ - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// { +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); - const int MIXIN_COUNT = 4; +// std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); +// const int MIXIN_COUNT = 4; - Wallet::PendingTransaction * transaction = wallet1->createTransaction(recepient_address, - AMOUNT_4BDX); - ASSERT_TRUE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(transaction->amount() == AMOUNT_4BDX); - ASSERT_TRUE(transaction->commit()); - ASSERT_FALSE(wallet1->balance(0) == balance); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// Wallet::PendingTransaction * transaction = wallet1->createTransaction(recepient_address, +// AMOUNT_4BDX); +// ASSERT_TRUE(transaction->good()); +// std::cout <<"refresh_started...\n"; +// wallet1->refresh(); +// std::cout <<"refresh_end...\n"; +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_TRUE(transaction->amount() == AMOUNT_4BDX); +// ASSERT_TRUE(transaction->commit()); +// ASSERT_FALSE(wallet1->balance(0) == balance); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } TEST_F(WalletTest1, BnsBuyTransaction) { @@ -702,22 +703,22 @@ TEST_F(WalletTest1, BnsBuyTransaction) -// TEST_F(WalletTest1, WalletHistory) -// { -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// ASSERT_TRUE(wallet1->refresh()); -// Wallet::TransactionHistory * history = wallet1->history(); -// history->refresh(); -// ASSERT_TRUE(history->count() > 0); +TEST_F(WalletTest1, WalletHistory) +{ + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(wallet1->refresh()); + Wallet::TransactionHistory * history = wallet1->history(); + history->refresh(); + ASSERT_TRUE(history->count() > 0); -// for (auto t: history->getAll()) { -// ASSERT_TRUE(t != nullptr); -// Utils::print_transaction(t); -// } -// } + for (auto t: history->getAll()) { + ASSERT_TRUE(t != nullptr); + Utils::print_transaction(t); + } +} // TEST_F(WalletTest1, WalletTransactionAndHistory) // { @@ -902,6 +903,7 @@ struct MyWalletListener : public Wallet::WalletListener // Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); // MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); // ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet_src->refresh()); // ASSERT_TRUE(wallet_src_listener->refresh_triggered); // ASSERT_TRUE(wallet_src->connected()); // std::unique_lock lock{wallet_src_listener->mutex}; From 1e7b0e7a34e4568cbae756dcb71c889dcbd5f0e0 Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Mon, 17 Jul 2023 15:41:05 +0530 Subject: [PATCH 07/23] Testcase for wrong bnsType --- tests/libwallet_api_tests/main.cpp | 58 +++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 43066826f2..e42b1e0fbe 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -124,6 +124,11 @@ struct Utils << std::endl; } + static void print_status(std::pair status_) + { + std::cout <<"status: " << status_.second << std::endl; + } + static std::string get_wallet_address(const std::string &filename, const std::string &password) { Wallet::WalletManagerBase *wmgr = Wallet::WalletManagerFactory::getWalletManager(); @@ -621,6 +626,35 @@ TEST_F(WalletTest1, BnsBuyTransaction) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } +TEST_F(WalletTest1, BnsBuyTransactionWithWrongType) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; + std::string name ="blackpearl.bdx"; + std::string type ="belnett"; + Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, + backup_owner, + value, + name, + type); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + // TEST_F(WalletTest1, WalletTransactionWithMixin) // { // std::vector mixins; @@ -898,18 +932,18 @@ struct MyWalletListener : public Wallet::WalletListener -// TEST_F(WalletTest2, WalletCallBackRefreshedSync) -// { -// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); -// ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); -// ASSERT_TRUE(wallet_src->refresh()); -// ASSERT_TRUE(wallet_src_listener->refresh_triggered); -// ASSERT_TRUE(wallet_src->connected()); -// std::unique_lock lock{wallet_src_listener->mutex}; -// wallet_src_listener->cv_refresh.wait_for(lock, 3min); -// wmgr->closeWallet(wallet_src); -// } +TEST_F(WalletTest2, WalletCallBackRefreshedSync) +{ + Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); + ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(wallet_src->refresh()); + ASSERT_TRUE(wallet_src_listener->refresh_triggered); + ASSERT_TRUE(wallet_src->connected()); + std::unique_lock lock{wallet_src_listener->mutex}; + wallet_src_listener->cv_refresh.wait_for(lock, 3min); + wmgr->closeWallet(wallet_src); +} From 7f883b6a3d08899ee72a7bb95ab8d4b14b1f3d3d Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Mon, 17 Jul 2023 16:45:33 +0530 Subject: [PATCH 08/23] validate_bns updated for checking hf_version --- src/wallet/api/wallet.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index ce13d96322..876cf4d9ca 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1720,6 +1720,19 @@ bool WalletImpl::validate_bns_type(std::string mapping,bns::mapping_type *mappin { LOG_PRINT_L1(__FUNCTION__ << "Check bns type"); std::optional mapping_type_; + std::optional hf_version = hardForkVersion(); + if (!hf_version) + { + setStatusError(tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED); + return false; + } + + //TODO Enable this at the final stage + // if(hf_version <= cryptonote::network_version_17_POS) + // { + // setStatusError(tr("BNS Support is not available in this version ")); + // return false; + // } //TODO wallet bns type check have to add if (tools::string_iequal(mapping, "bchat")) From ad98ebbd977b05165069275e653e6a5cf326d3fe Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Tue, 18 Jul 2023 12:04:16 +0530 Subject: [PATCH 09/23] New testcase for bnsBuy with old value --- src/wallet/api/wallet.cpp | 2 +- tests/libwallet_api_tests/main.cpp | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 876cf4d9ca..ae70067b36 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1727,7 +1727,7 @@ bool WalletImpl::validate_bns_type(std::string mapping,bns::mapping_type *mappin return false; } - //TODO Enable this at the final stage + //TODO Enable this validation in the final stage // if(hf_version <= cryptonote::network_version_17_POS) // { // setStatusError(tr("BNS Support is not available in this version ")); diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index e42b1e0fbe..b333a9966e 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -655,6 +655,41 @@ TEST_F(WalletTest1, BnsBuyTransactionWithWrongType) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } +TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; + std::string name ="blackpearl.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, + backup_owner, + value, + name, + type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + // TEST_F(WalletTest1, WalletTransactionWithMixin) // { // std::vector mixins; From 50cc3143a4b56ec622adb626b57e317d6bb82084 Mon Sep 17 00:00:00 2001 From: deen-kakarot Date: Tue, 18 Jul 2023 14:41:33 +0530 Subject: [PATCH 10/23] error fixed --- src/wallet/api/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index ae70067b36..c4dea42d3d 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -2604,7 +2604,7 @@ void WalletImpl::hardForkInfo(uint8_t &version, uint64_t &earliest_height) const EXPORT std::optional WalletImpl::hardForkVersion() const { - m_wallet_ptr->get_hard_fork_version(); + return m_wallet_ptr->get_hard_fork_version(); } EXPORT From ad16f399c6980c2d4221baf45b1c1668a480d759 Mon Sep 17 00:00:00 2001 From: tore-tto Date: Tue, 18 Jul 2023 15:39:10 +0530 Subject: [PATCH 11/23] bnsUpdateTransaction() has added for libwalletapi --- src/wallet/api/wallet.cpp | 116 +++++++++++++++++++++++++++++++++++ src/wallet/api/wallet.h | 8 +++ src/wallet/api/wallet2_api.h | 21 ++++++- 3 files changed, 144 insertions(+), 1 deletion(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index c4dea42d3d..e8d6766c83 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1874,6 +1874,122 @@ PendingTransaction *WalletImpl::createBnsTransaction(std::string& owner, std::st return transaction; } +EXPORT +PendingTransaction *WalletImpl::bnsUpdateTransaction(std::string& owner, std::string& backup_owner,std::string &value,std::string &name,std::string &bnstype, + uint32_t priority, uint32_t subaddr_account, std::set subaddr_indices) + +{ + clearStatus(); + // Pause refresh thread while creating transaction + pauseRefresh(); + + PendingTransactionImpl * transaction = new PendingTransactionImpl(*this); + + do { + auto w = wallet(); + bns::mapping_type mapping_type; + if(!validate_bns_type(bnstype, &mapping_type)) + break; + + // Getting subaddress for create a transaction from this subaddress + if (subaddr_indices.empty()) { + for (uint32_t index = 0; index < w->get_num_subaddresses(subaddr_account); ++index) + subaddr_indices.insert(index); + } + + std::string reason; + try { + LOG_PRINT_L1(__FUNCTION__ << "Create bns_update is start..."); + transaction->m_pending_tx = w->bns_create_update_mapping_tx(mapping_type, + name, + value.size() ? &value : nullptr, + owner.size() ? &owner : nullptr, + backup_owner.size() ? &backup_owner : nullptr, + nullptr, + &reason, + priority, + subaddr_account, + subaddr_indices); + pendingTxPostProcess(transaction); + + }catch (const tools::error::daemon_busy&) { + // TODO: make it translatable with "tr"? + setStatusError(tr("daemon is busy. Please try again later.")); + } catch (const tools::error::no_connection_to_daemon&) { + setStatusError(tr("no connection to daemon. Please make sure daemon is running.")); + } catch (const tools::error::wallet_rpc_error& e) { + setStatusError(tr("RPC error: ") + e.to_string()); + } catch (const tools::error::get_outs_error &e) { + setStatusError((boost::format(tr("failed to get outputs to mix: %s")) % e.what()).str()); + } catch (const tools::error::not_enough_unlocked_money& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, available only %s, sent amount %s")) % + print_money(e.available()) % + print_money(e.tx_amount()); + setStatusError(writer.str()); + } catch (const tools::error::not_enough_money& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, overall balance only %s, sent amount %s")) % + print_money(e.available()) % + print_money(e.tx_amount()); + setStatusError(writer.str()); + } catch (const tools::error::tx_not_possible& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) % + print_money(e.available()) % + print_money(e.tx_amount() + e.fee()) % + print_money(e.tx_amount()) % + print_money(e.fee()); + setStatusError(writer.str()); + } catch (const tools::error::not_enough_outs_to_mix& e) { + std::ostringstream writer; + writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":"; + for (const std::pair outs_for_amount : e.scanty_outs()) { + writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second; + } + writer << "\n" << tr("Please sweep unmixable outputs."); + setStatusError(writer.str()); + } catch (const tools::error::tx_not_constructed&) { + setStatusError(tr("transaction was not constructed")); + } catch (const tools::error::tx_rejected& e) { + std::ostringstream writer; + writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status(); + setStatusError(writer.str()); + } catch (const tools::error::tx_sum_overflow& e) { + setStatusError(e.what()); + } catch (const tools::error::zero_destination&) { + setStatusError(tr("one of destinations is zero")); + } catch (const tools::error::tx_too_big& e) { + setStatusError(tr("failed to find a suitable way to split transactions")); + } catch (const tools::error::transfer_error& e) { + setStatusError(std::string(tr("unknown transfer error: ")) + e.what()); + } catch (const tools::error::wallet_internal_error& e) { + setStatusError(std::string(tr("internal error: ")) + e.what()); + } catch (const std::exception& e) { + setStatusError(std::string(tr("unexpected error: ")) + e.what()); + } catch (...) { + setStatusError(tr("unknown error")); + } + + if (transaction->m_pending_tx.empty()) + { + LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); + setStatusError(reason); + return transaction; + } + + }while(false); + + LOG_PRINT_L1(__FUNCTION__ << "Status given to transaction object"); + transaction->m_status = status(); + // Resume refresh thread + startRefresh(); + return transaction; +} + EXPORT PendingTransaction *WalletImpl::createSweepUnmixableTransaction() diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 5e88098dde..6c0b612859 100755 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -188,6 +188,14 @@ class WalletImpl : public Wallet uint32_t priority = 0, uint32_t subaddr_account = 0, std::set subaddr_indices = {}) override; + PendingTransaction* bnsUpdateTransaction(std::string& owner, + std::string& backup_owner, + std::string &value, + std::string &name, + std::string &bnstype, + uint32_t priority = 0, + uint32_t subaddr_account = 0, + std::set subaddr_indices = {}) override; PendingTransaction* createSweepUnmixableTransaction() override; bool submitTransaction(std::string_view filename) override; UnsignedTransaction* loadUnsignedTx(std::string_view unsigned_filename) override; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index f578446726..38a57b0de3 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -881,7 +881,26 @@ struct Wallet uint32_t priority = 0, uint32_t subaddr_account = 0, std::set subaddr_indices = {}) = 0; - + /*! + * \brief createBnsTransaction creates bns transaction + * \param owner owner + * \param backup_owner backup_owner + * \param value bchatid or belnet or wallet address + * \param name bns name + * \param bnstype type(bchat,belnet,wallet) + * \param subaddr_account subaddress account from which the input funds are taken + * \param subaddr_indices set of subaddress indices to use for transfer or sweeping. if set empty, all are chosen when sweeping, and one or more are automatically chosen when transferring. after execution, returns the set of actually used indices + * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() + * after object returned + */ + virtual PendingTransaction* bnsUpdateTransaction(std::string& owner, + std::string& backup_owner, + std::string& value, + std::string& name, + std::string& bnstype, + uint32_t priority = 0, + uint32_t subaddr_account = 0, + std::set subaddr_indices = {}) = 0; /*! * \brief createSweepUnmixableTransaction creates transaction with unmixable outputs. * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() From a0584b722ecbdc75b37c2aca5beb07773fe6b098 Mon Sep 17 00:00:00 2001 From: deen-kakarot Date: Tue, 18 Jul 2023 16:05:11 +0530 Subject: [PATCH 12/23] testcases added for bnsUpdateTransaction() --- src/wallet/api/wallet2_api.h | 2 +- tests/libwallet_api_tests/main.cpp | 61 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 38a57b0de3..87093143cc 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -882,7 +882,7 @@ struct Wallet uint32_t subaddr_account = 0, std::set subaddr_indices = {}) = 0; /*! - * \brief createBnsTransaction creates bns transaction + * \brief bnsUpdateTransaction creates bns update transaction * \param owner owner * \param backup_owner backup_owner * \param value bchatid or belnet or wallet address diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index b333a9966e..3dbdad2ca0 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -690,6 +690,67 @@ TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } +TEST_F(WalletTest1, BnsUpdateTransaction) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; + std::string name ="tontin.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_TRUE(transaction->commit()); + ASSERT_FALSE(wallet1->balance(0) == balance); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + +TEST_F(WalletTest1, BnsUpdateWithSameValue) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; + std::string name ="tontin.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + // TEST_F(WalletTest1, WalletTransactionWithMixin) // { // std::vector mixins; From 7cd8ce27f0e81aa4d82c43a52ec3aec362ff505d Mon Sep 17 00:00:00 2001 From: victor-tucci Date: Tue, 18 Jul 2023 16:47:02 +0530 Subject: [PATCH 13/23] ERROR: reason are added into the pendingTransaction::status() --- src/wallet/api/wallet.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index e8d6766c83..0f369c992f 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1793,7 +1793,13 @@ PendingTransaction *WalletImpl::createBnsTransaction(std::string& owner, std::st priority, subaddr_account, subaddr_indices); - + + if (transaction->m_pending_tx.empty()) + { + LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); + setStatusError(reason); + break; + } pendingTxPostProcess(transaction); }catch (const tools::error::daemon_busy&) { @@ -1858,13 +1864,6 @@ PendingTransaction *WalletImpl::createBnsTransaction(std::string& owner, std::st setStatusError(tr("unknown error")); } - if (transaction->m_pending_tx.empty()) - { - LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); - setStatusError(reason); - return transaction; - } - }while(false); LOG_PRINT_L1(__FUNCTION__ << "Status given to transaction object"); @@ -1910,6 +1909,13 @@ PendingTransaction *WalletImpl::bnsUpdateTransaction(std::string& owner, std::st priority, subaddr_account, subaddr_indices); + + if (transaction->m_pending_tx.empty()) + { + LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); + setStatusError(reason); + break; + } pendingTxPostProcess(transaction); }catch (const tools::error::daemon_busy&) { @@ -1974,13 +1980,6 @@ PendingTransaction *WalletImpl::bnsUpdateTransaction(std::string& owner, std::st setStatusError(tr("unknown error")); } - if (transaction->m_pending_tx.empty()) - { - LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); - setStatusError(reason); - return transaction; - } - }while(false); LOG_PRINT_L1(__FUNCTION__ << "Status given to transaction object"); From 3da269afa92234e61094ae41a5b65b0c5f8edb73 Mon Sep 17 00:00:00 2001 From: MogamboPuri Date: Tue, 18 Jul 2023 17:52:01 +0530 Subject: [PATCH 14/23] bnsRenewTransaction() has added for libwalletapi --- src/wallet/api/wallet.cpp | 113 +++++++++++++++++++++++++++++++++++ src/wallet/api/wallet.h | 5 ++ src/wallet/api/wallet2_api.h | 15 +++++ 3 files changed, 133 insertions(+) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 0f369c992f..f92466d64f 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1989,6 +1989,119 @@ PendingTransaction *WalletImpl::bnsUpdateTransaction(std::string& owner, std::st return transaction; } +EXPORT +PendingTransaction *WalletImpl::bnsRenewTransaction(std::string &name,std::string &bnstype,uint32_t priority, + uint32_t m_current_subaddress_account,std::set subaddr_indices) + +{ + clearStatus(); + // Pause refresh thread while creating transaction + pauseRefresh(); + + PendingTransactionImpl * transaction = new PendingTransactionImpl(*this); + +do { + auto w = wallet(); + bns::mapping_type mapping_type; + if(!validate_bns_type(bnstype, &mapping_type)) + break; + + // Getting subaddress for create a transaction from this subaddress + if (subaddr_indices.empty()) { + for (uint32_t index = 0; index < w->get_num_subaddresses(m_current_subaddress_account); ++index) + subaddr_indices.insert(index); + } + +std::string reason; +try + { + LOG_PRINT_L1(__FUNCTION__ << "Create bns_renew is start..."); + transaction->m_pending_tx = w->bns_create_renewal_tx(mapping_type, + name, + &reason, + priority, + m_current_subaddress_account, + subaddr_indices); + + if (transaction->m_pending_tx.empty()) + { + LOG_PRINT_L1(__FUNCTION__ << "Transaction data is empty"); + setStatusError(reason); + break; + } + pendingTxPostProcess(transaction); + + }catch (const tools::error::daemon_busy&) { + // TODO: make it translatable with "tr"? + setStatusError(tr("daemon is busy. Please try again later.")); + } catch (const tools::error::no_connection_to_daemon&) { + setStatusError(tr("no connection to daemon. Please make sure daemon is running.")); + } catch (const tools::error::wallet_rpc_error& e) { + setStatusError(tr("RPC error: ") + e.to_string()); + } catch (const tools::error::get_outs_error &e) { + setStatusError((boost::format(tr("failed to get outputs to mix: %s")) % e.what()).str()); + } catch (const tools::error::not_enough_unlocked_money& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, available only %s, sent amount %s")) % + print_money(e.available()) % + print_money(e.tx_amount()); + setStatusError(writer.str()); + } catch (const tools::error::not_enough_money& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, overall balance only %s, sent amount %s")) % + print_money(e.available()) % + print_money(e.tx_amount()); + setStatusError(writer.str()); + } catch (const tools::error::tx_not_possible& e) { + std::ostringstream writer; + + writer << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) % + print_money(e.available()) % + print_money(e.tx_amount() + e.fee()) % + print_money(e.tx_amount()) % + print_money(e.fee()); + setStatusError(writer.str()); + } catch (const tools::error::not_enough_outs_to_mix& e) { + std::ostringstream writer; + writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":"; + for (const std::pair outs_for_amount : e.scanty_outs()) { + writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second; + } + writer << "\n" << tr("Please sweep unmixable outputs."); + setStatusError(writer.str()); + } catch (const tools::error::tx_not_constructed&) { + setStatusError(tr("transaction was not constructed")); + } catch (const tools::error::tx_rejected& e) { + std::ostringstream writer; + writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status(); + setStatusError(writer.str()); + } catch (const tools::error::tx_sum_overflow& e) { + setStatusError(e.what()); + } catch (const tools::error::zero_destination&) { + setStatusError(tr("one of destinations is zero")); + } catch (const tools::error::tx_too_big& e) { + setStatusError(tr("failed to find a suitable way to split transactions")); + } catch (const tools::error::transfer_error& e) { + setStatusError(std::string(tr("unknown transfer error: ")) + e.what()); + } catch (const tools::error::wallet_internal_error& e) { + setStatusError(std::string(tr("internal error: ")) + e.what()); + } catch (const std::exception& e) { + setStatusError(std::string(tr("unexpected error: ")) + e.what()); + } catch (...) { + setStatusError(tr("unknown error")); + } + + }while(false); + + LOG_PRINT_L1(__FUNCTION__ << "Status given to transaction object"); + transaction->m_status = status(); + // Resume refresh thread + startRefresh(); + return transaction; +} + EXPORT PendingTransaction *WalletImpl::createSweepUnmixableTransaction() diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 6c0b612859..ded68f697b 100755 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -196,6 +196,11 @@ class WalletImpl : public Wallet uint32_t priority = 0, uint32_t subaddr_account = 0, std::set subaddr_indices = {}) override; + PendingTransaction* bnsRenewTransaction(std::string &name, + std::string &bnstype, + uint32_t priority=0, + uint32_t m_current_subaddress_account = 0, + std::set subaddr_indices = {}) override; PendingTransaction* createSweepUnmixableTransaction() override; bool submitTransaction(std::string_view filename) override; UnsignedTransaction* loadUnsignedTx(std::string_view unsigned_filename) override; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 87093143cc..55a424e8e8 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -901,6 +901,21 @@ struct Wallet uint32_t priority = 0, uint32_t subaddr_account = 0, std::set subaddr_indices = {}) = 0; + /*! + * \brief bnsRenewTransaction creates bns renew transaction + * \param name bns name + * \param bnstype type(belnet) + * \param m_current_subaddress_account subaddress account from which the input funds are taken + * \param subaddr_indices set of subaddress indices to use for transfer or sweeping. if set empty, all are chosen when sweeping, and one or more are automatically chosen when transferring. after execution, returns the set of actually used indices + * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() + * after object returned + */ + virtual PendingTransaction *bnsRenewTransaction(std::string &name, + std::string &bnstype, + uint32_t priority=0, + uint32_t m_current_subaddress_account = 0, + std::set subaddr_indices = {}) = 0; + /*! * \brief createSweepUnmixableTransaction creates transaction with unmixable outputs. * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() From 3406b37cfb67b99063d6a22e0d10b7b0640afc91 Mon Sep 17 00:00:00 2001 From: MogamboPuri Date: Tue, 18 Jul 2023 17:58:52 +0530 Subject: [PATCH 15/23] bnsRenewTransaction() has added for libwalletapi --- src/wallet/api/wallet2_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 55a424e8e8..f82c5a10db 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -904,7 +904,7 @@ struct Wallet /*! * \brief bnsRenewTransaction creates bns renew transaction * \param name bns name - * \param bnstype type(belnet) + * \param bnstype type(belnet,belnet_2y,belnet_5y,belnet_10y) * \param m_current_subaddress_account subaddress account from which the input funds are taken * \param subaddr_indices set of subaddress indices to use for transfer or sweeping. if set empty, all are chosen when sweeping, and one or more are automatically chosen when transferring. after execution, returns the set of actually used indices * \return PendingTransaction object. caller is responsible to check PendingTransaction::status() From 6093eaf05e515abdfa2a45aaf8fbae78fa2d3bf2 Mon Sep 17 00:00:00 2001 From: peter-pratt Date: Tue, 18 Jul 2023 19:39:00 +0530 Subject: [PATCH 16/23] testcase added for bnsRenewTransaction() --- tests/libwallet_api_tests/main.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 3dbdad2ca0..d586f56b65 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -751,6 +751,35 @@ TEST_F(WalletTest1, BnsUpdateWithSameValue) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } +TEST_F(WalletTest1, BnsRenewTransaction) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + std::string name ="cat.bdx"; + std::string type ="belnet_5y"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, + name); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(transaction->good()); + ASSERT_FALSE(wallet1->balance(0) == balance); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} // TEST_F(WalletTest1, WalletTransactionWithMixin) // { // std::vector mixins; From d46c003b771891168002b744569b22af89b3940d Mon Sep 17 00:00:00 2001 From: peter-pratt Date: Wed, 19 Jul 2023 16:41:38 +0530 Subject: [PATCH 17/23] moreTestCases added for bnsRenewTransaction() --- tests/libwallet_api_tests/main.cpp | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index d586f56b65..a7bf12b90e 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -780,6 +780,91 @@ TEST_F(WalletTest1, BnsRenewTransaction) ASSERT_FALSE(wallet1->balance(0) == balance); ASSERT_TRUE(wmgr->closeWallet(wallet1)); } + +TEST_F(WalletTest1, BnsRenewTransactionForWrongName) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + std::string name ="hell"; + std::string type ="belnet"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, + name); + ASSERT_FALSE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + +TEST_F(WalletTest1, BnsRenewTransactionForBchat) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + std::string name ="boot.bdx"; + std::string type ="bchat"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, + name); + ASSERT_FALSE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + +TEST_F(WalletTest1, BnsRenewTransactionForWallet) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + std::string name ="hell.bdx"; + std::string type ="wallet"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, + name); + ASSERT_FALSE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + // TEST_F(WalletTest1, WalletTransactionWithMixin) // { // std::vector mixins; From 087da2a2bd5407c05edb1dfc91ede19c4110e910 Mon Sep 17 00:00:00 2001 From: deen-kakarot Date: Wed, 19 Jul 2023 18:43:27 +0530 Subject: [PATCH 18/23] testcase added for wrong value bnsUpdateTransaction() --- tests/libwallet_api_tests/main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index a7bf12b90e..9b6554ba04 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -704,7 +704,7 @@ TEST_F(WalletTest1, BnsUpdateTransaction) ASSERT_TRUE(wallet1->good()); // Change the value based on your datas - std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string owner = ""; std::string backup_owner = ""; std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; std::string name ="tontin.bdx"; @@ -751,6 +751,31 @@ TEST_F(WalletTest1, BnsUpdateWithSameValue) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } +TEST_F(WalletTest1, BnsUpdateWrongValues) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); + + // Change the value based on your datas + std::string owner = ""; + std::string backup_owner = ""; + std::string value ="bd6eada11acbbaa92d8f1d7ca5d5482dc0ddbec8ed7f0966f75ce5ef2483408f72"; + std::string name ="test"; + std::string type ="belnet"; + Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); + ASSERT_FALSE(transaction->good()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + TEST_F(WalletTest1, BnsRenewTransaction) { //TODO=Beldex_bns have to check more conditions also the wallet_listener check From aeb07d4ca136985c1e6f8f3e9ff441ec194e372a Mon Sep 17 00:00:00 2001 From: peter-pratt Date: Wed, 19 Jul 2023 19:27:29 +0530 Subject: [PATCH 19/23] updated test cases for bnsRenewTransaction() --- tests/libwallet_api_tests/main.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 9b6554ba04..0d1d87a9e8 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -799,7 +799,7 @@ TEST_F(WalletTest1, BnsRenewTransaction) std::cout <<"refresh_end...\n"; ASSERT_TRUE(wallet1->balance(0) == balance); Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->commit()); + ASSERT_TRUE(transaction->commit()); Utils::print_status(transaction->status()); ASSERT_TRUE(transaction->good()); ASSERT_FALSE(wallet1->balance(0) == balance); @@ -824,13 +824,7 @@ TEST_F(WalletTest1, BnsRenewTransactionForWrongName) Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, name); ASSERT_FALSE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_FALSE(transaction->commit()); Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->good()); ASSERT_TRUE(wmgr->closeWallet(wallet1)); } @@ -852,13 +846,7 @@ TEST_F(WalletTest1, BnsRenewTransactionForBchat) Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, name); ASSERT_FALSE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_FALSE(transaction->commit()); Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->good()); ASSERT_TRUE(wmgr->closeWallet(wallet1)); } @@ -880,13 +868,7 @@ TEST_F(WalletTest1, BnsRenewTransactionForWallet) Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, name); ASSERT_FALSE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_FALSE(transaction->commit()); Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->good()); ASSERT_TRUE(wmgr->closeWallet(wallet1)); } From 3e9bddb0a0334bdd9e2b502d5c10ba34896dc890 Mon Sep 17 00:00:00 2001 From: tore-tto Date: Thu, 20 Jul 2023 11:55:03 +0530 Subject: [PATCH 20/23] bns type validation added for wallet --- src/wallet/api/wallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index f92466d64f..925f7407d6 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1747,6 +1747,8 @@ bool WalletImpl::validate_bns_type(std::string mapping,bns::mapping_type *mappin mapping_type_ = bns::mapping_type::belnet_5years; else if (tools::string_iequal_any(mapping, "belnet_10y", "belnet_10years")) mapping_type_ = bns::mapping_type::belnet_10years; + else if (tools::string_iequal(mapping, "wallet")) + mapping_type_ = bns::mapping_type::wallet; else { setStatusError(tr("Unsupported BNS type")); From e3e291af5e82d08196f86a0fcbb81417c7b98422 Mon Sep 17 00:00:00 2001 From: peter-pratt Date: Fri, 21 Jul 2023 19:08:18 +0530 Subject: [PATCH 21/23] countBns() added for libwalletapi --- src/wallet/api/wallet.cpp | 29 ++ src/wallet/api/wallet.h | 1 + src/wallet/api/wallet2_api.h | 5 + tests/libwallet_api_tests/main.cpp | 590 ++++++++++++++--------------- 4 files changed, 330 insertions(+), 295 deletions(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 925f7407d6..4295c9ed79 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1061,6 +1061,35 @@ uint64_t WalletImpl::unlockedBalance(uint32_t accountIndex) const return wallet()->unlocked_balance(accountIndex, false); } +EXPORT +int WalletImpl::countBns() +{ + clearStatus(); + auto w = wallet(); + std::vector requests(1); + int count=0; + + for (uint32_t index = 0; index < w->get_num_subaddresses(0); ++index) + { + if (requests.back().entries.size() >= cryptonote::rpc::BNS_OWNERS_TO_NAMES::MAX_REQUEST_ENTRIES) + requests.emplace_back(); + requests.back().entries.push_back(w->get_subaddress_as_str({0, index})); + } + + for (auto const &request : requests) + { + auto [success, result] = w->bns_owners_to_names(request); + if (!success) + { + LOG_PRINT_L1(__FUNCTION__ << "Connection to daemon failed when requesting BNS names"); + setStatusError(tr("Connection to daemon failed when requesting BNS names")); + break; + } + count += result.size(); + } + return count; +} + EXPORT std::vector* WalletImpl::listCurrentStakes() const { diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index ded68f697b..16f9f77ae5 100755 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -118,6 +118,7 @@ class WalletImpl : public Wallet bool trustedDaemon() const override; uint64_t balance(uint32_t accountIndex = 0) const override; uint64_t unlockedBalance(uint32_t accountIndex = 0) const override; + int countBns() override; std::vector* listCurrentStakes() const override; uint64_t blockChainHeight() const override; uint64_t approximateBlockChainHeight() const override; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index f82c5a10db..353c3ee040 100755 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -612,6 +612,11 @@ struct Wallet return result; } + /** + * @brief interface for counting number of BNS + */ + virtual int countBns() = 0; + /** * @brief listCurrentStakes - returns a list of the wallets locked stakes, provides both service node address and the staked amount * @return diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 0d1d87a9e8..6092c99bea 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -463,16 +463,16 @@ struct WalletTest2 : public testing::Test -TEST_F(WalletManagerTest, WalletManagerFindsWallet) -{ - std::vector wallets = wmgr->findWallets(WALLETS_ROOT_DIR); - // wallet have to create by own - ASSERT_FALSE(wallets.empty()); - std::cout << "Found wallets: " << std::endl; - for (auto wallet_path: wallets) { - std::cout << wallet_path << std::endl; - } -} +// TEST_F(WalletManagerTest, WalletManagerFindsWallet) +// { +// std::vector wallets = wmgr->findWallets(WALLETS_ROOT_DIR); +// // wallet have to create by own +// ASSERT_FALSE(wallets.empty()); +// std::cout << "Found wallets: " << std::endl; +// for (auto wallet_path: wallets) { +// std::cout << wallet_path << std::endl; +// } +// } // TEST_F(WalletTest1, WalletGeneratesPaymentId) @@ -492,24 +492,24 @@ TEST_F(WalletManagerTest, WalletManagerFindsWallet) // } -TEST_F(WalletTest1, WalletShowsBalance) -{ - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet1->balance(0) > 0); - ASSERT_TRUE(wallet1->unlockedBalance(0) > 0); +// TEST_F(WalletTest1, WalletShowsBalance) +// { +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet1->balance(0) > 0); +// ASSERT_TRUE(wallet1->unlockedBalance(0) > 0); - uint64_t balance1 = wallet1->balance(0); - uint64_t unlockedBalance1 = wallet1->unlockedBalance(0); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); - Wallet::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - ASSERT_TRUE(wallet2->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(balance1 == wallet2->balance(0)); - std::cout << "wallet balance: " << wallet2->balance(0) << std::endl; - ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0)); - std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl; - ASSERT_TRUE(wmgr->closeWallet(wallet2)); -} +// uint64_t balance1 = wallet1->balance(0); +// uint64_t unlockedBalance1 = wallet1->unlockedBalance(0); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// Wallet::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// ASSERT_TRUE(wallet2->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(balance1 == wallet2->balance(0)); +// std::cout << "wallet balance: " << wallet2->balance(0) << std::endl; +// ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0)); +// std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl; +// ASSERT_TRUE(wmgr->closeWallet(wallet2)); +// } // TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight) // { @@ -537,17 +537,17 @@ TEST_F(WalletTest1, WalletShowsBalance) // } -TEST_F(WalletTest1, WalletRefresh) -{ +// TEST_F(WalletTest1, WalletRefresh) +// { - std::cout << "Opening wallet: " << CURRENT_SRC_WALLET << std::endl; - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // 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)); -} +// std::cout << "Opening wallet: " << CURRENT_SRC_WALLET << std::endl; +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // 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)); +// } // TEST_F(WalletTest1, WalletConvertsToString) // { @@ -592,189 +592,189 @@ TEST_F(WalletTest1, WalletRefresh) // ASSERT_TRUE(wmgr->closeWallet(wallet1)); // } -TEST_F(WalletTest1, BnsBuyTransaction) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsBuyTransaction) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - // Change the value based on your datas - std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); - std::string backup_owner = ""; - std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; - std::string name ="blackpearl.bdx"; - std::string type ="belnet"; - Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, - backup_owner, - value, - name, - type); - ASSERT_TRUE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(transaction->commit()); - ASSERT_FALSE(wallet1->balance(0) == balance); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// // Change the value based on your datas +// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); +// std::string backup_owner = ""; +// std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; +// std::string name ="blackpearl.bdx"; +// std::string type ="belnet"; +// Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, +// backup_owner, +// value, +// name, +// type); +// ASSERT_TRUE(transaction->good()); +// std::cout <<"refresh_started...\n"; +// wallet1->refresh(); +// std::cout <<"refresh_end...\n"; +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_TRUE(transaction->commit()); +// ASSERT_FALSE(wallet1->balance(0) == balance); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsBuyTransactionWithWrongType) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsBuyTransactionWithWrongType) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - // Change the value based on your datas - std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); - std::string backup_owner = ""; - std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; - std::string name ="blackpearl.bdx"; - std::string type ="belnett"; - Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, - backup_owner, - value, - name, - type); - Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->good()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// // Change the value based on your datas +// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); +// std::string backup_owner = ""; +// std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; +// std::string name ="blackpearl.bdx"; +// std::string type ="belnett"; +// Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, +// backup_owner, +// value, +// name, +// type); +// Utils::print_status(transaction->status()); +// ASSERT_FALSE(transaction->good()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - // Change the value based on your datas - std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); - std::string backup_owner = ""; - std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; - std::string name ="blackpearl.bdx"; - std::string type ="belnet"; - Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, - backup_owner, - value, - name, - type); - ASSERT_TRUE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_FALSE(transaction->commit()); - Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->good()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// // Change the value based on your datas +// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); +// std::string backup_owner = ""; +// std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; +// std::string name ="blackpearl.bdx"; +// std::string type ="belnet"; +// Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, +// backup_owner, +// value, +// name, +// type); +// ASSERT_TRUE(transaction->good()); +// std::cout <<"refresh_started...\n"; +// wallet1->refresh(); +// std::cout <<"refresh_end...\n"; +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_FALSE(transaction->commit()); +// Utils::print_status(transaction->status()); +// ASSERT_FALSE(transaction->good()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsUpdateTransaction) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsUpdateTransaction) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - // Change the value based on your datas - std::string owner = ""; - std::string backup_owner = ""; - std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; - std::string name ="tontin.bdx"; - std::string type ="belnet"; - Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); - ASSERT_TRUE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_TRUE(transaction->commit()); - ASSERT_FALSE(wallet1->balance(0) == balance); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// // Change the value based on your datas +// std::string owner = ""; +// std::string backup_owner = ""; +// std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; +// std::string name ="tontin.bdx"; +// std::string type ="belnet"; +// Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); +// ASSERT_TRUE(transaction->good()); +// std::cout <<"refresh_started...\n"; +// wallet1->refresh(); +// std::cout <<"refresh_end...\n"; +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_TRUE(transaction->commit()); +// ASSERT_FALSE(wallet1->balance(0) == balance); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsUpdateWithSameValue) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsUpdateWithSameValue) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - // Change the value based on your datas - std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); - std::string backup_owner = ""; - std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; - std::string name ="tontin.bdx"; - std::string type ="belnet"; - Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); - ASSERT_TRUE(transaction->good()); - std::cout <<"refresh_started...\n"; - wallet1->refresh(); - std::cout <<"refresh_end...\n"; - ASSERT_TRUE(wallet1->balance(0) == balance); - ASSERT_FALSE(transaction->commit()); - Utils::print_status(transaction->status()); - ASSERT_FALSE(transaction->good()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// // Change the value based on your datas +// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); +// std::string backup_owner = ""; +// std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; +// std::string name ="tontin.bdx"; +// std::string type ="belnet"; +// Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); +// ASSERT_TRUE(transaction->good()); +// std::cout <<"refresh_started...\n"; +// wallet1->refresh(); +// std::cout <<"refresh_end...\n"; +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_FALSE(transaction->commit()); +// Utils::print_status(transaction->status()); +// ASSERT_FALSE(transaction->good()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsUpdateWrongValues) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsUpdateWrongValues) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - // Change the value based on your datas - std::string owner = ""; - std::string backup_owner = ""; - std::string value ="bd6eada11acbbaa92d8f1d7ca5d5482dc0ddbec8ed7f0966f75ce5ef2483408f72"; - std::string name ="test"; - std::string type ="belnet"; - Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); - ASSERT_FALSE(transaction->good()); - Utils::print_status(transaction->status()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// // Change the value based on your datas +// std::string owner = ""; +// std::string backup_owner = ""; +// std::string value ="bd6eada11acbbaa92d8f1d7ca5d5482dc0ddbec8ed7f0966f75ce5ef2483408f72"; +// std::string name ="test"; +// std::string type ="belnet"; +// Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); +// ASSERT_FALSE(transaction->good()); +// Utils::print_status(transaction->status()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } TEST_F(WalletTest1, BnsRenewTransaction) { @@ -806,71 +806,71 @@ TEST_F(WalletTest1, BnsRenewTransaction) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } -TEST_F(WalletTest1, BnsRenewTransactionForWrongName) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsRenewTransactionForWrongName) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - std::string name ="hell"; - std::string type ="belnet"; - Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, - name); - ASSERT_FALSE(transaction->good()); - Utils::print_status(transaction->status()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// std::string name ="hell"; +// std::string type ="belnet"; +// Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, +// name); +// ASSERT_FALSE(transaction->good()); +// Utils::print_status(transaction->status()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsRenewTransactionForBchat) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsRenewTransactionForBchat) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - std::string name ="boot.bdx"; - std::string type ="bchat"; - Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, - name); - ASSERT_FALSE(transaction->good()); - Utils::print_status(transaction->status()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// std::string name ="boot.bdx"; +// std::string type ="bchat"; +// Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, +// name); +// ASSERT_FALSE(transaction->good()); +// Utils::print_status(transaction->status()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } -TEST_F(WalletTest1, BnsRenewTransactionForWallet) -{ - //TODO=Beldex_bns have to check more conditions also the wallet_listener check - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - std::cout <<"Refresh_started...\n"; - ASSERT_TRUE(wallet1->refresh()); - std::cout <<"Refresh_end...\n"; - uint64_t balance = wallet1->balance(0); - std::cout <<"**balance: " << balance << std::endl; - ASSERT_TRUE(wallet1->good()); +// TEST_F(WalletTest1, BnsRenewTransactionForWallet) +// { +// //TODO=Beldex_bns have to check more conditions also the wallet_listener check +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// std::cout <<"Refresh_started...\n"; +// ASSERT_TRUE(wallet1->refresh()); +// std::cout <<"Refresh_end...\n"; +// uint64_t balance = wallet1->balance(0); +// std::cout <<"**balance: " << balance << std::endl; +// ASSERT_TRUE(wallet1->good()); - std::string name ="hell.bdx"; - std::string type ="wallet"; - Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, - name); - ASSERT_FALSE(transaction->good()); - Utils::print_status(transaction->status()); - ASSERT_TRUE(wmgr->closeWallet(wallet1)); -} +// std::string name ="hell.bdx"; +// std::string type ="wallet"; +// Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, +// name); +// ASSERT_FALSE(transaction->good()); +// Utils::print_status(transaction->status()); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } // TEST_F(WalletTest1, WalletTransactionWithMixin) // { @@ -954,22 +954,22 @@ TEST_F(WalletTest1, BnsRenewTransactionForWallet) -TEST_F(WalletTest1, WalletHistory) -{ - Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - // make sure testnet daemon is running - ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet1->refresh()); - Wallet::TransactionHistory * history = wallet1->history(); - history->refresh(); - ASSERT_TRUE(history->count() > 0); +// TEST_F(WalletTest1, WalletHistory) +// { +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// // make sure testnet daemon is running +// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet1->refresh()); +// Wallet::TransactionHistory * history = wallet1->history(); +// history->refresh(); +// ASSERT_TRUE(history->count() > 0); - for (auto t: history->getAll()) { - ASSERT_TRUE(t != nullptr); - Utils::print_transaction(t); - } -} +// for (auto t: history->getAll()) { +// ASSERT_TRUE(t != nullptr); +// Utils::print_transaction(t); +// } +// } // TEST_F(WalletTest1, WalletTransactionAndHistory) // { @@ -1149,18 +1149,18 @@ struct MyWalletListener : public Wallet::WalletListener -TEST_F(WalletTest2, WalletCallBackRefreshedSync) -{ - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); - ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); - ASSERT_TRUE(wallet_src->refresh()); - ASSERT_TRUE(wallet_src_listener->refresh_triggered); - ASSERT_TRUE(wallet_src->connected()); - std::unique_lock lock{wallet_src_listener->mutex}; - wallet_src_listener->cv_refresh.wait_for(lock, 3min); - wmgr->closeWallet(wallet_src); -} +// TEST_F(WalletTest2, WalletCallBackRefreshedSync) +// { +// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); +// MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); +// ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); +// ASSERT_TRUE(wallet_src->refresh()); +// ASSERT_TRUE(wallet_src_listener->refresh_triggered); +// ASSERT_TRUE(wallet_src->connected()); +// std::unique_lock lock{wallet_src_listener->mutex}; +// wallet_src_listener->cv_refresh.wait_for(lock, 3min); +// wmgr->closeWallet(wallet_src); +// } From 40f44ec9fbdaebfbde0af3be8e3660388e4857d1 Mon Sep 17 00:00:00 2001 From: MogamboPuri Date: Fri, 21 Jul 2023 23:15:36 +0530 Subject: [PATCH 22/23] Testcases added for countBns() --- tests/libwallet_api_tests/main.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 6092c99bea..b405938fce 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -872,6 +872,31 @@ TEST_F(WalletTest1, BnsRenewTransaction) // ASSERT_TRUE(wmgr->closeWallet(wallet1)); // } +TEST_F(WalletTest1, countForBns) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + + int val = wallet1->countBns(); + std::cout<<"Bns count is :"<closeWallet(wallet1)); +} + +TEST_F(WalletTest1, statusOfCountBns) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + + int val = wallet1->countBns(); + std::cout<<"Bns count is :"<status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} + // TEST_F(WalletTest1, WalletTransactionWithMixin) // { // std::vector mixins; From 8be8fa0fa8f76ccf1a84ff5d0c22883df673627d Mon Sep 17 00:00:00 2001 From: tore-tto Date: Fri, 21 Jul 2023 23:36:39 +0530 Subject: [PATCH 23/23] testcases fixed for bnsrenew --- src/wallet/api/wallet.cpp | 1 - tests/libwallet_api_tests/main.cpp | 594 ++++++++++++++--------------- 2 files changed, 297 insertions(+), 298 deletions(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 4295c9ed79..2d05bdc011 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -1763,7 +1763,6 @@ bool WalletImpl::validate_bns_type(std::string mapping,bns::mapping_type *mappin // return false; // } - //TODO wallet bns type check have to add if (tools::string_iequal(mapping, "bchat")) mapping_type_ = bns::mapping_type::bchat; else if (tools::string_iequal(mapping, "belnet")) diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index b405938fce..d146ec73ea 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -463,16 +463,16 @@ struct WalletTest2 : public testing::Test -// TEST_F(WalletManagerTest, WalletManagerFindsWallet) -// { -// std::vector wallets = wmgr->findWallets(WALLETS_ROOT_DIR); -// // wallet have to create by own -// ASSERT_FALSE(wallets.empty()); -// std::cout << "Found wallets: " << std::endl; -// for (auto wallet_path: wallets) { -// std::cout << wallet_path << std::endl; -// } -// } +TEST_F(WalletManagerTest, WalletManagerFindsWallet) +{ + std::vector wallets = wmgr->findWallets(WALLETS_ROOT_DIR); + // wallet have to create by own + ASSERT_FALSE(wallets.empty()); + std::cout << "Found wallets: " << std::endl; + for (auto wallet_path: wallets) { + std::cout << wallet_path << std::endl; + } +} // TEST_F(WalletTest1, WalletGeneratesPaymentId) @@ -492,24 +492,24 @@ struct WalletTest2 : public testing::Test // } -// TEST_F(WalletTest1, WalletShowsBalance) -// { -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// ASSERT_TRUE(wallet1->balance(0) > 0); -// ASSERT_TRUE(wallet1->unlockedBalance(0) > 0); +TEST_F(WalletTest1, WalletShowsBalance) +{ + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(wallet1->balance(0) > 0); + ASSERT_TRUE(wallet1->unlockedBalance(0) > 0); -// uint64_t balance1 = wallet1->balance(0); -// uint64_t unlockedBalance1 = wallet1->unlockedBalance(0); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// Wallet::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// ASSERT_TRUE(wallet2->init(TESTNET_DAEMON_ADDRESS, 0)); -// ASSERT_TRUE(balance1 == wallet2->balance(0)); -// std::cout << "wallet balance: " << wallet2->balance(0) << std::endl; -// ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0)); -// std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl; -// ASSERT_TRUE(wmgr->closeWallet(wallet2)); -// } + uint64_t balance1 = wallet1->balance(0); + uint64_t unlockedBalance1 = wallet1->unlockedBalance(0); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); + Wallet::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + ASSERT_TRUE(wallet2->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(balance1 == wallet2->balance(0)); + std::cout << "wallet balance: " << wallet2->balance(0) << std::endl; + ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0)); + std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl; + ASSERT_TRUE(wmgr->closeWallet(wallet2)); +} // TEST_F(WalletTest1, WalletReturnsCurrentBlockHeight) // { @@ -537,17 +537,17 @@ struct WalletTest2 : public testing::Test // } -// TEST_F(WalletTest1, WalletRefresh) -// { +TEST_F(WalletTest1, WalletRefresh) +{ -// std::cout << "Opening wallet: " << CURRENT_SRC_WALLET << std::endl; -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // 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)); -// } + std::cout << "Opening wallet: " << CURRENT_SRC_WALLET << std::endl; + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // 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)); +} // TEST_F(WalletTest1, WalletConvertsToString) // { @@ -592,189 +592,189 @@ struct WalletTest2 : public testing::Test // ASSERT_TRUE(wmgr->closeWallet(wallet1)); // } -// TEST_F(WalletTest1, BnsBuyTransaction) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsBuyTransaction) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// // Change the value based on your datas -// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); -// std::string backup_owner = ""; -// std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; -// std::string name ="blackpearl.bdx"; -// std::string type ="belnet"; -// Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, -// backup_owner, -// value, -// name, -// type); -// ASSERT_TRUE(transaction->good()); -// std::cout <<"refresh_started...\n"; -// wallet1->refresh(); -// std::cout <<"refresh_end...\n"; -// ASSERT_TRUE(wallet1->balance(0) == balance); -// ASSERT_TRUE(transaction->commit()); -// ASSERT_FALSE(wallet1->balance(0) == balance); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; + std::string name ="blackpearl.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, + backup_owner, + value, + name, + type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_TRUE(transaction->commit()); + ASSERT_FALSE(wallet1->balance(0) == balance); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsBuyTransactionWithWrongType) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsBuyTransactionWithWrongType) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// // Change the value based on your datas -// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); -// std::string backup_owner = ""; -// std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; -// std::string name ="blackpearl.bdx"; -// std::string type ="belnett"; -// Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, -// backup_owner, -// value, -// name, -// type); -// Utils::print_status(transaction->status()); -// ASSERT_FALSE(transaction->good()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; + std::string name ="blackpearl.bdx"; + std::string type ="belnett"; + Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, + backup_owner, + value, + name, + type); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// // Change the value based on your datas -// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); -// std::string backup_owner = ""; -// std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; -// std::string name ="blackpearl.bdx"; -// std::string type ="belnet"; -// Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, -// backup_owner, -// value, -// name, -// type); -// ASSERT_TRUE(transaction->good()); -// std::cout <<"refresh_started...\n"; -// wallet1->refresh(); -// std::cout <<"refresh_end...\n"; -// ASSERT_TRUE(wallet1->balance(0) == balance); -// ASSERT_FALSE(transaction->commit()); -// Utils::print_status(transaction->status()); -// ASSERT_FALSE(transaction->good()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "a6iiyy3c4qsp8kdt49ao79dqxskd81eejidhq9j36d8oodznibqy.bdx"; + std::string name ="blackpearl.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction * transaction = wallet1->createBnsTransaction(owner, + backup_owner, + value, + name, + type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsUpdateTransaction) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsUpdateTransaction) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// // Change the value based on your datas -// std::string owner = ""; -// std::string backup_owner = ""; -// std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; -// std::string name ="tontin.bdx"; -// std::string type ="belnet"; -// Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); -// ASSERT_TRUE(transaction->good()); -// std::cout <<"refresh_started...\n"; -// wallet1->refresh(); -// std::cout <<"refresh_end...\n"; -// ASSERT_TRUE(wallet1->balance(0) == balance); -// ASSERT_TRUE(transaction->commit()); -// ASSERT_FALSE(wallet1->balance(0) == balance); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + // Change the value based on your datas + std::string owner = ""; + std::string backup_owner = ""; + std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; + std::string name ="tontin.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_TRUE(transaction->commit()); + ASSERT_FALSE(wallet1->balance(0) == balance); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsUpdateWithSameValue) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsUpdateWithSameValue) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// // Change the value based on your datas -// std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); -// std::string backup_owner = ""; -// std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; -// std::string name ="tontin.bdx"; -// std::string type ="belnet"; -// Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); -// ASSERT_TRUE(transaction->good()); -// std::cout <<"refresh_started...\n"; -// wallet1->refresh(); -// std::cout <<"refresh_end...\n"; -// ASSERT_TRUE(wallet1->balance(0) == balance); -// ASSERT_FALSE(transaction->commit()); -// Utils::print_status(transaction->status()); -// ASSERT_FALSE(transaction->good()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + // Change the value based on your datas + std::string owner = Utils::get_wallet_address(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS); + std::string backup_owner = ""; + std::string value = "fcbzchy4kknz1tq8eb5aiakibyfo7nqg6qxpons46h1qytexfc4y.bdx"; + std::string name ="tontin.bdx"; + std::string type ="belnet"; + Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); + ASSERT_TRUE(transaction->good()); + std::cout <<"refresh_started...\n"; + wallet1->refresh(); + std::cout <<"refresh_end...\n"; + ASSERT_TRUE(wallet1->balance(0) == balance); + ASSERT_FALSE(transaction->commit()); + Utils::print_status(transaction->status()); + ASSERT_FALSE(transaction->good()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsUpdateWrongValues) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsUpdateWrongValues) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// // Change the value based on your datas -// std::string owner = ""; -// std::string backup_owner = ""; -// std::string value ="bd6eada11acbbaa92d8f1d7ca5d5482dc0ddbec8ed7f0966f75ce5ef2483408f72"; -// std::string name ="test"; -// std::string type ="belnet"; -// Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); -// ASSERT_FALSE(transaction->good()); -// Utils::print_status(transaction->status()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + // Change the value based on your datas + std::string owner = ""; + std::string backup_owner = ""; + std::string value ="bd6eada11acbbaa92d8f1d7ca5d5482dc0ddbec8ed7f0966f75ce5ef2483408f72"; + std::string name ="test"; + std::string type ="belnet"; + Wallet::PendingTransaction *transaction = wallet1->bnsUpdateTransaction(owner, backup_owner, value, name, type); + ASSERT_FALSE(transaction->good()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} TEST_F(WalletTest1, BnsRenewTransaction) { @@ -791,8 +791,8 @@ TEST_F(WalletTest1, BnsRenewTransaction) std::string name ="cat.bdx"; std::string type ="belnet_5y"; - Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, - name); + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(name, + type); ASSERT_TRUE(transaction->good()); std::cout <<"refresh_started...\n"; wallet1->refresh(); @@ -806,71 +806,71 @@ TEST_F(WalletTest1, BnsRenewTransaction) ASSERT_TRUE(wmgr->closeWallet(wallet1)); } -// TEST_F(WalletTest1, BnsRenewTransactionForWrongName) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsRenewTransactionForWrongName) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// std::string name ="hell"; -// std::string type ="belnet"; -// Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, -// name); -// ASSERT_FALSE(transaction->good()); -// Utils::print_status(transaction->status()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + std::string name ="hell"; + std::string type ="belnet"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(name, + type); + ASSERT_FALSE(transaction->good()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsRenewTransactionForBchat) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsRenewTransactionForBchat) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// std::string name ="boot.bdx"; -// std::string type ="bchat"; -// Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, -// name); -// ASSERT_FALSE(transaction->good()); -// Utils::print_status(transaction->status()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + std::string name ="boot.bdx"; + std::string type ="bchat"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(name, + type); + ASSERT_FALSE(transaction->good()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -// TEST_F(WalletTest1, BnsRenewTransactionForWallet) -// { -// //TODO=Beldex_bns have to check more conditions also the wallet_listener check -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// std::cout <<"Refresh_started...\n"; -// ASSERT_TRUE(wallet1->refresh()); -// std::cout <<"Refresh_end...\n"; -// uint64_t balance = wallet1->balance(0); -// std::cout <<"**balance: " << balance << std::endl; -// ASSERT_TRUE(wallet1->good()); +TEST_F(WalletTest1, BnsRenewTransactionForWallet) +{ + //TODO=Beldex_bns have to check more conditions also the wallet_listener check + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + std::cout <<"Refresh_started...\n"; + ASSERT_TRUE(wallet1->refresh()); + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); -// std::string name ="hell.bdx"; -// std::string type ="wallet"; -// Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(type, -// name); -// ASSERT_FALSE(transaction->good()); -// Utils::print_status(transaction->status()); -// ASSERT_TRUE(wmgr->closeWallet(wallet1)); -// } + std::string name ="hell.bdx"; + std::string type ="wallet"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(name, + type); + ASSERT_FALSE(transaction->good()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} TEST_F(WalletTest1, countForBns) { @@ -979,22 +979,22 @@ TEST_F(WalletTest1, statusOfCountBns) -// TEST_F(WalletTest1, WalletHistory) -// { -// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// // make sure testnet daemon is running -// ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); -// ASSERT_TRUE(wallet1->refresh()); -// Wallet::TransactionHistory * history = wallet1->history(); -// history->refresh(); -// ASSERT_TRUE(history->count() > 0); +TEST_F(WalletTest1, WalletHistory) +{ + Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + // make sure testnet daemon is running + ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(wallet1->refresh()); + Wallet::TransactionHistory * history = wallet1->history(); + history->refresh(); + ASSERT_TRUE(history->count() > 0); -// for (auto t: history->getAll()) { -// ASSERT_TRUE(t != nullptr); -// Utils::print_transaction(t); -// } -// } + for (auto t: history->getAll()) { + ASSERT_TRUE(t != nullptr); + Utils::print_transaction(t); + } +} // TEST_F(WalletTest1, WalletTransactionAndHistory) // { @@ -1174,18 +1174,18 @@ struct MyWalletListener : public Wallet::WalletListener -// TEST_F(WalletTest2, WalletCallBackRefreshedSync) -// { -// Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); -// MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); -// ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); -// ASSERT_TRUE(wallet_src->refresh()); -// ASSERT_TRUE(wallet_src_listener->refresh_triggered); -// ASSERT_TRUE(wallet_src->connected()); -// std::unique_lock lock{wallet_src_listener->mutex}; -// wallet_src_listener->cv_refresh.wait_for(lock, 3min); -// wmgr->closeWallet(wallet_src); -// } +TEST_F(WalletTest2, WalletCallBackRefreshedSync) +{ + Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); + ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); + ASSERT_TRUE(wallet_src->refresh()); + ASSERT_TRUE(wallet_src_listener->refresh_triggered); + ASSERT_TRUE(wallet_src->connected()); + std::unique_lock lock{wallet_src_listener->mutex}; + wallet_src_listener->cv_refresh.wait_for(lock, 3min); + wmgr->closeWallet(wallet_src); +}