Correctly clamp when the taker balance is the limiting factor

This commit is contained in:
Nik Bougalis
2015-05-12 21:07:26 -07:00
committed by Vinnie Falco
parent 7efd0ab0d6
commit 8289d4140a
2 changed files with 13 additions and 9 deletions

View File

@@ -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 (

View File

@@ -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