From 774dcad39244124587951d07377837ad21a2586f Mon Sep 17 00:00:00 2001 From: seelabs Date: Tue, 4 Aug 2015 12:18:47 -0400 Subject: [PATCH] Remove common_ledger --- Builds/VisualStudio2013/RippleD.vcxproj | 10 - .../VisualStudio2013/RippleD.vcxproj.filters | 12 - src/ripple/app/ledger/tests/Ledger_test.cpp | 152 ----- src/ripple/app/ledger/tests/common_ledger.cpp | 569 ------------------ src/ripple/app/ledger/tests/common_ledger.h | 294 --------- src/ripple/ledger/tests/PathSet.h | 1 - .../ledger/tests/PaymentSandbox_test.cpp | 1 - src/ripple/unity/app_ledger.cpp | 2 - 8 files changed, 1041 deletions(-) delete mode 100644 src/ripple/app/ledger/tests/Ledger_test.cpp delete mode 100644 src/ripple/app/ledger/tests/common_ledger.cpp delete mode 100644 src/ripple/app/ledger/tests/common_ledger.h diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 6ad660c23..8589000d7 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -1455,16 +1455,6 @@ - - True - True - - - - - True - True - True True diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index f9a40cac4..58e9d6765 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -250,9 +250,6 @@ {0EF1A571-94CC-4D70-E004-48579DF8AF2B} - - {55A76B5B-A18E-E655-1A07-9492C6F8F356} - {91D5931B-D981-52BC-BC12-08DA9F7BF606} @@ -2211,15 +2208,6 @@ ripple\app\ledger - - ripple\app\ledger\tests - - - ripple\app\ledger\tests - - - ripple\app\ledger\tests - ripple\app\ledger diff --git a/src/ripple/app/ledger/tests/Ledger_test.cpp b/src/ripple/app/ledger/tests/Ledger_test.cpp deleted file mode 100644 index 20905db4c..000000000 --- a/src/ripple/app/ledger/tests/Ledger_test.cpp +++ /dev/null @@ -1,152 +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 - -namespace ripple { -namespace test { - -#if 0 - -class Ledger_test : public beast::unit_test::suite -{ - void test_genesisLedger (bool sign, KeyType keyType) - { - std::uint64_t const xrp = std::mega::num; - - auto master = createAccount ("masterpassphrase", keyType); - - std::shared_ptr LCL; - Ledger::pointer ledger; - std::tie(LCL, ledger) = createGenesisLedger(100000*xrp, master); - - // User accounts - auto gw1 = createAccount ("gw1", keyType); - expect (gw1.pk != master.pk, "gw1.pk != master.pk"); - expect (gw1.sk != master.sk, "gw1.sk != master.sk"); - auto gw2 = createAccount ("gw2", keyType); - auto gw3 = createAccount ("gw3", keyType); - auto alice = createAccount ("alice", keyType); - auto mark = createAccount ("mark", keyType); - - // Fund gw1, gw2, gw3, alice, mark from master - pay(master, gw1, 5000 * xrp, ledger, sign); - pay(master, gw2, 4000 * xrp, ledger, sign); - pay(master, gw3, 3000 * xrp, ledger, sign); - pay(master, alice, 2000 * xrp, ledger, sign); - pay(master, mark, 1000 * xrp, ledger, sign); - - close_and_advance(ledger, LCL); - - // alice trusts FOO/gw1 - trust (alice, gw1, "FOO", 1, ledger, sign); - - // mark trusts FOO/gw2 - trust (mark, gw2, "FOO", 1, ledger, sign); - - // mark trusts FOO/gw3 - trust (mark, gw3, "FOO", 1, ledger, sign); - - // gw2 pays mark with FOO - pay(gw2, mark, "FOO", "0.1", ledger, sign); - - // gw3 pays mark with FOO - pay(gw3, mark, "FOO", "0.2", ledger, sign); - - // gw1 pays alice with FOO - pay(gw1, alice, "FOO", "0.3", ledger, sign); - - verifyBalance(ledger, mark, Amount(0.1, "FOO", gw2)); - verifyBalance(ledger, mark, Amount(0.2, "FOO", gw3)); - verifyBalance(ledger, alice, Amount(0.3, "FOO", gw1)); - - close_and_advance(ledger, LCL); - - createOffer (mark, Amount (1, "FOO", gw1), Amount (1, "FOO", gw2), ledger, sign); - createOffer (mark, Amount (1, "FOO", gw2), Amount (1, "FOO", gw3), ledger, sign); - cancelOffer (mark, ledger, sign); - freezeAccount (alice, ledger, sign); - - close_and_advance(ledger, LCL); - - pay(alice, mark, 1 * xrp, ledger, sign); - - close_and_advance(ledger, LCL); - - pass (); - } - - void test_unsigned_fails (KeyType keyType) - { - std::uint64_t const xrp = std::mega::num; - - auto master = createAccount ("masterpassphrase", keyType); - - std::shared_ptr LCL; - Ledger::pointer ledger; - std::tie(LCL, ledger) = createGenesisLedger (100000 * xrp, master); - - auto gw1 = createAccount ("gw1", keyType); - - auto tx = getPaymentTx(master, gw1, 5000 * xrp, false); - - try - { - applyTransaction (ledger, tx, true); - fail ("apply unsigned transaction should fail"); - } - catch (std::runtime_error const& e) - { - if (std::string (e.what()) != "r != tesSUCCESS") - throw std::runtime_error(e.what()); - } - - pass (); - } - - void test_getQuality () - { - uint256 uBig = from_hex_text ( - "D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000"); - expect (6125895493223874560 == getQuality (uBig)); - - pass (); - } -public: - void run () - { - test_genesisLedger (true, KeyType::secp256k1); - test_genesisLedger (true, KeyType::ed25519); - -// test_genesisLedger (false, KeyType::secp256k1); -// test_genesisLedger (false, KeyType::ed25519); - - test_unsigned_fails (KeyType::secp256k1); - test_unsigned_fails (KeyType::ed25519); - - test_getQuality (); - } -}; - -BEAST_DEFINE_TESTSUITE(Ledger,ripple_app,ripple); - -#endif - -} // test -} // ripple diff --git a/src/ripple/app/ledger/tests/common_ledger.cpp b/src/ripple/app/ledger/tests/common_ledger.cpp deleted file mode 100644 index fae95ec65..000000000 --- a/src/ripple/app/ledger/tests/common_ledger.cpp +++ /dev/null @@ -1,569 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012-2015 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 -#include -#include -#include -#include -#include - -#if 0 - -namespace ripple { -namespace test { - -Json::Value -TestJson::getJson() const -{ - Json::Value tx_json; - getJson(tx_json); - return tx_json; -} - -Currency::Currency(std::string currency) - : currency_(currency) -{ -} - -void -Currency::getJson(Json::Value& tx_json) const -{ - tx_json[jss::currency] = currency_; -} - -std::string -Currency::getCurrency() const -{ - return currency_; -} - - -Issuer::Issuer(TestAccount issuer) - :issuer_(issuer) -{ -} - -void -Issuer::getJson(Json::Value& tx_json) const -{ - tx_json[jss::issuer] = toBase58(calcAccountID(issuer_.pk)); -} - -TestAccount const& -Issuer::getAccount() const -{ - return issuer_; -} - - -Amount::Amount(double value, std::string currency, TestAccount issuer) - : value_(value) - , currency_(Currency(currency)) - , issuer_(Issuer(issuer)) -{ -} - -void -Amount::getJson(Json::Value& tx_json) const -{ - currency_.getJson(tx_json); - issuer_.getJson(tx_json); - tx_json[jss::value] = std::to_string(value_); -} - -double -Amount::getValue() const -{ - return value_; -} - -TestAccount const& -Amount::getIssuer() const -{ - return issuer_.getAccount(); -} - -Currency const& -Amount::getCurrency() const -{ - return currency_; -} - - -// Helper function to parse a transaction in Json, sign it with account, -// and return it as a STTx -STTx -parseTransaction(TestAccount& account, Json::Value const& tx_json, bool sign) -{ - STParsedJSONObject parsed("tx_json", tx_json); - if (!parsed.object) - throw std::runtime_error( - "object not parseable"); - parsed.object->setFieldVL(sfSigningPubKey, account.pk.getAccountPublic()); - auto tx = STTx(std::move (*parsed.object)); - if (sign) - tx.sign(account.sk); - return tx; -} - -// Helper function to apply a transaction to a ledger -void -applyTransaction(Ledger::pointer const& ledger, STTx const& tx, bool check) -{ - auto const r = apply (*ledger, tx, - check ? tapNONE : tapNO_CHECK_SIGN, getConfig(), - beast::Journal{}); - if (r.first != tesSUCCESS) - throw std::runtime_error("r != tesSUCCESS"); - if (!r.second) - throw std::runtime_error("didApply"); -} - -// Create genesis ledger from a start amount in drops, and the public -// master RippleAddress -std::pair, Ledger::pointer> -createGenesisLedger(std::uint64_t start_amount_drops, TestAccount const& master) -{ - initializePathfinding(); - auto ledger = std::make_shared(master.pk, - start_amount_drops); - ledger->getHash(); // updates the hash - ledger->setClosed(); - if (!ledger->assertSane()) - throw std::runtime_error( - "! ledger->assertSane()"); - return std::make_pair(std::move(ledger), std::make_shared(false, *ledger)); -} - -// Create an account represented by public RippleAddress and private -// RippleAddress -TestAccount -createAccount(std::string const& passphrase, KeyType keyType) -{ - RippleAddress const seed - = RippleAddress::createSeedGeneric(passphrase); - - auto keyPair = generateKeysFromSeed(keyType, seed); - - return { - std::move(keyPair.publicKey), - std::move(keyPair.secretKey), - std::uint64_t(0) - }; -} - -TestAccount -createAndFundAccount(TestAccount& from, std::string const& passphrase, - KeyType keyType, std::uint64_t amountDrops, - Ledger::pointer const& ledger, bool sign) -{ - auto to = createAccount(passphrase, keyType); - pay(from, to, amountDrops, ledger, sign); - return to; -} - -std::map -createAndFundAccounts(TestAccount& from, std::vector passphrases, - KeyType keyType, std::uint64_t amountDrops, - Ledger::pointer const& ledger, bool sign) -{ - std::map accounts; - for (auto const& passphrase : passphrases) - { - auto to = createAndFundAccount(from, passphrase, keyType, - amountDrops, ledger, sign); - accounts.emplace(passphrase, std::move(to)); - } - return accounts; -} - -std::map -createAndFundAccountsWithFlags(TestAccount& from, - std::vector passphrases, - KeyType keyType, std::uint64_t amountDrops, - Ledger::pointer& ledger, - std::shared_ptr& LCL, - const std::uint32_t flags, bool sign) -{ - auto accounts = createAndFundAccounts(from, - passphrases, keyType, amountDrops, ledger, sign); - close_and_advance(ledger, LCL); - setAllAccountFlags(accounts, ledger, flags); - close_and_advance(ledger, LCL); - return accounts; -} - -Json::Value -getCommonTransactionJson(TestAccount& account) -{ - Json::Value tx_json; - tx_json[jss::Account] = toBase58(calcAccountID(account.pk)); - tx_json[jss::Fee] = std::to_string(10); - tx_json[jss::Sequence] = ++account.sequence; - return tx_json; -} - -void -setAccountFlags(TestAccount& account, Ledger::pointer const& ledger, - const std::uint32_t flags, bool sign) -{ - Json::Value tx_json = getCommonTransactionJson(account); - tx_json[jss::TransactionType] = "AccountSet"; - tx_json[jss::SetFlag] = flags; - STTx tx = parseTransaction(account, tx_json, sign); - applyTransaction(ledger, tx, sign); -} - -void -setAllAccountFlags(std::vector& accounts, Ledger::pointer const& ledger, -const std::uint32_t flags, bool sign) -{ - for (auto& account : accounts) - { - setAccountFlags(account, ledger, flags, sign); - } -} - -void -clearAccountFlags(TestAccount& account, Ledger::pointer const& ledger, - const std::uint32_t flags, bool sign) -{ - Json::Value tx_json = getCommonTransactionJson(account); - tx_json[jss::TransactionType] = "AccountSet"; - tx_json[jss::ClearFlag] = flags; - STTx tx = parseTransaction(account, tx_json, sign); - applyTransaction(ledger, tx, sign); -} - -void -freezeAccount(TestAccount& account, Ledger::pointer const& ledger, bool sign) -{ - setAccountFlags(account, ledger, asfGlobalFreeze, sign); -} - -void -unfreezeAccount(TestAccount& account, Ledger::pointer const& ledger, bool sign) -{ - clearAccountFlags(account, ledger, asfGlobalFreeze, sign); -} - -Json::Value -getPaymentJson(TestAccount& from, TestAccount const& to, - Json::Value amountJson) -{ - Json::Value tx_json = getCommonTransactionJson(from); - tx_json[jss::Amount] = amountJson; - tx_json[jss::Destination] = toBase58(calcAccountID(to.pk)); - tx_json[jss::TransactionType] = "Payment"; - tx_json[jss::Flags] = tfUniversal; - return tx_json; -} - -STTx -getPaymentTx(TestAccount& from, TestAccount const& to, - std::uint64_t amountDrops, - bool sign) -{ - Json::Value tx_json = getPaymentJson(from, to, - std::to_string(amountDrops)); - return parseTransaction(from, tx_json, sign); -} - -STTx -pay(TestAccount& from, TestAccount const& to, - std::uint64_t amountDrops, - Ledger::pointer const& ledger, bool sign) -{ - auto tx = getPaymentTx(from, to, amountDrops, sign); - applyTransaction(ledger, tx, sign); - return tx; -} - -STTx -getPaymentTx(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - bool sign) -{ - Json::Value tx_json = getPaymentJson(from, to, - Amount(std::stod(amount), currency, to).getJson()); - return parseTransaction(from, tx_json, sign); -} - -STTx -pay(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, bool sign) -{ - auto tx = getPaymentTx(from, to, currency, amount, sign); - applyTransaction(ledger, tx, sign); - return tx; -} - -STTx -getPaymentTxWithPath(TestAccount& from, TestAccount const& to, -std::string const& currency, std::string const& amount, -Ledger::pointer const& ledger, bool sign) -{ - auto amountJson = Amount(std::stod(amount), currency, to).getJson(); - Json::Value tx_json = getPaymentJson(from, to, amountJson); - - // Find path. Note that the sign command can do this transparently - // with the "build_path" field, but we don't have that here. - auto cache = std::make_shared(ledger); - STPathSet pathSet; - STPath fullLiquidityPath; - auto stDstAmount = amountFromJson(sfGeneric, amountJson); - Issue srcIssue = Issue(stDstAmount.getCurrency(), - calcAccountID(from.pk)); - - auto found = findPathsForOneIssuer(cache, - calcAccountID(from.pk), calcAccountID(to.pk), - srcIssue, stDstAmount, 7, 4, pathSet, fullLiquidityPath); - if (!found) - throw std::runtime_error( - "!found"); - if (pathSet.isDefault()) - throw std::runtime_error( - "pathSet.isDefault()"); - - tx_json[jss::Paths] = pathSet.getJson(0); - - return parseTransaction(from, tx_json, sign); -} - -STTx -payWithPath(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, bool sign) -{ - auto tx = getPaymentTxWithPath(from, to, currency, amount, ledger, sign); - applyTransaction(ledger, tx, sign); - return tx; -} - -STTx -payWithPath(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, Json::Value const& path, - std::uint32_t flags, bool sign) -{ - auto amountJson = Amount(std::stod(amount), currency, to).getJson(); - Json::Value tx_json = getPaymentJson(from, to, amountJson); - - tx_json[jss::Paths] = path; - tx_json[jss::Flags] = flags; - - auto tx = parseTransaction(from, tx_json, sign); - applyTransaction(ledger, tx, sign); - return tx; -} - - -void -createOffer(TestAccount& from, Amount const& in, Amount const& out, - Ledger::pointer ledger, bool sign) -{ - Json::Value tx_json = getCommonTransactionJson(from); - tx_json[jss::TransactionType] = "OfferCreate"; - tx_json[jss::TakerPays] = in.getJson(); - tx_json[jss::TakerGets] = out.getJson(); - STTx tx = parseTransaction(from, tx_json, sign); - applyTransaction(ledger, tx, sign); -} - -void -createOfferWithFlags(TestAccount& from, Amount const& in, Amount const& out, - Ledger::pointer ledger, std::uint32_t flags, - bool sign) -{ - Json::Value tx_json = getCommonTransactionJson(from); - tx_json[jss::TransactionType] = "OfferCreate"; - tx_json[jss::TakerPays] = in.getJson(); - tx_json[jss::TakerGets] = out.getJson(); - tx_json[jss::Flags] = flags; - STTx tx = parseTransaction(from, tx_json, sign); - applyTransaction(ledger, tx, sign); -} - - -// As currently implemented, this will cancel only the last offer made -// from this account. -void -cancelOffer(TestAccount& from, Ledger::pointer ledger, bool sign) -{ - auto seq = from.sequence; - Json::Value tx_json = getCommonTransactionJson(from); - tx_json[jss::TransactionType] = "OfferCancel"; - tx_json[jss::OfferSequence] = seq; - STTx tx = parseTransaction(from, tx_json, sign); - applyTransaction(ledger, tx, sign); -} - -void -trust(TestAccount& from, TestAccount const& issuer, - std::string const& currency, double amount, - Ledger::pointer const& ledger, bool sign) -{ - Json::Value tx_json = getCommonTransactionJson(from); - Json::Value& limitAmount = tx_json[jss::LimitAmount]; - limitAmount[jss::currency] = currency; - limitAmount[jss::issuer] = toBase58(calcAccountID(issuer.pk)); - limitAmount[jss::value] = std::to_string(amount); - tx_json[jss::TransactionType] = "TrustSet"; - tx_json[jss::Flags] = 0; // tfClearNoRipple; - STTx tx = parseTransaction(from, tx_json, sign); - applyTransaction(ledger, tx, sign); -} - -void -close_and_advance(Ledger::pointer& ledger, std::shared_ptr& LCL) -{ - auto const& set = ledger->txMap(); - CanonicalTXSet retriableTransactions(set.getHash()); - // 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); - MetaView accum(*newLCL, tapNONE); - // Set up to write SHAMap changes to our database, - // perform updates, extract changes - applyTransactions(&set, accum, newLCL, retriableTransactions); - accum.apply(*newLCL, {}); - newLCL->updateSkipList(); - newLCL->setClosed(); - newLCL->stateMap().flushDirty( - hotACCOUNT_NODE, newLCL->info().seq); - newLCL->txMap().flushDirty( - hotTRANSACTION_NODE, newLCL->info().seq); - using namespace std::chrono; - auto const epoch_offset = days(10957); // 2000-01-01 - std::uint32_t closeTime = time_point_cast // now - (system_clock::now() - epoch_offset). - time_since_epoch().count(); - int closeResolution = seconds(ledgerDefaultTimeResolution).count(); - bool closeTimeCorrect = true; - newLCL->setAccepted(closeTime, closeResolution, closeTimeCorrect); - - if (!newLCL->assertSane()) - throw std::runtime_error( - "!newLCL->assertSane()"); - - LCL = newLCL; - ledger = std::make_shared(false, *newLCL); -} - -Json::Value findPath(Ledger::pointer ledger, TestAccount const& src, - TestAccount const& dest, std::vector srcCurrencies, - Amount const& dstAmount, beast::abstract_ostream& log, - boost::optional contextPaths) -{ - int const level = 8; - - auto cache = std::make_shared(ledger); - - STAmount saDstAmount; - if (!amountFromJsonNoThrow(saDstAmount, dstAmount.getJson())) - throw std::runtime_error( - "!amountFromJsonNoThrow(saDstAmount, dstAmount.getJson())"); - log << "Dst amount: " << saDstAmount; - - auto jvSrcCurrencies = Json::Value(Json::arrayValue); - for (auto const& srcCurrency : srcCurrencies) - { - jvSrcCurrencies.append(srcCurrency.getJson()); - } - log << "Source currencies: " << jvSrcCurrencies; - - auto result = ripplePathFind(cache, calcAccountID(src.pk), - calcAccountID(dest.pk), saDstAmount, - jvSrcCurrencies, contextPaths, level); - if(!result.first) - throw std::runtime_error( - "ripplePathFind find failed"); - - return result.second; -} - -std::shared_ptr -getLedgerEntryRippleState(Ledger::pointer ledger, - TestAccount const& account1, TestAccount const& account2, - Currency currency) -{ - auto k = keylet::line( - calcAccountID(account1.pk), calcAccountID(account2.pk), - to_currency(currency.getCurrency())); - - if (! k.key.isNonZero()) - throw std::runtime_error( - "!k.key.isNonZero()"); - - return ledger->read(k); -} - -void -verifyBalance(Ledger::pointer ledger, TestAccount const& account, - Amount const& amount) -{ - auto const sle = getLedgerEntryRippleState(ledger, account, - amount.getIssuer(), amount.getCurrency()); - if (!sle) - throw std::runtime_error( - "!sle"); - STAmount amountReq; - amountFromJsonNoThrow(amountReq, amount.getJson()); - - auto high = sle->getFieldAmount(sfHighLimit); - auto balance = sle->getFieldAmount(sfBalance); - if (high.getIssuer() == calcAccountID(account.pk)) - { - balance.negate(); - } - if (balance != amountReq) - throw std::runtime_error( - "balance != amountReq"); -} - -Json::Value pathNode (TestAccount const& acc) -{ - Json::Value result; - result["account"] = toBase58(calcAccountID(acc.pk)); - result["type"] = 1; - result["type_hex"] = "0000000000000001"; - return result; -} - -Json::Value pathNode (OfferPathNode const& offer) -{ - Json::Value result; - result["currency"] = offer.currency; - result["type"] = 48; - result["type_hex"] = "0000000000000030"; - if (offer.issuer) - result["issuer"] = toBase58(calcAccountID(offer.issuer->pk)); - return result; -} - -} -} - -#endif diff --git a/src/ripple/app/ledger/tests/common_ledger.h b/src/ripple/app/ledger/tests/common_ledger.h deleted file mode 100644 index 9506b98cc..000000000 --- a/src/ripple/app/ledger/tests/common_ledger.h +++ /dev/null @@ -1,294 +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_APP_TESTS_COMMON_LEDGER_H_INCLUDED -#define RIPPLE_APP_TESTS_COMMON_LEDGER_H_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ripple { -namespace test { - -struct TestAccount -{ - RippleAddress pk; - RippleAddress sk; - unsigned sequence; -}; - -struct TestJson -{ - Json::Value - getJson() const; - - virtual void - getJson(Json::Value& tx_json) const = 0; -}; - -struct Currency : TestJson -{ - Currency(std::string currency); - - void - getJson(Json::Value& tx_json) const override; - - std::string - getCurrency() const; - - using TestJson::getJson; - -private: - std::string currency_; -}; - -struct Issuer : TestJson -{ - Issuer(TestAccount issuer); - - void - getJson(Json::Value& tx_json) const override; - - TestAccount const& - getAccount() const; - - using TestJson::getJson; - -private: - TestAccount issuer_; -}; - -struct Amount : TestJson -{ - Amount(double value, std::string currency, TestAccount issuer); - - void - getJson(Json::Value& tx_json) const override; - - double - getValue() const; - - TestAccount const& - getIssuer() const; - - Currency const& - getCurrency() const; - - using TestJson::getJson; - -private: - double value_; - Currency currency_; - Issuer issuer_; -}; - -// Helper function to parse a transaction in Json, sign it with account, -// and return it as a STTx -STTx -parseTransaction(TestAccount& account, Json::Value const& tx_json, bool sign = true); - -// Helper function to apply a transaction to a ledger -void -applyTransaction(Ledger::pointer const& ledger, STTx const& tx, bool check = true); - -// Create genesis ledger from a start amount in drops, and the public -// master RippleAddress -std::pair, Ledger::pointer> -createGenesisLedger(std::uint64_t start_amount_drops, TestAccount const& master); - -// Create an account represented by public RippleAddress and private -// RippleAddress -TestAccount -createAccount(std::string const& passphrase, KeyType keyType); - -TestAccount -createAndFundAccount(TestAccount& from, std::string const& passphrase, - KeyType keyType, std::uint64_t amountDrops, - Ledger::pointer const& ledger, bool sign = true); - -std::map -createAndFundAccounts(TestAccount& from, std::vector passphrases, - KeyType keyType, std::uint64_t amountDrops, - Ledger::pointer const& ledger, bool sign = true); - -std::map -createAndFundAccountsWithFlags(TestAccount& from, - std::vector passphrases, - KeyType keyType, std::uint64_t amountDrops, - Ledger::pointer& ledger, - std::shared_ptr& LCL, - const std::uint32_t flags, bool sign = true); - -void -setAccountFlags(TestAccount& account, Ledger::pointer const& ledger, - const std::uint32_t flags, bool sign = true); - -void -setAllAccountFlags(std::vector& accounts, Ledger::pointer const& ledger, - const std::uint32_t flags, bool sign = true); - -template -void -setAllAccountFlags(std::map& accounts, Ledger::pointer const& ledger, -const std::uint32_t flags, bool sign = true) -{ - for (auto& pair : accounts) - { - setAccountFlags(pair.second, ledger, flags, sign); - } -} - -void -clearAccountFlags(TestAccount& account, Ledger::pointer const& ledger, - const std::uint32_t flags, bool sign = true); - -void -freezeAccount(TestAccount& account, Ledger::pointer const& ledger, bool sign = true); - -void -unfreezeAccount(TestAccount& account, Ledger::pointer const& ledger, bool sign = true); - -STTx -getPaymentTx(TestAccount& from, TestAccount const& to, - std::uint64_t amountDrops, - bool sign = true); - -STTx -pay(TestAccount& from, TestAccount const& to, - std::uint64_t amountDrops, - Ledger::pointer const& ledger, bool sign = true); - -STTx -getPaymentTx(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - bool sign = true); - -STTx -pay(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, bool sign = true); - -STTx -getPaymentTxWithPath(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, bool sign = true); - -STTx -payWithPath(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, bool sign = true); - -STTx -payWithPath(TestAccount& from, TestAccount const& to, - std::string const& currency, std::string const& amount, - Ledger::pointer const& ledger, Json::Value const& path, - std::uint32_t flags, - bool sign = true); - -void -createOffer(TestAccount& from, Amount const& in, Amount const& out, - Ledger::pointer ledger, bool sign = true); - -void -createOfferWithFlags(TestAccount& from, Amount const& in, Amount const& out, - Ledger::pointer ledger, std::uint32_t flags, - bool sign = true); - -// As currently implemented, this will cancel only the last offer made -// from this account. -void -cancelOffer(TestAccount& from, Ledger::pointer ledger, bool sign = true); - -void -trust(TestAccount& from, TestAccount const& issuer, - std::string const& currency, double amount, - Ledger::pointer const& ledger, bool sign = true); - -void -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, - Amount const& dstAmount, beast::abstract_ostream& log, - boost::optional contextPaths = boost::none); - -struct OfferPathNode -{ - std::string currency; - boost::optional issuer; - OfferPathNode(std::string s, TestAccount const& iss) - :currency(std::move(s)), issuer(iss) {} -}; - -Json::Value pathNode (TestAccount const& acc); - -Json::Value pathNode (OfferPathNode const& offer); - -inline void createPathHelper (Json::Value& result) -{ - // base case -} - -template -void createPathHelper (Json::Value& result, - First&& first, - Rest&&... rest) -{ - result.append (pathNode (std::forward (first))); - createPathHelper(result, rest...); -} - -template -Json::Value createPath (First&& first, - Rest&&... rest) -{ - Json::Value result; - createPathHelper (result, first, rest...); - return result; -} - - -SLE::pointer -get_ledger_entry_ripple_state(Ledger::pointer ledger, - RippleAddress account1, RippleAddress account2, - Currency currency); - -void -verifyBalance(Ledger::pointer ledger, TestAccount const& account, Amount const& amount); - -} // test -} // ripple - -#endif diff --git a/src/ripple/ledger/tests/PathSet.h b/src/ripple/ledger/tests/PathSet.h index 0c15ac820..caa61d600 100644 --- a/src/ripple/ledger/tests/PathSet.h +++ b/src/ripple/ledger/tests/PathSet.h @@ -18,7 +18,6 @@ //============================================================================== #include -#include #include #include #include diff --git a/src/ripple/ledger/tests/PaymentSandbox_test.cpp b/src/ripple/ledger/tests/PaymentSandbox_test.cpp index 9e0fe515f..6e76e6a14 100644 --- a/src/ripple/ledger/tests/PaymentSandbox_test.cpp +++ b/src/ripple/ledger/tests/PaymentSandbox_test.cpp @@ -17,7 +17,6 @@ */ //============================================================================== -#include #include #include #include diff --git a/src/ripple/unity/app_ledger.cpp b/src/ripple/unity/app_ledger.cpp index 4b07ce883..da1509b4f 100644 --- a/src/ripple/unity/app_ledger.cpp +++ b/src/ripple/unity/app_ledger.cpp @@ -41,5 +41,3 @@ #include #include -#include -#include