1#include <test/jtx/TestSuite.h>
3#include <xrpl/basics/contract.h>
4#include <xrpl/beast/unit_test/suite.h>
5#include <xrpl/config/BasicConfig.h>
6#include <xrpl/config/Constants.h>
7#include <xrpl/rdb/SociDB.h>
9#include <boost/algorithm/string/predicate.hpp>
10#include <boost/filesystem/operations.hpp>
11#include <boost/filesystem/path.hpp>
12#include <boost/optional/optional.hpp>
15#include <soci/session.h>
37 auto value = dbPath.string();
45 using namespace boost::filesystem;
46 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
54 using namespace boost::filesystem;
57 create_directory(dbPath);
61 if (!is_directory(dbPath))
67 static boost::filesystem::path
70 return boost::filesystem::current_path() /
"socidb_test_databases";
102 {{
"peerfinder",
".sqlite"},
105 {
"validators",
".sqlite"}});
107 for (
auto const& i : d)
122 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
126 s <<
"SELECT StringData, IntData FROM SociTestTable;", soci::into(stringResult),
127 soci::into(intResult);
129 stringResult.
size() == stringData.size() && intResult.
size() == intData.size());
130 for (
int i = 0; i < stringResult.
size(); ++i)
135 BEAST_EXPECT(si == ii && si < stringResult.
size());
142 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
143 " Key INTEGER PRIMARY KEY,"
148 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
149 "(:stringData, :intData);",
150 soci::use(stringData), soci::use(intData);
160 namespace bfs = boost::filesystem;
163 if (bfs::is_regular_file(dbPath))
185 s <<
"DROP TABLE IF EXISTS STT;";
187 s <<
"CREATE TABLE STT ("
189 " UI INTEGER UNSIGNED,"
191 " UBI BIGINT UNSIGNED"
194 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
195 "(:id, :idu, :bid, :bidu);",
196 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
204 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig),
205 soci::into(big), soci::into(ubig);
206 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] && ubig == ubid[0]);
216 boost::optional<std::int32_t> ig;
220 boost::optional<std::int64_t> big;
221 boost::optional<std::uint64_t> ubig;
222 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig),
223 soci::into(big), soci::into(ubig);
224 BEAST_EXPECT(*ig ==
id[0] && uig == uid[0] && *big == bid[0] && *ubig == ubid[0]);
242 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
247 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
261 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
266 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
279 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
280 BEAST_EXPECT(
get<0>(d) ==
id[0] &&
get<1>(d) == uid[0] &&
290 namespace bfs = boost::filesystem;
293 if (bfs::is_regular_file(dbPath))
309 "BEGIN TRANSACTION;",
310 "CREATE TABLE Ledgers ( \
311 LedgerHash CHARACTER(64) PRIMARY KEY, \
312 LedgerSeq BIGINT UNSIGNED \
314 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
315 for (
auto const c : dbInit)
321 int const numRows = 16;
325 ledgerIndexes.
reserve(numRows);
326 for (
int i = 0; i < numRows; ++i)
329 if (lh[toIncIndex] ==
'z')
334 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
336 soci::use(ledgerHashes), soci::use(ledgerIndexes);
339 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
340 BEAST_EXPECT(ledgersLS.
size() == numRows);
342 namespace bfs = boost::filesystem;
345 if (bfs::is_regular_file(dbPath))
void fail(String const &reason, char const *file, int line)
Record a failure.
TestcaseT testcase
Memberspace for declaring test cases.
Holds unparsed configuration information.
void overwrite(std::string const §ion, std::string const &key, std::string const &value)
Overwrite a key/value pair with a command line argument If the section does not exist it is created.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
DBConfig is used when a client wants to delay opening a soci::session after parsing the config parame...
void open(soci::session &s) const
std::string connectionString() const
static void setupDatabaseDir(boost::filesystem::path const &dbPath)
void testSQLiteFileNames()
static boost::filesystem::path getDatabasePath()
static void setupSQLiteConfig(BasicConfig &config, boost::filesystem::path const &dbPath)
void testSQLiteDeleteWithSubselect()
void run() override
Runs the suite.
static void cleanupDatabaseDir(boost::filesystem::path const &dbPath)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
static constexpr auto kBackend
static constexpr auto kSqdb
static constexpr auto kDatabasePath