Testing to make sure source is pulled in.

This commit is contained in:
clemahieu 2014-11-24 21:28:29 -06:00
commit d44b1fab85
2 changed files with 32 additions and 6 deletions

View file

@ -2706,12 +2706,8 @@ void rai::block_path::send_block (rai::send_block const & block_a)
void rai::block_path::receive_block (rai::receive_block const & block_a)
{
auto existing1 (blocks.find (block_a.hashables.source));
if (existing1 != blocks.end ())
{
path.push_back (std::move (existing1->second));
blocks.erase (existing1);
}
rai::block_path path_l (path, blocks);
path_l.generate (block_a.hashables.source);
auto existing2 (blocks.find (block_a.hashables.previous));
if (existing2 != blocks.end ())
{

View file

@ -68,4 +68,34 @@ TEST (block_path, receive_one)
ASSERT_EQ (*block3, *path [0]);
ASSERT_EQ (*block2, *path [1]);
ASSERT_EQ (*block1, *path [2]);
}
TEST (block_path, receive_two)
{
std::vector <std::unique_ptr <rai::block>> path;
std::unordered_map <rai::block_hash, std::unique_ptr <rai::block>> blocks;
std::unique_ptr <rai::send_block> block1 (new rai::send_block);
block1->hashables.previous = 1;
auto hash1 (block1->hash ());
blocks [hash1] = block1->clone ();
std::unique_ptr <rai::send_block> block4 (new rai::send_block);
auto hash4 (block4->hash ());
blocks [hash4] = block4->clone ();
std::unique_ptr <rai::send_block> block2 (new rai::send_block);
block2->hashables.previous = hash4;
auto hash2 (block2->hash ());
blocks [hash2] = block2->clone ();
std::unique_ptr <rai::receive_block> block3 (new rai::receive_block);
block3->hashables.previous = hash1;
block3->hashables.source = hash2;
auto hash3 (block3->hash ());
blocks [hash3] = block3->clone ();
rai::block_path block_path (path, blocks);
block_path.generate (hash3);
ASSERT_EQ (4, path.size ());
ASSERT_EQ (0, blocks.size ());
ASSERT_EQ (*block3, *path [0]);
ASSERT_EQ (*block2, *path [1]);
ASSERT_EQ (*block4, *path [2]);
ASSERT_EQ (*block1, *path [3]);
}