jtx: Add ledger advance.

Conflicts:
	src/ripple/test/jtx/impl/Env_test.cpp
This commit is contained in:
Edward Hennis
2015-06-11 21:41:19 -04:00
committed by Vinnie Falco
parent 27274c9620
commit c334093223
14 changed files with 148 additions and 20 deletions

View File

@@ -3337,6 +3337,8 @@
</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">
@@ -3353,6 +3355,10 @@
<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

@@ -4068,6 +4068,9 @@
<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>
@@ -4089,6 +4092,9 @@
<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

@@ -57,7 +57,7 @@ class DeferredCredits_test : public beast::unit_test::suite
auto master = createAccount ("masterpassphrase", keyType);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie (LCL, ledger) = createGenesisLedger (100000 * xrp, master);
@@ -124,7 +124,7 @@ class DeferredCredits_test : public beast::unit_test::suite
auto master = createAccount ("masterpassphrase", keyType);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie (LCL, ledger) = createGenesisLedger (100000 * xrp, master);

View File

@@ -30,7 +30,7 @@ class Ledger_test : public beast::unit_test::suite
auto master = createAccount ("masterpassphrase", keyType);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie(LCL, ledger) = createGenesisLedger(100000*xrp, master);
@@ -96,7 +96,7 @@ class Ledger_test : public beast::unit_test::suite
auto master = createAccount ("masterpassphrase", keyType);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie(LCL, ledger) = createGenesisLedger (100000 * xrp, master);

View File

