more CurrentBlockchainStatus tests added

pull/93/merge
moneroexamples 6 years ago
parent aed9eff7aa
commit 4d8b631e1b

@ -3,7 +3,7 @@ var config = {
mainnetExplorerUrl: "https://xmrchain.com/",
testnetExplorerUrl: "https://testnet.xmrchain.com/",
stagenetExplorerUrl: "http://162.210.173.150:8083/",
nettype: 0, /* 0 - MAINNET, 1 - TESTNET, 2 - STAGENET */
nettype: 2, /* 0 - MAINNET, 1 - TESTNET, 2 - STAGENET */
coinUnitPlaces: 12,
txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero
txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero

@ -213,19 +213,6 @@ CurrentBlockchainStatus::tx_exist(const string& tx_hash_str, uint64_t& tx_index)
return false;
}
bool
CurrentBlockchainStatus::tx_exist(const string& tx_hash_str)
{
crypto::hash tx_hash;
if (hex_to_pod(tx_hash_str, tx_hash))
{
return tx_exist(tx_hash);
}
throw runtime_error("(hex_to_pod(tx_hash_str, tx_hash) failed!");
}
bool
CurrentBlockchainStatus::get_tx_with_output(
uint64_t output_idx, uint64_t amount,

@ -99,9 +99,6 @@ public:
virtual bool
tx_exist(const string& tx_hash_str, uint64_t& tx_index);
virtual bool
tx_exist(const string& tx_hash_str);
virtual bool
get_tx_with_output(uint64_t output_idx, uint64_t amount,
transaction& tx, uint64_t& output_idx_in_tx);

@ -92,16 +92,16 @@ public:
return core_storage.get_db().get_blocks_range(h1, h2);
}
template <typename... T>
auto have_tx(T&&... args) const
virtual bool
have_tx(crypto::hash const& tx_hash) const
{
return core_storage.have_tx(std::forward<T>(args)...);
return core_storage.have_tx(tx_hash);
}
template<typename... T>
auto tx_exists(T&&... args) const
virtual bool
tx_exists(crypto::hash const& tx_hash, uint64_t& tx_id) const
{
return core_storage.get_db().tx_exists(std::forward<T>(args)...);
return core_storage.get_db().tx_exists(tx_hash, tx_id);
}
template<typename... T>

@ -28,6 +28,8 @@ using ::testing::HasSubstr;
using ::testing::Not;
using ::testing::Return;
using ::testing::Throw;
using ::testing::DoAll;
using ::testing::SetArgReferee;
using ::testing::_;
using ::testing::internal::FilePath;
@ -41,6 +43,8 @@ public:
MOCK_CONST_METHOD3(get_transactions, bool(const std::vector<crypto::hash>& txs_ids,
std::vector<transaction>& txs,
std::vector<crypto::hash>& missed_txs));
MOCK_CONST_METHOD1(have_tx, bool(crypto::hash const& tx_hash));
MOCK_CONST_METHOD2(tx_exists, bool(crypto::hash const& tx_hash, uint64_t& tx_id));
};
@ -109,7 +113,7 @@ TEST_F(BCSTATUS_TEST, GetBlock)
ACTION(ThrowBlockDNE)
{
throw BLOCK_DNE("ddddd");
throw BLOCK_DNE("Mock Throw: Block does not exist!");
}
TEST_F(BCSTATUS_TEST, GetBlockRange)
@ -146,6 +150,63 @@ TEST_F(BCSTATUS_TEST, GetBlockTxs)
EXPECT_TRUE(bcs->get_block_txs(dummy_blk, blk_txs, missed_txs));
EXPECT_CALL(*mcore_ptr, get_transactions(_, _, _))
.WillOnce(Return(false));
EXPECT_FALSE(bcs->get_block_txs(dummy_blk, blk_txs, missed_txs));
}
TEST_F(BCSTATUS_TEST, GetTxs)
{
EXPECT_CALL(*mcore_ptr, get_transactions(_, _, _))
.WillOnce(Return(true));
vector<crypto::hash> txs_to_get;
vector<transaction> blk_txs;
vector<crypto::hash> missed_txs;
EXPECT_TRUE(bcs->get_txs(txs_to_get, blk_txs, missed_txs));
EXPECT_CALL(*mcore_ptr, get_transactions(_, _, _))
.WillOnce(Return(false));
EXPECT_FALSE(bcs->get_txs(txs_to_get, blk_txs, missed_txs));
}
TEST_F(BCSTATUS_TEST, TxExist)
{
EXPECT_CALL(*mcore_ptr, have_tx(_))
.WillOnce(Return(true));
EXPECT_TRUE(bcs->tx_exist(crypto::hash()));
uint64_t mock_tx_index_to_return {4444};
// return true and set tx_index (ret by ref) to mock_tx_index_to_return
EXPECT_CALL(*mcore_ptr, tx_exists(_, _))
.WillOnce(DoAll(SetArgReferee<1>(mock_tx_index_to_return), Return(true)));
uint64_t tx_index {0};
EXPECT_TRUE(bcs->tx_exist(crypto::hash(), tx_index));
EXPECT_EQ(tx_index, mock_tx_index_to_return);
// just some dummy hash
string tx_hash_str {"fc4b8d5956b30dc4a353b171b4d974697dfc32730778f138a8e7f16c11907691"};
tx_index = 0;
EXPECT_CALL(*mcore_ptr, tx_exists(_, _))
.WillOnce(DoAll(SetArgReferee<1>(mock_tx_index_to_return), Return(true)));
EXPECT_TRUE(bcs->tx_exist(tx_hash_str, tx_index));
EXPECT_EQ(tx_index, mock_tx_index_to_return);
tx_hash_str = "wrong_hash";
EXPECT_FALSE(bcs->tx_exist(tx_hash_str, tx_index));
}
}

Loading…
Cancel
Save