rippled
LedgerReplay_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2018 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/ledger/BuildLedger.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/ledger/LedgerReplay.h>
23 #include <test/jtx.h>
24 
25 namespace ripple {
26 namespace test {
27 
28 struct LedgerReplay_test : public beast::unit_test::suite
29 {
30  void
31  run() override
32  {
33  testcase("Replay ledger");
34 
35  using namespace jtx;
36 
37  // Build a ledger normally
38  auto const alice = Account("alice");
39  auto const bob = Account("bob");
40 
41  Env env(*this);
42  env.fund(XRP(100000), alice, bob);
43  env.close();
44 
46  auto const lastClosed = ledgerMaster.getClosedLedger();
47  auto const lastClosedParent =
48  ledgerMaster.getLedgerByHash(lastClosed->info().parentHash);
49 
50  auto const replayed = buildLedger(
51  LedgerReplay(lastClosedParent, lastClosed),
52  tapNONE,
53  env.app(),
54  env.journal);
55 
56  BEAST_EXPECT(replayed->info().hash == lastClosed->info().hash);
57  }
58 };
59 
61 
62 } // namespace test
63 } // namespace ripple
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
ripple::test::jtx::XRP
const XRP_t XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
ripple::test::LedgerReplay_test::run
void run() override
Definition: LedgerReplay_test.cpp:31
ripple::LedgerMaster
Definition: LedgerMaster.h:54
ripple::test::jtx::Env::journal
const beast::Journal journal
Definition: Env.h:141
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:238
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:31
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::Env::close
bool close(NetClock::time_point closeTime, boost::optional< std::chrono::milliseconds > consensusDelay=boost::none)
Close and advance the ledger.
Definition: Env.cpp:111
ripple::test::jtx::Env::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:209
ripple::buildLedger
std::shared_ptr< Ledger > buildLedger(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, const bool closeTimeCorrect, NetClock::duration closeResolution, Application &app, CanonicalTXSet &txns, std::set< TxID > &failedTxs, beast::Journal j)
Build a new ledger by applying consensus transactions.
Definition: BuildLedger.cpp:172
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::test::LedgerReplay_test
Definition: LedgerReplay_test.cpp:28
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:114
ripple::LedgerReplay
Definition: LedgerReplay.h:32