@@ -137,11 +137,11 @@ applyTransaction(Ledger::pointer const& ledger, STTx const& tx, bool check)
// Create genesis ledger from a start amount in drops, and the public
// master RippleAddress
std::pair<Ledger::pointer, Ledger::pointer>
std::pair<std::shared_ptr<Ledger const>, Ledger::pointer>
createGenesisLedger(std::uint64_t start_amount_drops, TestAccount const& master)
{
initializePathfinding();
Ledger::pointer ledger = std::make_shared<Ledger>(master.pk,
auto ledger = std::make_shared<Ledger>(master.pk,
start_amount_drops);
ledger->getHash(); // updates the hash
ledger->setClosed();
@@ -198,7 +198,7 @@ createAndFundAccountsWithFlags(TestAccount& from,
std::vector<std::string> passphrases,
KeyType keyType, std::uint64_t amountDrops,
Ledger::pointer& ledger,
Ledger::pointer& LCL,
std::shared_ptr<Ledger const>& LCL,
const std::uint32_t flags, bool sign)
{
auto accounts = createAndFundAccounts(from,
@@ -430,11 +430,14 @@ trust(TestAccount& from, TestAccount const& issuer,
}
void
close_and_advance(Ledger::pointer& ledger, Ledger::pointer& LCL)
close_and_advance(Ledger::pointer& ledger, std::shared_ptr<Ledger const>& LCL)
{
std::shared_ptr<SHAMap> set = ledger->peekTransactionMap();
CanonicalTXSet retriableTransactions(set->getHash());
Ledger::pointer newLCL = std::make_shared<Ledger>(false, *LCL);
// Make a non-const copy of LCL. This won't be necessary once
// that other Ledger constructor can take a const Ledger.
Ledger oldLCL(*LCL, false);
Ledger::pointer newLCL = std::make_shared<Ledger>(false, oldLCL);
// Set up to write SHAMap changes to our database,
// perform updates, extract changes
applyTransactions(set, newLCL, newLCL, retriableTransactions, false);
@@ -453,8 +456,12 @@ close_and_advance(Ledger::pointer& ledger, Ledger::pointer& LCL)
bool closeTimeCorrect = true;
newLCL->setAccepted(closeTime, closeResolution, closeTimeCorrect);
if (!newLCL->assertSane())
throw std::runtime_error(
"!newLCL->assertSane()");
LCL = newLCL;
ledger = std::make_shared<Ledger>(false, *LCL);
ledger = std::make_shared<Ledger>(false, *newLCL);
}
Json::Value findPath(Ledger::pointer ledger, TestAccount const& src,

View File

@@ -125,7 +125,7 @@ applyTransaction(Ledger::pointer const& ledger, STTx const& tx, bool check = tru
// Create genesis ledger from a start amount in drops, and the public
// master RippleAddress
std::pair<Ledger::pointer, Ledger::pointer>
std::pair<std::shared_ptr<Ledger const>, Ledger::pointer>
createGenesisLedger(std::uint64_t start_amount_drops, TestAccount const& master);
// Create an account represented by public RippleAddress and private
@@ -148,7 +148,7 @@ createAndFundAccountsWithFlags(TestAccount& from,
std::vector<std::string> passphrases,
KeyType keyType, std::uint64_t amountDrops,
Ledger::pointer& ledger,
Ledger::pointer& LCL,
std::shared_ptr<Ledger const>& LCL,
const std::uint32_t flags, bool sign = true);
void
@@ -237,7 +237,7 @@ trust(TestAccount& from, TestAccount const& issuer,
Ledger::pointer const& ledger, bool sign = true);
void
close_and_advance(Ledger::pointer& ledger, Ledger::pointer& LCL);
close_and_advance(Ledger::pointer& ledger, std::shared_ptr<Ledger const>& LCL);
Json::Value findPath(Ledger::pointer ledger, TestAccount const& src,
TestAccount const& dest, std::vector<Currency> srcCurrencies,

View File

@@ -37,7 +37,7 @@ class Path_test : public TestSuite
auto master = createAccount("masterpassphrase", KeyType::ed25519);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie(LCL, ledger) = createGenesisLedger(100000 * xrp, master);
@@ -62,7 +62,7 @@ class Path_test : public TestSuite
auto master = createAccount("masterpassphrase", KeyType::ed25519);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie(LCL, ledger) = createGenesisLedger(100000 * xrp, master);
@@ -100,7 +100,7 @@ class Path_test : public TestSuite
auto master = createAccount("masterpassphrase", KeyType::ed25519);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie(LCL, ledger) = createGenesisLedger(100000 * xrp, master);
@@ -140,7 +140,7 @@ class Path_test : public TestSuite
auto master = createAccount("masterpassphrase", KeyType::ed25519);
Ledger::pointer LCL;
std::shared_ptr<Ledger const> LCL;
Ledger::pointer ledger;
std::tie(LCL, ledger) = createGenesisLedger(100000 * xrp, master);

View File

@@ -103,7 +103,6 @@ std::pair<TER, bool> TestLedger::applyTransaction (STTx const& tx, bool check)
// call to this method gets applied individually. So this transaction
// is guaranteed to be applied before the next one.
close_and_advance(openLedger_, lastClosedLedger_);
suite_.expect (lastClosedLedger_->assertSane() == true);
// Check for the transaction in the closed ledger.
bool const foundTx =

View File

@@ -101,7 +101,7 @@ public:
class TestLedger
{
private:
Ledger::pointer lastClosedLedger_;
std::shared_ptr<Ledger const> lastClosedLedger_;
Ledger::pointer openLedger_;
beast::unit_test::suite& suite_;

View File

@@ -23,6 +23,7 @@
// 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/Env.h>

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
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

@@ -530,6 +530,38 @@ public:
env(noop("alice"), memo("data1", "format1", "type1"), memo("data2", "format2", "type2"));
}
void
testAdvance()
{
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 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
run()
{
@@ -543,7 +575,6 @@ public:
testRequire();
testKeyType();
testPayments();
testMultiSign();
testMultiSign2();
testTicket();
@@ -552,6 +583,7 @@ public:
testJTxCopy();
testJTxMove();
testMemo();
testAdvance();
}
};

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
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

@@ -20,6 +20,7 @@
#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/Env.cpp>