rippled
Loading...
Searching...
No Matches
RCLCensorshipDetector_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2018 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/consensus/RCLCensorshipDetector.h>
21#include <xrpl/beast/unit_test.h>
22#include <algorithm>
23#include <vector>
24
25namespace ripple {
26namespace test {
27
29{
30 void
33 int round,
34 std::vector<int> proposed,
36 std::vector<int> remain,
37 std::vector<int> remove)
38 {
39 // Begin tracking what we're proposing this round
41 for (auto const& i : proposed)
42 proposal.emplace_back(i, round);
43 cdet.propose(std::move(proposal));
44
45 // Finalize the round, by processing what we accepted; then
46 // remove anything that needs to be removed and ensure that
47 // what remains is correct.
48 cdet.check(std::move(accepted), [&remove, &remain](auto id, auto seq) {
49 // If the item is supposed to be removed from the censorship
50 // detector internal tracker manually, do it now:
51 if (std::find(remove.begin(), remove.end(), id) != remove.end())
52 return true;
53
54 // If the item is supposed to still remain in the censorship
55 // detector internal tracker; remove it from the vector.
56 auto it = std::find(remain.begin(), remain.end(), id);
57 if (it != remain.end())
58 remain.erase(it);
59 return false;
60 });
61
62 // On entry, this set contained all the elements that should be tracked
63 // by the detector after we process this round. We removed all the items
64 // that actually were in the tracker, so this should now be empty:
65 BEAST_EXPECT(remain.empty());
66 }
67
68public:
69 void
70 run() override
71 {
72 testcase("Censorship Detector");
73
75 int round = 0;
76 // proposed accepted remain remove
77 test(cdet, ++round, {}, {}, {}, {});
78 test(cdet, ++round, {10, 11, 12, 13}, {11, 2}, {10, 13}, {});
79 test(cdet, ++round, {10, 13, 14, 15}, {14}, {10, 13, 15}, {});
80 test(cdet, ++round, {10, 13, 15, 16}, {15, 16}, {10, 13}, {});
81 test(cdet, ++round, {10, 13}, {17, 18}, {10, 13}, {});
82 test(cdet, ++round, {10, 19}, {}, {10, 19}, {});
83 test(cdet, ++round, {10, 19, 20}, {20}, {10}, {19});
84 test(cdet, ++round, {21}, {21}, {}, {});
85 test(cdet, ++round, {}, {22}, {}, {});
86 test(cdet, ++round, {23, 24, 25, 26}, {25, 27}, {23, 26}, {24});
87 test(cdet, ++round, {23, 26, 28}, {26, 28}, {23}, {});
88
89 for (int i = 0; i != 10; ++i)
90 test(cdet, ++round, {23}, {}, {23}, {});
91
92 test(cdet, ++round, {23, 29}, {29}, {23}, {});
93 test(cdet, ++round, {30, 31}, {31}, {30}, {});
94 test(cdet, ++round, {30}, {30}, {}, {});
95 test(cdet, ++round, {}, {}, {}, {});
96 }
97};
98
99BEAST_DEFINE_TESTSUITE(RCLCensorshipDetector, app, ripple);
100} // namespace test
101} // namespace ripple
T begin(T... args)
A testsuite class.
Definition: suite.h:53
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
void check(std::vector< TxID > accepted, Predicate &&pred)
Determine which transactions made it and perform censorship detection.
void propose(TxIDSeqVec proposed)
Add transactions being proposed for the current consensus round.
void test(RCLCensorshipDetector< int, int > &cdet, int round, std::vector< int > proposed, std::vector< int > accepted, std::vector< int > remain, std::vector< int > remove)
T empty(T... args)
T end(T... args)
T erase(T... args)
T find(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ accepted
Manifest is valid.
@ proposal
proposal for signing
Set the sequence number on a JTx.
Definition: seq.h:34