diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj
index 40ab9f2dc..b1991cdd8 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj
+++ b/Builds/VisualStudio2013/RippleD.vcxproj
@@ -3437,8 +3437,6 @@
-
-
@@ -3457,10 +3455,6 @@
True
True
-
- True
- True
-
True
True
diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters
index f3a1b1f92..065ee44b2 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters
@@ -4191,9 +4191,6 @@
ripple\test\jtx
-
- ripple\test\jtx
-
ripple\test\jtx
@@ -4218,9 +4215,6 @@
ripple\test\jtx\impl
-
- ripple\test\jtx\impl
-
ripple\test\jtx\impl
diff --git a/src/ripple/app/ledger/OpenLedger.h b/src/ripple/app/ledger/OpenLedger.h
index fc9fd66f2..0b82c5dca 100644
--- a/src/ripple/app/ledger/OpenLedger.h
+++ b/src/ripple/app/ledger/OpenLedger.h
@@ -100,7 +100,7 @@ private:
std::mutex mutable modify_mutex_;
std::mutex mutable current_mutex_;
std::shared_ptr current_;
-
+
public:
OpenLedger() = delete;
OpenLedger (OpenLedger const&) = delete;
diff --git a/src/ripple/app/ledger/tests/DeferredCredits.test.cpp b/src/ripple/app/ledger/tests/DeferredCredits.test.cpp
index a569d2aac..5f37187e2 100644
--- a/src/ripple/app/ledger/tests/DeferredCredits.test.cpp
+++ b/src/ripple/app/ledger/tests/DeferredCredits.test.cpp
@@ -118,7 +118,7 @@ class DeferredCredits_test : public beast::unit_test::suite
STAmount const toDebit (USD_gw1 (20));
{
// accountSend, no deferredCredits
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
auto const iss = USD_gw1.issue ();
auto const startingAmount = accountHolds (
@@ -137,7 +137,7 @@ class DeferredCredits_test : public beast::unit_test::suite
{
// rippleCredit, no deferredCredits
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
auto const iss = USD_gw1.issue ();
auto const startingAmount = accountHolds (
@@ -156,7 +156,7 @@ class DeferredCredits_test : public beast::unit_test::suite
{
// accountSend, w/ deferredCredits
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
PaymentView pv (les, tapNONE);
auto const iss = USD_gw1.issue ();
@@ -176,7 +176,7 @@ class DeferredCredits_test : public beast::unit_test::suite
{
// rippleCredit, w/ deferredCredits
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
PaymentView pv (les, tapNONE);
auto const iss = USD_gw1.issue ();
@@ -191,7 +191,7 @@ class DeferredCredits_test : public beast::unit_test::suite
{
// redeemIOU, w/ deferredCredits
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
PaymentView pv (les, tapNONE);
auto const iss = USD_gw1.issue ();
@@ -206,7 +206,7 @@ class DeferredCredits_test : public beast::unit_test::suite
{
// issueIOU, w/ deferredCredits
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
PaymentView pv (les, tapNONE);
auto const iss = USD_gw1.issue ();
@@ -221,7 +221,7 @@ class DeferredCredits_test : public beast::unit_test::suite
{
// accountSend, w/ deferredCredits and stacked views
- MetaView les (*env.ledger, tapNONE);
+ MetaView les (*env.open(), tapNONE);
PaymentView pv (les, tapNONE);
auto const iss = USD_gw1.issue ();
diff --git a/src/ripple/app/ledger/tests/MetaView_test.cpp b/src/ripple/app/ledger/tests/MetaView_test.cpp
index 0a2f3b1d4..61a59d2bf 100644
--- a/src/ripple/app/ledger/tests/MetaView_test.cpp
+++ b/src/ripple/app/ledger/tests/MetaView_test.cpp
@@ -72,17 +72,39 @@ class MetaView_test
// Erase all state items
static
void
- wipe (BasicView& v)
+ wipe (OpenLedger& openLedger)
+ {
+ openLedger.modify(
+ [](View& view, beast::Journal)
+ {
+ // HACK!
+ boost::optional next;
+ next.emplace(0);
+ for(;;)
+ {
+ next = view.succ(*next);
+ if (! next)
+ break;
+ view.erase(view.peek(
+ keylet::unchecked(*next)));
+ }
+ return true;
+ });
+ }
+
+ static
+ void
+ wipe (Ledger& ledger)
{
// HACK!
boost::optional next;
next.emplace(0);
for(;;)
{
- next = v.succ(*next);
+ next = ledger.succ(*next);
if (! next)
break;
- v.unchecked_erase(*next);
+ ledger.unchecked_erase(*next);
}
}
@@ -122,9 +144,12 @@ class MetaView_test
testLedger()
{
using namespace jtx;
- Env env(*this);
- wipe(*env.ledger);
- BasicView& v = *env.ledger;
+ Account const master("master");
+ auto const ledger =
+ std::make_shared(
+ master.pk(), 1000000000);
+ wipe(*ledger);
+ BasicView& v = *ledger;
succ(v, 0, boost::none);
v.unchecked_insert(sle(1, 1));
expect(v.exists(k(1)));
@@ -151,8 +176,9 @@ class MetaView_test
{
using namespace jtx;
Env env(*this);
- wipe(*env.ledger);
- MetaView v(*env.ledger, tapNONE);
+ wipe(env.openLedger);
+ auto const open = env.open();
+ MetaView v(*open, tapNONE);
succ(v, 0, boost::none);
v.insert(sle(1));
expect(v.exists(k(1)));
@@ -181,9 +207,9 @@ class MetaView_test
{
using namespace jtx;
Env env(*this);
- wipe(*env.ledger);
- BasicView& v0 = *env.ledger;
-
+ wipe(env.openLedger);
+ auto const open = env.open();
+ MetaView v0(*open, tapNONE);
v0.unchecked_insert(sle(1));
v0.unchecked_insert(sle(2));
v0.unchecked_insert(sle(4));
@@ -245,8 +271,9 @@ class MetaView_test
{
using namespace jtx;
Env env(*this);
- wipe(*env.ledger);
- BasicView& v0 = *env.ledger;
+ wipe(env.openLedger);
+ auto const open = env.open();
+ MetaView v0 (*open, tapNONE);
v0.unchecked_insert(sle(1, 1));
v0.unchecked_insert(sle(2, 2));
v0.unchecked_insert(sle(4, 4));
@@ -310,13 +337,14 @@ class MetaView_test
using namespace jtx;
{
Env env(*this);
- wipe(*env.ledger);
- MetaView v0(*env.ledger, tapNONE);
+ wipe(env.openLedger);
+ auto const open = env.open();
+ MetaView v0(*open, tapNONE);
expect(v0.seq() != 98);
- expect(v0.seq() == env.ledger->seq());
+ expect(v0.seq() == open->seq());
expect(v0.parentCloseTime() != 99);
expect(v0.parentCloseTime() ==
- env.ledger->parentCloseTime());
+ open->parentCloseTime());
expect(v0.flags() == tapNONE);
{
MetaView v1(shallow_copy, v0);
@@ -360,9 +388,12 @@ class MetaView_test
// MetaView on that, then another MetaView,
// erase the item, apply.
{
- Env env(*this);
- wipe(*env.ledger);
- BasicView& v0 = *env.ledger;
+ Account const master("master");
+ auto const ledger =
+ std::make_shared(
+ master.pk(), 1000000000);
+ wipe(*ledger);
+ BasicView& v0 = *ledger;
v0.unchecked_insert(sle(1));
MetaView v1(v0, tapNONE);
{
diff --git a/src/ripple/app/paths/tests/Path_test.cpp b/src/ripple/app/paths/tests/Path_test.cpp
index 67247635f..3d7f1dde0 100644
--- a/src/ripple/app/paths/tests/Path_test.cpp
+++ b/src/ripple/app/paths/tests/Path_test.cpp
@@ -35,9 +35,10 @@ class Path_test : public beast::unit_test::suite
{
public:
Json::Value
- findPath (Ledger::ref ledger, Account const& src,
- Account const& dest, std::vector const& srcIssues,
- STAmount const& saDstAmount)
+ findPath (std::shared_ptr const& view,
+ Account const& src, Account const& dest,
+ std::vector const& srcIssues,
+ STAmount const& saDstAmount)
{
auto jvSrcCurrencies = Json::Value(Json::arrayValue);
for (auto const& i : srcIssues)
@@ -48,9 +49,9 @@ public:
int const level = 8;
auto result = ripplePathFind(
- std::make_shared(
- ledger), src.id(), dest.id(), saDstAmount,
- jvSrcCurrencies, boost::none, level);
+ std::make_shared(view),
+ src.id(), dest.id(), saDstAmount,
+ jvSrcCurrencies, boost::none, level);
if(!result.first)
throw std::runtime_error(
"Path_test::findPath: ripplePathFind find failed");
@@ -65,7 +66,7 @@ public:
Env env(*this);
env.fund(XRP(10000), "alice", "bob");
- auto const alternatives = findPath(env.ledger, "alice", "bob",
+ auto const alternatives = findPath(env.open(), "alice", "bob",
{Account("alice")["USD"]}, Account("bob")["USD"](5));
expect(alternatives.size() == 0);
}
@@ -78,7 +79,7 @@ public:
env.fund(XRP(10000), "alice", "bob");
env.trust(Account("alice")["USD"](700), "bob");
- auto const alternatives = findPath(env.ledger, "alice", "bob",
+ auto const alternatives = findPath(env.open(), "alice", "bob",
{Account("alice")["USD"]}, Account("bob")["USD"](5));
Json::Value jv;
Json::Reader().parse(R"([{
@@ -125,7 +126,7 @@ public:
env(pay(gw, "alice", USD(70)));
env(pay(gw, "bob", USD(50)));
- auto const alternatives = findPath(env.ledger, "alice", "bob",
+ auto const alternatives = findPath(env.open(), "alice", "bob",
{USD}, Account("bob")["USD"](5));
Json::Value jv;
Json::Reader().parse(R"([{
@@ -152,7 +153,7 @@ public:
env.trust(Account("alice")["USD"](600), gw);
env.trust(USD(700), "bob");
- auto const alternatives = findPath(env.ledger, "alice", "bob",
+ auto const alternatives = findPath(env.open(), "alice", "bob",
{USD}, Account("bob")["USD"](1));
Json::Value jv;
Json::Reader().parse(R"([{
@@ -275,7 +276,7 @@ public:
env(pay("carol", "alice", Account("carol")["USD"](100)));
env(pay(gw, "alice", USD(100)));
- auto const alternatives = findPath(env.ledger, "alice", "bob",
+ auto const alternatives = findPath(env.open(), "alice", "bob",
{USD}, Account("bob")["USD"](5));
Json::Value jv;
Json::Reader().parse(R"([{
@@ -304,14 +305,14 @@ public:
env.require(balance("bob", Account("carol")["USD"](-75)));
env.require(balance("carol", Account("bob")["USD"](75)));
- auto alternatives = findPath(env.ledger, "alice", "bob",
+ auto alternatives = findPath(env.open(), "alice", "bob",
{Account("alice")["USD"]}, Account("bob")["USD"](25));
expect(alternatives.size() == 0);
env(pay("alice", "bob", Account("alice")["USD"](25)),
ter(tecPATH_DRY));
- alternatives = findPath(env.ledger, "alice", "bob",
+ alternatives = findPath(env.open(), "alice", "bob",
{Account("alice")["USD"]}, Account("alice")["USD"](25));
expect(alternatives.size() == 0);
@@ -391,7 +392,7 @@ public:
env.require(balance("bob", AUD(10)));
env.require(balance("carol", AUD(39)));
- auto const alternatives = findPath(env.ledger, "alice", "bob",
+ auto const alternatives = findPath(env.open(), "alice", "bob",
{Account("alice")["USD"]}, Account("bob")["USD"](25));
expect(alternatives.size() == 0);
}
@@ -405,7 +406,7 @@ public:
env.trust(Account("alice")["USD"](1000), "bob");
env.trust(Account("bob")["USD"](1000), "carol");
- auto const alternatives = findPath(env.ledger, "alice", "carol",
+ auto const alternatives = findPath(env.open(), "alice", "carol",
{Account("alice")["USD"]}, Account("carol")["USD"](5));
Json::Value jv;
Json::Reader().parse(R"([{
diff --git a/src/ripple/app/tx/tests/Offer.test.cpp b/src/ripple/app/tx/tests/Offer.test.cpp
index 335ff2152..e487a5a32 100644
--- a/src/ripple/app/tx/tests/Offer.test.cpp
+++ b/src/ripple/app/tx/tests/Offer.test.cpp
@@ -28,17 +28,14 @@
namespace ripple {
namespace test {
-/** An offer exists
- */
+// An offer exists
bool isOffer (jtx::Env const& env,
jtx::Account const& account,
STAmount const& takerPays,
STAmount const& takerGets)
{
bool exists = false;
- CachedView view(*env.ledger,
- getApp().getSLECache());
- forEachItem (view, account.id (),
+ forEachItem (*env.open(), account,
[&](std::shared_ptr const& sle)
{
if (sle->getType () == ltOFFER &&
diff --git a/src/ripple/app/tx/tests/PathSet.h b/src/ripple/app/tx/tests/PathSet.h
index b432204c0..6a41a3a5c 100644
--- a/src/ripple/app/tx/tests/PathSet.h
+++ b/src/ripple/app/tx/tests/PathSet.h
@@ -38,7 +38,7 @@ isOffer (jtx::Env const& env,
STAmount const& takerGets)
{
bool exists = false;
- forEachItem (*env.ledger, account,
+ forEachItem (*env.open(), account,
[&](std::shared_ptr const& sle)
{
if (sle->getType () == ltOFFER &&
diff --git a/src/ripple/test/jtx.h b/src/ripple/test/jtx.h
index fdfcbbd8f..ac0a7ce6c 100644
--- a/src/ripple/test/jtx.h
+++ b/src/ripple/test/jtx.h
@@ -23,7 +23,6 @@
// Convenience header that includes everything
#include
-#include
#include
#include
#include
diff --git a/src/ripple/test/jtx/Env.h b/src/ripple/test/jtx/Env.h
index 342151481..62b82681f 100644
--- a/src/ripple/test/jtx/Env.h
+++ b/src/ripple/test/jtx/Env.h
@@ -27,6 +27,8 @@
#include
#include
+#include
+#include
#include
#include
#include
@@ -116,8 +118,14 @@ noripple (Account const& account,
class Env
{
public:
+ using clock_type = TestClock;
+
+ clock_type clock;
+
beast::unit_test::suite& test;
+ beast::Journal const journal;
+
/** Configuration used. */
// VFALCO NOTE Some code still calls getConfig()
Config const config;
@@ -125,12 +133,89 @@ public:
/** The master account. */
Account const master;
- /** The open ledger. */
- std::shared_ptr ledger;
+private:
+ std::shared_ptr closed_;
+public:
+
+ // Careful with this
+ OpenLedger openLedger;
public:
+ Env() = delete;
+ Env (Env const&) = delete;
+ Env& operator= (Env const&) = delete;
+
Env (beast::unit_test::suite& test_);
-
+
+ /** Creates a genesis ledger.
+
+ This is called by the implementation but provided
+ as a public member for interested callers.
+ */
+ static
+ std::shared_ptr
+ genesis();
+
+ /** Returns the open ledger.
+
+ This is a non-modifiable snapshot of the
+ open ledger at the moment of the call.
+ Transactions applied after the call to open()
+ will not be visible.
+
+ */
+ std::shared_ptr
+ open() const;
+
+ /** Returns the last closed ledger.
+
+ The open ledger is built on top of the
+ last closed ledger. When the open ledger
+ is closed, it becomes the new closed ledger
+ and a new open ledger takes its place.
+ */
+ std::shared_ptr
+ closed() const;
+
+ /** Close and advance the ledger.
+
+ Effects:
+
+ Creates a new closed ledger from the last
+ closed ledger.
+
+ All transactions that made it into the open
+ ledger are applied to the closed ledger.
+
+ The Env clock is set to the new time.
+ */
+ void
+ close (TestClock::time_point const& closeTime);
+
+ /** Close and advance the ledger.
+
+ The time is calculated as the duration from
+ the previous ledger closing time.
+ */
+ template
+ void
+ close (std::chrono::duration<
+ Rep, Period> const& elapsed)
+ {
+ close (clock.now() + elapsed);
+ }
+
+ /** Close and advance the ledger.
+
+ The time is calculated as five seconds from
+ the previous ledger closing time.
+ */
+ void
+ close()
+ {
+ close (std::chrono::seconds(5));
+ }
+
/** Turn on JSON tracing.
With no arguments, trace all
*/
diff --git a/src/ripple/test/jtx/advance.h b/src/ripple/test/jtx/advance.h
deleted file mode 100644
index 8fb3a2853..000000000
--- a/src/ripple/test/jtx/advance.h
+++ /dev/null
@@ -1,38 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- This file is part of rippled: https://github.com/ripple/rippled
- Copyright (c) 2012, 2013 Ripple Labs Inc.
-
- Permission to use, copy, modify, and/or distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
-//==============================================================================
-
-#ifndef RIPPLE_TEST_JTX_ADVANCE_H_INCLUDED
-#define RIPPLE_TEST_JTX_ADVANCE_H_INCLUDED
-
-#include
-
-namespace ripple {
-namespace test {
-namespace jtx {
-
-// TODO EHENNIS: Return the transaction list.
-// (Coming soon.)
-void
-advance(Env& env, std::shared_ptr& last);
-
-} // jtx
-} // test
-} // ripple
-
-#endif
diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp
index e5685bf42..97f5f8fb4 100644
--- a/src/ripple/test/jtx/impl/Env.cpp
+++ b/src/ripple/test/jtx/impl/Env.cpp
@@ -29,6 +29,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -50,16 +51,85 @@ namespace test {
namespace jtx {
+std::shared_ptr
+Env::genesis()
+{
+ Account master("master", generateKeysFromSeed(
+ KeyType::secp256k1, RippleAddress::createSeedGeneric(
+ "masterpassphrase")));
+ auto const ledger =
+ std::make_shared(master.pk(),
+ SYSTEM_CURRENCY_START);
+ ledger->setClosed();
+ return ledger;
+}
+
+// VFALCO Could wrap the log in a Journal here
Env::Env (beast::unit_test::suite& test_)
: test(test_)
, master("master", generateKeysFromSeed(
KeyType::secp256k1, RippleAddress::createSeedGeneric(
"masterpassphrase")))
+ , closed_ (genesis())
+ , openLedger (closed_, config, clock, journal)
{
memoize(master);
initializePathfinding();
- ledger = std::make_shared(
- master.pk(), SYSTEM_CURRENCY_START);
+}
+
+std::shared_ptr
+Env::open() const
+{
+ return openLedger.current();
+}
+
+std::shared_ptr
+Env::closed() const
+{
+ return closed_;
+}
+
+void
+Env::close(
+ TestClock::time_point const& closeTime)
+{
+ clock.set(closeTime);
+ auto next = std::make_shared(
+ false, *closed_);
+ next->setClosed();
+#if 0
+ // Build a SHAMap, put all the transactions
+ // in it, and calculate the hash of the SHAMap
+ // to construct the OrderedTxs
+ SHAMap sm;
+ OrderedTxs txs(sm.getRootHash());
+ ...
+#else
+ std::vector> txs;
+#endif
+ auto cur = openLedger.current();
+ for (auto iter = cur->txs.begin();
+ iter != cur->txs.end(); ++iter)
+ txs.push_back(iter->first);
+ std::unique_ptr router(
+ IHashRouter::New(60));
+ OrderedTxs retries(uint256{});
+ {
+ MetaView accum(*next, tapNONE);
+ OpenLedger::apply(accum, *closed_,
+ txs, retries, *router, config,
+ journal);
+ accum.apply(*next);
+ }
+ next->setAccepted(
+ closeTime.time_since_epoch().count(),
+ ledgerPossibleTimeResolutions[0],
+ true);
+ OrderedTxs locals({});
+ openLedger.accept(next, locals,
+ false, retries, *router);
+ closed_ = next;
}
void
@@ -138,7 +208,7 @@ Env::le (Account const& account) const
std::shared_ptr
Env::le (Keylet const& k) const
{
- return ledger->read(k);
+ return open()->read(k);
}
void
@@ -151,7 +221,7 @@ Env::fund (bool setDefaultRipple,
{
// VFALCO NOTE Is the fee formula correct?
apply(pay(master, account, amount +
- drops(ledger->getBaseFee())),
+ drops(open()->fees().base)),
jtx::seq(jtx::autofill),
fee(jtx::autofill),
sig(jtx::autofill));
@@ -182,7 +252,7 @@ Env::trust (STAmount const& amount,
fee(jtx::autofill),
sig(jtx::autofill));
apply(pay(master, account,
- drops(ledger->getBaseFee())),
+ drops(open()->fees().base)),
jtx::seq(jtx::autofill),
fee(jtx::autofill),
sig(jtx::autofill));
@@ -192,18 +262,21 @@ Env::trust (STAmount const& amount,
void
Env::submit (JTx const& jt)
{
- auto const stx = st(jt);
+ auto stx = st(jt);
TER ter;
bool didApply;
if (stx)
{
- ViewFlags flags = tapNONE;
- flags = flags | tapENABLE_TESTING;
- // VFALCO Could wrap the log in a Journal here
- std::tie(ter, didApply) =
- ripple::apply(
- *ledger, *stx, flags, config,
- beast::Journal{});
+ openLedger.modify(
+ [&](View& view, beast::Journal j)
+ {
+ ViewFlags flags = tapNONE;
+ flags = flags | tapENABLE_TESTING;
+ std::tie(ter, didApply) = ripple::apply(
+ view, *stx, flags, config,
+ beast::Journal{});
+ return didApply;
+ });
}
else
{
@@ -229,6 +302,9 @@ Env::submit (JTx const& jt)
}
for (auto const& f : jt.requires)
f(*this);
+ //if (isTerRetry(ter))
+ //if (! isTesSuccess(ter))
+ // held.insert(stx);
}
void
@@ -255,9 +331,9 @@ Env::autofill (JTx& jt)
{
auto& jv = jt.jv;
if(jt.fill_fee)
- jtx::fill_fee(jv, *ledger);
+ jtx::fill_fee(jv, *open());
if(jt.fill_seq)
- jtx::fill_seq(jv, *ledger);
+ jtx::fill_seq(jv, *open());
// Must come last
try
{
diff --git a/src/ripple/test/jtx/impl/Env_test.cpp b/src/ripple/test/jtx/impl/Env_test.cpp
index fa254fed0..15f031a44 100644
--- a/src/ripple/test/jtx/impl/Env_test.cpp
+++ b/src/ripple/test/jtx/impl/Env_test.cpp
@@ -420,8 +420,13 @@ public:
Env env(*this);
}
+ struct UDT
+ {
+ };
+
void testJTxProperties()
{
+ struct T { };
using namespace jtx;
JTx jt1;
// Test a straightforward
@@ -476,12 +481,9 @@ public:
expect(!*jt3.get());
}
- struct UDT
- {
- };
-
void testJTxCopy()
{
+ struct T { };
using namespace jtx;
JTx jt1;
jt1.set(7);
@@ -501,6 +503,7 @@ public:
void testJTxMove()
{
+ struct T { };
using namespace jtx;
JTx jt1;
jt1.set(7);
@@ -542,31 +545,32 @@ public:
{
using namespace jtx;
Env env(*this);
- // Create the LCL as a copy of the Env's
- // ledger. This will have the side effect
- // of skipping one seq in Env.ledger the
- // first time it is advanced. This can be
- // worked around if desired by assigning
- // an advanced ledger back to Env before
- // starting, but it won't matter to most
- // tests.
- std::shared_ptr lastClosedLedger =
- std::make_shared(
- *env.ledger, false);
+ auto seq = env.open()->seq();
+ expect(seq == env.closed()->seq() + 1);
+ env.close();
+ expect(env.closed()->seq() == seq);
+ expect(env.open()->seq() == seq + 1);
+ env.close();
+ expect(env.closed()->seq() == seq + 1);
+ expect(env.open()->seq() == seq + 2);
+ }
- auto firstSeq = env.ledger->seq();
-
- expect(lastClosedLedger->seq() == firstSeq);
-
- advance(env, lastClosedLedger);
-
- expect(lastClosedLedger->seq() == firstSeq + 1);
- expect(env.ledger->seq() == firstSeq + 2);
-
- advance(env, lastClosedLedger);
-
- expect(lastClosedLedger->seq() == firstSeq + 2);
- expect(env.ledger->seq() == firstSeq + 3);
+ void
+ testClose()
+ {
+ using namespace jtx;
+ Env env(*this);
+ env.close();
+ env.close();
+ env.fund(XRP(100000), "alice", "bob");
+ auto const epoch =
+ Env::clock_type::time_point{};
+ env.close();
+ env(pay("alice", "bob", XRP(100)));
+ env.close();
+ env(noop("alice"));
+ env.close();
+ env(noop("bob"));
}
void
@@ -591,6 +595,7 @@ public:
testJTxMove();
testMemo();
testAdvance();
+ testClose();
}
};
diff --git a/src/ripple/test/jtx/impl/advance.cpp b/src/ripple/test/jtx/impl/advance.cpp
deleted file mode 100644
index 655babd1c..000000000
--- a/src/ripple/test/jtx/impl/advance.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- This file is part of rippled: https://github.com/ripple/rippled
- Copyright (c) 2012, 2013 Ripple Labs Inc.
-
- Permission to use, copy, modify, and/or distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
-//==============================================================================
-
-#include
-#include
-#include
-#include
-
-namespace ripple {
-namespace test {
-namespace jtx {
-
-void
-advance(Env& env, std::shared_ptr& last)
-{
- close_and_advance(env.ledger, last);
-}
-
-
-} // jtx
-} // test
-} // ripple
diff --git a/src/ripple/test/jtx/impl/owners.cpp b/src/ripple/test/jtx/impl/owners.cpp
index 5d4973dc1..1b77bd320 100644
--- a/src/ripple/test/jtx/impl/owners.cpp
+++ b/src/ripple/test/jtx/impl/owners.cpp
@@ -27,12 +27,12 @@ namespace jtx {
namespace detail {
std::uint32_t
-owned_count_of(Ledger const& ledger,
+owned_count_of(BasicView const& view,
AccountID const& id,
LedgerEntryType type)
{
std::uint32_t count = 0;
- forEachItem(ledger, id,
+ forEachItem (view, id,
[&count, type](std::shared_ptr const& sle)
{
if (sle->getType() == type)
@@ -48,7 +48,7 @@ owned_count_helper(Env const& env,
std::uint32_t value)
{
env.test.expect(owned_count_of(
- *env.ledger, id, type) == value);
+ *env.open(), id, type) == value);
}
} // detail
diff --git a/src/ripple/test/jtx/impl/paths.cpp b/src/ripple/test/jtx/impl/paths.cpp
index ab79d9bc4..7a3ff397c 100644
--- a/src/ripple/test/jtx/impl/paths.cpp
+++ b/src/ripple/test/jtx/impl/paths.cpp
@@ -40,7 +40,7 @@ paths::operator()(Env const& env, JTx& jt) const
STPathSet ps;
auto const found = findPathsForOneIssuer(
std::make_shared(
- env.ledger), from, to,
+ env.open()), from, to,
in_, amount,
depth_, limit_, ps, fp);
// VFALCO TODO API to allow caller to examine the STPathSet
diff --git a/src/ripple/test/jtx/impl/utility.cpp b/src/ripple/test/jtx/impl/utility.cpp
index ab837bf54..4de016c80 100644
--- a/src/ripple/test/jtx/impl/utility.cpp
+++ b/src/ripple/test/jtx/impl/utility.cpp
@@ -58,17 +58,17 @@ sign (Json::Value& jv,
void
fill_fee (Json::Value& jv,
- Ledger const& ledger)
+ BasicView const& view)
{
if (jv.isMember(jss::Fee))
return;
jv[jss::Fee] = std::to_string(
- ledger.getBaseFee());
+ view.fees().base);
}
void
fill_seq (Json::Value& jv,
- Ledger const& ledger)
+ BasicView const& view)
{
if (jv.isMember(jss::Sequence))
return;
@@ -78,10 +78,11 @@ fill_seq (Json::Value& jv,
if (! account)
throw parse_error(
"unexpected invalid Account");
- auto const ar = ledger.read(
+ auto const ar = view.read(
keylet::account(*account));
- if (!ar)
- return;
+ if (! ar)
+ throw parse_error(
+ "unexpected missing account root");
jv[jss::Sequence] =
ar->getFieldU32(sfSequence);
}
diff --git a/src/ripple/test/jtx/owners.h b/src/ripple/test/jtx/owners.h
index 371a9658f..eb8582da8 100644
--- a/src/ripple/test/jtx/owners.h
+++ b/src/ripple/test/jtx/owners.h
@@ -21,7 +21,7 @@
#define RIPPLE_TEST_JTX_OWNERS_H_INCLUDED
#include
-#include
+#include
#include
#include
#include
@@ -33,7 +33,7 @@ namespace jtx {
namespace detail {
std::uint32_t
-owned_count_of (Ledger const& ledger,
+owned_count_of (BasicView const& view,
AccountID const& id,
LedgerEntryType type);
diff --git a/src/ripple/test/jtx/utility.h b/src/ripple/test/jtx/utility.h
index 7b88649ab..48e9a539c 100644
--- a/src/ripple/test/jtx/utility.h
+++ b/src/ripple/test/jtx/utility.h
@@ -59,12 +59,12 @@ sign (Json::Value& jv,
/** Set the fee automatically. */
void
fill_fee (Json::Value& jv,
- Ledger const& ledger);
+ BasicView const& view);
/** Set the sequence number automatically. */
void
fill_seq (Json::Value& jv,
- Ledger const& ledger);
+ BasicView const& view);
} // jtx
} // test
diff --git a/src/ripple/unity/test.cpp b/src/ripple/unity/test.cpp
index b9008d1a5..a89cea70d 100644
--- a/src/ripple/unity/test.cpp
+++ b/src/ripple/unity/test.cpp
@@ -20,7 +20,6 @@
#include
#include
-#include
#include
#include
#include