CurrentBlockchainStatus::find_txs_in_mempool tested

pull/93/merge
moneroexamples 6 years ago
parent 9a4ebd2b94
commit 12349ec9b2

File diff suppressed because it is too large Load Diff

@ -1,5 +1,4 @@
#ifndef RESTBED_XMR_CURRENTBLOCKCHAINSTATUS_H #pragma once
#define RESTBED_XMR_CURRENTBLOCKCHAINSTATUS_H
#define MYSQLPP_SSQLS_NO_STATICS 1 #define MYSQLPP_SSQLS_NO_STATICS 1
@ -293,4 +292,3 @@ protected:
} }
#endif //RESTBED_XMR_CURRENTBLOCKCHAINSTATUS_H

@ -589,8 +589,7 @@ TxSearch::get_known_outputs_keys()
}; };
json json
TxSearch::find_txs_in_mempool( TxSearch::find_txs_in_mempool(TxSearch::pool_txs_t mempool_txs)
vector<pair<uint64_t, transaction>> mempool_txs)
{ {
json j_transactions = json::array(); json j_transactions = json::array();
@ -605,9 +604,9 @@ TxSearch::find_txs_in_mempool(
// time in a single connection. // time in a single connection.
// so we create local connection here, only to be used in this method. // so we create local connection here, only to be used in this method.
shared_ptr<MySqlAccounts> local_xmr_accounts = make_shared<MySqlAccounts>(current_bc_status); auto local_xmr_accounts = make_shared<MySqlAccounts>(current_bc_status);
for (const pair<uint64_t, transaction>& mtx: mempool_txs) for (auto const& mtx: mempool_txs)
{ {
uint64_t recieve_time = mtx.first; uint64_t recieve_time = mtx.first;
@ -683,7 +682,8 @@ TxSearch::find_txs_in_mempool(
// tx public key and its index in that tx // tx public key and its index in that tx
XmrOutput out; XmrOutput out;
if (local_xmr_accounts->output_exists(pod_to_hex(in_info.out_pub_key), out)) if (local_xmr_accounts->output_exists(
pod_to_hex(in_info.out_pub_key), out))
{ {
total_sent += out.amount; total_sent += out.amount;

@ -1,17 +1,10 @@
// #pragma once
// Created by mwo on 8/01/17.
//
#ifndef RESTBED_XMR_TXSEARCH_H
#define RESTBED_XMR_TXSEARCH_H
#include "MySqlAccounts.h" #include "MySqlAccounts.h"
#include "OutputInputIdentification.h" #include "OutputInputIdentification.h"
#include <iostream>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <thread>
#include <atomic> #include <atomic>
#include <algorithm> #include <algorithm>
#include <unordered_map> #include <unordered_map>
@ -37,6 +30,7 @@ public:
// out_pk , amount // out_pk , amount
using known_outputs_t = std::unordered_map<public_key, uint64_t>; using known_outputs_t = std::unordered_map<public_key, uint64_t>;
using addr_view_t = std::pair<address_parse_info, secret_key>; using addr_view_t = std::pair<address_parse_info, secret_key>;
using pool_txs_t = std::vector<pair<uint64_t, transaction>>;
private: private:
@ -139,7 +133,7 @@ public:
* @return json * @return json
*/ */
virtual json virtual json
find_txs_in_mempool(vector<pair<uint64_t, transaction>> mempool_txs); find_txs_in_mempool(pool_txs_t mempool_txs);
virtual addr_view_t virtual addr_view_t
get_xmr_address_viewkey() const; get_xmr_address_viewkey() const;
@ -157,4 +151,3 @@ public:
} }
#endif //RESTBED_XMR_TXSEARCH_H

@ -24,14 +24,14 @@ add_om_test(microcore)
add_om_test(bcstatus) add_om_test(bcstatus)
SETUP_TARGET_FOR_COVERAGE( SETUP_TARGET_FOR_COVERAGE(
NAME mysql_cov # New target name NAME mysql_cov
EXECUTABLE mysql_tests) EXECUTABLE mysql_tests)
SETUP_TARGET_FOR_COVERAGE( SETUP_TARGET_FOR_COVERAGE(
NAME microcore_cov # New target name NAME microcore_cov
EXECUTABLE microcore_tests) EXECUTABLE microcore_tests)
SETUP_TARGET_FOR_COVERAGE( SETUP_TARGET_FOR_COVERAGE(
NAME bcstatus_cov # New target name NAME bcstatus_cov
EXECUTABLE bcstatus_tests) EXECUTABLE bcstatus_tests)

@ -132,6 +132,9 @@ public:
MOCK_CONST_METHOD0(get_xmr_address_viewkey, MOCK_CONST_METHOD0(get_xmr_address_viewkey,
xmreg::TxSearch::addr_view_t()); xmreg::TxSearch::addr_view_t());
MOCK_METHOD1(find_txs_in_mempool,
json(xmreg::TxSearch::pool_txs_t mempool_txs));
}; };
@ -1038,7 +1041,44 @@ TEST_P(BCSTATUS_TEST, GetSearchedBlkOutputsAndAddrViewkey)
EXPECT_FALSE(bcs->get_xmr_address_viewkey(acc.address, EXPECT_FALSE(bcs->get_xmr_address_viewkey(acc.address,
address_returned, address_returned,
viewkey_returned)); viewkey_returned));
}
TEST_P(BCSTATUS_TEST, FindTxsInMempool)
{
xmreg::XmrAccount acc; // empty, mock account
acc.address = "whatever mock address";
auto tx_search = std::make_unique<MockTxSearch>();
json txs_to_return = json::array();
txs_to_return.push_back(json {"tx_hash1", "some_tx_hash1"});
txs_to_return.push_back(json {"tx_hash2", "some_tx_hash2"});
txs_to_return.push_back(json {"tx_hash3", "some_tx_hash3"});
EXPECT_CALL(*tx_search, find_txs_in_mempool(_))
.WillRepeatedly(Return(txs_to_return));
EXPECT_CALL(*tx_search, operator_fcall()) // mock operator()
.WillRepeatedly(MockSearchWhile2());
ASSERT_TRUE(bcs->start_tx_search_thread(acc, std::move(tx_search)));
json txs;
EXPECT_TRUE(bcs->find_txs_in_mempool(acc.address, txs));
while(bcs->search_thread_exist(acc.address))
{
cout << "\nsearch thread still exists\n";
std::this_thread::sleep_for(1s);
bcs->clean_search_thread_map();
}
// once we removed the search thread as it finshed,
// we should be getting false now
EXPECT_FALSE(bcs->find_txs_in_mempool(acc.address, txs));
} }

Loading…
Cancel
Save