20 #include <ripple/app/tx/impl/Taker.h>
21 #include <ripple/beast/unit_test.h>
22 #include <ripple/beast/core/LexicalCast.h>
29 static bool const Buy =
false;
30 static bool const Sell =
true;
41 Amounts
const& amount,
42 Quality
const& quality,
75 cross (Amounts offer, Quality quality)
78 return Amounts (offer.in.zeroed (), offer.out.zeroed ());
82 return Amounts (offer.in.zeroed (), offer.out.zeroed ());
85 return Amounts (offer.in.zeroed (), offer.out.zeroed ());
95 cross (Amounts offer1, Quality quality1, Amounts offer2, Quality quality2)
103 Amounts { offer1.in.zeroed (), offer1.out.zeroed () },
104 Amounts { offer2.in.zeroed (), offer2.out.zeroed () });
108 Amounts { offer1.in.zeroed (), offer1.out.zeroed () },
109 Amounts { offer2.in.zeroed (), offer2.out.zeroed () });
122 static Issue const issue (
129 static Issue const issue (
136 static Issue const issue (
183 Quality taker_quality,
186 Quality cross_quality,
190 Issue const& issue_in,
191 Issue const& issue_out,
197 offer.out, issue_out));
201 cross.
out, issue_out));
205 if (
isXRP (issue_out))
207 else if (
isXRP (issue_in))
214 TestTaker taker (cross_type, taker_offer, taker_quality,
220 auto result = taker.
cross (cross_offer, cross_quality);
224 flow.out, issue_out));
226 BEAST_EXPECT(expected == result);
228 if (expected != result)
260 testcase (
"XRP Quantization: input");
267 attempt (
Sell,
"N:N", q1, {
"2",
"2" },
"2", q1, {
"2",
"2" },
"2", {
"2",
"2" },
xrp(),
usd());
268 attempt (
Sell,
"N:B", q1, {
"2",
"2" },
"2", q1, {
"2",
"2" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
269 attempt (
Buy,
"N:T", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"2", {
"1",
"1" },
xrp(),
usd());
270 attempt (
Buy,
"N:BT", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"1.8", {
"1",
"1" },
xrp(),
usd());
271 attempt (
Buy,
"N:TB", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"0.8", {
"0",
"0.8" },
xrp(),
usd());
273 attempt (
Sell,
"T:N", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"2", {
"1",
"1" },
xrp(),
usd());
274 attempt (
Sell,
"T:B", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
275 attempt (
Buy,
"T:T", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"2", {
"1",
"1" },
xrp(),
usd());
276 attempt (
Buy,
"T:BT", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"1.8", {
"1",
"1" },
xrp(),
usd());
277 attempt (
Buy,
"T:TB", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"0.8", {
"0",
"0.8" },
xrp(),
usd());
279 attempt (
Sell,
"A:N", q1, {
"2",
"2" },
"1", q1, {
"2",
"2" },
"2", {
"1",
"1" },
xrp(),
usd());
280 attempt (
Sell,
"A:B", q1, {
"2",
"2" },
"1", q1, {
"2",
"2" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
281 attempt (
Buy,
"A:T", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"3", {
"1",
"1" },
xrp(),
usd());
282 attempt (
Buy,
"A:BT", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"2.4", {
"1",
"1" },
xrp(),
usd());
283 attempt (
Buy,
"A:TB", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"0.8", {
"0",
"0.8" },
xrp(),
usd());
285 attempt (
Sell,
"TA:N", q1, {
"2",
"2" },
"1", q1, {
"2",
"2" },
"2", {
"1",
"1" },
xrp(),
usd());
286 attempt (
Sell,
"TA:B", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
287 attempt (
Buy,
"TA:T", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"3", {
"1",
"1" },
xrp(),
usd());
288 attempt (
Buy,
"TA:BT", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
289 attempt (
Buy,
"TA:TB", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
291 attempt (
Sell,
"AT:N", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"3", {
"1",
"1" },
xrp(),
usd());
292 attempt (
Sell,
"AT:B", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
293 attempt (
Buy,
"AT:T", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"3", {
"1",
"1" },
xrp(),
usd());
294 attempt (
Buy,
"AT:BT", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"1.8", {
"1",
"1.8" },
xrp(),
usd());
295 attempt (
Buy,
"AT:TB", q1, {
"2",
"2" },
"1", q1, {
"3",
"3" },
"0.8", {
"0",
"0.8" },
xrp(),
usd());
301 testcase (
"XRP Quantization: output");
308 attempt (
Sell,
"N:N", q1, {
"3",
"3" },
"3", q1, {
"3",
"3" },
"3", {
"3",
"3" },
usd(),
xrp());
309 attempt (
Sell,
"N:B", q1, {
"3",
"3" },
"3", q1, {
"3",
"3" },
"2", {
"2",
"2" },
usd(),
xrp());
310 attempt (
Buy,
"N:T", q1, {
"3",
"3" },
"2.5", q1, {
"5",
"5" },
"5", {
"2.5",
"2" },
usd(),
xrp());
311 attempt (
Buy,
"N:BT", q1, {
"3",
"3" },
"1.5", q1, {
"5",
"5" },
"4", {
"1.5",
"1" },
usd(),
xrp());
312 attempt (
Buy,
"N:TB", q1, {
"3",
"3" },
"2.2", q1, {
"5",
"5" },
"1", {
"1",
"1" },
usd(),
xrp());
314 attempt (
Sell,
"T:N", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"2", {
"1",
"1" },
usd(),
xrp());
315 attempt (
Sell,
"T:B", q1, {
"2",
"2" },
"2", q1, {
"3",
"3" },
"1", {
"1",
"1" },
usd(),
xrp());
316 attempt (
Buy,
"T:T", q1, {
"1",
"1" },
"2", q1, {
"2",
"2" },
"2", {
"1",
"1" },
usd(),
xrp());
317 attempt (
Buy,
"T:BT", q1, {
"1",
"1" },
"2", q1, {
"3",
"3" },
"2", {
"1",
"1" },
usd(),
xrp());
318 attempt (
Buy,
"T:TB", q1, {
"2",
"2" },
"2", q1, {
"3",
"3" },
"1", {
"1",
"1" },
usd(),
xrp());
320 attempt (
Sell,
"A:N", q1, {
"2",
"2" },
"1.5", q1, {
"2",
"2" },
"2", {
"1.5",
"1" },
usd(),
xrp());
321 attempt (
Sell,
"A:B", q1, {
"2",
"2" },
"1.8", q1, {
"3",
"3" },
"2", {
"1.8",
"1" },
usd(),
xrp());
322 attempt (
Buy,
"A:T", q1, {
"2",
"2" },
"1.2", q1, {
"3",
"3" },
"3", {
"1.2",
"1" },
usd(),
xrp());
323 attempt (
Buy,
"A:BT", q1, {
"2",
"2" },
"1.5", q1, {
"4",
"4" },
"3", {
"1.5",
"1" },
usd(),
xrp());
324 attempt (
Buy,
"A:TB", q1, {
"2",
"2" },
"1.5", q1, {
"4",
"4" },
"1", {
"1",
"1" },
usd(),
xrp());
326 attempt (
Sell,
"TA:N", q1, {
"2",
"2" },
"1.5", q1, {
"2",
"2" },
"2", {
"1.5",
"1" },
usd(),
xrp());
327 attempt (
Sell,
"TA:B", q1, {
"2",
"2" },
"1.5", q1, {
"3",
"3" },
"1", {
"1",
"1" },
usd(),
xrp());
328 attempt (
Buy,
"TA:T", q1, {
"2",
"2" },
"1.5", q1, {
"3",
"3" },
"3", {
"1.5",
"1" },
usd(),
xrp());
329 attempt (
Buy,
"TA:BT", q1, {
"2",
"2" },
"1.8", q1, {
"4",
"4" },
"3", {
"1.8",
"1" },
usd(),
xrp());
330 attempt (
Buy,
"TA:TB", q1, {
"2",
"2" },
"1.2", q1, {
"3",
"3" },
"1", {
"1",
"1" },
usd(),
xrp());
332 attempt (
Sell,
"AT:N", q1, {
"2",
"2" },
"2.5", q1, {
"4",
"4" },
"4", {
"2",
"2" },
usd(),
xrp());
333 attempt (
Sell,
"AT:B", q1, {
"2",
"2" },
"2.5", q1, {
"3",
"3" },
"1", {
"1",
"1" },
usd(),
xrp());
334 attempt (
Buy,
"AT:T", q1, {
"2",
"2" },
"2.5", q1, {
"3",
"3" },
"3", {
"2",
"2" },
usd(),
xrp());
335 attempt (
Buy,
"AT:BT", q1, {
"2",
"2" },
"2.5", q1, {
"4",
"4" },
"3", {
"2",
"2" },
usd(),
xrp());
336 attempt (
Buy,
"AT:TB", q1, {
"2",
"2" },
"2.5", q1, {
"3",
"3" },
"1", {
"1",
"1" },
usd(),
xrp());
342 testcase (
"IOU to IOU");
352 attempt (
Sell,
"N:N", q1, {
"2",
"2" },
"10", q1, {
"2",
"2" },
"10", {
"2",
"2" },
eur(),
usd(), rate, rate);
353 attempt (
Sell,
"N:B", q1, {
"4",
"4" },
"10", q1, {
"4",
"4" },
"4", {
"2.666666666666666",
"2.666666666666666" },
eur(),
usd(), rate, rate);
354 attempt (
Buy,
"N:T", q1, {
"1",
"1" },
"10", q1, {
"2",
"2" },
"10", {
"1",
"1" },
eur(),
usd(), rate, rate);
355 attempt (
Buy,
"N:BT", q1, {
"2",
"2" },
"10", q1, {
"6",
"6" },
"5", {
"2",
"2" },
eur(),
usd(), rate, rate);
356 attempt (
Buy,
"N:TB", q1, {
"2",
"2" },
"2", q1, {
"6",
"6" },
"1", {
"0.6666666666666667",
"0.6666666666666667" },
eur(),
usd(), rate, rate);
357 attempt (
Sell,
"A:N", q1, {
"2",
"2" },
"2.5", q1, {
"2",
"2" },
"10", {
"1.666666666666666",
"1.666666666666666" },
eur(),
usd(), rate, rate);
void set_funds(STAmount const &funds)
A currency issued by an account.
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
Represents a transfer rate.
Quality composed_quality(Quality const &lhs, Quality const &rhs)
Issue const & xrp() const
void attempt(bool sell, std::string name, Quality taker_quality, cross_attempt_offer const offer, std::string const funds, Quality cross_quality, cross_attempt_offer const cross, std::string const cross_funds, cross_attempt_offer const flow, Issue const &issue_in, Issue const &issue_out, Rate rate_in=parityRate, Rate rate_out=parityRate)
BasicTaker::Flow do_cross(Amounts offer, Quality quality, AccountID const &owner)
Perform direct crossing through given offer.
bool reject(Quality const &quality) const noexcept
Returns true if the quality does not meet the taker's requirements.
std::string getText() const override
State for the active party during order book or payment operations.
Issue const & eur() const
std::string to_string(ListDisposition disposition)
Amounts cross(Amounts offer, Quality quality)
CrossType cross_type() const
Returns the type of crossing that is being performed.
const Rate parityRate(QUALITY_ONE)
A transfer rate signifying a 1:1 exchange.
Amounts parse_amounts(std::string const &amount_in, Issue const &issue_in, std::string const &amount_out, Issue const &issue_out)
std::string format_amount(STAmount const &amount)
CrossType
The flavor of an offer crossing.
STAmount get_funds(AccountID const &owner, STAmount const &funds) const override
AccountID const & xrpAccount()
Compute AccountID from public key.
bool isXRP(AccountID const &c)
cross_attempt_offer(std::string const &in_, std::string const &out_)
TestTaker(CrossType cross_type, Amounts const &amount, Quality const &quality, STAmount const &funds, std::uint32_t flags, Rate const &rate_in, Rate const &rate_out)
Issue const & usd() const
STAmount parse_amount(std::string const &amount, Issue const &issue)
bool done() const
Returns true if order crossing should not continue.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STAmount amountFromString(Issue const &issue, std::string const &amount)
const std::uint32_t tfSell
Issue const & issue() const
path::RippleCalc::Output flow(PaymentSandbox &view, STAmount const &deliver, AccountID const &src, AccountID const &dst, STPathSet const &paths, bool defaultPaths, bool partialPayment, bool ownerPaysTransferFee, bool offerCrossing, boost::optional< Quality > const &limitQuality, boost::optional< STAmount > const &sendMax, beast::Journal j, path::detail::FlowDebugInfo *flowDebugInfo=nullptr)
Make a payment from the src account to the dst account.
std::pair< Amounts, Amounts > cross(Amounts offer1, Quality quality1, Amounts offer2, Quality quality2)
Quality get_quality(std::string in, std::string out)
AccountID const & account() const noexcept
Returns the account identifier of the taker.
Currency const & xrpCurrency()
XRP currency.