Debian Codegraph @

tests/unit_tests/block_queue.cpp

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