diff --git a/src/ripple/test/jtx/Env.h b/src/ripple/test/jtx/Env.h index e6de9ff0ca..34cff51f16 100644 --- a/src/ripple/test/jtx/Env.h +++ b/src/ripple/test/jtx/Env.h @@ -37,7 +37,6 @@ #include #include #include -#include #include // #include // #include @@ -49,36 +48,6 @@ namespace ripple { namespace test { namespace jtx { -/** A view to an account's account root. */ -class AccountInfo -{ -private: - Account account_; - std::shared_ptr ledger_; - std::shared_ptr root_; - -public: - AccountInfo(Account const& account, - std::shared_ptr ledger) - : account_(account) - , ledger_(std::move(ledger)) - , root_(ledger_->fetch( - getAccountRootIndex(account.id()))) - { - } - - STAmount - balance (Issue const& issue) const; - - std::uint32_t - seq() const; - - std::uint32_t - flags() const; -}; - -//------------------------------------------------------------------------------ - namespace detail { #ifdef _MSC_VER @@ -164,10 +133,10 @@ public: /** Returns the Account given the AccountID. */ /** @{ */ Account const& - lookup (std::string const& base58ID) const; + lookup (AccountID const& id) const; Account const& - lookup (AccountID const& id) const; + lookup (std::string const& base58ID) const; /** @} */ /** Returns the XRP balance on an account. @@ -204,26 +173,6 @@ public: std::shared_ptr le (uint256 const& key) const; - /** Set the fee autofill setting. */ - void auto_fee (bool value) - { - fill_fee_ = value; - } - - /** Set the sequence number autofill setting. */ - void auto_seq (bool value) - { - fill_seq_ = value; - } - - /** Set the signature autofill setting. - @note autofill multisigning is not supported - */ - void auto_sig (bool value) - { - fill_sig_ = value; - } - /** Create a JTx from parameters. */ template @@ -468,10 +417,6 @@ protected: // Map of account IDs to Account std::unordered_map< AccountID, Account> map_; - - bool fill_fee_ = true; - bool fill_seq_ = true; - bool fill_sig_ = true; }; } // jtx diff --git a/src/ripple/test/jtx/JTx.h b/src/ripple/test/jtx/JTx.h index 1c5da26e00..1b3e9ad84a 100644 --- a/src/ripple/test/jtx/JTx.h +++ b/src/ripple/test/jtx/JTx.h @@ -23,7 +23,6 @@ #include #include #include -#include #include namespace ripple { @@ -32,17 +31,15 @@ namespace jtx { class Env; -BOOST_TRIBOOL_THIRD_STATE(use_default) - /** Execution context for applying a JSON transaction. This augments the transaction with various settings. */ struct JTx { Json::Value jv; - boost::tribool fill_fee = boost::logic::indeterminate; - boost::tribool fill_seq = boost::logic::indeterminate; - boost::tribool fill_sig = boost::logic::indeterminate; + bool fill_fee = true; + bool fill_seq = true; + bool fill_sig = true; std::function signer; requires_t requires; TER ter = tesSUCCESS; diff --git a/src/ripple/test/jtx/fee.h b/src/ripple/test/jtx/fee.h index e112f04e24..890227a0f1 100644 --- a/src/ripple/test/jtx/fee.h +++ b/src/ripple/test/jtx/fee.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace ripple { namespace test { @@ -33,28 +33,26 @@ namespace jtx { class fee { private: - STAmount v_; - boost::tribool b_ = - boost::logic::indeterminate; + bool manual_ = true; + boost::optional amount_; public: explicit fee (autofill_t) - : b_(true) + : manual_(false) { } explicit fee (none_t) - : b_(false) { } explicit - fee (STAmount const& v) - : v_(v) + fee (STAmount const& amount) + : amount_(amount) { - if (! isXRP(v_)) + if (! isXRP(*amount_)) throw std::runtime_error( "fee: not XRP"); } diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp index a769679dba..97c6162b5a 100644 --- a/src/ripple/test/jtx/impl/Env.cpp +++ b/src/ripple/test/jtx/impl/Env.cpp @@ -67,16 +67,6 @@ Env::memoize (Account const& account) map_.emplace(account.id(), account); } -Account const& -Env::lookup (std::string const& base58ID) const -{ - RippleAddress ra; - if (! ra.setAccountID(base58ID)) - throw std::runtime_error( - "Env::lookup: invalid account ID"); - return lookup(ra.getAccountID()); -} - Account const& Env::lookup (AccountID const& id) const { @@ -87,6 +77,16 @@ Env::lookup (AccountID const& id) const return iter->second; } +Account const& +Env::lookup (std::string const& base58ID) const +{ + RippleAddress ra; + if (! ra.setAccountID(base58ID)) + throw std::runtime_error( + "Env::lookup: invalid account ID"); + return lookup(ra.getAccountID()); +} + PrettyAmount Env::balance (Account const& account) const { @@ -130,24 +130,14 @@ Env::seq (Account const& account) const std::shared_ptr Env::le (Account const& account) const { - // VFALCO NOTE This hack should be removed - // when fetch returns shared_ptr again - auto const st = ledger->fetch( + return ledger->fetch( getAccountRootIndex(account.id())); - if (! st) - return nullptr; - return std::make_shared(*st); } std::shared_ptr Env::le (uint256 const& key) const { - // VFALCO NOTE This hack should be removed - // when fetch returns shared_ptr again - auto const st = ledger->fetch(key); - if (! st) - return nullptr; - return std::make_shared(*st); + return ledger->fetch(key); } void @@ -229,21 +219,13 @@ void Env::autofill_sig (JTx& jt) { auto& jv = jt.jv; - auto const should = [](boost::tribool v, bool b) - { - if (boost::indeterminate(v)) - return b; - return bool(v); - }; - if (jt.signer) jt.signer(*this, jt); - else if(should(jt.fill_sig, fill_sig_)) + else if(jt.fill_sig) { auto const account = lookup(jv[jss::Account].asString()); - auto const ar = - ledger->fetch(getAccountRootIndex(account)); + auto const ar = le(account); if (ar->isFieldPresent(sfRegularKey)) jtx::sign(jv, lookup( ar->getFieldAccount160(sfRegularKey))); @@ -256,19 +238,10 @@ void Env::autofill (JTx& jt) { auto& jv = jt.jv; - auto const should = [](boost::tribool v, bool b) - { - if (boost::indeterminate(v)) - return b; - return bool(v); - }; - - if(should(jt.fill_fee, fill_fee_)) + if(jt.fill_fee) jtx::fill_fee(jv, *ledger); - - if(should(jt.fill_seq, fill_seq_)) + if(jt.fill_seq) jtx::fill_seq(jv, *ledger); - // Must come last autofill_sig(jt); } diff --git a/src/ripple/test/jtx/impl/Env_test.cpp b/src/ripple/test/jtx/impl/Env_test.cpp index 5a6635dd64..ef4ea7074c 100644 --- a/src/ripple/test/jtx/impl/Env_test.cpp +++ b/src/ripple/test/jtx/impl/Env_test.cpp @@ -165,13 +165,6 @@ public: env.require(nflags("xavier", asfDefaultRipple)); env.fund(n, "yana"); env.require(flags("yana", asfDefaultRipple)); - - // fund always autofills - env.auto_fee(false); - env.auto_seq(false); - env.auto_sig(false); - env.fund(n, "zeke"); - env.require(balance("zeke", n)); } // trust @@ -179,13 +172,6 @@ public: Env env(*this); env.fund(n, "alice", "bob", gw); env(trust("alice", USD(100)), require(lines("alice", 1))); - - // trust always autofills - env.auto_fee(false); - env.auto_seq(false); - env.auto_sig(false); - env.trust(USD(100), "bob"); - env.require(lines("bob", 1)); } // balance @@ -215,7 +201,6 @@ public: { Env env(*this); env.fund(n, "alice"); - env.auto_fee(false); env.require(balance("alice", n)); env(noop("alice"), fee(1), ter(telINSUF_FEE_P)); env(noop("alice"), seq(none), ter(temMALFORMED)); @@ -223,9 +208,7 @@ public: env(noop("alice"), fee(none), ter(temMALFORMED)); env(noop("alice"), sig(none), ter(temMALFORMED)); env(noop("alice"), fee(autofill)); - env.auto_seq(false); env(noop("alice"), fee(autofill), seq(autofill)); - env.auto_sig(false); env(noop("alice"), fee(autofill), seq(autofill), sig(autofill)); } } diff --git a/src/ripple/test/jtx/impl/fee.cpp b/src/ripple/test/jtx/impl/fee.cpp index 0fd5b903b2..219745c8a7 100644 --- a/src/ripple/test/jtx/impl/fee.cpp +++ b/src/ripple/test/jtx/impl/fee.cpp @@ -28,11 +28,12 @@ namespace jtx { void fee::operator()(Env const&, JTx& jt) const { - if (boost::indeterminate(b_)) + if (! manual_) + return; + jt.fill_fee = false; + if (amount_) jt[jss::Fee] = - v_.getJson(0); - else - jt.fill_fee = b_; + amount_->getJson(0); } } // jtx diff --git a/src/ripple/test/jtx/impl/seq.cpp b/src/ripple/test/jtx/impl/seq.cpp index 95f69c532c..fe198c8067 100644 --- a/src/ripple/test/jtx/impl/seq.cpp +++ b/src/ripple/test/jtx/impl/seq.cpp @@ -28,10 +28,11 @@ namespace jtx { void seq::operator()(Env const&, JTx& jt) const { - if (boost::indeterminate(b_)) - jt[jss::Sequence] = v_; - else - jt.fill_seq = b_; + if (! manual_) + return; + jt.fill_seq = false; + if (num_) + jt[jss::Sequence] = *num_; } } // jtx diff --git a/src/ripple/test/jtx/impl/sig.cpp b/src/ripple/test/jtx/impl/sig.cpp index dd786ca151..7a06aacbe8 100644 --- a/src/ripple/test/jtx/impl/sig.cpp +++ b/src/ripple/test/jtx/impl/sig.cpp @@ -28,19 +28,18 @@ namespace jtx { void sig::operator()(Env const&, JTx& jt) const { - if(boost::indeterminate(b_)) + if (! manual_) + return; + jt.fill_sig = false; + if(account_) { // VFALCO Inefficient pre-C++14 - auto const account = account_; + auto const account = *account_; jt.signer = [account](Env&, JTx& jt) { jtx::sign(jt.jv, account); }; } - else - { - jt.fill_sig = b_; - } } } // jtx diff --git a/src/ripple/test/jtx/seq.h b/src/ripple/test/jtx/seq.h index e176c9ceeb..d91b2be45d 100644 --- a/src/ripple/test/jtx/seq.h +++ b/src/ripple/test/jtx/seq.h @@ -22,7 +22,7 @@ #include #include -#include +#include namespace ripple { namespace test { @@ -32,26 +32,24 @@ namespace jtx { struct seq { private: - std::uint32_t v_; - boost::tribool b_ = - boost::logic::indeterminate; + bool manual_ = true; + boost::optional num_; public: explicit seq (autofill_t) - : b_(true) + : manual_(false) { } explicit seq (none_t) - : b_(false) { } explicit - seq (std::uint32_t v) - : v_(v) + seq (std::uint32_t num) + : num_(num) { } diff --git a/src/ripple/test/jtx/sig.h b/src/ripple/test/jtx/sig.h index beeb79b2b7..ada0fcd9bd 100644 --- a/src/ripple/test/jtx/sig.h +++ b/src/ripple/test/jtx/sig.h @@ -21,6 +21,7 @@ #define RIPPLE_TEST_JTX_SIG_H_INCLUDED #include +#include namespace ripple { namespace test { @@ -32,20 +33,18 @@ namespace jtx { class sig { private: - Account account_; - boost::tribool b_ = - boost::logic::indeterminate; + bool manual_ = true; + boost::optional account_; public: explicit sig (autofill_t) - : b_(true) + : manual_(false) { } explicit sig (none_t) - : b_(false) { }