21#include <test/jtx/Env.h>
23#include <xrpl/beast/unit_test.h>
24#include <xrpl/beast/unit_test/suite.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/beast/utility/temp_dir.h>
27#include <xrpl/protocol/SField.h>
28#include <xrpl/protocol/jss.h>
30#include <boost/algorithm/string.hpp>
31#include <boost/filesystem.hpp>
46 cfg->START_LEDGER = ledger;
48 cfg->TRAP_TX_HASH = trapTxHash;
49 assert(!dbPath.
empty());
50 cfg->legacy(
"database_path", dbPath);
67 using namespace test::jtx;
75 for (
auto i = 0; i < 20; ++i)
78 env.fund(XRP(10000), acct);
80 if (i > 0 && BEAST_EXPECT(prev))
82 env.trust(acct[
"USD"](1000), *prev);
83 env(pay(acct, *prev, acct[
"USD"](5)));
85 env(offer(acct, XRP(100), acct[
"USD"](1)));
87 prev.emplace(std::move(acct));
90 retval.
ledger = env.rpc(
"ledger",
"current",
"full")[jss::result];
92 retval.
ledger[jss::ledger][jss::accountState].
size() == 102);
95 for (
auto const& it : retval.
ledger[jss::ledger][jss::accountState])
97 if (it[sfLedgerEntryType.fieldName] == jss::LedgerHashes)
98 return it[sfHashes.fieldName];
105 auto const txs = env.rpc(
108 "tx")[jss::result][jss::ledger][jss::transactions];
109 BEAST_EXPECT(txs.isArray() && txs.size() > 0);
111 BEAST_EXPECT(tmp.
parseHex(txs[0u][jss::hash].asString()));
126 using namespace test::jtx;
139 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
141 sd.
ledger[jss::ledger][jss::accountState].
size() ==
142 jrb[jss::ledger][jss::accountState].size());
149 using namespace test::jtx;
150 using namespace boost::filesystem;
181 boost::system::error_code ec;
182 auto ledgerFileCorrupt =
183 boost::filesystem::path{sd.
dbPath} /
"ledgerdata_bad.json";
187 copy_options::overwrite_existing,
189 if (!BEAST_EXPECTS(!ec, ec.message()))
191 auto filesize = file_size(ledgerFileCorrupt, ec);
192 if (!BEAST_EXPECTS(!ec, ec.message()))
194 resize_file(ledgerFileCorrupt, filesize - 10, ec);
195 if (!BEAST_EXPECTS(!ec, ec.message()))
204 ledgerFileCorrupt.
string(),
216 using namespace test::jtx;
220 boost::erase_all(ledgerHash,
"\"");
231 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
232 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 98);
234 jrb[jss::ledger][jss::accountState].size() <=
235 sd.
ledger[jss::ledger][jss::accountState].
size());
241 testcase(
"Load and replay by hash");
242 using namespace test::jtx;
246 boost::erase_all(ledgerHash,
"\"");
257 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
258 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
262 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
263 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
265 closed[jss::ledger][jss::accountState].size() <=
266 sd.
ledger[jss::ledger][jss::accountState].
size());
272 testcase(
"Load and replay transaction by hash");
273 using namespace test::jtx;
277 boost::erase_all(ledgerHash,
"\"");
288 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
289 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
293 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
294 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
296 closed[jss::ledger][jss::accountState].size() <=
297 sd.
ledger[jss::ledger][jss::accountState].
size());
303 testcase(
"Load and replay transaction by hash failure");
304 using namespace test::jtx;
308 boost::erase_all(ledgerHash,
"\"");
339 using namespace test::jtx;
348 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
350 sd.
ledger[jss::ledger][jss::accountState].
size() ==
351 jrb[jss::ledger][jss::accountState].size());
358 using namespace test::jtx;
367 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
369 sd.
ledger[jss::ledger][jss::accountState].
size() ==
370 jrb[jss::ledger][jss::accountState].size());
392BEAST_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)