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
22#include <xrpl/beast/unit_test.h>
23
24#include <algorithm>
25#include <vector>
26
27namespace ripple {
28namespace test {
29
31{
32 void
35 int round,
36 std::vector<int> proposed,
38 std::vector<int> remain,
39 std::vector<int> remove)
40 {
41 // Begin tracking what we're proposing this round
43 for (auto const& i : proposed)
44 proposal.emplace_back(i, round);
45 cdet.propose(std::move(proposal));
46
47 // Finalize the round, by processing what we accepted; then
48 // remove anything that needs to be removed and ensure that
49 // what remains is correct.
50 cdet.check(std::move(accepted), [&remove, &remain](auto id, auto seq) {
51 // If the item is supposed to be removed from the censorship
52 // detector internal tracker manually, do it now:
53 if (std::find(remove.begin(), remove.end(), id) != remove.end())
54 return true;
55
56 // If the item is supposed to still remain in the censorship
57 // detector internal tracker; remove it from the vector.
58 auto it = std::find(remain.begin(), remain.end(), id);
59 if (it != remain.end())
60 remain.erase(it);
61 return false;
62 });
63
64 // On entry, this set contained all the elements that should be tracked
65 // by the detector after we process this round. We removed all the items
66 // that actually were in the tracker, so this should now be empty:
67 BEAST_EXPECT(remain.empty());
68 }
69
70public:
71 void
72 run() override
73 {
74 testcase("Censorship Detector");
75
77 int round = 0;
78 // proposed accepted remain remove
79 test(cdet, ++round, {}, {}, {}, {});
80 test(cdet, ++round, {10, 11, 12, 13}, {11, 2}, {10, 13}, {});
81 test(cdet, ++round, {10, 13, 14, 15}, {14}, {10, 13, 15}, {});
82 test(cdet, ++round, {10, 13, 15, 16}, {15, 16}, {10, 13}, {});
83 test(cdet, ++round, {10, 13}, {17, 18}, {10, 13}, {});
84 test(cdet, ++round, {10, 19}, {}, {10, 19}, {});
85 test(cdet, ++round, {10, 19, 20}, {20}, {10}, {19});
86 test(cdet, ++round, {21}, {21}, {}, {});
87 test(cdet, ++round, {}, {22}, {}, {});
88 test(cdet, ++round, {23, 24, 25, 26}, {25, 27}, {23, 26}, {24});
89 test(cdet, ++round, {23, 26, 28}, {26, 28}, {23}, {});
90
91 for (int i = 0; i != 10; ++i)
92 test(cdet, ++round, {23}, {}, {23}, {});
93
94 test(cdet, ++round, {23, 29}, {29}, {23}, {});
95 test(cdet, ++round, {30, 31}, {31}, {30}, {});
96 test(cdet, ++round, {30}, {30}, {}, {});
97 test(cdet, ++round, {}, {}, {}, {});
98 }
99};
100
101BEAST_DEFINE_TESTSUITE(RCLCensorshipDetector, consensus, ripple);
102} // namespace test
103} // namespace ripple
T begin(T... args)
A testsuite class.
Definition suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
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:25
@ accepted
Manifest is valid.
@ proposal
proposal for signing
Set the sequence number on a JTx.
Definition seq.h:34