Skip to content

Commit

Permalink
BlockchainDB unit tests, lmdb linker flag
Browse files Browse the repository at this point in the history
Some BlockchainDB unit testing fleshed out (and working), rudimentary
linker flag for lmdb in CMakeLists, but should probably be done
"correctly" at some point (find it on whatever system you're building on
and all that jazz).

update for rebase (warptangent 2015-01-04)
  fix conflicts with upstream CMakeLists.txt files

  tests/CMakeLists.txt (remove edits from original commit)
  • Loading branch information
tewinget authored and warptangent committed Jan 5, 2015
1 parent b98b964 commit 1240cf8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ link_directories(${UNBOUND_LIBRARY_DIRS})
# Final setup for rapidjson
include_directories(external/rapidjson)

# TODO: make this find lmdb similarly to how unbound and boost are handled
set(LMDB_LIBRARIES "-llmdb")

if(MSVC)
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
Expand Down
28 changes: 22 additions & 6 deletions tests/unit_tests/BlockchainDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "gtest/gtest.h"

#include "cryptonote_core/blockchain_db.h"
#include "cryptonote_core/BlockchainDB_impl/lmdb.h"
#include "cryptonote_core/BlockchainDB_impl/db_lmdb.h"
#include "cryptonote_core/cryptonote_format_utils.h"

using namespace cryptonote;
Expand Down Expand Up @@ -81,10 +81,19 @@ const std::vector<std::vector<std::string>> t_transactions =
// from std::string, this might break.
bool compare_blocks(const block& a, const block& b)
{
auto ab = block_to_blob(a);
auto bb = block_to_blob(b);
auto hash_a = pod_to_hex(get_block_hash(a));
auto hash_b = pod_to_hex(get_block_hash(b));

return ab == bb;
return hash_a == hash_b;
}

void print_block(const block& blk, const std::string& prefix = "")
{
std::cerr << prefix << ": " << std::endl
<< "\thash - " << pod_to_hex(get_block_hash(blk)) << std::endl
<< "\tparent - " << pod_to_hex(blk.prev_id) << std::endl
<< "\ttimestamp - " << blk.timestamp << std::endl
;
}

// if the return type (blobdata for now) of tx_to_blob ever changes
Expand Down Expand Up @@ -187,6 +196,9 @@ class BlockchainDBTest : public testing::Test
std::cerr << "File created by test not to be removed (for safety): " << f << std::endl;
}
}

// remove directory if it still exists
boost::filesystem::remove(m_prefix);
}

void set_prefix(const std::string& prefix)
Expand All @@ -197,7 +209,7 @@ class BlockchainDBTest : public testing::Test

using testing::Types;

typedef Types<> implementations;
typedef Types<BlockchainLMDB> implementations;

TYPED_TEST_CASE(BlockchainDBTest, implementations);

Expand Down Expand Up @@ -225,7 +237,11 @@ TYPED_TEST(BlockchainDBTest, AddBlock)

// adding a block with no parent in the blockchain should throw.
// note: this shouldn't be possible, but is a good (and cheap) failsafe.
ASSERT_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]), BLOCK_PARENT_DNE);
//
// TODO: need at least one more block to make this reasonable, as the
// BlockchainDB implementation should not check for parent if
// no blocks have been added yet (because genesis has no parent).
//ASSERT_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]), BLOCK_PARENT_DNE);

ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
Expand Down

0 comments on commit 1240cf8

Please sign in to comment.