rippled
Loading...
Searching...
No Matches
STAmount_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/basics/random.h>
21#include <xrpl/beast/unit_test.h>
22#include <xrpl/protocol/STAmount.h>
23
24namespace ripple {
25
27{
28public:
29 static STAmount
31 {
32 Serializer ser;
33 s.add(ser);
34
35 SerialIter sit(ser.slice());
36 return STAmount(sit, sfGeneric);
37 }
38
39 //--------------------------------------------------------------------------
41 roundSelf(STAmount const& amount)
42 {
43 if (amount.native())
44 return amount;
45
46 std::uint64_t mantissa = amount.mantissa();
47 std::uint64_t valueDigits = mantissa % 1000000000;
48
49 if (valueDigits == 1)
50 {
51 mantissa--;
52
53 if (mantissa < STAmount::cMinValue)
54 return {
55 amount.issue(),
56 mantissa,
57 amount.exponent(),
58 amount.negative()};
59
60 return {
61 amount.issue(),
62 mantissa,
63 amount.exponent(),
64 amount.negative(),
66 }
67
68 if (valueDigits == 999999999)
69 {
70 mantissa++;
71
72 if (mantissa > STAmount::cMaxValue)
73 return {
74 amount.issue(),
75 mantissa,
76 amount.exponent(),
77 amount.negative()};
78
79 return {
80 amount.issue(),
81 mantissa,
82 amount.exponent(),
83 amount.negative(),
85 }
86
87 return amount;
88 }
89
90 void
91 roundTest(int n, int d, int m)
92 {
93 // check STAmount rounding
94 STAmount num(noIssue(), n);
95 STAmount den(noIssue(), d);
96 STAmount mul(noIssue(), m);
97 STAmount quot = divide(STAmount(n), STAmount(d), noIssue());
98 STAmount res = roundSelf(multiply(quot, mul, noIssue()));
99
100 BEAST_EXPECT(!res.native());
101
102 STAmount cmp(noIssue(), (n * m) / d);
103
104 BEAST_EXPECT(!cmp.native());
105
106 BEAST_EXPECT(cmp.issue().currency == res.issue().currency);
107
108 if (res != cmp)
109 {
110 log << "(" << num.getText() << "/" << den.getText() << ") X "
111 << mul.getText() << " = " << res.getText() << " not "
112 << cmp.getText();
113 fail("Rounding");
114 return;
115 }
116 }
117
118 void
119 mulTest(int a, int b)
120 {
121 STAmount aa(noIssue(), a);
122 STAmount bb(noIssue(), b);
123 STAmount prod1(multiply(aa, bb, noIssue()));
124
125 BEAST_EXPECT(!prod1.native());
126
127 STAmount prod2(
128 noIssue(),
129 static_cast<std::uint64_t>(a) * static_cast<std::uint64_t>(b));
130
131 if (prod1 != prod2)
132 {
133 log << "nn(" << aa.getFullText() << " * " << bb.getFullText()
134 << ") = " << prod1.getFullText() << " not "
135 << prod2.getFullText();
136 fail("Multiplication result is not exact");
137 }
138 }
139
140 //--------------------------------------------------------------------------
141
142 void
144 std::string const& value,
145 Issue const& issue,
146 bool success = true)
147 {
148 try
149 {
150 STAmount const amount = amountFromString(issue, value);
151 BEAST_EXPECT(amount.getText() == value);
152 }
153 catch (std::exception const&)
154 {
155 BEAST_EXPECT(!success);
156 }
157 }
158
159 void
161 {
162 {
163 testcase("set value (native)");
164
165 Issue const xrp(xrpIssue());
166
167 // fractional XRP (i.e. drops)
168 testSetValue("1", xrp);
169 testSetValue("22", xrp);
170 testSetValue("333", xrp);
171 testSetValue("4444", xrp);
172 testSetValue("55555", xrp);
173 testSetValue("666666", xrp);
174
175 // 1 XRP up to 100 billion, in powers of 10 (in drops)
176 testSetValue("1000000", xrp);
177 testSetValue("10000000", xrp);
178 testSetValue("100000000", xrp);
179 testSetValue("1000000000", xrp);
180 testSetValue("10000000000", xrp);
181 testSetValue("100000000000", xrp);
182 testSetValue("1000000000000", xrp);
183 testSetValue("10000000000000", xrp);
184 testSetValue("100000000000000", xrp);
185 testSetValue("1000000000000000", xrp);
186 testSetValue("10000000000000000", xrp);
187 testSetValue("100000000000000000", xrp);
188
189 // Invalid native values:
190 testSetValue("1.1", xrp, false);
191 testSetValue("100000000000000001", xrp, false);
192 testSetValue("1000000000000000000", xrp, false);
193 }
194
195 {
196 testcase("set value (iou)");
197
198 Issue const usd(Currency(0x5553440000000000), AccountID(0x4985601));
199
200 testSetValue("1", usd);
201 testSetValue("10", usd);
202 testSetValue("100", usd);
203 testSetValue("1000", usd);
204 testSetValue("10000", usd);
205 testSetValue("100000", usd);
206 testSetValue("1000000", usd);
207 testSetValue("10000000", usd);
208 testSetValue("100000000", usd);
209 testSetValue("1000000000", usd);
210 testSetValue("10000000000", usd);
211
212 testSetValue("1234567.1", usd);
213 testSetValue("1234567.12", usd);
214 testSetValue("1234567.123", usd);
215 testSetValue("1234567.1234", usd);
216 testSetValue("1234567.12345", usd);
217 testSetValue("1234567.123456", usd);
218 testSetValue("1234567.1234567", usd);
219 testSetValue("1234567.12345678", usd);
220 testSetValue("1234567.123456789", usd);
221 }
222 }
223
224 //--------------------------------------------------------------------------
225
226 void
228 {
229 testcase("native currency");
230 STAmount zeroSt, one(1), hundred(100);
231 // VFALCO NOTE Why repeat "STAmount fail" so many times??
232 unexpected(serializeAndDeserialize(zeroSt) != zeroSt, "STAmount fail");
233 unexpected(serializeAndDeserialize(one) != one, "STAmount fail");
235 serializeAndDeserialize(hundred) != hundred, "STAmount fail");
236 unexpected(!zeroSt.native(), "STAmount fail");
237 unexpected(!hundred.native(), "STAmount fail");
238 unexpected(zeroSt != beast::zero, "STAmount fail");
239 unexpected(one == beast::zero, "STAmount fail");
240 unexpected(hundred == beast::zero, "STAmount fail");
241 unexpected((zeroSt < zeroSt), "STAmount fail");
242 unexpected(!(zeroSt < one), "STAmount fail");
243 unexpected(!(zeroSt < hundred), "STAmount fail");
244 unexpected((one < zeroSt), "STAmount fail");
245 unexpected((one < one), "STAmount fail");
246 unexpected(!(one < hundred), "STAmount fail");
247 unexpected((hundred < zeroSt), "STAmount fail");
248 unexpected((hundred < one), "STAmount fail");
249 unexpected((hundred < hundred), "STAmount fail");
250 unexpected((zeroSt > zeroSt), "STAmount fail");
251 unexpected((zeroSt > one), "STAmount fail");
252 unexpected((zeroSt > hundred), "STAmount fail");
253 unexpected(!(one > zeroSt), "STAmount fail");
254 unexpected((one > one), "STAmount fail");
255 unexpected((one > hundred), "STAmount fail");
256 unexpected(!(hundred > zeroSt), "STAmount fail");
257 unexpected(!(hundred > one), "STAmount fail");
258 unexpected((hundred > hundred), "STAmount fail");
259 unexpected(!(zeroSt <= zeroSt), "STAmount fail");
260 unexpected(!(zeroSt <= one), "STAmount fail");
261 unexpected(!(zeroSt <= hundred), "STAmount fail");
262 unexpected((one <= zeroSt), "STAmount fail");
263 unexpected(!(one <= one), "STAmount fail");
264 unexpected(!(one <= hundred), "STAmount fail");
265 unexpected((hundred <= zeroSt), "STAmount fail");
266 unexpected((hundred <= one), "STAmount fail");
267 unexpected(!(hundred <= hundred), "STAmount fail");
268 unexpected(!(zeroSt >= zeroSt), "STAmount fail");
269 unexpected((zeroSt >= one), "STAmount fail");
270 unexpected((zeroSt >= hundred), "STAmount fail");
271 unexpected(!(one >= zeroSt), "STAmount fail");
272 unexpected(!(one >= one), "STAmount fail");
273 unexpected((one >= hundred), "STAmount fail");
274 unexpected(!(hundred >= zeroSt), "STAmount fail");
275 unexpected(!(hundred >= one), "STAmount fail");
276 unexpected(!(hundred >= hundred), "STAmount fail");
277 unexpected(!(zeroSt == zeroSt), "STAmount fail");
278 unexpected((zeroSt == one), "STAmount fail");
279 unexpected((zeroSt == hundred), "STAmount fail");
280 unexpected((one == zeroSt), "STAmount fail");
281 unexpected(!(one == one), "STAmount fail");
282 unexpected((one == hundred), "STAmount fail");
283 unexpected((hundred == zeroSt), "STAmount fail");
284 unexpected((hundred == one), "STAmount fail");
285 unexpected(!(hundred == hundred), "STAmount fail");
286 unexpected((zeroSt != zeroSt), "STAmount fail");
287 unexpected(!(zeroSt != one), "STAmount fail");
288 unexpected(!(zeroSt != hundred), "STAmount fail");
289 unexpected(!(one != zeroSt), "STAmount fail");
290 unexpected((one != one), "STAmount fail");
291 unexpected(!(one != hundred), "STAmount fail");
292 unexpected(!(hundred != zeroSt), "STAmount fail");
293 unexpected(!(hundred != one), "STAmount fail");
294 unexpected((hundred != hundred), "STAmount fail");
295 unexpected(STAmount().getText() != "0", "STAmount fail");
296 unexpected(STAmount(31).getText() != "31", "STAmount fail");
297 unexpected(STAmount(310).getText() != "310", "STAmount fail");
298 unexpected(to_string(Currency()) != "XRP", "cHC(XRP)");
299 Currency c;
300 unexpected(!to_currency(c, "USD"), "create USD currency");
301 unexpected(to_string(c) != "USD", "check USD currency");
302
303 std::string const cur = "015841551A748AD2C1F76FF6ECB0CCCD00000000";
304 unexpected(!to_currency(c, cur), "create custom currency");
305 unexpected(to_string(c) != cur, "check custom currency");
306 }
307
308 //--------------------------------------------------------------------------
309
310 void
312 {
313 testcase("custom currency");
314 STAmount zeroSt(noIssue()), one(noIssue(), 1), hundred(noIssue(), 100);
315 unexpected(serializeAndDeserialize(zeroSt) != zeroSt, "STAmount fail");
316 unexpected(serializeAndDeserialize(one) != one, "STAmount fail");
318 serializeAndDeserialize(hundred) != hundred, "STAmount fail");
319 unexpected(zeroSt.native(), "STAmount fail");
320 unexpected(hundred.native(), "STAmount fail");
321 unexpected(zeroSt != beast::zero, "STAmount fail");
322 unexpected(one == beast::zero, "STAmount fail");
323 unexpected(hundred == beast::zero, "STAmount fail");
324 unexpected((zeroSt < zeroSt), "STAmount fail");
325 unexpected(!(zeroSt < one), "STAmount fail");
326 unexpected(!(zeroSt < hundred), "STAmount fail");
327 unexpected((one < zeroSt), "STAmount fail");
328 unexpected((one < one), "STAmount fail");
329 unexpected(!(one < hundred), "STAmount fail");
330 unexpected((hundred < zeroSt), "STAmount fail");
331 unexpected((hundred < one), "STAmount fail");
332 unexpected((hundred < hundred), "STAmount fail");
333 unexpected((zeroSt > zeroSt), "STAmount fail");
334 unexpected((zeroSt > one), "STAmount fail");
335 unexpected((zeroSt > hundred), "STAmount fail");
336 unexpected(!(one > zeroSt), "STAmount fail");
337 unexpected((one > one), "STAmount fail");
338 unexpected((one > hundred), "STAmount fail");
339 unexpected(!(hundred > zeroSt), "STAmount fail");
340 unexpected(!(hundred > one), "STAmount fail");
341 unexpected((hundred > hundred), "STAmount fail");
342 unexpected(!(zeroSt <= zeroSt), "STAmount fail");
343 unexpected(!(zeroSt <= one), "STAmount fail");
344 unexpected(!(zeroSt <= hundred), "STAmount fail");
345 unexpected((one <= zeroSt), "STAmount fail");
346 unexpected(!(one <= one), "STAmount fail");
347 unexpected(!(one <= hundred), "STAmount fail");
348 unexpected((hundred <= zeroSt), "STAmount fail");
349 unexpected((hundred <= one), "STAmount fail");
350 unexpected(!(hundred <= hundred), "STAmount fail");
351 unexpected(!(zeroSt >= zeroSt), "STAmount fail");
352 unexpected((zeroSt >= one), "STAmount fail");
353 unexpected((zeroSt >= hundred), "STAmount fail");
354 unexpected(!(one >= zeroSt), "STAmount fail");
355 unexpected(!(one >= one), "STAmount fail");
356 unexpected((one >= hundred), "STAmount fail");
357 unexpected(!(hundred >= zeroSt), "STAmount fail");
358 unexpected(!(hundred >= one), "STAmount fail");
359 unexpected(!(hundred >= hundred), "STAmount fail");
360 unexpected(!(zeroSt == zeroSt), "STAmount fail");
361 unexpected((zeroSt == one), "STAmount fail");
362 unexpected((zeroSt == hundred), "STAmount fail");
363 unexpected((one == zeroSt), "STAmount fail");
364 unexpected(!(one == one), "STAmount fail");
365 unexpected((one == hundred), "STAmount fail");
366 unexpected((hundred == zeroSt), "STAmount fail");
367 unexpected((hundred == one), "STAmount fail");
368 unexpected(!(hundred == hundred), "STAmount fail");
369 unexpected((zeroSt != zeroSt), "STAmount fail");
370 unexpected(!(zeroSt != one), "STAmount fail");
371 unexpected(!(zeroSt != hundred), "STAmount fail");
372 unexpected(!(one != zeroSt), "STAmount fail");
373 unexpected((one != one), "STAmount fail");
374 unexpected(!(one != hundred), "STAmount fail");
375 unexpected(!(hundred != zeroSt), "STAmount fail");
376 unexpected(!(hundred != one), "STAmount fail");
377 unexpected((hundred != hundred), "STAmount fail");
378 unexpected(STAmount(noIssue()).getText() != "0", "STAmount fail");
379 unexpected(STAmount(noIssue(), 31).getText() != "31", "STAmount fail");
381 STAmount(noIssue(), 31, 1).getText() != "310", "STAmount fail");
383 STAmount(noIssue(), 31, -1).getText() != "3.1", "STAmount fail");
385 STAmount(noIssue(), 31, -2).getText() != "0.31", "STAmount fail");
388 .getText() != "60",
389 "STAmount multiply fail 1");
392 .getText() != "60",
393 "STAmount multiply fail 2");
395 multiply(STAmount(20), STAmount(3), noIssue()).getText() != "60",
396 "STAmount multiply fail 3");
398 multiply(STAmount(20), STAmount(3), xrpIssue()).getText() != "60",
399 "STAmount multiply fail 4");
400
401 if (divide(STAmount(noIssue(), 60), STAmount(3), noIssue()).getText() !=
402 "20")
403 {
404 log << "60/3 = "
405 << divide(STAmount(noIssue(), 60), STAmount(3), noIssue())
406 .getText();
407 fail("STAmount divide fail");
408 }
409 else
410 {
411 pass();
412 }
413
416 .getText() != "20",
417 "STAmount divide fail");
418
421 .getText() != "20",
422 "STAmount divide fail");
423
426 .getText() != "20",
427 "STAmount divide fail");
428
429 STAmount a1(noIssue(), 60), a2(noIssue(), 10, -1);
430
432 divide(a2, a1, noIssue()) != amountFromQuality(getRate(a1, a2)),
433 "STAmount setRate(getRate) fail");
434
436 divide(a1, a2, noIssue()) != amountFromQuality(getRate(a2, a1)),
437 "STAmount setRate(getRate) fail");
438 }
439
440 //--------------------------------------------------------------------------
441
442 void
444 {
445 testcase("arithmetic");
446
447 // Test currency multiplication and division operations such as
448 // convertToDisplayAmount, convertToInternalAmount, getRate, getClaimed,
449 // and getNeeded
450
452 getRate(STAmount(1), STAmount(10)) !=
453 (((100ull - 14) << (64 - 8)) | 1000000000000000ull),
454 "STAmount getRate fail 1");
455
457 getRate(STAmount(10), STAmount(1)) !=
458 (((100ull - 16) << (64 - 8)) | 1000000000000000ull),
459 "STAmount getRate fail 2");
460
462 getRate(STAmount(noIssue(), 1), STAmount(noIssue(), 10)) !=
463 (((100ull - 14) << (64 - 8)) | 1000000000000000ull),
464 "STAmount getRate fail 3");
465
467 getRate(STAmount(noIssue(), 10), STAmount(noIssue(), 1)) !=
468 (((100ull - 16) << (64 - 8)) | 1000000000000000ull),
469 "STAmount getRate fail 4");
470
472 getRate(STAmount(noIssue(), 1), STAmount(10)) !=
473 (((100ull - 14) << (64 - 8)) | 1000000000000000ull),
474 "STAmount getRate fail 5");
475
477 getRate(STAmount(noIssue(), 10), STAmount(1)) !=
478 (((100ull - 16) << (64 - 8)) | 1000000000000000ull),
479 "STAmount getRate fail 6");
480
482 getRate(STAmount(1), STAmount(noIssue(), 10)) !=
483 (((100ull - 14) << (64 - 8)) | 1000000000000000ull),
484 "STAmount getRate fail 7");
485
487 getRate(STAmount(10), STAmount(noIssue(), 1)) !=
488 (((100ull - 16) << (64 - 8)) | 1000000000000000ull),
489 "STAmount getRate fail 8");
490
491 roundTest(1, 3, 3);
492 roundTest(2, 3, 9);
493 roundTest(1, 7, 21);
494 roundTest(1, 2, 4);
495 roundTest(3, 9, 18);
496 roundTest(7, 11, 44);
497
498 for (int i = 0; i <= 100000; ++i)
499 {
500 mulTest(rand_int(10000000), rand_int(10000000));
501 }
502 }
503
504 //--------------------------------------------------------------------------
505
506 void
508 {
509 testcase("underflow");
510
511 STAmount bigNative(STAmount::cMaxNative / 2);
512 STAmount bigValue(
513 noIssue(),
516 STAmount smallValue(
517 noIssue(),
520 STAmount zeroSt(noIssue(), 0);
521
522 STAmount smallXsmall = multiply(smallValue, smallValue, noIssue());
523
524 BEAST_EXPECT(smallXsmall == beast::zero);
525
526 STAmount bigDsmall = divide(smallValue, bigValue, noIssue());
527
528 BEAST_EXPECT(bigDsmall == beast::zero);
529
530 BEAST_EXPECT(bigDsmall == beast::zero);
531
532 bigDsmall = divide(smallValue, bigValue, xrpIssue());
533
534 BEAST_EXPECT(bigDsmall == beast::zero);
535
536 bigDsmall = divide(smallValue, bigNative, xrpIssue());
537
538 BEAST_EXPECT(bigDsmall == beast::zero);
539
540 // very bad offer
541 std::uint64_t r = getRate(smallValue, bigValue);
542
543 BEAST_EXPECT(r == 0);
544
545 // very good offer
546 r = getRate(bigValue, smallValue);
547
548 BEAST_EXPECT(r == 0);
549 }
550
551 //--------------------------------------------------------------------------
552
553 void
555 {
556 // VFALCO TODO There are no actual tests here, just printed output?
557 // Change this to actually do something.
558
559#if 0
560 beginTestCase ("rounding ");
561
562 std::uint64_t value = 25000000000000000ull;
563 int offset = -14;
564 canonicalizeRound (false, value, offset, true);
565
566 STAmount one (noIssue(), 1);
567 STAmount two (noIssue(), 2);
568 STAmount three (noIssue(), 3);
569
570 STAmount oneThird1 = divRound (one, three, noIssue(), false);
571 STAmount oneThird2 = divide (one, three, noIssue());
572 STAmount oneThird3 = divRound (one, three, noIssue(), true);
573 log << oneThird1;
574 log << oneThird2;
575 log << oneThird3;
576
577 STAmount twoThird1 = divRound (two, three, noIssue(), false);
578 STAmount twoThird2 = divide (two, three, noIssue());
579 STAmount twoThird3 = divRound (two, three, noIssue(), true);
580 log << twoThird1;
581 log << twoThird2;
582 log << twoThird3;
583
584 STAmount oneA = mulRound (oneThird1, three, noIssue(), false);
585 STAmount oneB = multiply (oneThird2, three, noIssue());
586 STAmount oneC = mulRound (oneThird3, three, noIssue(), true);
587 log << oneA;
588 log << oneB;
589 log << oneC;
590
591 STAmount fourThirdsB = twoThird2 + twoThird2;
592 log << fourThirdsA;
593 log << fourThirdsB;
594 log << fourThirdsC;
595
596 STAmount dripTest1 = mulRound (twoThird2, two, xrpIssue (), false);
597 STAmount dripTest2 = multiply (twoThird2, two, xrpIssue ());
598 STAmount dripTest3 = mulRound (twoThird2, two, xrpIssue (), true);
599 log << dripTest1;
600 log << dripTest2;
601 log << dripTest3;
602#endif
603 }
604
605 void
607 {
608 testcase("STAmount to XRPAmount conversions");
609
610 Issue const usd{Currency(0x5553440000000000), AccountID(0x4985601)};
611 Issue const xrp{xrpIssue()};
612
613 for (std::uint64_t drops = 100000000000000000; drops != 1;
614 drops = drops / 10)
615 {
616 auto const t = amountFromString(xrp, std::to_string(drops));
617 auto const s = t.xrp();
618 BEAST_EXPECT(s.drops() == drops);
619 BEAST_EXPECT(t == STAmount(XRPAmount(drops)));
620 BEAST_EXPECT(s == XRPAmount(drops));
621 }
622
623 try
624 {
625 auto const t = amountFromString(usd, "136500");
626 fail(to_string(t.xrp()));
627 }
628 catch (std::logic_error const&)
629 {
630 pass();
631 }
632 catch (std::exception const&)
633 {
634 fail("wrong exception");
635 }
636 }
637
638 void
640 {
641 testcase("STAmount to IOUAmount conversions");
642
643 Issue const usd{Currency(0x5553440000000000), AccountID(0x4985601)};
644 Issue const xrp{xrpIssue()};
645
646 for (std::uint64_t dollars = 10000000000; dollars != 1;
647 dollars = dollars / 10)
648 {
649 auto const t = amountFromString(usd, std::to_string(dollars));
650 auto const s = t.iou();
651 BEAST_EXPECT(t == STAmount(s, usd));
652 BEAST_EXPECT(s.mantissa() == t.mantissa());
653 BEAST_EXPECT(s.exponent() == t.exponent());
654 }
655
656 try
657 {
658 auto const t = amountFromString(xrp, "136500");
659 fail(to_string(t.iou()));
660 }
661 catch (std::logic_error const&)
662 {
663 pass();
664 }
665 catch (std::exception const&)
666 {
667 fail("wrong exception");
668 }
669 }
670
671 //--------------------------------------------------------------------------
672
673 void
674 run() override
675 {
676 testSetValue();
681 testRounding();
684 }
685};
686
687BEAST_DEFINE_TESTSUITE(STAmount, ripple_data, ripple);
688
689} // namespace ripple
A testsuite class.
Definition: suite.h:55
log_os< char > log
Logging output stream.
Definition: suite.h:152
void pass()
Record a successful test condition.
Definition: suite.h:511
bool unexpected(Condition shouldBeFalse, String const &reason)
Definition: suite.h:499
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition: suite.h:533
A currency issued by an account.
Definition: Issue.h:36
Currency currency
Definition: Issue.h:38
void roundTest(int n, int d, int m)
STAmount roundSelf(STAmount const &amount)
static STAmount serializeAndDeserialize(STAmount const &s)
void testSetValue(std::string const &value, Issue const &issue, bool success=true)
void mulTest(int a, int b)
void run() override
Runs the suite.
int exponent() const noexcept
Definition: STAmount.h:452
static int const cMaxOffset
Definition: STAmount.h:66
static int const cMinOffset
Definition: STAmount.h:65
static std::uint64_t const cMinValue
Definition: STAmount.h:69
void add(Serializer &s) const override
Definition: STAmount.cpp:647
static std::uint64_t const cMaxValue
Definition: STAmount.h:70
std::string getText() const override
Definition: STAmount.cpp:550
bool negative() const noexcept
Definition: STAmount.h:471
Issue const & issue() const
Definition: STAmount.h:496
static std::uint64_t const cMaxNative
Definition: STAmount.h:71
std::uint64_t mantissa() const noexcept
Definition: STAmount.h:477
std::string getFullText() const override
Definition: STAmount.cpp:540
bool native() const noexcept
Definition: STAmount.h:458
Slice slice() const noexcept
Definition: Serializer.h:67
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition: Issue.h:118
STAmount divide(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:93
constexpr Number one
Definition: Number.cpp:175
std::enable_if_t< std::is_integral< Integral >::value, Integral > rand_int()
SField const sfGeneric
STAmount amountFromQuality(std::uint64_t rate)
Definition: STAmount.cpp:857
STAmount multiply(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:53
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:486
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
Definition: Issue.h:126
STAmount divRound(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
Definition: STAmount.cpp:1595
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
STAmount amountFromString(Asset const &asset, std::string const &amount)
Definition: STAmount.cpp:869
STAmount mulRound(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
Definition: STAmount.cpp:1488
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition: UintTypes.cpp:84
static void canonicalizeRound(bool native, std::uint64_t &value, int &offset, bool)
Definition: STAmount.cpp:1276
T to_string(T... args)