From c334093223f3238db952e159c7bd7afa6b1c2144 Mon Sep 17 00:00:00 2001 From: Edward Hennis Date: Thu, 11 Jun 2015 21:41:19 -0400 Subject: [PATCH] jtx: Add ledger advance. Conflicts: src/ripple/test/jtx/impl/Env_test.cpp --- Builds/VisualStudio2013/RippleD.vcxproj | 6 +++ .../VisualStudio2013/RippleD.vcxproj.filters | 6 +++ .../app/ledger/tests/DeferredCredits.test.cpp | 4 +- src/ripple/app/ledger/tests/Ledger_test.cpp | 4 +- src/ripple/app/ledger/tests/common_ledger.cpp | 19 +++++++--- src/ripple/app/ledger/tests/common_ledger.h | 6 +-- src/ripple/app/paths/tests/Path_test.cpp | 8 ++-- src/ripple/app/tx/tests/common_transactor.cpp | 1 - src/ripple/app/tx/tests/common_transactor.h | 2 +- src/ripple/test/jtx.h | 1 + src/ripple/test/jtx/advance.h | 38 +++++++++++++++++++ src/ripple/test/jtx/impl/Env_test.cpp | 34 ++++++++++++++++- src/ripple/test/jtx/impl/advance.cpp | 38 +++++++++++++++++++ src/ripple/unity/test.cpp | 1 + 14 files changed, 148 insertions(+), 20 deletions(-) create mode 100644 src/ripple/test/jtx/advance.h create mode 100644 src/ripple/test/jtx/impl/advance.cpp diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index bc089866bb..3ca3c12677 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -3337,6 +3337,8 @@ + + @@ -3353,6 +3355,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 4cf6a31ca8..ef5c986d5e 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -4068,6 +4068,9 @@ ripple\test\jtx + + ripple\test\jtx + ripple\test\jtx @@ -4089,6 +4092,9 @@ ripple\test\jtx\impl + + ripple\test\jtx\impl + ripple\test\jtx\impl diff --git a/src/ripple/app/ledger/tests/DeferredCredits.test.cpp b/src/ripple/app/ledger/tests/DeferredCredits.test.cpp index a7518f491e..4640744f5a 100644 --- a/src/ripple/app/ledger/tests/DeferredCredits.test.cpp +++ b/src/ripple/app/ledger/tests/DeferredCredits.test.cpp @@ -57,7 +57,7 @@ class DeferredCredits_test : public beast::unit_test::suite auto master = createAccount ("masterpassphrase", keyType); - Ledger::pointer LCL; + std::shared_ptr 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 LCL; Ledger::pointer ledger; std::tie (LCL, ledger) = createGenesisLedger (100000 * xrp, master); diff --git a/src/ripple/app/ledger/tests/Ledger_test.cpp b/src/ripple/app/ledger/tests/Ledger_test.cpp index 94c0d3aeda..deba77692c 100644 --- a/src/ripple/app/ledger/tests/Ledger_test.cpp +++ b/src/ripple/app/ledger/tests/Ledger_test.cpp @@ -30,7 +30,7 @@ class Ledger_test : public beast::unit_test::suite auto master = createAccount ("masterpassphrase", keyType); - Ledger::pointer LCL; + std::shared_ptr 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 LCL; Ledger::pointer ledger; std::tie(LCL, ledger) = createGenesisLedger (100000 * xrp, master); diff --git a/src/ripple/app/ledger/tests/common_ledger.cpp b/src/ripple/app/ledger/tests/common_ledger.cpp index b3d2cec4ea..622ddfd80f 100644 --- a/src/ripple/app/ledger/tests/common_ledger.cpp +++ b/src/ripple/app/ledger/tests/common_ledger.cpp @@ -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 +std::pair, Ledger::pointer> createGenesisLedger(std::uint64_t start_amount_drops, TestAccount const& master) { initializePathfinding(); - Ledger::pointer ledger = std::make_shared(master.pk, + auto ledger = std::make_shared(master.pk, start_amount_drops); ledger->getHash(); // updates the hash ledger->setClosed(); @@ -198,7 +198,7 @@ createAndFundAccountsWithFlags(TestAccount& from, std::vector passphrases, KeyType keyType, std::uint64_t amountDrops, Ledger::pointer& ledger, - Ledger::pointer& LCL, + std::shared_ptr& 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& LCL) { std::shared_ptr set = ledger->peekTransactionMap(); CanonicalTXSet retriableTransactions(set->getHash()); - Ledger::pointer newLCL = std::make_shared(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(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(false, *LCL); + ledger = std::make_shared(false, *newLCL); } Json::Value findPath(Ledger::pointer ledger, TestAccount const& src, diff --git a/src/ripple/app/ledger/tests/common_ledger.h b/src/ripple/app/ledger/tests/common_ledger.h index 0fbcdf7caa..9e0f99cfc1 100644 --- a/src/ripple/app/ledger/tests/common_ledger.h +++ b/src/ripple/app/ledger/tests/common_ledger.h @@ -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 +std::pair, 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 passphrases, KeyType keyType, std::uint64_t amountDrops, Ledger::pointer& ledger, - Ledger::pointer& LCL, + std::shared_ptr& 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& LCL); Json::Value findPath(Ledger::pointer ledger, TestAccount const& src, TestAccount const& dest, std::vector srcCurrencies, diff --git a/src/ripple/app/paths/tests/Path_test.cpp b/src/ripple/app/paths/tests/Path_test.cpp index ca355eebbc..3c5a2dc859 100644 --- a/src/ripple/app/paths/tests/Path_test.cpp +++ b/src/ripple/app/paths/tests/Path_test.cpp @@ -37,7 +37,7 @@ class Path_test : public TestSuite auto master = createAccount("masterpassphrase", KeyType::ed25519); - Ledger::pointer LCL; + std::shared_ptr 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 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 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 LCL; Ledger::pointer ledger; std::tie(LCL, ledger) = createGenesisLedger(100000 * xrp, master); diff --git a/src/ripple/app/tx/tests/common_transactor.cpp b/src/ripple/app/tx/tests/common_transactor.cpp index 57bd5466e8..eb73aadd1e 100644 --- a/src/ripple/app/tx/tests/common_transactor.cpp +++ b/src/ripple/app/tx/tests/common_transactor.cpp @@ -103,7 +103,6 @@ std::pair 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 = diff --git a/src/ripple/app/tx/tests/common_transactor.h b/src/ripple/app/tx/tests/common_transactor.h index 9ab15cd58b..6baf109da6 100644 --- a/src/ripple/app/tx/tests/common_transactor.h +++ b/src/ripple/app/tx/tests/common_transactor.h @@ -101,7 +101,7 @@ public: class TestLedger { private: - Ledger::pointer lastClosedLedger_; + std::shared_ptr lastClosedLedger_; Ledger::pointer openLedger_; beast::unit_test::suite& suite_; diff --git a/src/ripple/test/jtx.h b/src/ripple/test/jtx.h index ed8ea395ed..3c48ba40ea 100644 --- a/src/ripple/test/jtx.h +++ b/src/ripple/test/jtx.h @@ -23,6 +23,7 @@ // Convenience header that includes everything #include +#include #include #include #include diff --git a/src/ripple/test/jtx/advance.h b/src/ripple/test/jtx/advance.h new file mode 100644 index 0000000000..8fb3a28530 --- /dev/null +++ b/src/ripple/test/jtx/advance.h @@ -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 + +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_test.cpp b/src/ripple/test/jtx/impl/Env_test.cpp index 98ed35ac13..7cc5a8ffa3 100644 --- a/src/ripple/test/jtx/impl/Env_test.cpp +++ b/src/ripple/test/jtx/impl/Env_test.cpp @@ -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 lastClosedLedger = + std::make_shared( + *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(); } }; diff --git a/src/ripple/test/jtx/impl/advance.cpp b/src/ripple/test/jtx/impl/advance.cpp new file mode 100644 index 0000000000..655babd1c2 --- /dev/null +++ b/src/ripple/test/jtx/impl/advance.cpp @@ -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 +#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/unity/test.cpp b/src/ripple/unity/test.cpp index 8429b9c47c..4364861c70 100644 --- a/src/ripple/unity/test.cpp +++ b/src/ripple/unity/test.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include