diff --git a/src/ripple/app/book/impl/Taker.cpp b/src/ripple/app/book/impl/Taker.cpp index ab98ed6c91..fac4302f91 100644 --- a/src/ripple/app/book/impl/Taker.cpp +++ b/src/ripple/app/book/impl/Taker.cpp @@ -294,7 +294,7 @@ BasicTaker::flow_iou_to_iou ( f.issuers.in = rate_in.multiply (f.order.in); } - // Clamp on the taker's input balance and input offer + // Clamp on the taker's input offer if (remaining_.in < f.order.in) { f.order.in = remaining_.in; @@ -303,7 +303,8 @@ BasicTaker::flow_iou_to_iou ( f.issuers.out = rate_out.multiply (f.order.out); } - if (taker_funds < f.order.in) + // Clamp on the taker's input balance + if (taker_funds < f.issuers.in) { f.issuers.in = taker_funds; f.order.in = rate_in.divide (f.issuers.in); @@ -503,7 +504,15 @@ TER Taker::redeem_iou ( if (account == issue.account) return tesSUCCESS; - return m_view.redeem_iou (account, amount, issue); + if (get_funds (account, amount) <= zero) + throw std::logic_error ("redeem_iou has no funds to redeem"); + + auto ret = m_view.redeem_iou (account, amount, issue); + + if (get_funds (account, amount) < zero) + throw std::logic_error ("redeem_iou redeemed more funds than available"); + + return ret; } TER Taker::issue_iou ( diff --git a/src/ripple/app/book/tests/Taker.test.cpp b/src/ripple/app/book/tests/Taker.test.cpp index 126ff5c3df..d5973492b8 100644 --- a/src/ripple/app/book/tests/Taker.test.cpp +++ b/src/ripple/app/book/tests/Taker.test.cpp @@ -229,8 +229,6 @@ private: " Actual: " << format_amount (result.in) << " : " << format_amount (result.out); } - - assert (expected == result); } Quality get_quality(std::string in, std::string out) @@ -239,10 +237,6 @@ private: } public: - Taker_test () - { - } - // Notation for clamp scenario descriptions: // // IN:OUT (with the last in the list being limiting factor) @@ -356,6 +350,7 @@ public: attempt (Buy, "N:T", q1, { "1", "1" }, "10", q1, { "2", "2" }, "10", { "1", "1" }, eur(), usd(), rate, rate); attempt (Buy, "N:BT", q1, { "2", "2" }, "10", q1, { "6", "6" }, "5", { "2", "2" }, eur(), usd(), rate, rate); attempt (Buy, "N:TB", q1, { "2", "2" }, "2", q1, { "6", "6" }, "1", { "0.6666666666666667", "0.6666666666666667" }, eur(), usd(), rate, rate); + attempt (Sell, "A:N", q1, { "2", "2" }, "2.5", q1, { "2", "2" }, "10", { "1.666666666666666", "1.666666666666666" }, eur(), usd(), rate, rate); } void