Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
block_queue.cpp
Go to the documentation of this file.
1
// Copyright (c) 2017-Present, Electroneum
2
// Copyright (c) 2017-2019, The Monero Project
3
//
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without modification, are
7
// permitted provided that the following conditions are met:
8
//
9
// 1. Redistributions of source code must retain the above copyright notice, this list of
10
// conditions and the following disclaimer.
11
//
12
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13
// of conditions and the following disclaimer in the documentation and/or other
14
// materials provided with the distribution.
15
//
16
// 3. Neither the name of the copyright holder nor the names of its contributors may be
17
// used to endorse or promote products derived from this software without specific
18
// prior written permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
#include <boost/uuid/uuid.hpp>
31
#include "gtest/gtest.h"
32
#include "
crypto/crypto.h
"
33
#include "
cryptonote_protocol/cryptonote_protocol_defs.h
"
34
#include "
cryptonote_protocol/block_queue.h
"
35
36
static
const
boost::uuids::uuid &uuid1()
37
{
38
static
const
boost::uuids::uuid
uuid
=
crypto::rand<boost::uuids::uuid>
();
39
return
uuid
;
40
}
41
42
static
const
boost::uuids::uuid &uuid2()
43
{
44
static
const
boost::uuids::uuid
uuid
=
crypto::rand<boost::uuids::uuid>
();
45
return
uuid
;
46
}
47
48
TEST
(block_queue, empty)
49
{
50
cryptonote::block_queue
bq;
51
ASSERT_EQ
(bq.
get_max_block_height
(), 0);
52
}
53
54
TEST
(block_queue, add_stepwise)
55
{
56
cryptonote::block_queue
bq;
57
bq.
add_blocks
(0, 200, uuid1());
58
ASSERT_EQ
(bq.
get_max_block_height
(), 199);
59
bq.
add_blocks
(200, 200, uuid1());
60
ASSERT_EQ
(bq.
get_max_block_height
(), 399);
61
bq.
add_blocks
(401, 200, uuid1());
62
ASSERT_EQ
(bq.
get_max_block_height
(), 600);
63
bq.
add_blocks
(400, 10, uuid1());
64
ASSERT_EQ
(bq.
get_max_block_height
(), 600);
65
}
66
67
TEST
(block_queue, flush_uuid)
68
{
69
cryptonote::block_queue
bq;
70
71
bq.
add_blocks
(0, 200, uuid1());
72
ASSERT_EQ
(bq.
get_max_block_height
(), 199);
73
bq.
add_blocks
(200, 200, uuid2());
74
ASSERT_EQ
(bq.
get_max_block_height
(), 399);
75
bq.
flush_spans
(uuid2());
76
ASSERT_EQ
(bq.
get_max_block_height
(), 199);
77
bq.
flush_spans
(uuid1());
78
ASSERT_EQ
(bq.
get_max_block_height
(), 0);
79
80
bq.
add_blocks
(0, 200, uuid1());
81
ASSERT_EQ
(bq.
get_max_block_height
(), 199);
82
bq.
add_blocks
(200, 200, uuid2());
83
ASSERT_EQ
(bq.
get_max_block_height
(), 399);
84
bq.
flush_spans
(uuid1());
85
ASSERT_EQ
(bq.
get_max_block_height
(), 399);
86
bq.
add_blocks
(0, 200, uuid1());
87
ASSERT_EQ
(bq.
get_max_block_height
(), 399);
88
}
block_queue.h
cryptonote::block_queue
Definition
block_queue.h:49
cryptonote::block_queue::flush_spans
void flush_spans(const boost::uuids::uuid &connection_id, bool all=false)
Definition
block_queue.cpp:80
cryptonote::block_queue::add_blocks
void add_blocks(uint64_t height, std::vector< cryptonote::block_complete_entry > bcel, const boost::uuids::uuid &connection_id, float rate, size_t size)
Definition
block_queue.cpp:56
cryptonote::block_queue::get_max_block_height
uint64_t get_max_block_height() const
Definition
block_queue.cpp:148
crypto.h
cryptonote_protocol_defs.h
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition
gtest.h:1956
TEST
#define TEST(test_case_name, test_name)
Definition
gtest.h:2187
crypto::rand
std::enable_if< std::is_pod< T >::value, T >::type rand()
Definition
crypto.h:216
nodetool::uuid
boost::uuids::uuid uuid
Definition
net_node_common.h:43
tests
unit_tests
block_queue.cpp
Generated on
for Electroneum by
1.17.0