3#include <xrpld/app/consensus/RCLValidations.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/unit_test.h>
7#include <xrpl/ledger/Ledger.h>
17 testcase(
"Change validation trusted status");
24 [&](
STValidation& v) { v.setFieldU32(sfLedgerSequence, 123456); });
26 BEAST_EXPECT(v->isTrusted());
28 BEAST_EXPECT(!v->isTrusted());
31 BEAST_EXPECT(!rcv.trusted());
33 BEAST_EXPECT(rcv.trusted());
35 BEAST_EXPECT(!rcv.trusted());
41 testcase(
"RCLValidatedLedger ancestry");
49 Seq
const maxAncestors = 256;
64 env.
app().getNodeFamily());
66 for (
auto i = 0; i < ((2 * maxAncestors) + 1); ++i)
69 next->updateSkipList();
75 Seq
const diverge = history.
size() / 2;
79 using namespace std::chrono_literals;
81 prev = altHistory.
back();
82 bool forceHash =
true;
83 while (altHistory.
size() < history.
size())
87 next->updateSkipList();
104 BEAST_EXPECT(a.seq() == Seq{0});
105 BEAST_EXPECT(a[Seq{0}] == ID{0});
106 BEAST_EXPECT(a.minSeq() == Seq{0});
113 BEAST_EXPECT(a.seq() == ledger->header().seq);
114 BEAST_EXPECT(a.minSeq() == a.seq() - maxAncestors);
116 for (Seq s = a.seq(); s > 0; s--)
120 BEAST_EXPECT(a[s] == history[s - 1]->header().hash);
124 BEAST_EXPECT(a[s] == ID{0});
135 for (
auto const& ledger : {history.
back(), history[maxAncestors - 1]})
145 for (Seq s = a.seq(); s > 0; s--)
150 BEAST_EXPECT(
mismatch(a, b) == b.seq() + 1);
151 BEAST_EXPECT(
mismatch(b, a) == b.seq() + 1);
155 BEAST_EXPECT(
mismatch(a, b) == Seq{1});
156 BEAST_EXPECT(
mismatch(b, a) == Seq{1});
163 for (Seq s = 1; s < history.
size(); ++s)
168 BEAST_EXPECT(a.seq() == b.seq());
171 BEAST_EXPECT(a[a.seq()] == b[b.seq()]);
172 BEAST_EXPECT(
mismatch(a, b) == a.seq() + 1);
173 BEAST_EXPECT(
mismatch(b, a) == a.seq() + 1);
177 BEAST_EXPECT(a[a.seq()] != b[b.seq()]);
178 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
179 BEAST_EXPECT(
mismatch(b, a) == diverge + 1);
187 for (Seq offset = diverge / 2; offset < 3 * diverge / 2; ++offset)
190 if (offset <= diverge)
192 BEAST_EXPECT(
mismatch(a, b) == b.seq() + 1);
196 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
205 testcase(
"RCLValidatedLedger LedgerTrie");
218 Seq
const maxAncestors = 256;
230 env.
app().getNodeFamily());
232 for (
auto i = 0; i < (maxAncestors + 10); ++i)
235 next->updateSkipList();
261 BEAST_EXPECT(trie.
remove(ledg_258, 3));
testcase_t testcase
Memberspace for declaring test cases.
std::unordered_set< uint256, beast::uhash<> > features
Ancestry trie of ledgers.
std::uint32_t tipSupport(Ledger const &ledger) const
Return count of tip support for the specific ledger.
std::uint32_t branchSupport(Ledger const &ledger) const
Return the count of branch support for the specific ledger.
std::optional< SpanTip< Ledger > > getPreferred(Seq const largestIssued) const
Return the preferred ledger ID.
void insert(Ledger const &ledger, std::uint32_t count=1)
Insert and/or increment the support for the given ledger.
bool remove(Ledger const &ledger, std::uint32_t count=1)
Decrease support for a ledger, removing and compressing if possible.
Wraps a ledger instance for use in generic Validations LedgerTrie.
Wrapper over STValidation for generic Validation code.
Rules controlling protocol behavior.
virtual TimeKeeper & getTimeKeeper()=0
time_point closeTime() const
Returns the predicted close time, in network time.
time_point now() const override
Returns the current time.
void run() override
Runs the suite.
void testLedgerTrieRCLValidatedLedger()
void testRCLValidatedLedger()
A transaction testing environment.
ManualTimeKeeper & timeKeeper()
beast::Journal const journal
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
create_genesis_t const create_genesis
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
RCLValidatedLedger::Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
Fees toFees() const
Convert to a Fees object for use with Ledger construction.