rippled
Loading...
Searching...
No Matches
RCLCensorshipDetector_test.cpp
1#include <xrpld/app/consensus/RCLCensorshipDetector.h>
2
3#include <xrpl/beast/unit_test.h>
4
5#include <algorithm>
6#include <vector>
7
8namespace ripple {
9namespace test {
10
12{
13 void
16 int round,
17 std::vector<int> proposed,
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::find(remove.begin(), remove.end(), 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::find(remain.begin(), remain.end(), 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 BEAST_EXPECT(remain.empty());
49 }
50
51public:
52 void
53 run() override
54 {
55 testcase("Censorship Detector");
56
58 int round = 0;
59 // proposed accepted remain remove
60 test(cdet, ++round, {}, {}, {}, {});
61 test(cdet, ++round, {10, 11, 12, 13}, {11, 2}, {10, 13}, {});
62 test(cdet, ++round, {10, 13, 14, 15}, {14}, {10, 13, 15}, {});
63 test(cdet, ++round, {10, 13, 15, 16}, {15, 16}, {10, 13}, {});
64 test(cdet, ++round, {10, 13}, {17, 18}, {10, 13}, {});
65 test(cdet, ++round, {10, 19}, {}, {10, 19}, {});
66 test(cdet, ++round, {10, 19, 20}, {20}, {10}, {19});
67 test(cdet, ++round, {21}, {21}, {}, {});
68 test(cdet, ++round, {}, {22}, {}, {});
69 test(cdet, ++round, {23, 24, 25, 26}, {25, 27}, {23, 26}, {24});
70 test(cdet, ++round, {23, 26, 28}, {26, 28}, {23}, {});
71
72 for (int i = 0; i != 10; ++i)
73 test(cdet, ++round, {23}, {}, {23}, {});
74
75 test(cdet, ++round, {23, 29}, {29}, {23}, {});
76 test(cdet, ++round, {30, 31}, {31}, {30}, {});
77 test(cdet, ++round, {30}, {30}, {}, {});
78 test(cdet, ++round, {}, {}, {}, {});
79 }
80};
81
82BEAST_DEFINE_TESTSUITE(RCLCensorshipDetector, consensus, ripple);
83} // namespace test
84} // namespace ripple
T begin(T... args)
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
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 emplace_back(T... args)
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:6
@ accepted
Manifest is valid.
@ proposal
proposal for signing
Set the sequence number on a JTx.
Definition seq.h:15