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>
45 cfg->START_LEDGER = ledger;
47 cfg->TRAP_TX_HASH = trapTxHash;
48 assert(!dbPath.
empty());
49 cfg->legacy(
"database_path", dbPath);
66 using namespace test::jtx;
74 for (
auto i = 0; i < 20; ++i)
77 env.fund(XRP(10000), acct);
79 if (i > 0 && BEAST_EXPECT(prev))
81 env.trust(acct[
"USD"](1000), *prev);
82 env(pay(acct, *prev, acct[
"USD"](5)));
84 env(offer(acct, XRP(100), acct[
"USD"](1)));
86 prev.emplace(std::move(acct));
89 retval.
ledger = env.rpc(
"ledger",
"current",
"full")[jss::result];
91 retval.
ledger[jss::ledger][jss::accountState].
size() == 102);
94 for (
auto const& it : retval.
ledger[jss::ledger][jss::accountState])
96 if (it[sfLedgerEntryType.fieldName] == jss::LedgerHashes)
97 return it[sfHashes.fieldName];
104 auto const txs = env.rpc(
107 "tx")[jss::result][jss::ledger][jss::transactions];
108 BEAST_EXPECT(txs.isArray() && txs.size() > 0);
110 BEAST_EXPECT(tmp.
parseHex(txs[0u][jss::hash].asString()));
125 using namespace test::jtx;
138 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
140 sd.
ledger[jss::ledger][jss::accountState].
size() ==
141 jrb[jss::ledger][jss::accountState].size());
148 using namespace test::jtx;
149 using namespace boost::filesystem;
180 boost::system::error_code ec;
181 auto ledgerFileCorrupt =
182 boost::filesystem::path{sd.
dbPath} /
"ledgerdata_bad.json";
186 copy_options::overwrite_existing,
188 if (!BEAST_EXPECTS(!ec, ec.message()))
190 auto filesize = file_size(ledgerFileCorrupt, ec);
191 if (!BEAST_EXPECTS(!ec, ec.message()))
193 resize_file(ledgerFileCorrupt, filesize - 10, ec);
194 if (!BEAST_EXPECTS(!ec, ec.message()))
203 ledgerFileCorrupt.
string(),
215 using namespace test::jtx;
219 boost::erase_all(ledgerHash,
"\"");
230 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
231 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 98);
233 jrb[jss::ledger][jss::accountState].size() <=
234 sd.
ledger[jss::ledger][jss::accountState].
size());
240 testcase(
"Load and replay by hash");
241 using namespace test::jtx;
245 boost::erase_all(ledgerHash,
"\"");
256 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
257 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
261 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
262 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
264 closed[jss::ledger][jss::accountState].size() <=
265 sd.
ledger[jss::ledger][jss::accountState].
size());
271 testcase(
"Load and replay transaction by hash");
272 using namespace test::jtx;
276 boost::erase_all(ledgerHash,
"\"");
287 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
288 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
292 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
293 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
295 closed[jss::ledger][jss::accountState].size() <=
296 sd.
ledger[jss::ledger][jss::accountState].
size());
302 testcase(
"Load and replay transaction by hash failure");
303 using namespace test::jtx;
307 boost::erase_all(ledgerHash,
"\"");
338 using namespace test::jtx;
347 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
349 sd.
ledger[jss::ledger][jss::accountState].
size() ==
350 jrb[jss::ledger][jss::accountState].size());
357 using namespace test::jtx;
366 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
368 sd.
ledger[jss::ledger][jss::accountState].
size() ==
369 jrb[jss::ledger][jss::accountState].size());
391BEAST_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)