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/wallet.cpp b/src/wallet/api/wallet.cpp index 24adeb1050..2d05bdc011 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 { @@ -1715,6 +1744,394 @@ 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_; + std::optional hf_version = hardForkVersion(); + if (!hf_version) + { + setStatusError(tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED); + return false; + } + + //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 ")); + // return false; + // } + + 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 if (tools::string_iequal(mapping, "wallet")) + mapping_type_ = bns::mapping_type::wallet; + 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); + + 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::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); + + 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::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() @@ -2445,7 +2862,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 diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index e6a0ea7f57..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; @@ -180,6 +181,27 @@ 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* 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* 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; @@ -242,6 +264,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; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 55f1994098..353c3ee040 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; @@ -611,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 @@ -860,6 +866,61 @@ 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 bnsUpdateTransaction creates bns update 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 bnsRenewTransaction creates bns renew transaction + * \param name bns name + * \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() + * 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() diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index ff6b753b73..e02175b90e 100755 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -81,7 +81,8 @@ 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 = ""; @@ -120,9 +121,15 @@ 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; } + 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(); @@ -201,70 +208,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,181 +297,177 @@ 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) -{ +// 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(); - 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); -} +// ASSERT_TRUE(wallet1->store("")); +// ASSERT_TRUE(wallet1->good()); -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(); - - ASSERT_TRUE(wallet1->store("")); - ASSERT_TRUE(wallet1->good()); - - ASSERT_TRUE(wallet1->store("")); - ASSERT_TRUE(wallet1->good()); - - 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)); -} +// ASSERT_TRUE(wallet1->store("")); +// ASSERT_TRUE(wallet1->good()); + +// 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, 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 +476,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 +504,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 +512,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,235 +550,541 @@ 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_2BDX); +// ASSERT_TRUE(AMOUNT_2BDX == 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_2BDX == Wallet::Wallet::amountFromDouble(2.0)); +// ASSERT_TRUE(AMOUNT_4BDX == Wallet::Wallet::amountFromDouble(4.0)); +// ASSERT_TRUE(AMOUNT_1BDX == Wallet::Wallet::amountFromDouble(1.0)); -} +// } + + + +// 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()); + +// std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); +// const int MIXIN_COUNT = 4; -TEST_F(WalletTest1, WalletTransaction) +// 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) { - std::cout <<"++++++++++++++++++++++ 23 ++++++++++++++++++++++\n"; + //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 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); + // 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->amount() == AMOUNT_4BDX); + 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()); + // 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) +TEST_F(WalletTest1, BnsBuyTransactionWithOldValue) { - 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); + //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)); +} - std::string payment_id = ""; +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()); - 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); - } - + // 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, WalletTransactionWithPriority) +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()); - std::string payment_id = ""; + // 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()); - std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); - uint32_t mixin = 2; - uint64_t fee = 0; + // 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)); +} - std::vector priorities = { - 1,2,3 - }; +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()); - 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); - } + std::string name ="cat.bdx"; + std::string type ="belnet_5y"; + Wallet::PendingTransaction * transaction = wallet1->bnsRenewTransaction(name, + type); + 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_TRUE(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, 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(name, + type); + ASSERT_FALSE(transaction->good()); + Utils::print_status(transaction->status()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} -TEST_F(WalletTest1, WalletHistory) +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()); - Wallet::TransactionHistory * history = wallet1->history(); - history->refresh(); - ASSERT_TRUE(history->count() > 0); - + std::cout <<"Refresh_end...\n"; + uint64_t balance = wallet1->balance(0); + std::cout <<"**balance: " << balance << std::endl; + ASSERT_TRUE(wallet1->good()); - for (auto t: history->getAll()) { - ASSERT_TRUE(t != nullptr); - Utils::print_transaction(t); - } + 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, WalletTransactionAndHistory) +TEST_F(WalletTest1, BnsRenewTransactionForWallet) { - return; - Wallet::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); + //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(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(); + 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::cout << "**** Transactions before transfer (" << count1 << ")" << std::endl; - for (auto t: history->getAll()) { - ASSERT_TRUE(t != nullptr); - Utils::print_transaction(t); - } + 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)); +} - std::string wallet4_addr = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); +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)); - Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, - AMOUNT_4BDX * 2); + int val = wallet1->countBns(); + std::cout<<"Bns count is :"<good()); - ASSERT_TRUE(tx->commit()); - history = wallet_src->history(); - history->refresh(); - ASSERT_TRUE(count1 != history->count()); + ASSERT_TRUE(wmgr->closeWallet(wallet1)); +} - 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, 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; +// // 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, 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::string payment_id = ""; - std::cout << "**** Transactions before transfer (" << count1 << ")" << std::endl; - for (auto t: history->getAll()) { - ASSERT_TRUE(t != nullptr); - Utils::print_transaction(t); - } +// 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()); + +// 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); +// } + +// wallet1->refresh(); - std::string wallet4_addr = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS); +// ASSERT_TRUE(wallet1->balance(0) == balance); +// ASSERT_TRUE(wmgr->closeWallet(wallet1)); +// } - std::string payment_id = Wallet::Wallet::genPaymentId(); - ASSERT_TRUE(payment_id.length() == 16); +// TEST_F(WalletTest1, WalletTransactionWithPriority) +// { +// std::string payment_id = ""; - Wallet::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr, - AMOUNT_1XMR); +// Wallet::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, Wallet::NetworkType::TESTNET); - ASSERT_TRUE(tx->good()); - ASSERT_TRUE(tx->commit()); - history = wallet_src->history(); +// // 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::vector priorities = { +// 1,2,3 +// }; + +// 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(count1 != history->count()); + ASSERT_TRUE(history->count() > 0); - 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); } +// 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_1BDX); + +// 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 { @@ -877,10 +1181,10 @@ 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}; @@ -891,237 +1195,229 @@ TEST_F(WalletTest2, WalletCallBackRefreshedSync) -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) -{ - - 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(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) +// { +// 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_1BDX * 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_1BDX * 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"; + +// } -} - -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"; - -}