22#include <xrpld/app/consensus/RCLValidations.h>
23#include <xrpld/app/ledger/Ledger.h>
25#include <xrpl/basics/base_uint.h>
26#include <xrpl/beast/unit_test.h>
36 testcase(
"Change validation trusted status");
43 [&](
STValidation& v) { v.setFieldU32(sfLedgerSequence, 123456); });
45 BEAST_EXPECT(v->isTrusted());
47 BEAST_EXPECT(!v->isTrusted());
50 BEAST_EXPECT(!rcv.trusted());
52 BEAST_EXPECT(rcv.trusted());
54 BEAST_EXPECT(!rcv.trusted());
60 testcase(
"RCLValidatedLedger ancestry");
68 Seq
const maxAncestors = 256;
82 env.
app().getNodeFamily());
84 for (
auto i = 0; i < (2 * maxAncestors + 1); ++i)
88 next->updateSkipList();
94 Seq
const diverge = history.
size() / 2;
98 using namespace std::chrono_literals;
100 prev = altHistory.
back();
101 bool forceHash =
true;
102 while (altHistory.
size() < history.
size())
107 next->updateSkipList();
111 next->setImmutable();
124 BEAST_EXPECT(a.seq() == Seq{0});
125 BEAST_EXPECT(a[Seq{0}] == ID{0});
126 BEAST_EXPECT(a.minSeq() == Seq{0});
133 BEAST_EXPECT(a.seq() == ledger->info().seq);
134 BEAST_EXPECT(a.minSeq() == a.seq() - maxAncestors);
136 for (Seq s = a.seq(); s > 0; s--)
139 BEAST_EXPECT(a[s] == history[s - 1]->info().hash);
141 BEAST_EXPECT(a[s] == ID{0});
151 for (
auto ledger : {history.
back(), history[maxAncestors - 1]})
161 for (Seq s = a.seq(); s > 0; s--)
166 BEAST_EXPECT(
mismatch(a, b) == b.seq() + 1);
167 BEAST_EXPECT(
mismatch(b, a) == b.seq() + 1);
171 BEAST_EXPECT(
mismatch(a, b) == Seq{1});
172 BEAST_EXPECT(
mismatch(b, a) == Seq{1});
179 for (Seq s = 1; s < history.
size(); ++s)
184 BEAST_EXPECT(a.seq() == b.seq());
187 BEAST_EXPECT(a[a.seq()] == b[b.seq()]);
188 BEAST_EXPECT(
mismatch(a, b) == a.seq() + 1);
189 BEAST_EXPECT(
mismatch(b, a) == a.seq() + 1);
193 BEAST_EXPECT(a[a.seq()] != b[b.seq()]);
194 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
195 BEAST_EXPECT(
mismatch(b, a) == diverge + 1);
203 for (Seq offset = diverge / 2; offset < 3 * diverge / 2; ++offset)
206 if (offset <= diverge)
208 BEAST_EXPECT(
mismatch(a, b) == b.seq() + 1);
212 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
221 testcase(
"RCLValidatedLedger LedgerTrie");
234 Seq
const maxAncestors = 256;
245 env.
app().getNodeFamily());
247 for (
auto i = 0; i < (maxAncestors + 10); ++i)
251 next->updateSkipList();
277 BEAST_EXPECT(trie.
remove(ledg_258, 3));
testcase_t testcase
Memberspace for declaring test cases.
virtual TimeKeeper & timeKeeper()=0
Ancestry trie of ledgers.
std::uint32_t tipSupport(Ledger const &ledger) const
Return count of tip support for the specific ledger.
void insert(Ledger const &ledger, std::uint32_t count=1)
Insert and/or increment the support for the given ledger.
std::optional< SpanTip< Ledger > > getPreferred(Seq const largestIssued) const
Return the preferred ledger ID.
std::uint32_t branchSupport(Ledger const &ledger) const
Return the count of branch support for the specific 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.
time_point closeTime() const
Returns the predicted close time, in network time.
time_point now() const override
Returns the current time.
void testRCLValidatedLedger()
void run() override
Runs the suite.
void testLedgerTrieRCLValidatedLedger()
A transaction testing environment.
beast::Journal const journal
ManualTimeKeeper & timeKeeper()
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.
RCLValidatedLedger::Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
create_genesis_t const create_genesis
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.