2#include <test/jtx/Env.h>
4#include <xrpld/app/consensus/RCLValidations.h>
5#include <xrpld/consensus/LedgerTrie.h>
6#include <xrpld/core/Config.h>
8#include <xrpl/basics/base_uint.h>
9#include <xrpl/basics/chrono.h>
10#include <xrpl/beast/unit_test/suite.h>
11#include <xrpl/ledger/Ledger.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/KeyType.h>
14#include <xrpl/protocol/PublicKey.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STValidation.h>
17#include <xrpl/protocol/SecretKey.h>
29 testcase(
"Change validation trusted status");
36 [&](
STValidation& v) { v.setFieldU32(sfLedgerSequence, 123456); });
38 BEAST_EXPECT(v->isTrusted());
40 BEAST_EXPECT(!v->isTrusted());
53 testcase(
"RCLValidatedLedger ancestry");
61 Seq const maxAncestors = 256;
76 env.
app().getNodeFamily());
78 for (
auto i = 0; i < ((2 * maxAncestors) + 1); ++i)
81 next->updateSkipList();
87 Seq const diverge = history.
size() / 2;
91 using namespace std::chrono_literals;
93 prev = altHistory.
back();
94 bool forceHash =
true;
95 while (altHistory.
size() < history.
size())
99 next->updateSkipList();
103 next->setImmutable();
116 BEAST_EXPECT(a.
seq() ==
Seq{0});
117 BEAST_EXPECT(a[
Seq{0}] == ID{0});
125 BEAST_EXPECT(a.
seq() == ledger->header().seq);
126 BEAST_EXPECT(a.
minSeq() == a.
seq() - maxAncestors);
128 for (
Seq s = a.
seq(); s > 0; s--)
132 BEAST_EXPECT(a[s] == history[s - 1]->header().hash);
136 BEAST_EXPECT(a[s] == ID{0});
147 for (
auto const& ledger : {history.
back(), history[maxAncestors - 1]})
157 for (
Seq s = a.
seq(); s > 0; s--)
175 for (
Seq s = 1; s < history.
size(); ++s)
180 BEAST_EXPECT(a.
seq() == b.
seq());
183 BEAST_EXPECT(a[a.
seq()] == b[b.
seq()]);
189 BEAST_EXPECT(a[a.
seq()] != b[b.
seq()]);
190 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
191 BEAST_EXPECT(
mismatch(b, a) == diverge + 1);
199 for (
Seq offset = diverge / 2; offset < 3 * diverge / 2; ++offset)
202 if (offset <= diverge)
208 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
217 testcase(
"RCLValidatedLedger LedgerTrie");
230 Seq const maxAncestors = 256;
242 env.
app().getNodeFamily());
244 for (
auto i = 0; i < (maxAncestors + 10); ++i)
247 next->updateSkipList();
273 BEAST_EXPECT(trie.
remove(ledg258, 3));
TestcaseT 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.
std::chrono::time_point< NetClock > time_point
Wraps a ledger instance for use in generic Validations LedgerTrie.
Seq seq() const
The sequence (index) of the ledger.
Wrapper over STValidation for generic Validation code.
bool trusted() const
Whether the validation is considered trusted.
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 & feeSettings() noexcept
The (fixed) index of the object containing the ledger fees.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
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.
CreateGenesisT const kCreateGenesis
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
Validations< RCLValidationsAdaptor > RCLValidations
Alias for RCL-specific instantiation of generic Validations.
RCLValidatedLedger::Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
Fees toFees() const
Convert to a Fees object for use with Ledger construction.
Set the sequence number on a JTx.