1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/amount.h>
4#include <test/jtx/envconfig.h>
5#include <test/jtx/noop.h>
7#include <xrpld/app/ledger/LedgerMaster.h>
8#include <xrpld/app/misc/SHAMapStore.h>
9#include <xrpld/core/Config.h>
11#include <xrpl/basics/ToString.h>
12#include <xrpl/basics/base_uint.h>
13#include <xrpl/beast/unit_test/suite.h>
14#include <xrpl/core/JobQueue.h>
15#include <xrpl/protocol/Feature.h>
16#include <xrpl/protocol/Protocol.h>
17#include <xrpl/protocol/SField.h>
18#include <xrpl/protocol/STObject.h>
19#include <xrpl/protocol/STTx.h>
38 cfg->networkId = networkID;
40 cfg->fees.referenceFee = 10;
55 auto const alice =
Account(
"alice");
62 auto const startLegSeq = env.
current()->header().seq;
63 for (
int i = 0; i < 2; ++i)
72 auto const endLegSeq = env.
closed()->header().seq;
79 BEAST_EXPECT(!result);
83 uint32_t const txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
85 BEAST_EXPECT(!result);
90 BEAST_EXPECT(!result);
94 uint32_t const txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
96 BEAST_EXPECT(!result);
100 uint32_t const txnIndex = metas[0]->getFieldU32(sfTransactionIndex);
106 "277F4FD89C20B92457FEF05FF63F6405563AD0563C73D967A29727"
111 uint32_t const txnIndex = metas[1]->getFieldU32(sfTransactionIndex);
117 "293DF7335EBBAF4420D52E70ABF470EB4C5792CAEA2F91F76193C2"
131 [[nodiscard]]
static bool
192 for (
int extraCloses = 0;; ++extraCloses)
196 if (store.getLastRotated() != 0 || extraCloses == maxExtraCloses)
198 if (extraCloses != 0)
200 log <<
"initializeStore: the store needed " << extraCloses
201 <<
" extra ledger close(s) to pick up a validated ledger. "
202 "SHAMapStoreImp::run() dropped the notification for the "
203 "first one; see the comment on initializeStore()."
219 testcase(
"Complete Ledger operations");
223 auto const deleteInterval = 8;
227 auto const alice =
Account(
"alice");
247 if (!BEAST_EXPECT(extraCloses.has_value()))
251 if (!BEAST_EXPECTS(lastRotated >= minSeq && lastRotated <= maxSeq,
to_string(lastRotated)))
256 BEAST_EXPECTS(maxSeq == 3 + *extraCloses,
to_string(maxSeq));
258 initialRange << minSeq <<
"-" << maxSeq;
259 BEAST_EXPECTS(lm.getCompleteLedgers() == initialRange.
str(), lm.getCompleteLedgers());
260 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq, maxSeq) == 0);
265 if (minSeq + 1 <= maxSeq - 1)
267 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq + 1, maxSeq - 1) == 0);
269 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq - 1, maxSeq + 1) == 2);
270 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq - 2, maxSeq - 2) == 2);
271 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq + 2, maxSeq + 2) == 2);
274 for (
int i = 0; i < 24; ++i)
276 for (
int t = 0; t < 3; ++t)
285 if (maxSeq == lastRotated + deleteInterval)
287 minSeq = lastRotated;
288 lastRotated = maxSeq;
292 BEAST_EXPECTS(store.getLastRotated() == lastRotated,
to_string(store.getLastRotated()));
294 expectedRange << minSeq <<
"-" << maxSeq;
295 BEAST_EXPECTS(lm.getCompleteLedgers() == expectedRange.
str(), lm.getCompleteLedgers());
296 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq, maxSeq) == 0);
302 if (minSeq + 1 <= maxSeq - 1)
304 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq + 1, maxSeq - 1) == 0);
310 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq - 1, maxSeq + 1) == 2);
311 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq - 2, maxSeq - 2) == 2);
312 BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq + 2, maxSeq + 2) == 2);
LogOs< char > log
Logging output stream.
TestcaseT testcase
Memberspace for declaring test cases.
void rendezvous()
Block until no jobs running.
Tracks the current ledger and any ledgers in the process of closing.
std::optional< UInt256 > txnIdFromIndex(uint32_t ledgerSeq, uint32_t txnIndex)
Iff a txn exists at the specified ledger and offset then return its txnid.
virtual bool rendezvous(std::optional< std::chrono::milliseconds > const &timeout={}) const =0
virtual JobQueue & getJobQueue()=0
virtual SHAMapStore & getSHAMapStore()=0
virtual LedgerMaster & getLedgerMaster()=0
void testWithFeats(FeatureBitset features)
std::optional< int > initializeStore(jtx::Env &env, int const maxExtraCloses=3)
void testTxnIdFromIndex(FeatureBitset features)
void run() override
Runs the suite.
static bool syncStore(jtx::Env &env)
static std::unique_ptr< Config > makeNetworkConfig(uint32_t networkID)
void testCompleteLedgerRange(FeatureBitset features)
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
T emplace_back(T... args)
XrpT const XRP
Converts to XRP Issue or STAmount.
json::Value noop(Account const &account)
The null transaction.
FeatureBitset testableAmendments()
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
std::unique_ptr< Config > onlineDelete(std::unique_ptr< Config > cfg, std::uint32_t deleteInterval=8)
adjust config to enable online_delete
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::uint32_t LedgerIndex
A ledger index.
std::string to_string(BaseUInt< Bits, Tag > const &a)