xrpld
Loading...
Searching...
No Matches
CensorshipDetector.cpp
1#include <xrpl/consensus/CensorshipDetector.h>
2
3#include <gtest/gtest.h>
4
5#include <algorithm>
6#include <utility>
7#include <vector>
8
9namespace xrpl::test {
10
11namespace {
12
13void
14runRound(
15 CensorshipDetector<int, int>& cdet,
16 int round,
17 std::vector<int> proposed,
18 std::vector<int> accepted,
19 std::vector<int> remain,
20 std::vector<int> remove)
21{
22 // Begin tracking what we're proposing this round
24 for (auto const& i : proposed)
25 proposal.emplace_back(i, round);
26 cdet.propose(std::move(proposal));
27
28 // Finalize the round, by processing what we accepted; then
29 // remove anything that needs to be removed and ensure that
30 // what remains is correct.
31 cdet.check(std::move(accepted), [&remove, &remain](auto id, auto seq) {
32 // If the item is supposed to be removed from the censorship
33 // detector internal tracker manually, do it now:
34 if (std::ranges::find(remove, id) != remove.end())
35 return true;
36
37 // If the item is supposed to still remain in the censorship
38 // detector internal tracker; remove it from the vector.
39 auto it = std::ranges::find(remain, id);
40 if (it != remain.end())
41 remain.erase(it);
42 return false;
43 });
44
45 // On entry, this set contained all the elements that should be tracked
46 // by the detector after we process this round. We removed all the items
47 // that actually were in the tracker, so this should now be empty:
48 EXPECT_TRUE(remain.empty());
49}
50
51} // namespace
52
53TEST(CensorshipDetectorTest, censorship_detector)
54{
55 SCOPED_TRACE("Censorship Detector");
56
58 int round = 0;
59 // proposed accepted remain remove
60 runRound(cdet, ++round, {}, {}, {}, {});
61 runRound(cdet, ++round, {10, 11, 12, 13}, {11, 2}, {10, 13}, {});
62 runRound(cdet, ++round, {10, 13, 14, 15}, {14}, {10, 13, 15}, {});
63 runRound(cdet, ++round, {10, 13, 15, 16}, {15, 16}, {10, 13}, {});
64 runRound(cdet, ++round, {10, 13}, {17, 18}, {10, 13}, {});
65 runRound(cdet, ++round, {10, 19}, {}, {10, 19}, {});
66 runRound(cdet, ++round, {10, 19, 20}, {20}, {10}, {19});
67 runRound(cdet, ++round, {21}, {21}, {}, {});
68 runRound(cdet, ++round, {}, {22}, {}, {});
69 runRound(cdet, ++round, {23, 24, 25, 26}, {25, 27}, {23, 26}, {24});
70 runRound(cdet, ++round, {23, 26, 28}, {26, 28}, {23}, {});
71
72 for (auto i = 0uz; i != 10; ++i)
73 runRound(cdet, ++round, {23}, {}, {23}, {});
74
75 runRound(cdet, ++round, {23, 29}, {29}, {23}, {});
76 runRound(cdet, ++round, {30, 31}, {31}, {30}, {});
77 runRound(cdet, ++round, {30}, {30}, {}, {});
78 runRound(cdet, ++round, {}, {}, {}, {});
79}
80
81} // namespace xrpl::test
std::vector< TxIDSeq > TxIDSeqVec
T emplace_back(T... args)
T empty(T... args)
T end(T... args)
T erase(T... args)
T find(T... args)
TEST(UnitsTest, types)
Definition Units.cpp:16