Removing test code.

Fixing issue with checking if pending or latest exists.
This commit is contained in:
clemahieu 2014-12-27 20:43:16 -06:00
commit f6f4d5f2a6
4 changed files with 73 additions and 57 deletions

View file

@ -2448,34 +2448,6 @@ public:
};
}
void rai::block_store::block_del (rai::block_hash const & hash_a)
{
auto status (blocks->Delete (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ())));
assert (status.ok ());
}
void rai::block_store::latest_del (rai::account const & account_a)
{
auto status (accounts->Delete (leveldb::WriteOptions (), leveldb::Slice (account_a.chars.data (), account_a.chars.size ())));
assert (status.ok ());
}
bool rai::block_store::latest_exists (rai::account const & account_a)
{
std::unique_ptr <leveldb::Iterator> existing (accounts->NewIterator (leveldb::ReadOptions {}));
existing->Seek (leveldb::Slice (account_a.chars.data (), account_a.chars.size ()));
bool result;
if (existing->Valid ())
{
result = true;
}
else
{
result = false;
}
return result;
}
namespace
{
bool parse_address_port (std::string const & string, boost::asio::ip::address & address_a, uint16_t & port_a)
@ -3364,31 +3336,6 @@ void rai::bulk_pull_client::received_block (boost::system::error_code const & ec
}
}
bool rai::block_store::block_exists (rai::block_hash const & hash_a)
{
bool result;
std::unique_ptr <leveldb::Iterator> iterator (blocks->NewIterator (leveldb::ReadOptions ()));
iterator->Seek (leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()));
if (iterator->Valid ())
{
rai::uint256_union hash;
hash = iterator->key ();
if (hash == hash_a)
{
result = true;
}
else
{
result = false;
}
}
else
{
result = false;
}
return result;
}
rai::endpoint rai::network::endpoint ()
{
return rai::endpoint (boost::asio::ip::address_v6::loopback (), socket.local_endpoint ().port ());

View file

@ -429,4 +429,26 @@ TEST (block_store, roots)
ASSERT_EQ (receive_block.hashables.previous, receive_block.root ());
rai::open_block open_block;
ASSERT_EQ (open_block.hashables.source ^ rai::open_block::root_mask, open_block.root ());
}
TEST (block_store, pending_exists)
{
leveldb::Status init;
rai::block_store store (init, rai::block_store_temp);
rai::block_hash two (2);
rai::receivable receivable;
store.pending_put (two, receivable);
rai::block_hash one (1);
ASSERT_FALSE (store.pending_exists (one));
}
TEST (block_store, latest_exists)
{
leveldb::Status init;
rai::block_store store (init, rai::block_store_temp);
rai::block_hash two (2);
rai::frontier frontier;
store.latest_put (two, frontier);
rai::block_hash one (1);
ASSERT_FALSE (store.latest_exists (one));
}

View file

@ -82,9 +82,6 @@ TEST (gap_cache, gap_bootstrap)
send.hashables.destination = key.pub;
send.hashables.previous = system.clients [0]->ledger.latest (rai::test_genesis_key.pub);
send.work = system.clients [0]->create_work (send);
std::string hash;
send.hash ().encode_hex (hash);
std::cerr << hash << std::endl;
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send.hash (), send.signature);
ASSERT_EQ (rai::process_result::progress, system.clients [0]->processor.process_receive (send));
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - 100, system.clients [0]->ledger.account_balance (rai::genesis_account));

View file

@ -1814,6 +1814,54 @@ std::unique_ptr <rai::block> rai::block_store::block_get (rai::block_hash const
return result;
}
void rai::block_store::block_del (rai::block_hash const & hash_a)
{
auto status (blocks->Delete (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ())));
assert (status.ok ());
}
bool rai::block_store::block_exists (rai::block_hash const & hash_a)
{
bool result;
std::unique_ptr <leveldb::Iterator> iterator (blocks->NewIterator (leveldb::ReadOptions ()));
iterator->Seek (leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()));
if (iterator->Valid ())
{
rai::block_hash hash;
hash = iterator->key ();
result = hash == hash_a;
}
else
{
result = false;
}
return result;
}
void rai::block_store::latest_del (rai::account const & account_a)
{
auto status (accounts->Delete (leveldb::WriteOptions (), leveldb::Slice (account_a.chars.data (), account_a.chars.size ())));
assert (status.ok ());
}
bool rai::block_store::latest_exists (rai::account const & account_a)
{
std::unique_ptr <leveldb::Iterator> existing (accounts->NewIterator (leveldb::ReadOptions {}));
existing->Seek (leveldb::Slice (account_a.chars.data (), account_a.chars.size ()));
bool result;
if (existing->Valid ())
{
rai::account account;
account = existing->key ();
result = account == account_a;
}
else
{
result = false;
}
return result;
}
bool rai::block_store::latest_get (rai::account const & account_a, rai::frontier & frontier_a)
{
std::string value;
@ -1870,7 +1918,9 @@ bool rai::block_store::pending_exists (rai::block_hash const & hash_a)
bool result;
if (iterator->Valid ())
{
result = true;
rai::block_hash hash;
hash = iterator->key ();
result = hash == hash_a;
}
else
{