21#include <xrpld/app/consensus/RCLValidations.h>
22#include <xrpld/app/ledger/Ledger.h>
23#include <xrpl/basics/base_uint.h>
24#include <xrpl/beast/unit_test.h>
34 testcase(
"Change validation trusted status");
36 auto v = std::make_shared<STValidation>(
41 [&](
STValidation& v) { v.setFieldU32(sfLedgerSequence, 123456); });
43 BEAST_EXPECT(v->isTrusted());
45 BEAST_EXPECT(!v->isTrusted());
48 BEAST_EXPECT(!rcv.trusted());
50 BEAST_EXPECT(rcv.trusted());
52 BEAST_EXPECT(!rcv.trusted());
58 testcase(
"RCLValidatedLedger ancestry");
66 Seq
const maxAncestors = 256;
76 auto prev = std::make_shared<Ledger const>(
80 env.
app().getNodeFamily());
82 for (
auto i = 0; i < (2 * maxAncestors + 1); ++i)
84 auto next = std::make_shared<Ledger>(
86 next->updateSkipList();
92 Seq
const diverge = history.
size() / 2;
96 using namespace std::chrono_literals;
98 prev = altHistory.
back();
99 bool forceHash =
true;
100 while (altHistory.
size() < history.
size())
102 auto next = std::make_shared<Ledger>(
105 next->updateSkipList();
109 next->setImmutable();
122 BEAST_EXPECT(a.seq() == Seq{0});
123 BEAST_EXPECT(a[Seq{0}] == ID{0});
124 BEAST_EXPECT(a.minSeq() == Seq{0});
131 BEAST_EXPECT(a.seq() == ledger->info().seq);
132 BEAST_EXPECT(a.minSeq() == a.seq() - maxAncestors);
134 for (Seq s = a.seq(); s > 0; s--)
137 BEAST_EXPECT(a[s] == history[s - 1]->info().hash);
139 BEAST_EXPECT(a[s] == ID{0});
149 for (
auto ledger : {history.
back(), history[maxAncestors - 1]})
159 for (Seq s = a.seq(); s > 0; s--)
164 BEAST_EXPECT(
mismatch(a, b) == b.seq() + 1);
165 BEAST_EXPECT(
mismatch(b, a) == b.seq() + 1);
169 BEAST_EXPECT(
mismatch(a, b) == Seq{1});
170 BEAST_EXPECT(
mismatch(b, a) == Seq{1});
177 for (Seq s = 1; s < history.
size(); ++s)
182 BEAST_EXPECT(a.seq() == b.seq());
185 BEAST_EXPECT(a[a.seq()] == b[b.seq()]);
186 BEAST_EXPECT(
mismatch(a, b) == a.seq() + 1);
187 BEAST_EXPECT(
mismatch(b, a) == a.seq() + 1);
191 BEAST_EXPECT(a[a.seq()] != b[b.seq()]);
192 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
193 BEAST_EXPECT(
mismatch(b, a) == diverge + 1);
201 for (Seq offset = diverge / 2; offset < 3 * diverge / 2; ++offset)
204 if (offset <= diverge)
206 BEAST_EXPECT(
mismatch(a, b) == b.seq() + 1);
210 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
219 testcase(
"RCLValidatedLedger LedgerTrie");
233 Seq
const maxAncestors = 256;
240 auto prev = std::make_shared<Ledger const>(
244 env.
app().getNodeFamily());
246 for (
auto i = 0; i < (maxAncestors + 10); ++i)
248 auto next = std::make_shared<Ledger>(
250 next->updateSkipList();
276 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.