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/offer.h>
6#include <test/jtx/pay.h>
8#include <xrpld/core/Config.h>
10#include <xrpl/basics/base_uint.h>
11#include <xrpl/beast/unit_test/suite.h>
12#include <xrpl/beast/utility/Journal.h>
13#include <xrpl/beast/utility/temp_dir.h>
14#include <xrpl/core/StartUpType.h>
15#include <xrpl/json/json_value.h>
16#include <xrpl/json/to_string.h>
17#include <xrpl/protocol/SField.h>
18#include <xrpl/protocol/jss.h>
20#include <boost/algorithm/string/erase.hpp>
21#include <boost/filesystem/operations.hpp>
22#include <boost/system/detail/error_code.hpp>
43 cfg->startLedger = ledger;
45 cfg->trapTxHash = trapTxHash;
46 assert(!dbPath.
empty());
47 cfg->legacy(
"database_path", dbPath);
74 for (
auto i = 0; i < 20; ++i)
77 env.fund(XRP(10000), acct);
79 if (i > 0 && BEAST_EXPECT(prev.has_value()))
81 env.trust(acct[
"USD"](1000), *prev);
83 acct, *prev, acct[
"USD"](5)));
85 env(offer(acct, XRP(100), acct[
"USD"](1)));
90 retval.
ledger = env.rpc(
"ledger",
"current",
"full")[jss::result];
91 BEAST_EXPECT(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(
105 "ledger",
std::to_string(41),
"tx")[jss::result][jss::ledger][jss::transactions];
106 BEAST_EXPECT(txs.isArray() && txs.size() > 0);
108 BEAST_EXPECT(tmp.
parseHex(txs[0u][jss::hash].asString()));
131 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
133 sd.
ledger[jss::ledger][jss::accountState].
size() ==
134 jrb[jss::ledger][jss::accountState].size());
142 using namespace boost::filesystem;
164 boost::system::error_code ec;
165 auto ledgerFileCorrupt = boost::filesystem::path{sd.
dbPath} /
"ledgerdata_bad.json";
166 copy_file(sd.
ledgerFile, ledgerFileCorrupt, copy_options::overwrite_existing, ec);
167 if (!BEAST_EXPECTS(!ec, ec.message()))
169 auto filesize = file_size(ledgerFileCorrupt, ec);
170 if (!BEAST_EXPECTS(!ec, ec.message()))
172 resize_file(ledgerFileCorrupt, filesize - 10, ec);
173 if (!BEAST_EXPECTS(!ec, ec.message()))
182 ledgerFileCorrupt.
string(),
198 boost::erase_all(ledgerHash,
"\"");
204 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
205 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 98);
207 jrb[jss::ledger][jss::accountState].size() <=
208 sd.
ledger[jss::ledger][jss::accountState].
size());
214 testcase(
"Load and replay by hash");
219 boost::erase_all(ledgerHash,
"\"");
225 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
226 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
230 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
231 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
233 closed[jss::ledger][jss::accountState].size() <=
234 sd.
ledger[jss::ledger][jss::accountState].
size());
240 testcase(
"Load and replay transaction by hash");
245 boost::erase_all(ledgerHash,
"\"");
251 auto const jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
252 BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
256 auto const closed = env.rpc(
"ledger",
"current",
"full")[jss::result];
257 BEAST_EXPECT(closed[jss::ledger][jss::accountState].size() == 98);
259 closed[jss::ledger][jss::accountState].size() <=
260 sd.
ledger[jss::ledger][jss::accountState].
size());
266 testcase(
"Load and replay transaction by hash failure");
271 boost::erase_all(ledgerHash,
"\"");
305 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
307 sd.
ledger[jss::ledger][jss::accountState].
size() ==
308 jrb[jss::ledger][jss::accountState].size());
323 auto jrb = env.rpc(
"ledger",
"current",
"full")[jss::result];
325 sd.
ledger[jss::ledger][jss::accountState].
size() ==
326 jrb[jss::ledger][jss::accountState].size());
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.
bool except(F &&f, String const &reason)
TestcaseT testcase
Memberspace for declaring test cases.
UInt size() const
Number of values in array or object.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
void testLoadLatest(SetupData const &sd)
SetupData setupLedger(beast::TempDir const &td)
void testReplay(SetupData const &sd)
void testReplayTxFail(SetupData const &sd)
void run() override
Runs the suite.
static auto ledgerConfig(std::unique_ptr< Config > cfg, std::string const &dbPath, std::string const &ledger, StartUpType type, std::optional< uint256 > trapTxHash)
void testBadFiles(SetupData const &sd)
void testReplayTx(SetupData const &sd)
void testLoadByHash(SetupData const &sd)
void testLoadIndex(SetupData const &sd)
void testLoad(SetupData const &sd)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(BaseUInt< Bits, Tag > const &a)
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)