20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/SHAMapStore.h>
22 #include <ripple/core/ConfigSections.h>
23 #include <ripple/core/DatabaseCon.h>
24 #include <ripple/core/SociDB.h>
25 #include <ripple/protocol/jss.h>
27 #include <test/jtx/envconfig.h>
60 auto good =
json.isMember(jss::result) &&
62 json[jss::result][jss::ledger][jss::ledger_index] == ledgerID;
63 if (!good || !checkDB)
66 auto const seq =
json[jss::result][jss::ledger_index].asUInt();
81 *db <<
"SELECT LedgerHash,LedgerSeq,PrevHash,TotalCoins, "
82 "ClosingTime,PrevClosingTime,CloseTimeRes,CloseFlags, "
83 "AccountSetHash,TransSetHash "
85 "WHERE LedgerSeq = :seq",
86 soci::use(
seq), soci::into(outHash), soci::into(outSeq),
87 soci::into(outParentHash), soci::into(outDrops),
88 soci::into(outCloseTime), soci::into(outParentCloseTime),
89 soci::into(outCloseTimeResolution), soci::into(outCloseFlags),
90 soci::into(outAccountHash), soci::into(outTxHash);
93 auto const& ledger =
json[jss::result][jss::ledger];
94 return outHash == ledger[jss::hash].asString() && outSeq ==
seq &&
95 outParentHash == ledger[jss::parent_hash].asString() &&
96 outDrops == ledger[jss::total_coins].asString() &&
97 outCloseTime == ledger[jss::close_time].asUInt() &&
98 outParentCloseTime == ledger[jss::parent_close_time].asUInt() &&
99 outCloseTimeResolution ==
100 ledger[jss::close_time_resolution].asUInt() &&
101 outCloseFlags == ledger[jss::close_flags].asUInt() &&
102 outAccountHash == ledger[jss::account_hash].asString() &&
103 outTxHash == ledger[jss::transaction_hash].asString();
109 return json.isMember(jss::result) &&
111 json[jss::result][jss::error_code] == error;
118 json.isMember(jss::result) &&
119 json[jss::result].isMember(jss::ledger) &&
120 json[jss::result][jss::ledger].isMember(jss::hash) &&
121 json[jss::result][jss::ledger][jss::hash].isString());
122 return json[jss::result][jss::ledger][jss::hash].asString();
130 int actualRows, actualFirst, actualLast;
131 *db <<
"SELECT count(*) AS rows, "
132 "min(LedgerSeq) as first, "
133 "max(LedgerSeq) as last "
135 soci::into(actualRows), soci::into(actualFirst),
136 soci::into(actualLast);
138 BEAST_EXPECT(actualRows == rows);
139 BEAST_EXPECT(actualFirst == first);
140 BEAST_EXPECT(actualLast == first + rows - 1);
149 *db <<
"SELECT count(*) AS rows "
150 "FROM Transactions;",
151 soci::into(actualRows);
153 BEAST_EXPECT(actualRows == rows);
162 *db <<
"SELECT count(*) AS rows "
163 "FROM AccountTransactions;",
164 soci::into(actualRows);
166 BEAST_EXPECT(actualRows == rows);
172 using namespace std::chrono_literals;
178 BEAST_EXPECT(!store.getLastRotated());
183 auto ledger = env.
rpc(
"ledger",
"validated");
186 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
194 using namespace std::chrono_literals;
196 testcase(
"clearPrior");
210 auto ledgerTmp = env.
rpc(
"ledger",
"0");
211 BEAST_EXPECT(
bad(ledgerTmp));
214 BEAST_EXPECT(
goodLedger(env, ledgers[1],
"1"));
217 BEAST_EXPECT(
goodLedger(env, ledgers[2],
"2"));
219 ledgerTmp = env.
rpc(
"ledger",
"current");
220 BEAST_EXPECT(
goodLedger(env, ledgerTmp,
"3"));
222 ledgerTmp = env.
rpc(
"ledger",
"4");
223 BEAST_EXPECT(
bad(ledgerTmp));
225 ledgerTmp = env.
rpc(
"ledger",
"100");
226 BEAST_EXPECT(
bad(ledgerTmp));
229 auto lastRotated = firstSeq - 1;
236 ledgerTmp = env.
rpc(
"ledger",
"current");
239 BEAST_EXPECT(store.getLastRotated() == lastRotated);
258 auto ledger = env.
rpc(
"ledger",
"current");
266 lastRotated = store.getLastRotated();
267 BEAST_EXPECT(lastRotated == 11);
275 for (
auto i = lastRotated - 1; i < lastRotated +
deleteInterval - 1;
280 ledgerTmp = env.
rpc(
"ledger",
"current");
286 store.getLastRotated() == lastRotated ||
295 BEAST_EXPECT(store.getLastRotated() ==
deleteInterval + lastRotated);
305 testcase(
"automatic online_delete");
307 using namespace std::chrono_literals;
313 auto lastRotated = ledgerSeq - 1;
314 BEAST_EXPECT(store.getLastRotated() == lastRotated);
315 BEAST_EXPECT(lastRotated != 2);
319 auto const canDelete = env.
rpc(
"can_delete");
327 auto ledger = env.
rpc(
"ledger",
"validated");
337 BEAST_EXPECT(lastRotated == store.getLastRotated());
343 auto ledger = env.
rpc(
"ledger",
"validated");
350 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
351 BEAST_EXPECT(lastRotated != store.getLastRotated());
353 lastRotated = store.getLastRotated();
360 auto ledger = env.
rpc(
"ledger",
"validated");
368 BEAST_EXPECT(lastRotated != store.getLastRotated());
374 testcase(
"online_delete with advisory_delete");
376 using namespace std::chrono_literals;
383 auto lastRotated = ledgerSeq - 1;
384 BEAST_EXPECT(store.getLastRotated() == lastRotated);
385 BEAST_EXPECT(lastRotated != 2);
387 auto canDelete = env.
rpc(
"can_delete");
389 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == 0);
391 canDelete = env.
rpc(
"can_delete",
"never");
393 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == 0);
396 for (; ledgerSeq < firstBatch; ++ledgerSeq)
400 auto ledger = env.
rpc(
"ledger",
"validated");
408 BEAST_EXPECT(lastRotated == store.getLastRotated());
415 canDelete[jss::result][jss::can_delete] ==
421 BEAST_EXPECT(store.getLastRotated() == lastRotated);
427 auto ledger = env.
rpc(
"ledger",
"validated");
434 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
436 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
437 lastRotated = ledgerSeq - 1;
444 auto ledger = env.
rpc(
"ledger",
"validated");
451 BEAST_EXPECT(store.getLastRotated() == lastRotated);
457 auto ledger = env.
rpc(
"ledger",
"validated");
464 ledgerCheck(env, ledgerSeq - firstBatch, firstBatch);
466 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
467 lastRotated = ledgerSeq - 1;
470 canDelete = env.
rpc(
"can_delete",
"always");
473 canDelete[jss::result][jss::can_delete] ==
481 auto ledger = env.
rpc(
"ledger",
"validated");
488 BEAST_EXPECT(store.getLastRotated() == lastRotated);
494 auto ledger = env.
rpc(
"ledger",
"validated");
501 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
503 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
504 lastRotated = ledgerSeq - 1;
507 canDelete = env.
rpc(
"can_delete",
"now");
509 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == ledgerSeq - 1);
516 auto ledger = env.
rpc(
"ledger",
"validated");
523 BEAST_EXPECT(store.getLastRotated() == lastRotated);
529 auto ledger = env.
rpc(
"ledger",
"validated");
536 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
538 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
539 lastRotated = ledgerSeq - 1;