21#include <test/jtx/Env.h>
22#include <xrpl/beast/unit_test.h>
23#include <xrpl/beast/unit_test/suite.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/beast/utility/temp_dir.h>
26#include <xrpl/protocol/SField.h>
27#include <xrpl/protocol/jss.h>
29#include <boost/algorithm/string.hpp>
30#include <boost/filesystem.hpp>
44 cfg->START_LEDGER = ledger;
46 cfg->TRAP_TX_HASH = trapTxHash;
47 assert(!dbPath.
empty());
48 cfg->legacy(
"database_path", dbPath);
65 using namespace test::jtx;
73 for (
auto i = 0; i < 20; ++i)
76 env.fund(XRP(10000), acct);
78 if (i > 0 && BEAST_EXPECT(prev))
80 env.trust(acct[
"USD"](1000), *prev);
81 env(pay(acct, *prev, acct[
"USD"](5)));
83 env(offer(acct, XRP(100), acct[
"USD"](1)));
85 prev.emplace(std::move(acct));
88 retval.
ledger = env.rpc(
"ledger",
"current",
"full")[jss::result];
90 retval.
ledger[jss::ledger][jss::accountState].
size() == 102);
93 for (
auto const& it : retval.
ledger[jss::ledger][jss::accountState])
95 if (it[sfLedgerEntryType.fieldName] == jss::LedgerHashes)
96 return it[sfHashes.fieldName];
103 auto const txs = env.rpc(
106 "tx")[jss::result][jss::ledger][jss::transactions];
107 BEAST_EXPECT(txs.isArray() && txs.size() > 0);
109 BEAST_EXPECT(tmp.
parseHex(txs[0u][jss::hash].asString()));
124 using namespace test::jtx;
137 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
139 sd.
ledger[jss::ledger][jss::accountState].
size() ==
140 jrb[jss::ledger][jss::accountState].size());
147 using namespace test::jtx;
148 using namespace boost::filesystem;
179 boost::system::error_code ec;
180 auto ledgerFileCorrupt =
181 boost::filesystem::path{sd.
dbPath} /
"ledgerdata_bad.json";
185 copy_options::overwrite_existing,
187 if (!BEAST_EXPECTS(!ec, ec.message()))
189 auto filesize = file_size(ledgerFileCorrupt, ec);
190 if (!BEAST_EXPECTS(!ec, ec.message()))
192 resize_file(ledgerFileCorrupt, filesize - 10, ec);
193 if (!BEAST_EXPECTS(!ec, ec.message()))
202 ledgerFileCorrupt.
string(),
214 using namespace test::jtx;
218 boost::erase_all(ledgerHash,
"\"");
229 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
230 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 98);
232 jrb[jss::ledger][jss::accountState].size() <=
233 sd.
ledger[jss::ledger][jss::accountState].
size());
239 testcase(
"Load and replay by hash");
240 using namespace test::jtx;
244 boost::erase_all(ledgerHash,
"\"");
255 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
256 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
260 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
261 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
263 closed[jss::ledger][jss::accountState].size() <=
264 sd.
ledger[jss::ledger][jss::accountState].
size());
270 testcase(
"Load and replay transaction by hash");
271 using namespace test::jtx;
275 boost::erase_all(ledgerHash,
"\"");
286 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
287 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
291 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
292 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
294 closed[jss::ledger][jss::accountState].size() <=
295 sd.
ledger[jss::ledger][jss::accountState].
size());
301 testcase(
"Load and replay transaction by hash failure");
302 using namespace test::jtx;
306 boost::erase_all(ledgerHash,
"\"");
337 using namespace test::jtx;
346 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
348 sd.
ledger[jss::ledger][jss::accountState].
size() ==
349 jrb[jss::ledger][jss::accountState].size());
356 using namespace test::jtx;
365 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
367 sd.
ledger[jss::ledger][jss::accountState].
size() ==
368 jrb[jss::ledger][jss::accountState].size());
390BEAST_DEFINE_TESTSUITE(LedgerLoad, app,
ripple);
UInt size() const
Number of values in array or object.
RAII temporary directory.
std::string path() const
Get the native path for the temporary directory.
std::string file(std::string const &name) const
Get the native path for the a file.
testcase_t testcase
Memberspace for declaring test cases.
bool except(F &&f, String const &reason)
SetupData setupLedger(beast::temp_dir const &td)
void testReplayTx(SetupData const &sd)
void testLoadByHash(SetupData const &sd)
void testLoadIndex(SetupData const &sd)
void run() override
Runs the suite.
void testReplayTxFail(SetupData const &sd)
static auto ledgerConfig(std::unique_ptr< Config > cfg, std::string const &dbPath, std::string const &ledger, Config::StartUpType type, std::optional< uint256 > trapTxHash)
void testBadFiles(SetupData const &sd)
void testLoad(SetupData const &sd)
void testReplay(SetupData const &sd)
void testLoadLatest(SetupData const &sd)
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)