Use OpenLedger in Env

This commit is contained in:
Vinnie Falco
2015-06-30 15:58:24 -07:00
parent 023715474c
commit f3b172b0c9
20 changed files with 305 additions and 199 deletions

View File

@@ -3437,8 +3437,6 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\test\jtx\Account.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\test\jtx\advance.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\test\jtx\amount.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\test\jtx\balance.h">
@@ -3457,10 +3455,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\test\jtx\impl\advance.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\test\jtx\impl\amount.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -4191,9 +4191,6 @@
<ClInclude Include="..\..\src\ripple\test\jtx\Account.h">
<Filter>ripple\test\jtx</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\test\jtx\advance.h">
<Filter>ripple\test\jtx</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\test\jtx\amount.h">
<Filter>ripple\test\jtx</Filter>
</ClInclude>
@@ -4218,9 +4215,6 @@
<ClCompile Include="..\..\src\ripple\test\jtx\impl\Account.cpp">
<Filter>ripple\test\jtx\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\test\jtx\impl\advance.cpp">
<Filter>ripple\test\jtx\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\test\jtx\impl\amount.cpp">
<Filter>ripple\test\jtx\impl</Filter>
</ClCompile>

View File

@@ -100,7 +100,7 @@ private:
std::mutex mutable modify_mutex_;
std::mutex mutable current_mutex_;
std::shared_ptr<MetaView const> current_;
public:
OpenLedger() = delete;
OpenLedger (OpenLedger const&) = delete;

View File

@@ -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 ();

View File

@@ -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<uint256> 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<uint256> 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<Ledger>(
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<Ledger>(
master.pk(), 1000000000);
wipe(*ledger);
BasicView& v0 = *ledger;
v0.unchecked_insert(sle(1));
MetaView v1(v0, tapNONE);
{

View File

@@ -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<Issue> const& srcIssues,
STAmount const& saDstAmount)
findPath (std::shared_ptr<BasicView const> const& view,
Account const& src, Account const& dest,
std::vector<Issue> 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<RippleLineCache>(
ledger), src.id(), dest.id(), saDstAmount,
jvSrcCurrencies, boost::none, level);
std::make_shared<RippleLineCache>(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"([{

View File

@@ -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<SLE const> const& sle)
{
if (sle->getType () == ltOFFER &&

View File

@@ -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<SLE const> const& sle)
{
if (sle->getType () == ltOFFER &&

View File

@@ -23,7 +23,6 @@
// Convenience header that includes everything
#include <ripple/test/jtx/Account.h>
#include <ripple/test/jtx/advance.h>
#include <ripple/test/jtx/amount.h>
#include <ripple/test/jtx/balance.h>
#include <ripple/test/jtx/delivermin.h>

View File

@@ -27,6 +27,8 @@
#include <ripple/test/jtx/tags.h>
#include <ripple/app/ledger/Ledger.h>
#include <ripple/app/ledger/OpenLedger.h>
#include <ripple/basics/chrono.h>
#include <ripple/core/Config.h>
#include <ripple/json/json_value.h>
#include <ripple/json/to_string.h>
@@ -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> ledger;
private:
std::shared_ptr<Ledger> 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<Ledger>
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<BasicView const>
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<BasicView const>
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 <class Rep, class Period>
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
*/

View File

@@ -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 <ripple/test/jtx/Env.h>
namespace ripple {
namespace test {
namespace jtx {
// TODO EHENNIS: Return the transaction list.
// (Coming soon.)
void
advance(Env& env, std::shared_ptr<Ledger const>& last);
} // jtx
} // test
} // ripple
#endif

View File

@@ -29,6 +29,7 @@
#include <ripple/test/jtx/sig.h>
#include <ripple/test/jtx/utility.h>
#include <ripple/app/tx/apply.h>
#include <ripple/app/ledger/LedgerTiming.h>
#include <ripple/app/paths/FindPaths.h>
#include <ripple/basics/Slice.h>
#include <ripple/json/to_string.h>
@@ -50,16 +51,85 @@ namespace test {
namespace jtx {
std::shared_ptr<Ledger>
Env::genesis()
{
Account master("master", generateKeysFromSeed(
KeyType::secp256k1, RippleAddress::createSeedGeneric(
"masterpassphrase")));
auto const ledger =
std::make_shared<Ledger>(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<Ledger>(
master.pk(), SYSTEM_CURRENCY_START);
}
std::shared_ptr<BasicView const>
Env::open() const
{
return openLedger.current();
}
std::shared_ptr<BasicView const>
Env::closed() const
{
return closed_;
}
void
Env::close(
TestClock::time_point const& closeTime)
{
clock.set(closeTime);
auto next = std::make_shared<Ledger>(
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<std::shared_ptr<
STTx const>> 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<IHashRouter> 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<SLE const>
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
{

View File

@@ -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<bool>());
}
struct UDT
{
};
void testJTxCopy()
{
struct T { };
using namespace jtx;
JTx jt1;
jt1.set<int>(7);
@@ -501,6 +503,7 @@ public:
void testJTxMove()
{
struct T { };
using namespace jtx;
JTx jt1;
jt1.set<int>(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<Ledger const> lastClosedLedger =
std::make_shared<Ledger>(
*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();
}
};

View File

@@ -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 <BeastConfig.h>
#include <ripple/test/jtx/advance.h>
#include <ripple/app/ledger/tests/common_ledger.h>
#include <ripple/app/ledger/LedgerConsensus.h>
namespace ripple {
namespace test {
namespace jtx {
void
advance(Env& env, std::shared_ptr<Ledger const>& last)
{
close_and_advance(env.ledger, last);
}
} // jtx
} // test
} // ripple

View File

@@ -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<SLE const> 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

View File

@@ -40,7 +40,7 @@ paths::operator()(Env const& env, JTx& jt) const
STPathSet ps;
auto const found = findPathsForOneIssuer(
std::make_shared<RippleLineCache>(
env.ledger), from, to,
env.open()), from, to,
in_, amount,
depth_, limit_, ps, fp);
// VFALCO TODO API to allow caller to examine the STPathSet

View File

@@ -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);
}

View File

@@ -21,7 +21,7 @@
#define RIPPLE_TEST_JTX_OWNERS_H_INCLUDED
#include <ripple/test/jtx/Env.h>
#include <ripple/app/ledger/Ledger.h>
#include <ripple/ledger/View.h>
#include <ripple/protocol/LedgerFormats.h>
#include <ripple/protocol/UintTypes.h>
#include <cstdint>
@@ -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);

View File

@@ -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

View File

@@ -20,7 +20,6 @@
#include <BeastConfig.h>
#include <ripple/test/jtx/impl/Account.cpp>
#include <ripple/test/jtx/impl/advance.cpp>
#include <ripple/test/jtx/impl/amount.cpp>
#include <ripple/test/jtx/impl/balance.cpp>
#include <ripple/test/jtx/impl/delivermin.cpp>