xrpld
Loading...
Searching...
No Matches
EscrowToken_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/balance.h> // IWYU pragma: keep
7#include <test/jtx/escrow.h>
8#include <test/jtx/fee.h>
9#include <test/jtx/flags.h>
10#include <test/jtx/mpt.h>
11#include <test/jtx/pay.h>
12#include <test/jtx/rate.h>
13#include <test/jtx/ter.h>
14#include <test/jtx/trust.h>
15#include <test/jtx/txflags.h>
16
17#include <xrpl/beast/unit_test/suite.h>
18#include <xrpl/beast/utility/Journal.h>
19#include <xrpl/core/ServiceRegistry.h>
20#include <xrpl/json/json_value.h>
21#include <xrpl/ledger/ApplyView.h>
22#include <xrpl/ledger/OpenView.h>
23#include <xrpl/ledger/Sandbox.h>
24#include <xrpl/protocol/AccountID.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/MPTIssue.h>
28#include <xrpl/protocol/Protocol.h>
29#include <xrpl/protocol/SField.h>
30#include <xrpl/protocol/STAmount.h>
31#include <xrpl/protocol/SeqProxy.h>
32#include <xrpl/protocol/TER.h>
33#include <xrpl/protocol/TxFlags.h>
34#include <xrpl/protocol/UintTypes.h>
35#include <xrpl/protocol/jss.h>
36
37#include <algorithm>
38#include <array>
39#include <cstdint>
40#include <iterator>
41#include <memory>
42
43namespace xrpl::test {
44
46{
47 void
49 {
50 testcase("IOU Enablement");
51
52 using namespace jtx;
53 using namespace std::chrono;
54
55 for (bool const withTokenEscrow : {false, true})
56 {
57 auto const amend = withTokenEscrow ? features : features - featureTokenEscrow;
58 Env env{*this, amend};
59 auto const baseFee = env.current()->fees().base;
60 auto const alice = Account("alice");
61 auto const bob = Account("bob");
62 auto const gw = Account{"gateway"};
63 auto const usd = gw["USD"];
64 env.fund(XRP(5000), alice, bob, gw);
65 env(fset(gw, asfAllowTrustLineLocking));
66 env.close();
67 env.trust(usd(10'000), alice, bob);
68 env.close();
69 env(pay(gw, alice, usd(5000)));
70 env(pay(gw, bob, usd(5000)));
71 env.close();
72
73 auto const createResult = withTokenEscrow ? Ter(tesSUCCESS) : Ter(temBAD_AMOUNT);
74 auto const finishResult = withTokenEscrow ? Ter(tesSUCCESS) : Ter(tecNO_TARGET);
75
76 auto const seq1 = env.seq(alice);
77 env(escrow::create(alice, bob, usd(1'000)),
79 escrow::kFinishTime(env.now() + 1s),
80 Fee(baseFee * 150),
81 createResult);
82 env.close();
83 env(escrow::finish(bob, alice, seq1),
86 Fee(baseFee * 150),
87 finishResult);
88 env.close();
89
90 auto const seq2 = env.seq(alice);
91 env(escrow::create(alice, bob, usd(1'000)),
93 escrow::kFinishTime(env.now() + 1s),
94 escrow::kCancelTime(env.now() + 2s),
95 Fee(baseFee * 150),
96 createResult);
97 env.close();
98 env(escrow::cancel(bob, alice, seq2), finishResult);
99 env.close();
100 }
101
102 for (bool const withTokenEscrow : {false, true})
103 {
104 auto const amend = withTokenEscrow ? features : features - featureTokenEscrow;
105 Env env{*this, amend};
106 auto const baseFee = env.current()->fees().base;
107 auto const alice = Account("alice");
108 auto const bob = Account("bob");
109 auto const gw = Account{"gateway"};
110 auto const usd = gw["USD"];
111 env.fund(XRP(5000), alice, bob, gw);
112 env(fset(gw, asfAllowTrustLineLocking));
113 env.close();
114 env.trust(usd(10'000), alice, bob);
115 env.close();
116 env(pay(gw, alice, usd(5000)));
117 env(pay(gw, bob, usd(5000)));
118 env.close();
119
120 auto const seq1 = env.seq(alice);
121 env(escrow::finish(bob, alice, seq1),
124 Fee(baseFee * 150),
126 env.close();
127
128 env(escrow::cancel(bob, alice, seq1), Ter(tecNO_TARGET));
129 env.close();
130 }
131 }
132
133 void
135 {
136 testcase("IOU Allow Locking Flag");
137
138 using namespace jtx;
139 using namespace std::chrono;
140
141 Env env{*this, features};
142 auto const baseFee = env.current()->fees().base;
143 auto const alice = Account("alice");
144 auto const bob = Account("bob");
145 auto const gw = Account{"gateway"};
146 auto const usd = gw["USD"];
147 env.fund(XRP(5000), alice, bob, gw);
148 env(fset(gw, asfAllowTrustLineLocking));
149 env.close();
150 env.trust(usd(10'000), alice, bob);
151 env.close();
152 env(pay(gw, alice, usd(5000)));
153 env(pay(gw, bob, usd(5000)));
154 env.close();
155
156 // Create Escrow #1 & #2
157 auto const seq1 = env.seq(alice);
158 env(escrow::create(alice, bob, usd(1'000)),
160 escrow::kFinishTime(env.now() + 1s),
161 Fee(baseFee * 150),
162 Ter(tesSUCCESS));
163 env.close();
164
165 auto const seq2 = env.seq(alice);
166 env(escrow::create(alice, bob, usd(1'000)),
167 escrow::kFinishTime(env.now() + 1s),
168 escrow::kCancelTime(env.now() + 3s),
169 Fee(baseFee),
170 Ter(tesSUCCESS));
171 env.close();
172
173 // Clear the asfAllowTrustLineLocking flag
174 env(fclear(gw, asfAllowTrustLineLocking));
175 env.close();
176 env.require(Nflags(gw, asfAllowTrustLineLocking));
177
178 // Cannot Create Escrow without asfAllowTrustLineLocking
179 env(escrow::create(alice, bob, usd(1'000)),
181 escrow::kFinishTime(env.now() + 1s),
182 Fee(baseFee * 150),
184 env.close();
185
186 // Can finish the escrow created before the flag was cleared
187 env(escrow::finish(bob, alice, seq1),
190 Fee(baseFee * 150),
191 Ter(tesSUCCESS));
192 env.close();
193
194 // Can cancel the escrow created before the flag was cleared
195 env(escrow::cancel(bob, alice, seq2), Ter(tesSUCCESS));
196 env.close();
197 }
198
199 void
201 {
202 testcase("IOU Create Preflight");
203 using namespace test::jtx;
204 using namespace std::literals;
205
206 // temBAD_FEE: Exercises invalid preflight1.
207 {
208 Env env{*this, features};
209 auto const alice = Account("alice");
210 auto const bob = Account("bob");
211 auto const gw = Account{"gateway"};
212 auto const usd = gw["USD"];
213 env.fund(XRP(5000), alice, bob, gw);
214
215 env(escrow::create(alice, bob, usd(1)),
216 escrow::kFinishTime(env.now() + 1s),
217 Fee(XRP(-1)),
218 Ter(temBAD_FEE));
219 env.close();
220 }
221
222 // temBAD_AMOUNT: amount <= 0
223 {
224 Env env{*this, features};
225 auto const baseFee = env.current()->fees().base;
226 auto const alice = Account("alice");
227 auto const bob = Account("bob");
228 auto const gw = Account{"gateway"};
229 auto const usd = gw["USD"];
230 env.fund(XRP(5000), alice, bob, gw);
231
232 env(escrow::create(alice, bob, usd(-1)),
234 escrow::kFinishTime(env.now() + 1s),
235 Fee(baseFee * 150),
237 env.close();
238 }
239
240 // temBAD_CURRENCY: badCurrency() == amount.getCurrency()
241 {
242 Env env{*this, features};
243 auto const baseFee = env.current()->fees().base;
244 auto const alice = Account("alice");
245 auto const bob = Account("bob");
246 auto const gw = Account{"gateway"};
247 auto const bad = IOU(gw, badCurrency());
248 env.fund(XRP(5000), alice, bob, gw);
249
250 env(escrow::create(alice, bob, bad(1)),
252 escrow::kFinishTime(env.now() + 1s),
253 Fee(baseFee * 150),
255 env.close();
256 }
257 }
258
259 void
261 {
262 testcase("IOU Create Preclaim");
263 using namespace test::jtx;
264 using namespace std::literals;
265
266 // tecNO_PERMISSION: issuer is the same as the account
267 {
268 Env env{*this, features};
269 auto const baseFee = env.current()->fees().base;
270 auto const alice = Account("alice");
271 auto const bob = Account("bob");
272 auto const gw = Account{"gateway"};
273 auto const usd = gw["USD"];
274 env.fund(XRP(5000), alice, bob, gw);
275
276 env(escrow::create(gw, alice, usd(1)),
278 escrow::kFinishTime(env.now() + 1s),
279 Fee(baseFee * 150),
281 env.close();
282 }
283
284 // tecNO_ISSUER: Issuer does not exist
285 {
286 Env env{*this, features};
287 auto const baseFee = env.current()->fees().base;
288 auto const alice = Account("alice");
289 auto const bob = Account("bob");
290 auto const gw = Account{"gateway"};
291 auto const usd = gw["USD"];
292 env.fund(XRP(5000), alice, bob);
293 env.close();
294 env.memoize(gw);
295
296 env(escrow::create(alice, bob, usd(1)),
298 escrow::kFinishTime(env.now() + 1s),
299 Fee(baseFee * 150),
301 env.close();
302 }
303
304 // tecNO_PERMISSION: asfAllowTrustLineLocking is not set
305 {
306 Env env{*this, features};
307 auto const baseFee = env.current()->fees().base;
308 auto const alice = Account("alice");
309 auto const bob = Account("bob");
310 auto const gw = Account{"gateway"};
311 auto const usd = gw["USD"];
312 env.fund(XRP(5000), alice, bob, gw);
313 env.close();
314 env.trust(usd(10'000), alice, bob);
315 env.close();
316 env(pay(gw, alice, usd(5000)));
317 env(pay(gw, bob, usd(5000)));
318 env.close();
319
320 env(escrow::create(gw, alice, usd(1)),
322 escrow::kFinishTime(env.now() + 1s),
323 Fee(baseFee * 150),
325 env.close();
326 }
327
328 // tecNO_LINE: account does not have a trustline to the issuer
329 {
330 Env env{*this, features};
331 auto const baseFee = env.current()->fees().base;
332 auto const alice = Account("alice");
333 auto const bob = Account("bob");
334 auto const gw = Account{"gateway"};
335 auto const usd = gw["USD"];
336 env.fund(XRP(5000), alice, bob, gw);
337 env(fset(gw, asfAllowTrustLineLocking));
338 env.close();
339 env(escrow::create(alice, bob, usd(1)),
341 escrow::kFinishTime(env.now() + 1s),
342 Fee(baseFee * 150),
343 Ter(tecNO_LINE));
344 env.close();
345 }
346
347 // tecNO_PERMISSION: Not testable
348 // tecNO_PERMISSION: Not testable
349 // tecNO_AUTH: requireAuth
350 {
351 Env env{*this, features};
352 auto const baseFee = env.current()->fees().base;
353 auto const alice = Account("alice");
354 auto const bob = Account("bob");
355 auto const gw = Account{"gateway"};
356 auto const usd = gw["USD"];
357 env.fund(XRP(5000), alice, bob, gw);
358 env(fset(gw, asfAllowTrustLineLocking));
359 env(fset(gw, asfRequireAuth));
360 env.close();
361 env.trust(usd(10'000), alice, bob);
362 env.close();
363
364 env(escrow::create(alice, bob, usd(1)),
366 escrow::kFinishTime(env.now() + 1s),
367 Fee(baseFee * 150),
368 Ter(tecNO_AUTH));
369 env.close();
370 }
371
372 // tecNO_AUTH: requireAuth
373 {
374 Env env{*this, features};
375 auto const baseFee = env.current()->fees().base;
376 auto const alice = Account("alice");
377 auto const bob = Account("bob");
378 auto const gw = Account{"gateway"};
379 auto const usd = gw["USD"];
380 auto const aliceUSD = alice["USD"];
381 env.fund(XRP(5000), alice, bob, gw);
382 env(fset(gw, asfAllowTrustLineLocking));
383 env(fset(gw, asfRequireAuth));
384 env.close();
385 env(trust(gw, aliceUSD(10'000)), Txflags(tfSetfAuth));
386 env.trust(usd(10'000), alice, bob);
387 env.close();
388
389 env(escrow::create(alice, bob, usd(1)),
391 escrow::kFinishTime(env.now() + 1s),
392 Fee(baseFee * 150),
393 Ter(tecNO_AUTH));
394 env.close();
395 }
396
397 // tecFROZEN: account is frozen
398 {
399 // Env Setup
400 Env env{*this, features};
401 auto const alice = Account("alice");
402 auto const bob = Account("bob");
403 auto const gw = Account{"gateway"};
404 auto const usd = gw["USD"];
405 auto const baseFee = env.current()->fees().base;
406 env.fund(XRP(10'000), alice, bob, gw);
407 env(fset(gw, asfAllowTrustLineLocking));
408 env.close();
409 env(trust(alice, usd(100'000)));
410 env(trust(bob, usd(100'000)));
411 env.close();
412 env(pay(gw, alice, usd(10'000)));
413 env(pay(gw, bob, usd(10'000)));
414 env.close();
415
416 // set freeze on alice trustline
417 env(trust(gw, usd(10'000), alice, tfSetFreeze));
418 env.close();
419
420 env(escrow::create(alice, bob, usd(1)),
422 escrow::kFinishTime(env.now() + 1s),
423 Fee(baseFee * 150),
424 Ter(tecFROZEN));
425 env.close();
426 }
427
428 // tecFROZEN: dest is frozen
429 {
430 // Env Setup
431 Env env{*this, features};
432 auto const alice = Account("alice");
433 auto const bob = Account("bob");
434 auto const gw = Account{"gateway"};
435 auto const usd = gw["USD"];
436 auto const baseFee = env.current()->fees().base;
437 env.fund(XRP(10'000), alice, bob, gw);
438 env(fset(gw, asfAllowTrustLineLocking));
439 env.close();
440 env(trust(alice, usd(100'000)));
441 env(trust(bob, usd(100'000)));
442 env.close();
443 env(pay(gw, alice, usd(10'000)));
444 env(pay(gw, bob, usd(10'000)));
445 env.close();
446
447 // set freeze on bob trustline
448 env(trust(gw, usd(10'000), bob, tfSetFreeze));
449 env.close();
450
451 env(escrow::create(alice, bob, usd(1)),
453 escrow::kFinishTime(env.now() + 1s),
454 Fee(baseFee * 150),
455 Ter(tecFROZEN));
456 env.close();
457 }
458
459 // tecINSUFFICIENT_FUNDS
460 {
461 // Env Setup
462 Env env{*this, features};
463 auto const alice = Account("alice");
464 auto const bob = Account("bob");
465 auto const gw = Account{"gateway"};
466 auto const usd = gw["USD"];
467 auto const baseFee = env.current()->fees().base;
468 env.fund(XRP(10'000), alice, bob, gw);
469 env(fset(gw, asfAllowTrustLineLocking));
470 env.close();
471 env(trust(alice, usd(100'000)));
472 env(trust(bob, usd(100'000)));
473 env.close();
474
475 env(escrow::create(alice, bob, usd(1)),
477 escrow::kFinishTime(env.now() + 1s),
478 Fee(baseFee * 150),
480 env.close();
481 }
482
483 // tecINSUFFICIENT_FUNDS
484 {
485 // Env Setup
486 Env env{*this, features};
487 auto const alice = Account("alice");
488 auto const bob = Account("bob");
489 auto const gw = Account{"gateway"};
490 auto const usd = gw["USD"];
491 auto const baseFee = env.current()->fees().base;
492 env.fund(XRP(10'000), alice, bob, gw);
493 env(fset(gw, asfAllowTrustLineLocking));
494 env.close();
495 env(trust(alice, usd(100'000)));
496 env(trust(bob, usd(100'000)));
497 env.close();
498 env(pay(gw, alice, usd(10'000)));
499 env(pay(gw, bob, usd(10'000)));
500 env.close();
501
502 env(escrow::create(alice, bob, usd(10'001)),
504 escrow::kFinishTime(env.now() + 1s),
505 Fee(baseFee * 150),
507 env.close();
508 }
509
510 // tecPRECISION_LOSS
511 {
512 Env env{*this, features};
513 auto const alice = Account("alice");
514 auto const bob = Account("bob");
515 auto const gw = Account{"gateway"};
516 auto const usd = gw["USD"];
517 auto const baseFee = env.current()->fees().base;
518 env.fund(XRP(10'000), alice, bob, gw);
519 env(fset(gw, asfAllowTrustLineLocking));
520 env.close();
521 env.trust(usd(100000000000000000), alice);
522 env.trust(usd(100000000000000000), bob);
523 env.close();
524 env(pay(gw, alice, usd(10000000000000000)));
525 env(pay(gw, bob, usd(1)));
526 env.close();
527
528 bool const largeMantissa = features[featureSingleAssetVault] ||
529 features[featureLendingProtocol] || features[featureMPTokensV2];
530
531 // alice cannot create escrow for 1/10 iou - precision loss
532 env(escrow::create(alice, bob, usd(1)),
534 escrow::kFinishTime(env.now() + 1s),
535 Fee(baseFee * 150),
536 Ter(largeMantissa ? (TER)tesSUCCESS : (TER)tecPRECISION_LOSS));
537 env.close();
538 }
539 }
540
541 void
543 {
544 testcase("IOU Finish Preclaim");
545 using namespace test::jtx;
546 using namespace std::literals;
547
548 // tecNO_AUTH: requireAuth set: dest not authorized
549 {
550 Env env{*this, features};
551 auto const baseFee = env.current()->fees().base;
552 auto const alice = Account("alice");
553 auto const bob = Account("bob");
554 auto const gw = Account{"gateway"};
555 auto const usd = gw["USD"];
556 auto const aliceUSD = alice["USD"];
557 auto const bobUSD = bob["USD"];
558 env.fund(XRP(5000), alice, bob, gw);
559 env(fset(gw, asfAllowTrustLineLocking));
560 env(fset(gw, asfRequireAuth));
561 env.close();
562 env(trust(gw, aliceUSD(10'000)), Txflags(tfSetfAuth));
563 env(trust(gw, bobUSD(10'000)), Txflags(tfSetfAuth));
564 env.trust(usd(10'000), alice, bob);
565 env.close();
566 env(pay(gw, alice, usd(10'000)));
567 env(pay(gw, bob, usd(10'000)));
568 env.close();
569
570 auto const seq1 = env.seq(alice);
571 env(escrow::create(alice, bob, usd(1)),
573 escrow::kFinishTime(env.now() + 1s),
574 Fee(baseFee * 150),
575 Ter(tesSUCCESS));
576 env.close();
577
578 env(pay(bob, gw, usd(10'000)));
579 env(trust(gw, bobUSD(0)), Txflags(tfSetfAuth));
580 env(trust(bob, usd(0)));
581 env.close();
582
583 env.trust(usd(10'000), bob);
584 env.close();
585
586 // bob cannot finish because he is not authorized
587 env(escrow::finish(bob, alice, seq1),
590 Fee(baseFee * 150),
591 Ter(tecNO_AUTH));
592 env.close();
593 }
594
595 // tecFROZEN: issuer has deep frozen the dest
596 {
597 Env env{*this, features};
598 auto const baseFee = env.current()->fees().base;
599 auto const alice = Account("alice");
600 auto const bob = Account("bob");
601 auto const gw = Account{"gateway"};
602 auto const usd = gw["USD"];
603 env.fund(XRP(5000), alice, bob, gw);
604 env(fset(gw, asfAllowTrustLineLocking));
605 env.close();
606 env.trust(usd(10'000), alice, bob);
607 env.close();
608 env(pay(gw, alice, usd(10'000)));
609 env(pay(gw, bob, usd(10'000)));
610 env.close();
611
612 auto const seq1 = env.seq(alice);
613 env(escrow::create(alice, bob, usd(1)),
615 escrow::kFinishTime(env.now() + 1s),
616 Fee(baseFee * 150),
617 Ter(tesSUCCESS));
618 env.close();
619
620 // set freeze on bob trustline
621 env(trust(gw, usd(10'000), bob, tfSetFreeze | tfSetDeepFreeze));
622
623 // bob cannot finish because of deep freeze
624 env(escrow::finish(bob, alice, seq1),
627 Fee(baseFee * 150),
628 Ter(tecFROZEN));
629 env.close();
630 }
631 }
632
633 void
635 {
636 testcase("IOU Finish Do Apply");
637 using namespace test::jtx;
638 using namespace std::literals;
639
640 // tecNO_LINE_INSUF_RESERVE: insufficient reserve to create line
641 {
642 Env env{*this, features};
643 auto const baseFee = env.current()->fees().base;
644 auto const acctReserve = env.current()->fees().reserve;
645 auto const incReserve = env.current()->fees().increment;
646 auto const alice = Account("alice");
647 auto const bob = Account("bob");
648 auto const gw = Account{"gateway"};
649 auto const usd = gw["USD"];
650 env.fund(XRP(5000), alice, gw);
651 env.fund(acctReserve + (incReserve - 1), bob);
652 env.close();
653 env(fset(gw, asfAllowTrustLineLocking));
654 env.close();
655 env.trust(usd(10'000), alice);
656 env.close();
657 env(pay(gw, alice, usd(10'000)));
658 env.close();
659
660 auto const seq1 = env.seq(alice);
661 env(escrow::create(alice, bob, usd(1)),
663 escrow::kFinishTime(env.now() + 1s),
664 Fee(baseFee * 150),
665 Ter(tesSUCCESS));
666 env.close();
667
668 // bob cannot finish because insufficient reserve to create line
669 env(escrow::finish(bob, alice, seq1),
672 Fee(baseFee * 150),
674 env.close();
675 }
676
677 // tecNO_LINE: alice submits; finish IOU not created
678 {
679 Env env{*this, features};
680 auto const baseFee = env.current()->fees().base;
681 auto const alice = Account("alice");
682 auto const bob = Account("bob");
683 auto const gw = Account{"gateway"};
684 auto const usd = gw["USD"];
685 env.fund(XRP(5000), alice, bob, gw);
686 env.close();
687 env(fset(gw, asfAllowTrustLineLocking));
688 env.close();
689 env.trust(usd(10'000), alice);
690 env.close();
691 env(pay(gw, alice, usd(10'000)));
692 env.close();
693
694 auto const seq1 = env.seq(alice);
695 env(escrow::create(alice, bob, usd(1)),
697 escrow::kFinishTime(env.now() + 1s),
698 Fee(baseFee * 150),
699 Ter(tesSUCCESS));
700 env.close();
701
702 // alice cannot finish because bob does not have a trustline
703 env(escrow::finish(alice, alice, seq1),
706 Fee(baseFee * 150),
707 Ter(tecNO_LINE));
708 env.close();
709 }
710
711 // tecLIMIT_EXCEEDED: alice submits; IOU Limit < balance + amount
712 {
713 Env env{*this, features};
714 auto const baseFee = env.current()->fees().base;
715 auto const alice = Account("alice");
716 auto const bob = Account("bob");
717 auto const gw = Account{"gateway"};
718 auto const usd = gw["USD"];
719 env.fund(XRP(5000), alice, bob, gw);
720 env.close();
721 env(fset(gw, asfAllowTrustLineLocking));
722 env.close();
723 env.trust(usd(1000), alice, bob);
724 env.close();
725 env(pay(gw, alice, usd(1000)));
726 env.close();
727
728 auto const seq1 = env.seq(alice);
729 env(escrow::create(alice, bob, usd(5)),
731 escrow::kFinishTime(env.now() + 1s),
732 Fee(baseFee * 150),
733 Ter(tesSUCCESS));
734 env.close();
735
736 env.trust(usd(1), bob);
737 env.close();
738
739 // alice cannot finish because bob's limit is too low
740 env(escrow::finish(alice, alice, seq1),
743 Fee(baseFee * 150),
745 env.close();
746 }
747
748 // tesSUCCESS: bob submits; IOU Limit < balance + amount
749 {
750 Env env{*this, features};
751 auto const baseFee = env.current()->fees().base;
752 auto const alice = Account("alice");
753 auto const bob = Account("bob");
754 auto const gw = Account{"gateway"};
755 auto const usd = gw["USD"];
756 env.fund(XRP(5000), alice, bob, gw);
757 env.close();
758 env(fset(gw, asfAllowTrustLineLocking));
759 env.close();
760 env.trust(usd(1000), alice, bob);
761 env.close();
762 env(pay(gw, alice, usd(1000)));
763 env.close();
764
765 auto const seq1 = env.seq(alice);
766 env(escrow::create(alice, bob, usd(5)),
768 escrow::kFinishTime(env.now() + 1s),
769 Fee(baseFee * 150),
770 Ter(tesSUCCESS));
771 env.close();
772
773 env.trust(usd(1), bob);
774 env.close();
775
776 // bob can finish even if bob's limit is too low
777 auto const bobPreLimit = env.limit(bob, usd);
778
779 env(escrow::finish(bob, alice, seq1),
782 Fee(baseFee * 150),
783 Ter(tesSUCCESS));
784 env.close();
785
786 // bob's limit is not changed
787 BEAST_EXPECT(env.limit(bob, usd) == bobPreLimit);
788 }
789 }
790
791 void
793 {
794 testcase("IOU Cancel Preclaim");
795 using namespace test::jtx;
796 using namespace std::literals;
797
798 // tecNO_AUTH: requireAuth set: account not authorized
799 {
800 Env env{*this, features};
801 auto const baseFee = env.current()->fees().base;
802 auto const alice = Account("alice");
803 auto const bob = Account("bob");
804 auto const gw = Account{"gateway"};
805 auto const usd = gw["USD"];
806 auto const aliceUSD = alice["USD"];
807 auto const bobUSD = bob["USD"];
808 env.fund(XRP(5000), alice, bob, gw);
809 env(fset(gw, asfAllowTrustLineLocking));
810 env(fset(gw, asfRequireAuth));
811 env.close();
812 env(trust(gw, aliceUSD(10'000)), Txflags(tfSetfAuth));
813 env(trust(gw, bobUSD(10'000)), Txflags(tfSetfAuth));
814 env.trust(usd(10'000), alice, bob);
815 env.close();
816 env(pay(gw, alice, usd(10'000)));
817 env(pay(gw, bob, usd(10'000)));
818 env.close();
819
820 auto const seq1 = env.seq(alice);
821 env(escrow::create(alice, bob, usd(1)),
822 escrow::kFinishTime(env.now() + 1s),
823 escrow::kCancelTime(env.now() + 2s),
824 Fee(baseFee),
825 Ter(tesSUCCESS));
826 env.close();
827
828 env(pay(alice, gw, usd(9'999)));
829 env(trust(gw, aliceUSD(0)), Txflags(tfSetfAuth));
830 env(trust(alice, usd(0)));
831 env.close();
832
833 env.trust(usd(10'000), alice);
834 env.close();
835
836 // alice cannot cancel because she is not authorized
837 env(escrow::cancel(bob, alice, seq1), Fee(baseFee), Ter(tecNO_AUTH));
838 env.close();
839 }
840 }
841
842 void
844 {
845 testcase("IOU Cancel DoApply");
846 using namespace jtx;
847 using namespace std::literals;
848
849 {
850 Env env{*this, features};
851 auto const baseFee = env.current()->fees().base;
852 auto const alice = Account("alice");
853 auto const bob = Account("bob");
854 auto const gw = Account("gw");
855 auto const usd = gw["USD"];
856
857 env.fund(XRP(10'000), alice, bob, gw);
858 env.close();
859
860 env(fset(gw, asfAllowTrustLineLocking));
861 env.close();
862
863 env.trust(usd(100'000), alice);
864 env.trust(usd(100'000), bob);
865 env.close();
866
867 env(pay(gw, alice, usd(10'000)));
868 env.close();
869
870 auto const seq = env.seq(alice);
871 env(escrow::create(alice, bob, usd(1'000)),
872 escrow::kFinishTime(env.now() + 1s),
873 escrow::kCancelTime(env.now() + 2s),
874 Fee(baseFee));
875 env.close();
876
877 BEAST_EXPECT(env.balance(alice, usd) == usd(9'000));
878
879 env(pay(alice, gw, usd(9'000)));
880 env.close();
881
882 env(trust(alice, usd(0)));
883 env.close();
884
885 auto const trustLineKey = keylet::trustLine(alice.id(), gw.id(), usd.currency);
886 BEAST_EXPECT(!env.current()->exists(trustLineKey));
887
888 env.close();
889 env.close();
890
891 auto const expectedResult = env.current()->rules().enabled(fixCleanup3_2_0)
892 ? Ter(tesSUCCESS)
893 : Ter(tefINTERNAL);
894 env(escrow::cancel(alice, alice, seq), Fee(baseFee), expectedResult);
895 env.close();
896
897 if (env.current()->rules().enabled(fixCleanup3_2_0))
898 {
899 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(seq))));
900 BEAST_EXPECT(env.current()->exists(trustLineKey));
901 BEAST_EXPECT(env.balance(alice, usd) == usd(1'000));
902 }
903 }
904 }
905
906 void
908 {
909 testcase("IOU Cancel Reserve Recycle");
910 using namespace jtx;
911 using namespace std::literals;
912
913 // Escrowing the whole IOU balance lets the owner delete the now-zero
914 // trust line, so cancelling has to re-create it: one object destroyed,
915 // one created, and the reserve requirement unchanged.
916 Env env{*this, features};
917 bool const fixEnabled = env.current()->rules().enabled(fixCleanup3_4_0);
918
919 auto const baseFee = env.current()->fees().base;
920 auto const alice = Account("alice");
921 auto const bob = Account("bob");
922 auto const gw = Account("gw");
923 auto const usd = gw["USD"];
924
925 env.fund(XRP(10'000), alice, bob, gw);
926 env.close();
927
928 env(fset(gw, asfAllowTrustLineLocking));
929 env.close();
930
931 env.trust(usd(10'000), alice);
932 env.close();
933
934 env(pay(gw, alice, usd(10'000)));
935 env.close();
936 BEAST_EXPECT(env.ownerCount(alice) == 1);
937
938 auto const cancelAfter = env.now() + 100s;
939 auto const seq = env.seq(alice);
940 env(escrow::create(alice, bob, usd(10'000)),
941 escrow::kFinishTime(env.now() + 1s),
942 escrow::kCancelTime(cancelAfter),
943 Fee(baseFee));
944 env.close();
945 BEAST_EXPECT(env.ownerCount(alice) == 2);
946
947 auto const trustLineKey = keylet::trustLine(alice.id(), gw.id(), usd.currency);
948 env(trust(alice, usd(0)));
949 env.close();
950 BEAST_EXPECT(!env.current()->exists(trustLineKey));
951 BEAST_EXPECT(env.ownerCount(alice) == 1);
952
953 // Leave alice holding the reserve for exactly one owned object. That
954 // is the escrow now and the re-created trust line after the cancel.
955 auto const oneObject = env.current()->fees().accountReserve(1, 1);
956 auto const twoObjects = env.current()->fees().accountReserve(2, 1);
957 auto const balance = env.balance(alice).value().xrp();
958 auto const feeCushion = baseFee.drops() * 20;
959 env(pay(alice, bob, drops(balance.drops() - oneObject.drops() - feeCushion)));
960 env.close();
961 BEAST_EXPECT(env.balance(alice).value().xrp() >= oneObject);
962 BEAST_EXPECT(env.balance(alice).value().xrp() < twoObjects);
963
964 for (; env.now() < cancelAfter; env.close())
965 {
966 }
967 env.close();
968 env.close();
969
970 auto const expectedResult = fixEnabled ? Ter(tesSUCCESS) : Ter(tecNO_LINE_INSUF_RESERVE);
971 env(escrow::cancel(alice, alice, seq), Fee(baseFee), expectedResult);
972 env.close();
973
974 auto const escrowKey = keylet::escrow(alice.id(), SeqProxy::rawSequence(seq));
975 if (fixEnabled)
976 {
977 BEAST_EXPECT(!env.le(escrowKey));
978 BEAST_EXPECT(env.current()->exists(trustLineKey));
979 BEAST_EXPECT(env.balance(alice, usd) == usd(10'000));
980 BEAST_EXPECT(env.ownerCount(alice) == 1);
981 }
982 else
983 {
984 // The tec keeps the escrow, so one more owner reserve lets the
985 // retry through.
986 BEAST_EXPECT(env.le(escrowKey) != nullptr);
987 BEAST_EXPECT(!env.current()->exists(trustLineKey));
988 BEAST_EXPECT(env.ownerCount(alice) == 1);
989
990 env(pay(bob, alice, drops(twoObjects.drops() - oneObject.drops())));
991 env.close();
992 env(escrow::cancel(alice, alice, seq), Fee(baseFee), Ter(tesSUCCESS));
993 env.close();
994 BEAST_EXPECT(!env.le(escrowKey));
995 BEAST_EXPECT(env.balance(alice, usd) == usd(10'000));
996 }
997 }
998
999 void
1001 {
1002 testcase("IOU Balances");
1003
1004 using namespace jtx;
1005 using namespace std::chrono;
1006
1007 Env env{*this, features};
1008 auto const baseFee = env.current()->fees().base;
1009 auto const alice = Account("alice");
1010 auto const bob = Account("bob");
1011 auto const gw = Account{"gateway"};
1012 auto const usd = gw["USD"];
1013 env.fund(XRP(5000), alice, bob, gw);
1014 env(fset(gw, asfAllowTrustLineLocking));
1015 env.close();
1016 env.trust(usd(10'000), alice, bob);
1017 env.close();
1018 env(pay(gw, alice, usd(5'000)));
1019 env(pay(gw, bob, usd(5'000)));
1020 env.close();
1021
1022 auto const outstandingUSD = usd(10'000);
1023
1024 // Create & Finish Escrow
1025 auto const seq1 = env.seq(alice);
1026 {
1027 auto const preAliceUSD = env.balance(alice, usd);
1028 auto const preBobUSD = env.balance(bob, usd);
1029 env(escrow::create(alice, bob, usd(1'000)),
1031 escrow::kFinishTime(env.now() + 1s),
1032 Fee(baseFee * 150),
1033 Ter(tesSUCCESS));
1034 env.close();
1035
1036 BEAST_EXPECT(env.balance(alice, usd) == preAliceUSD - usd(1'000));
1037 BEAST_EXPECT(env.balance(bob, usd) == preBobUSD);
1038 BEAST_EXPECT(issuerBalance(env, gw, usd) == outstandingUSD - usd(1'000));
1039 BEAST_EXPECT(issuerEscrowed(env, gw, usd) == usd(1'000));
1040 }
1041 {
1042 auto const preAliceUSD = env.balance(alice, usd);
1043 auto const preBobUSD = env.balance(bob, usd);
1044 env(escrow::finish(bob, alice, seq1),
1047 Fee(baseFee * 150),
1048 Ter(tesSUCCESS));
1049 env.close();
1050
1051 BEAST_EXPECT(env.balance(alice, usd) == preAliceUSD);
1052 BEAST_EXPECT(env.balance(bob, usd) == preBobUSD + usd(1'000));
1053 BEAST_EXPECT(issuerBalance(env, gw, usd) == outstandingUSD);
1054 BEAST_EXPECT(issuerEscrowed(env, gw, usd) == usd(0));
1055 }
1056
1057 // Create & Cancel Escrow
1058 auto const seq2 = env.seq(alice);
1059 {
1060 auto const preAliceUSD = env.balance(alice, usd);
1061 auto const preBobUSD = env.balance(bob, usd);
1062 env(escrow::create(alice, bob, usd(1'000)),
1064 escrow::kFinishTime(env.now() + 1s),
1065 escrow::kCancelTime(env.now() + 2s),
1066 Fee(baseFee * 150),
1067 Ter(tesSUCCESS));
1068 env.close();
1069
1070 BEAST_EXPECT(env.balance(alice, usd) == preAliceUSD - usd(1'000));
1071 BEAST_EXPECT(env.balance(bob, usd) == preBobUSD);
1072 BEAST_EXPECT(issuerBalance(env, gw, usd) == outstandingUSD - usd(1'000));
1073 BEAST_EXPECT(issuerEscrowed(env, gw, usd) == usd(1'000));
1074 }
1075 {
1076 auto const preAliceUSD = env.balance(alice, usd);
1077 auto const preBobUSD = env.balance(bob, usd);
1078 env(escrow::cancel(bob, alice, seq2), Ter(tesSUCCESS));
1079 env.close();
1080
1081 BEAST_EXPECT(env.balance(alice, usd) == preAliceUSD + usd(1'000));
1082 BEAST_EXPECT(env.balance(bob, usd) == preBobUSD);
1083 BEAST_EXPECT(issuerBalance(env, gw, usd) == outstandingUSD);
1084 BEAST_EXPECT(issuerEscrowed(env, gw, usd) == usd(0));
1085 }
1086 }
1087
1088 void
1090 {
1091 using namespace jtx;
1092 using namespace std::chrono;
1093
1094 auto const alice = Account("alice");
1095 auto const bob = Account("bob");
1096 auto const carol = Account("carol");
1097 auto const gw = Account{"gateway"};
1098 auto const usd = gw["USD"];
1099 {
1100 testcase("IOU Metadata to self");
1101
1102 Env env{*this, features};
1103 env.fund(XRP(5000), alice, bob, carol, gw);
1104 env(fset(gw, asfAllowTrustLineLocking));
1105 env.close();
1106 env.trust(usd(10'000), alice, bob, carol);
1107 env.close();
1108 env(pay(gw, alice, usd(5000)));
1109 env(pay(gw, bob, usd(5000)));
1110 env(pay(gw, carol, usd(5000)));
1111 env.close();
1112 auto const aseq = env.seq(alice);
1113 auto const bseq = env.seq(bob);
1114
1115 env(escrow::create(alice, alice, usd(1'000)),
1116 escrow::kFinishTime(env.now() + 1s),
1117 escrow::kCancelTime(env.now() + 500s));
1118 BEAST_EXPECT(
1119 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1120 env.close(5s);
1121 auto const aa = env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq)));
1122 BEAST_EXPECT(aa);
1123 {
1124 auto const aod = ownerDirEntries(*env.current(), alice);
1125 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 2);
1126 BEAST_EXPECT(
1127 // NOLINTNEXTLINE(modernize-use-ranges)
1128 std::find(aod.begin(), aod.end(), aa) != aod.end());
1129 }
1130
1131 {
1132 auto const iod = ownerDirEntries(*env.current(), gw);
1133 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 4);
1134 BEAST_EXPECT(
1135 // NOLINTNEXTLINE(modernize-use-ranges)
1136 std::find(iod.begin(), iod.end(), aa) != iod.end());
1137 }
1138
1139 env(escrow::create(bob, bob, usd(1'000)),
1140 escrow::kFinishTime(env.now() + 1s),
1141 escrow::kCancelTime(env.now() + 2s));
1142 BEAST_EXPECT(
1143 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1144 env.close(5s);
1145 auto const bb = env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq)));
1146 BEAST_EXPECT(bb);
1147
1148 {
1149 auto const bod = ownerDirEntries(*env.current(), bob);
1150 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 2);
1151 BEAST_EXPECT(
1152 // NOLINTNEXTLINE(modernize-use-ranges)
1153 std::find(bod.begin(), bod.end(), bb) != bod.end());
1154 }
1155
1156 {
1157 auto const iod = ownerDirEntries(*env.current(), gw);
1158 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 5);
1159 BEAST_EXPECT(
1160 // NOLINTNEXTLINE(modernize-use-ranges)
1161 std::find(iod.begin(), iod.end(), bb) != iod.end());
1162 }
1163
1164 env.close(5s);
1165 env(escrow::finish(alice, alice, aseq));
1166 {
1167 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
1168 BEAST_EXPECT(
1169 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1170
1171 auto const aod = ownerDirEntries(*env.current(), alice);
1172 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
1173 BEAST_EXPECT(
1174 // NOLINTNEXTLINE(modernize-use-ranges)
1175 std::find(aod.begin(), aod.end(), aa) == aod.end());
1176
1177 auto const bod = ownerDirEntries(*env.current(), bob);
1178 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 2);
1179 BEAST_EXPECT(
1180 // NOLINTNEXTLINE(modernize-use-ranges)
1181 std::find(bod.begin(), bod.end(), bb) != bod.end());
1182
1183 auto const iod = ownerDirEntries(*env.current(), gw);
1184 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 4);
1185 BEAST_EXPECT(
1186 // NOLINTNEXTLINE(modernize-use-ranges)
1187 std::find(iod.begin(), iod.end(), bb) != iod.end());
1188 }
1189
1190 env.close(5s);
1191 env(escrow::cancel(bob, bob, bseq));
1192 {
1193 BEAST_EXPECT(!env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq))));
1194 BEAST_EXPECT(
1195 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1196
1197 auto const bod = ownerDirEntries(*env.current(), bob);
1198 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 1);
1199 BEAST_EXPECT(
1200 // NOLINTNEXTLINE(modernize-use-ranges)
1201 std::find(bod.begin(), bod.end(), bb) == bod.end());
1202
1203 auto const iod = ownerDirEntries(*env.current(), gw);
1204 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 3);
1205 BEAST_EXPECT(
1206 // NOLINTNEXTLINE(modernize-use-ranges)
1207 std::find(iod.begin(), iod.end(), bb) == iod.end());
1208 }
1209 }
1210 {
1211 testcase("IOU Metadata to other");
1212
1213 Env env{*this, features};
1214 env.fund(XRP(5000), alice, bob, carol, gw);
1215 env(fset(gw, asfAllowTrustLineLocking));
1216 env.close();
1217 env.trust(usd(10'000), alice, bob, carol);
1218 env.close();
1219 env(pay(gw, alice, usd(5000)));
1220 env(pay(gw, bob, usd(5000)));
1221 env(pay(gw, carol, usd(5000)));
1222 env.close();
1223 auto const aseq = env.seq(alice);
1224 auto const bseq = env.seq(bob);
1225
1226 env(escrow::create(alice, bob, usd(1'000)), escrow::kFinishTime(env.now() + 1s));
1227 BEAST_EXPECT(
1228 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1229 env.close(5s);
1230 env(escrow::create(bob, carol, usd(1'000)),
1231 escrow::kFinishTime(env.now() + 1s),
1232 escrow::kCancelTime(env.now() + 2s));
1233 BEAST_EXPECT(
1234 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1235 env.close(5s);
1236
1237 auto const ab = env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq)));
1238 BEAST_EXPECT(ab);
1239
1240 auto const bc = env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq)));
1241 BEAST_EXPECT(bc);
1242
1243 {
1244 auto const aod = ownerDirEntries(*env.current(), alice);
1245 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 2);
1246 BEAST_EXPECT(
1247 // NOLINTNEXTLINE(modernize-use-ranges)
1248 std::find(aod.begin(), aod.end(), ab) != aod.end());
1249
1250 auto const bod = ownerDirEntries(*env.current(), bob);
1251 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 3);
1252 BEAST_EXPECT(
1253 // NOLINTNEXTLINE(modernize-use-ranges)
1254 std::find(bod.begin(), bod.end(), ab) != bod.end());
1255 BEAST_EXPECT(
1256 // NOLINTNEXTLINE(modernize-use-ranges)
1257 std::find(bod.begin(), bod.end(), bc) != bod.end());
1258
1259 auto const cod = ownerDirEntries(*env.current(), carol);
1260 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 2);
1261 BEAST_EXPECT(
1262 // NOLINTNEXTLINE(modernize-use-ranges)
1263 std::find(cod.begin(), cod.end(), bc) != cod.end());
1264
1265 auto const iod = ownerDirEntries(*env.current(), gw);
1266 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 5);
1267 BEAST_EXPECT(
1268 // NOLINTNEXTLINE(modernize-use-ranges)
1269 std::find(iod.begin(), iod.end(), ab) != iod.end());
1270 BEAST_EXPECT(
1271 // NOLINTNEXTLINE(modernize-use-ranges)
1272 std::find(iod.begin(), iod.end(), bc) != iod.end());
1273 }
1274
1275 env.close(5s);
1276 env(escrow::finish(alice, alice, aseq));
1277 {
1278 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
1279 BEAST_EXPECT(env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq))));
1280
1281 auto const aod = ownerDirEntries(*env.current(), alice);
1282 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
1283 BEAST_EXPECT(
1284 // NOLINTNEXTLINE(modernize-use-ranges)
1285 std::find(aod.begin(), aod.end(), ab) == aod.end());
1286
1287 auto const bod = ownerDirEntries(*env.current(), bob);
1288 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 2);
1289 BEAST_EXPECT(
1290 // NOLINTNEXTLINE(modernize-use-ranges)
1291 std::find(bod.begin(), bod.end(), ab) == bod.end());
1292 BEAST_EXPECT(
1293 // NOLINTNEXTLINE(modernize-use-ranges)
1294 std::find(bod.begin(), bod.end(), bc) != bod.end());
1295
1296 auto const cod = ownerDirEntries(*env.current(), carol);
1297 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 2);
1298
1299 auto const iod = ownerDirEntries(*env.current(), gw);
1300 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 4);
1301 BEAST_EXPECT(
1302 // NOLINTNEXTLINE(modernize-use-ranges)
1303 std::find(iod.begin(), iod.end(), ab) == iod.end());
1304 BEAST_EXPECT(
1305 // NOLINTNEXTLINE(modernize-use-ranges)
1306 std::find(iod.begin(), iod.end(), bc) != iod.end());
1307 }
1308
1309 env.close(5s);
1310 env(escrow::cancel(bob, bob, bseq));
1311 {
1312 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
1313 BEAST_EXPECT(!env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq))));
1314
1315 auto const aod = ownerDirEntries(*env.current(), alice);
1316 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
1317 BEAST_EXPECT(
1318 // NOLINTNEXTLINE(modernize-use-ranges)
1319 std::find(aod.begin(), aod.end(), ab) == aod.end());
1320
1321 auto const bod = ownerDirEntries(*env.current(), bob);
1322 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 1);
1323 BEAST_EXPECT(
1324 // NOLINTNEXTLINE(modernize-use-ranges)
1325 std::find(bod.begin(), bod.end(), ab) == bod.end());
1326 BEAST_EXPECT(
1327 // NOLINTNEXTLINE(modernize-use-ranges)
1328 std::find(bod.begin(), bod.end(), bc) == bod.end());
1329
1330 auto const cod = ownerDirEntries(*env.current(), carol);
1331 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 1);
1332
1333 auto const iod = ownerDirEntries(*env.current(), gw);
1334 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 3);
1335 BEAST_EXPECT(
1336 // NOLINTNEXTLINE(modernize-use-ranges)
1337 std::find(iod.begin(), iod.end(), ab) == iod.end());
1338 BEAST_EXPECT(
1339 // NOLINTNEXTLINE(modernize-use-ranges)
1340 std::find(iod.begin(), iod.end(), bc) == iod.end());
1341 }
1342 }
1343
1344 {
1345 testcase("IOU Metadata to issuer");
1346
1347 Env env{*this, features};
1348 env.fund(XRP(5000), alice, carol, gw);
1349 env(fset(gw, asfAllowTrustLineLocking));
1350 env.close();
1351 env.trust(usd(10'000), alice, carol);
1352 env.close();
1353 env(pay(gw, alice, usd(5000)));
1354 env(pay(gw, carol, usd(5000)));
1355 env.close();
1356 auto const aseq = env.seq(alice);
1357
1358 env(escrow::create(alice, gw, usd(1'000)), escrow::kFinishTime(env.now() + 1s));
1359
1360 BEAST_EXPECT(
1361 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
1362 env.close(5s);
1363 env(escrow::create(gw, carol, usd(1'000)),
1364 escrow::kFinishTime(env.now() + 1s),
1365 escrow::kCancelTime(env.now() + 2s),
1367 env.close(5s);
1368
1369 auto const ag = env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq)));
1370 BEAST_EXPECT(ag);
1371
1372 {
1373 auto const aod = ownerDirEntries(*env.current(), alice);
1374 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 2);
1375 BEAST_EXPECT(
1376 // NOLINTNEXTLINE(modernize-use-ranges)
1377 std::find(aod.begin(), aod.end(), ag) != aod.end());
1378
1379 auto const cod = ownerDirEntries(*env.current(), carol);
1380 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 1);
1381
1382 auto const iod = ownerDirEntries(*env.current(), gw);
1383 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 3);
1384 BEAST_EXPECT(
1385 // NOLINTNEXTLINE(modernize-use-ranges)
1386 std::find(iod.begin(), iod.end(), ag) != iod.end());
1387 }
1388
1389 env.close(5s);
1390 env(escrow::finish(alice, alice, aseq));
1391 {
1392 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
1393
1394 auto const aod = ownerDirEntries(*env.current(), alice);
1395 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
1396 BEAST_EXPECT(
1397 // NOLINTNEXTLINE(modernize-use-ranges)
1398 std::find(aod.begin(), aod.end(), ag) == aod.end());
1399
1400 auto const cod = ownerDirEntries(*env.current(), carol);
1401 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 1);
1402
1403 auto const iod = ownerDirEntries(*env.current(), gw);
1404 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 2);
1405 BEAST_EXPECT(
1406 // NOLINTNEXTLINE(modernize-use-ranges)
1407 std::find(iod.begin(), iod.end(), ag) == iod.end());
1408 }
1409 }
1410 }
1411
1412 void
1414 {
1415 testcase("IOU RippleState");
1416 using namespace test::jtx;
1417 using namespace std::literals;
1418
1419 struct TestAccountData
1420 {
1421 Account src;
1422 Account dst;
1423 Account gw;
1424 bool hasTrustline;
1425 bool negative;
1426 };
1427
1429 {
1430 // src > dst && src > issuer && dst no trustline
1431 {
1432 .src = Account("alice2"),
1433 .dst = Account("bob0"),
1434 .gw = Account{"gw0"},
1435 .hasTrustline = false,
1436 .negative = true,
1437 },
1438 // src < dst && src < issuer && dst no trustline
1439 {
1440 .src = Account("carol0"),
1441 .dst = Account("dan1"),
1442 .gw = Account{"gw1"},
1443 .hasTrustline = false,
1444 .negative = false,
1445 },
1446 // dst > src && dst > issuer && dst no trustline
1447 {
1448 .src = Account("dan1"),
1449 .dst = Account("alice2"),
1450 .gw = Account{"gw0"},
1451 .hasTrustline = false,
1452 .negative = true,
1453 },
1454 // dst < src && dst < issuer && dst no trustline
1455 {
1456 .src = Account("bob0"),
1457 .dst = Account("carol0"),
1458 .gw = Account{"gw1"},
1459 .hasTrustline = false,
1460 .negative = false,
1461 },
1462 // src > dst && src > issuer && dst has trustline
1463 {
1464 .src = Account("alice2"),
1465 .dst = Account("bob0"),
1466 .gw = Account{"gw0"},
1467 .hasTrustline = true,
1468 .negative = true,
1469 },
1470 // src < dst && src < issuer && dst has trustline
1471 {
1472 .src = Account("carol0"),
1473 .dst = Account("dan1"),
1474 .gw = Account{"gw1"},
1475 .hasTrustline = true,
1476 .negative = false,
1477 },
1478 // dst > src && dst > issuer && dst has trustline
1479 {
1480 .src = Account("dan1"),
1481 .dst = Account("alice2"),
1482 .gw = Account{"gw0"},
1483 .hasTrustline = true,
1484 .negative = true,
1485 },
1486 // dst < src && dst < issuer && dst has trustline
1487 {
1488 .src = Account("bob0"),
1489 .dst = Account("carol0"),
1490 .gw = Account{"gw1"},
1491 .hasTrustline = true,
1492 .negative = false,
1493 },
1494 },
1495 };
1496
1497 for (auto const& t : tests)
1498 {
1499 Env env{*this, features};
1500 auto const baseFee = env.current()->fees().base;
1501 auto const usd = t.gw["USD"];
1502 env.fund(XRP(5000), t.src, t.dst, t.gw);
1503 env(fset(t.gw, asfAllowTrustLineLocking));
1504 env.close();
1505
1506 if (t.hasTrustline)
1507 {
1508 env.trust(usd(100'000), t.src, t.dst);
1509 }
1510 else
1511 {
1512 env.trust(usd(100'000), t.src);
1513 }
1514 env.close();
1515
1516 env(pay(t.gw, t.src, usd(10'000)));
1517 if (t.hasTrustline)
1518 env(pay(t.gw, t.dst, usd(10'000)));
1519 env.close();
1520
1521 // src can create escrow
1522 auto const seq1 = env.seq(t.src);
1523 auto const delta = usd(1'000);
1524 env(escrow::create(t.src, t.dst, delta),
1526 escrow::kFinishTime(env.now() + 1s),
1527 Fee(baseFee * 150));
1528 env.close();
1529
1530 // dst can finish escrow
1531 auto const preSrc = env.balance(t.src, usd);
1532 auto const preDst = env.balance(t.dst, usd);
1533
1534 env(escrow::finish(t.dst, t.src, seq1),
1537 Fee(baseFee * 150));
1538 env.close();
1539
1540 BEAST_EXPECT(env.balance(t.src, usd) == preSrc);
1541 BEAST_EXPECT(env.balance(t.dst, usd) == preDst + delta);
1542 }
1543 }
1544
1545 void
1547 {
1548 testcase("IOU Gateway");
1549 using namespace test::jtx;
1550 using namespace std::literals;
1551
1552 struct TestAccountData
1553 {
1554 Account src;
1555 Account dst;
1556 bool hasTrustline;
1557 };
1558
1559 // issuer is source
1560 {
1561 auto const gw = Account{"gateway"};
1562 auto const alice = Account{"alice"};
1563 Env env{*this, features};
1564 auto const baseFee = env.current()->fees().base;
1565 auto const usd = gw["USD"];
1566 env.fund(XRP(5000), alice, gw);
1567 env(fset(gw, asfAllowTrustLineLocking));
1568 env.close();
1569 env.trust(usd(100'000), alice);
1570 env.close();
1571
1572 env(pay(gw, alice, usd(10'000)));
1573 env.close();
1574
1575 // issuer cannot create escrow
1576 env(escrow::create(gw, alice, usd(1'000)),
1578 escrow::kFinishTime(env.now() + 1s),
1579 Fee(baseFee * 150),
1581 env.close();
1582 }
1583
1584 std::array<TestAccountData, 4> const gwDstTests = {
1585 {
1586 // src > dst && src > issuer && dst has trustline
1587 {.src = Account("alice2"), .dst = Account{"gw0"}, .hasTrustline = true},
1588 // src < dst && src < issuer && dst has trustline
1589 {.src = Account("carol0"), .dst = Account{"gw1"}, .hasTrustline = true},
1590 // dst > src && dst > issuer && dst has trustline
1591 {.src = Account("dan1"), .dst = Account{"gw0"}, .hasTrustline = true},
1592 // dst < src && dst < issuer && dst has trustline
1593 {.src = Account("bob0"), .dst = Account{"gw1"}, .hasTrustline = true},
1594 },
1595 };
1596
1597 // issuer is destination
1598 for (auto const& t : gwDstTests)
1599 {
1600 Env env{*this, features};
1601 auto const baseFee = env.current()->fees().base;
1602 auto const usd = t.dst["USD"];
1603 env.fund(XRP(5000), t.dst, t.src);
1604 env(fset(t.dst, asfAllowTrustLineLocking));
1605 env.close();
1606
1607 env.trust(usd(100'000), t.src);
1608 env.close();
1609
1610 env(pay(t.dst, t.src, usd(10'000)));
1611 env.close();
1612
1613 // issuer can receive escrow
1614 auto const seq1 = env.seq(t.src);
1615 auto const preSrc = env.balance(t.src, usd);
1616 env(escrow::create(t.src, t.dst, usd(1'000)),
1618 escrow::kFinishTime(env.now() + 1s),
1619 Fee(baseFee * 150));
1620 env.close();
1621
1622 // issuer can finish escrow, no dest trustline
1623 env(escrow::finish(t.dst, t.src, seq1),
1626 Fee(baseFee * 150));
1627 env.close();
1628 auto const preAmount = 10'000;
1629 BEAST_EXPECT(preSrc == usd(preAmount));
1630 auto const postAmount = 9000;
1631 BEAST_EXPECT(env.balance(t.src, usd) == usd(postAmount));
1632 BEAST_EXPECT(env.balance(t.dst, usd) == usd(0));
1633 }
1634
1635 // issuer is source and destination
1636 {
1637 auto const gw = Account{"gateway"};
1638 auto const usd = gw["USD"];
1639 Env env{*this, features};
1640 auto const baseFee = env.current()->fees().base;
1641 env.fund(XRP(5000), gw);
1642 env(fset(gw, asfAllowTrustLineLocking));
1643 env.close();
1644
1645 // issuer cannot receive escrow
1646 env(escrow::create(gw, gw, usd(1'000)),
1648 escrow::kFinishTime(env.now() + 1s),
1649 Fee(baseFee * 150),
1651 env.close();
1652 }
1653 }
1654
1655 void
1657 {
1658 testcase("IOU Locked Rate");
1659 using namespace test::jtx;
1660 using namespace std::literals;
1661
1662 auto const alice = Account("alice");
1663 auto const bob = Account("bob");
1664 auto const carol = Account("carol");
1665 auto const gw = Account{"gateway"};
1666 auto const usd = gw["USD"];
1667
1668 // test locked rate
1669 {
1670 Env env{*this, features};
1671 auto const baseFee = env.current()->fees().base;
1672 env.fund(XRP(10'000), alice, bob, gw);
1673 env(fset(gw, asfAllowTrustLineLocking));
1674 env(rate(gw, 1.25));
1675 env.close();
1676 env.trust(usd(100'000), alice);
1677 env.trust(usd(100'000), bob);
1678 env.close();
1679 env(pay(gw, alice, usd(10'000)));
1680 env(pay(gw, bob, usd(10'000)));
1681 env.close();
1682
1683 // alice can create escrow w/ xfer rate
1684 auto const preAlice = env.balance(alice, usd);
1685 auto const seq1 = env.seq(alice);
1686 auto const delta = usd(125);
1687 env(escrow::create(alice, bob, delta),
1689 escrow::kFinishTime(env.now() + 1s),
1690 Fee(baseFee * 150));
1691 env.close();
1692 auto const transferRate = escrow::rate(env, alice, seq1);
1693 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
1694
1695 // bob can finish escrow
1696 env(escrow::finish(bob, alice, seq1),
1699 Fee(baseFee * 150));
1700 env.close();
1701
1702 BEAST_EXPECT(env.balance(alice, usd) == preAlice - delta);
1703 BEAST_EXPECT(env.balance(bob, usd) == usd(10'100));
1704 }
1705 // test rate change - higher
1706 {
1707 Env env{*this, features};
1708 auto const baseFee = env.current()->fees().base;
1709 env.fund(XRP(10'000), alice, bob, gw);
1710 env(fset(gw, asfAllowTrustLineLocking));
1711 env(rate(gw, 1.25));
1712 env.close();
1713 env.trust(usd(100'000), alice);
1714 env.trust(usd(100'000), bob);
1715 env.close();
1716 env(pay(gw, alice, usd(10'000)));
1717 env(pay(gw, bob, usd(10'000)));
1718 env.close();
1719
1720 // alice can create escrow w/ xfer rate
1721 auto const preAlice = env.balance(alice, usd);
1722 auto const seq1 = env.seq(alice);
1723 auto const delta = usd(125);
1724 env(escrow::create(alice, bob, delta),
1726 escrow::kFinishTime(env.now() + 1s),
1727 Fee(baseFee * 150));
1728 env.close();
1729 auto const transferRate = escrow::rate(env, alice, seq1);
1730 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
1731
1732 // issuer changes rate higher
1733 env(rate(gw, 1.26));
1734 env.close();
1735
1736 // bob can finish escrow - rate unchanged
1737 env(escrow::finish(bob, alice, seq1),
1740 Fee(baseFee * 150));
1741 env.close();
1742
1743 BEAST_EXPECT(env.balance(alice, usd) == preAlice - delta);
1744 BEAST_EXPECT(env.balance(bob, usd) == usd(10'100));
1745 }
1746
1747 // test rate change - lower
1748 {
1749 Env env{*this, features};
1750 auto const baseFee = env.current()->fees().base;
1751 env.fund(XRP(10'000), alice, bob, gw);
1752 env(fset(gw, asfAllowTrustLineLocking));
1753 env(rate(gw, 1.25));
1754 env.close();
1755 env.trust(usd(100'000), alice);
1756 env.trust(usd(100'000), bob);
1757 env.close();
1758 env(pay(gw, alice, usd(10'000)));
1759 env(pay(gw, bob, usd(10'000)));
1760 env.close();
1761
1762 // alice can create escrow w/ xfer rate
1763 auto const preAlice = env.balance(alice, usd);
1764 auto const seq1 = env.seq(alice);
1765 auto const delta = usd(125);
1766 env(escrow::create(alice, bob, delta),
1768 escrow::kFinishTime(env.now() + 1s),
1769 Fee(baseFee * 150));
1770 env.close();
1771 auto const transferRate = escrow::rate(env, alice, seq1);
1772 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
1773
1774 // issuer changes rate lower
1775 env(rate(gw, 1.00));
1776 env.close();
1777
1778 // bob can finish escrow - rate changed
1779 env(escrow::finish(bob, alice, seq1),
1782 Fee(baseFee * 150));
1783 env.close();
1784
1785 BEAST_EXPECT(env.balance(alice, usd) == preAlice - delta);
1786 BEAST_EXPECT(env.balance(bob, usd) == usd(10125));
1787 }
1788
1789 // test cancel doesn't charge rate
1790 {
1791 Env env{*this, features};
1792 auto const baseFee = env.current()->fees().base;
1793 env.fund(XRP(10'000), alice, bob, gw);
1794 env(fset(gw, asfAllowTrustLineLocking));
1795 env(rate(gw, 1.25));
1796 env.close();
1797 env.trust(usd(100'000), alice);
1798 env.trust(usd(100'000), bob);
1799 env.close();
1800 env(pay(gw, alice, usd(10'000)));
1801 env(pay(gw, bob, usd(10'000)));
1802 env.close();
1803
1804 // alice can create escrow w/ xfer rate
1805 auto const preAlice = env.balance(alice, usd);
1806 auto const seq1 = env.seq(alice);
1807 auto const delta = usd(125);
1808 env(escrow::create(alice, bob, delta),
1809 escrow::kFinishTime(env.now() + 1s),
1810 escrow::kCancelTime(env.now() + 3s),
1811 Fee(baseFee));
1812 env.close();
1813 auto const transferRate = escrow::rate(env, alice, seq1);
1814 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
1815
1816 // issuer changes rate lower
1817 env(rate(gw, 1.00));
1818 env.close();
1819
1820 // alice can cancel escrow - rate is not charged
1821 env(escrow::cancel(alice, alice, seq1), Fee(baseFee));
1822 env.close();
1823
1824 BEAST_EXPECT(env.balance(alice, usd) == preAlice);
1825 BEAST_EXPECT(env.balance(bob, usd) == usd(10000));
1826 }
1827 }
1828
1829 void
1831 {
1832 testcase("IOU Limit");
1833 using namespace test::jtx;
1834 using namespace std::literals;
1835
1836 auto const alice = Account("alice");
1837 auto const bob = Account("bob");
1838 auto const gw = Account{"gateway"};
1839 auto const usd = gw["USD"];
1840
1841 // test LimitAmount
1842 {
1843 Env env{*this, features};
1844 auto const baseFee = env.current()->fees().base;
1845 env.fund(XRP(1'000), alice, bob, gw);
1846 env(fset(gw, asfAllowTrustLineLocking));
1847 env.close();
1848 env.trust(usd(10'000), alice, bob);
1849 env.close();
1850 env(pay(gw, alice, usd(1'000)));
1851 env(pay(gw, bob, usd(1'000)));
1852 env.close();
1853
1854 // alice can create escrow
1855 auto seq1 = env.seq(alice);
1856 auto const delta = usd(125);
1857 env(escrow::create(alice, bob, delta),
1859 escrow::kFinishTime(env.now() + 1s),
1860 Fee(baseFee * 150));
1861 env.close();
1862
1863 // bob can finish
1864 auto const preBobLimit = env.limit(bob, usd);
1865 env(escrow::finish(bob, alice, seq1),
1868 Fee(baseFee * 150));
1869 env.close();
1870 auto const postBobLimit = env.limit(bob, usd);
1871 // bob's limit is NOT changed
1872 BEAST_EXPECT(postBobLimit == preBobLimit);
1873 }
1874 }
1875
1876 void
1878 {
1879 testcase("IOU Require Auth");
1880 using namespace test::jtx;
1881 using namespace std::literals;
1882
1883 auto const alice = Account("alice");
1884 auto const bob = Account("bob");
1885 auto const carol = Account("carol");
1886 auto const gw = Account{"gateway"};
1887 auto const usd = gw["USD"];
1888
1889 auto const aliceUSD = alice["USD"];
1890 auto const bobUSD = bob["USD"];
1891
1892 Env env{*this, features};
1893 auto const baseFee = env.current()->fees().base;
1894 env.fund(XRP(1'000), alice, bob, gw);
1895 env(fset(gw, asfAllowTrustLineLocking));
1896 env(fset(gw, asfRequireAuth));
1897 env.close();
1898 env(trust(gw, aliceUSD(10'000)), Txflags(tfSetfAuth));
1899 env(trust(alice, usd(10'000)));
1900 env(trust(bob, usd(10'000)));
1901 env.close();
1902 env(pay(gw, alice, usd(1'000)));
1903 env.close();
1904
1905 // alice cannot create escrow - fails without auth
1906 auto seq1 = env.seq(alice);
1907 auto const delta = usd(125);
1908 env(escrow::create(alice, bob, delta),
1910 escrow::kFinishTime(env.now() + 1s),
1911 Fee(baseFee * 150),
1912 Ter(tecNO_AUTH));
1913 env.close();
1914
1915 // set auth on bob
1916 env(trust(gw, bobUSD(10'000)), Txflags(tfSetfAuth));
1917 env(trust(bob, usd(10'000)));
1918 env.close();
1919 env(pay(gw, bob, usd(1'000)));
1920 env.close();
1921
1922 // alice can create escrow - bob has auth
1923 seq1 = env.seq(alice);
1924 env(escrow::create(alice, bob, delta),
1926 escrow::kFinishTime(env.now() + 1s),
1927 Fee(baseFee * 150));
1928 env.close();
1929
1930 // bob can finish
1931 env(escrow::finish(bob, alice, seq1),
1934 Fee(baseFee * 150));
1935 env.close();
1936 }
1937
1938 void
1940 {
1941 testcase("IOU Freeze");
1942 using namespace test::jtx;
1943 using namespace std::literals;
1944
1945 auto const alice = Account("alice");
1946 auto const bob = Account("bob");
1947 auto const carol = Account("carol");
1948 auto const gw = Account{"gateway"};
1949 auto const usd = gw["USD"];
1950
1951 // test Global Freeze
1952 {
1953 Env env{*this, features};
1954 auto const baseFee = env.current()->fees().base;
1955 env.fund(XRP(10'000), alice, bob, gw);
1956 env(fset(gw, asfAllowTrustLineLocking));
1957 env.close();
1958 env.trust(usd(100'000), alice);
1959 env.trust(usd(100'000), bob);
1960 env.close();
1961 env(pay(gw, alice, usd(10'000)));
1962 env(pay(gw, bob, usd(10'000)));
1963 env.close();
1964 env(fset(gw, asfGlobalFreeze));
1965 env.close();
1966
1967 // setup transaction
1968 auto seq1 = env.seq(alice);
1969 auto const delta = usd(125);
1970
1971 // create escrow fails - frozen trustline
1972 env(escrow::create(alice, bob, delta),
1974 escrow::kFinishTime(env.now() + 1s),
1975 Fee(baseFee * 150),
1976 Ter(tecFROZEN));
1977 env.close();
1978
1979 // clear global freeze
1980 env(fclear(gw, asfGlobalFreeze));
1981 env.close();
1982
1983 // create escrow success
1984 seq1 = env.seq(alice);
1985 env(escrow::create(alice, bob, delta),
1987 escrow::kFinishTime(env.now() + 1s),
1988 Fee(baseFee * 150));
1989 env.close();
1990
1991 // set global freeze
1992 env(fset(gw, asfGlobalFreeze));
1993 env.close();
1994
1995 // bob finish escrow success regardless of frozen assets
1996 env(escrow::finish(bob, alice, seq1),
1999 Fee(baseFee * 150));
2000 env.close();
2001
2002 // clear global freeze
2003 env(fclear(gw, asfGlobalFreeze));
2004 env.close();
2005
2006 // create escrow success
2007 seq1 = env.seq(alice);
2008 env(escrow::create(alice, bob, delta),
2010 escrow::kCancelTime(env.now() + 1s),
2011 Fee(baseFee * 150));
2012 env.close();
2013
2014 // set global freeze
2015 env(fset(gw, asfGlobalFreeze));
2016 env.close();
2017
2018 // bob cancel escrow success regardless of frozen assets
2019 env(escrow::cancel(bob, alice, seq1), Fee(baseFee));
2020 env.close();
2021 }
2022
2023 // test Individual Freeze
2024 {
2025 // Env Setup
2026 Env env{*this, features};
2027 auto const baseFee = env.current()->fees().base;
2028 env.fund(XRP(10'000), alice, bob, gw);
2029 env(fset(gw, asfAllowTrustLineLocking));
2030 env.close();
2031 env(trust(alice, usd(100'000)));
2032 env(trust(bob, usd(100'000)));
2033 env.close();
2034 env(pay(gw, alice, usd(10'000)));
2035 env(pay(gw, bob, usd(10'000)));
2036 env.close();
2037
2038 // set freeze on alice trustline
2039 env(trust(gw, usd(10'000), alice, tfSetFreeze));
2040 env.close();
2041
2042 // setup transaction
2043 auto seq1 = env.seq(alice);
2044 auto const delta = usd(125);
2045
2046 // create escrow fails - frozen trustline
2047 env(escrow::create(alice, bob, delta),
2049 escrow::kFinishTime(env.now() + 1s),
2050 Fee(baseFee * 150),
2051 Ter(tecFROZEN));
2052 env.close();
2053
2054 // clear freeze on alice trustline
2055 env(trust(gw, usd(10'000), alice, tfClearFreeze));
2056 env.close();
2057
2058 // create escrow success
2059 seq1 = env.seq(alice);
2060 env(escrow::create(alice, bob, delta),
2062 escrow::kFinishTime(env.now() + 1s),
2063 Fee(baseFee * 150));
2064 env.close();
2065
2066 // set freeze on bob trustline
2067 env(trust(gw, usd(10'000), bob, tfSetFreeze));
2068 env.close();
2069
2070 // bob finish escrow success regardless of frozen assets
2071 env(escrow::finish(bob, alice, seq1),
2074 Fee(baseFee * 150));
2075 env.close();
2076
2077 // reset freeze on bob and alice trustline
2078 env(trust(gw, usd(10'000), alice, tfClearFreeze));
2079 env(trust(gw, usd(10'000), bob, tfClearFreeze));
2080 env.close();
2081
2082 // create escrow success
2083 seq1 = env.seq(alice);
2084 env(escrow::create(alice, bob, delta),
2086 escrow::kCancelTime(env.now() + 1s),
2087 Fee(baseFee * 150));
2088 env.close();
2089
2090 // set freeze on bob trustline
2091 env(trust(gw, usd(10'000), bob, tfSetFreeze));
2092 env.close();
2093
2094 // bob cancel escrow success regardless of frozen assets
2095 env(escrow::cancel(bob, alice, seq1), Fee(baseFee));
2096 env.close();
2097 }
2098
2099 // test Deep Freeze
2100 {
2101 // Env Setup
2102 Env env{*this, features};
2103 auto const baseFee = env.current()->fees().base;
2104 env.fund(XRP(10'000), alice, bob, gw);
2105 env(fset(gw, asfAllowTrustLineLocking));
2106 env.close();
2107 env(trust(alice, usd(100'000)));
2108 env(trust(bob, usd(100'000)));
2109 env.close();
2110 env(pay(gw, alice, usd(10'000)));
2111 env(pay(gw, bob, usd(10'000)));
2112 env.close();
2113
2114 // set freeze on alice trustline
2115 env(trust(gw, usd(10'000), alice, tfSetFreeze | tfSetDeepFreeze));
2116 env.close();
2117
2118 // setup transaction
2119 auto seq1 = env.seq(alice);
2120 auto const delta = usd(125);
2121
2122 // create escrow fails - frozen trustline
2123 env(escrow::create(alice, bob, delta),
2125 escrow::kFinishTime(env.now() + 1s),
2126 Fee(baseFee * 150),
2127 Ter(tecFROZEN));
2128 env.close();
2129
2130 // clear freeze on alice trustline
2131 env(trust(gw, usd(10'000), alice, tfClearFreeze | tfClearDeepFreeze));
2132 env.close();
2133
2134 // create escrow success
2135 seq1 = env.seq(alice);
2136 env(escrow::create(alice, bob, delta),
2138 escrow::kFinishTime(env.now() + 1s),
2139 Fee(baseFee * 150));
2140 env.close();
2141
2142 // set freeze on bob trustline
2143 env(trust(gw, usd(10'000), bob, tfSetFreeze | tfSetDeepFreeze));
2144 env.close();
2145
2146 // bob finish escrow fails because of deep frozen assets
2147 env(escrow::finish(bob, alice, seq1),
2150 Fee(baseFee * 150),
2151 Ter(tecFROZEN));
2152 env.close();
2153
2154 // reset freeze on alice and bob trustline
2155 env(trust(gw, usd(10'000), alice, tfClearFreeze | tfClearDeepFreeze));
2156 env(trust(gw, usd(10'000), bob, tfClearFreeze | tfClearDeepFreeze));
2157 env.close();
2158
2159 // create escrow success
2160 seq1 = env.seq(alice);
2161 env(escrow::create(alice, bob, delta),
2163 escrow::kCancelTime(env.now() + 1s),
2164 Fee(baseFee * 150));
2165 env.close();
2166
2167 // set freeze on bob trustline
2168 env(trust(gw, usd(10'000), bob, tfSetFreeze | tfSetDeepFreeze));
2169 env.close();
2170
2171 // bob cancel escrow fails because of deep frozen assets
2172 env(escrow::cancel(bob, alice, seq1), Fee(baseFee), Ter(tesSUCCESS));
2173 env.close();
2174 }
2175 }
2176 void
2178 {
2179 testcase("IOU Insufficient Funds");
2180 using namespace test::jtx;
2181 using namespace std::literals;
2182
2183 auto const alice = Account("alice");
2184 auto const bob = Account("bob");
2185 auto const carol = Account("carol");
2186 auto const gw = Account{"gateway"};
2187 auto const usd = gw["USD"];
2188 {
2189 // test tecPATH_PARTIAL
2190 // ie. has 10'000, escrow 1'000 then try to pay 10'000
2191 Env env{*this, features};
2192 auto const baseFee = env.current()->fees().base;
2193 env.fund(XRP(10'000), alice, bob, gw);
2194 env(fset(gw, asfAllowTrustLineLocking));
2195 env.close();
2196 env.trust(usd(100'000), alice);
2197 env.trust(usd(100'000), bob);
2198 env.close();
2199 env(pay(gw, alice, usd(10'000)));
2200 env(pay(gw, bob, usd(10'000)));
2201 env.close();
2202
2203 // create escrow success
2204 auto const delta = usd(1'000);
2205 env(escrow::create(alice, bob, delta),
2207 escrow::kFinishTime(env.now() + 1s),
2208 Fee(baseFee * 150));
2209 env.close();
2210 env(pay(alice, gw, usd(10'000)), Ter(tecPATH_PARTIAL));
2211 }
2212 {
2213 // test tecINSUFFICIENT_FUNDS
2214 // ie. has 10'000 escrow 1'000 then try to escrow 10'000
2215 Env env{*this, features};
2216 auto const baseFee = env.current()->fees().base;
2217 env.fund(XRP(10'000), alice, bob, gw);
2218 env(fset(gw, asfAllowTrustLineLocking));
2219 env.close();
2220 env.trust(usd(100'000), alice);
2221 env.trust(usd(100'000), bob);
2222 env.close();
2223 env(pay(gw, alice, usd(10'000)));
2224 env(pay(gw, bob, usd(10'000)));
2225 env.close();
2226
2227 auto const delta = usd(1'000);
2228 env(escrow::create(alice, bob, delta),
2230 escrow::kFinishTime(env.now() + 1s),
2231 Fee(baseFee * 150));
2232 env.close();
2233
2234 env(escrow::create(alice, bob, usd(10'000)),
2236 escrow::kFinishTime(env.now() + 1s),
2237 Fee(baseFee * 150),
2239 env.close();
2240 }
2241 }
2242
2243 void
2245 {
2246 testcase("IOU Precision Loss");
2247 using namespace test::jtx;
2248 using namespace std::literals;
2249
2250 auto const alice = Account("alice");
2251 auto const bob = Account("bob");
2252 auto const gw = Account{"gateway"};
2253 auto const usd = gw["USD"];
2254
2255 // test min create precision loss
2256 {
2257 Env env(*this, features);
2258 auto const baseFee = env.current()->fees().base;
2259 env.fund(XRP(10'000), alice, bob, gw);
2260 env(fset(gw, asfAllowTrustLineLocking));
2261 env.close();
2262 env.trust(usd(100000000000000000), alice);
2263 env.trust(usd(100000000000000000), bob);
2264 env.close();
2265 env(pay(gw, alice, usd(10000000000000000)));
2266 env(pay(gw, bob, usd(1)));
2267 env.close();
2268
2269 bool const largeMantissa = features[featureSingleAssetVault] ||
2270 features[featureLendingProtocol] || features[featureMPTokensV2];
2271
2272 // alice cannot create escrow for 1/10 iou - precision loss
2273 env(escrow::create(alice, bob, usd(1)),
2275 escrow::kFinishTime(env.now() + 1s),
2276 Fee(baseFee * 150),
2277 Ter(largeMantissa ? (TER)tesSUCCESS : (TER)tecPRECISION_LOSS));
2278 env.close();
2279
2280 auto const seq1 = env.seq(alice);
2281 // alice can create escrow for 1'000 iou
2282 env(escrow::create(alice, bob, usd(1'000)),
2284 escrow::kFinishTime(env.now() + 1s),
2285 Fee(baseFee * 150));
2286 env.close();
2287
2288 // bob finish escrow success
2289 env(escrow::finish(bob, alice, seq1),
2292 Fee(baseFee * 150));
2293 env.close();
2294 }
2295 }
2296
2297 void
2299 {
2300 testcase("MPT Enablement");
2301
2302 using namespace jtx;
2303 using namespace std::chrono;
2304
2305 for (bool const withTokenEscrow : {false, true})
2306 {
2307 auto const amend = withTokenEscrow ? features : features - featureTokenEscrow;
2308 Env env{*this, amend};
2309 auto const baseFee = env.current()->fees().base;
2310 auto const alice = Account("alice");
2311 auto const bob = Account("bob");
2312 auto const gw = Account("gw");
2313 env.fund(XRP(5000), bob);
2314
2315 MPTTester mptGw(env, gw, {.holders = {alice}});
2316 mptGw.create(
2317 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2318 mptGw.authorize({.account = alice});
2319 auto const mpt = mptGw["MPT"];
2320 env(pay(gw, alice, mpt(10'000)));
2321 env.close();
2322
2323 auto const createResult = withTokenEscrow ? Ter(tesSUCCESS) : Ter(temBAD_AMOUNT);
2324 auto const finishResult = withTokenEscrow ? Ter(tesSUCCESS) : Ter(tecNO_TARGET);
2325
2326 auto const seq1 = env.seq(alice);
2327 env(escrow::create(alice, bob, mpt(1'000)),
2329 escrow::kFinishTime(env.now() + 1s),
2330 Fee(baseFee * 150),
2331 createResult);
2332 env.close();
2333 env(escrow::finish(bob, alice, seq1),
2336 Fee(baseFee * 150),
2337 finishResult);
2338 env.close();
2339 auto const seq2 = env.seq(alice);
2340 env(escrow::create(alice, bob, mpt(1'000)),
2342 escrow::kFinishTime(env.now() + 1s),
2343 escrow::kCancelTime(env.now() + 2s),
2344 Fee(baseFee * 150),
2345 createResult);
2346 env.close();
2347 env(escrow::cancel(bob, alice, seq2), finishResult);
2348 env.close();
2349 }
2350 }
2351
2352 void
2354 {
2355 testcase("MPT Create Preflight");
2356 using namespace test::jtx;
2357 using namespace std::literals;
2358
2359 for (bool const withMPT : {true, false})
2360 {
2361 auto const amend = withMPT ? features : features - featureMPTokensV1;
2362 Env env{*this, amend};
2363 auto const baseFee = env.current()->fees().base;
2364 auto const alice = Account("alice");
2365 auto const bob = Account("bob");
2366 auto const gw = Account("gw");
2367 env.fund(XRP(1'000), alice, bob, gw);
2368
2369 json::Value jv = escrow::create(alice, bob, XRP(1));
2370 jv.removeMember(jss::Amount);
2371 jv[jss::Amount][jss::mpt_issuance_id] =
2372 "00000004A407AF5856CCF3C42619DAA925813FC955C72983";
2373 jv[jss::Amount][jss::value] = "-1";
2374
2375 auto const result = withMPT ? Ter(temBAD_AMOUNT) : Ter(temDISABLED);
2376 env(jv,
2378 escrow::kFinishTime(env.now() + 1s),
2379 Fee(baseFee * 150),
2380 result);
2381 env.close();
2382 }
2383
2384 // temBAD_AMOUNT: amount < 0
2385 {
2386 Env env{*this, features};
2387 auto const baseFee = env.current()->fees().base;
2388 auto const alice = Account("alice");
2389 auto const bob = Account("bob");
2390 auto const gw = Account("gw");
2391
2392 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2393 mptGw.create(
2394 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2395 mptGw.authorize({.account = alice});
2396 mptGw.authorize({.account = bob});
2397 auto const mpt = mptGw["MPT"];
2398 env(pay(gw, alice, mpt(10'000)));
2399 env(pay(gw, bob, mpt(10'000)));
2400 env.close();
2401
2402 env(escrow::create(alice, bob, mpt(-1)),
2404 escrow::kFinishTime(env.now() + 1s),
2405 Fee(baseFee * 150),
2407 env.close();
2408 }
2409 }
2410
2411 void
2413 {
2414 testcase("MPT Create Preclaim");
2415 using namespace test::jtx;
2416 using namespace std::literals;
2417
2418 // tecNO_PERMISSION: issuer is the same as the account
2419 {
2420 Env env{*this, features};
2421 auto const baseFee = env.current()->fees().base;
2422 auto const alice = Account("alice");
2423 auto const gw = Account("gw");
2424
2425 MPTTester mptGw(env, gw, {.holders = {alice}});
2426 mptGw.create(
2427 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2428 mptGw.authorize({.account = alice});
2429 auto const mpt = mptGw["MPT"];
2430 env(pay(gw, alice, mpt(10'000)));
2431 env.close();
2432
2433 env(escrow::create(gw, alice, mpt(1)),
2435 escrow::kFinishTime(env.now() + 1s),
2436 Fee(baseFee * 150),
2438 env.close();
2439 }
2440
2441 // tecOBJECT_NOT_FOUND: mpt does not exist
2442 {
2443 Env env{*this, features};
2444 auto const baseFee = env.current()->fees().base;
2445 auto const alice = Account("alice");
2446 auto const bob = Account("bob");
2447 auto const gw = Account("gw");
2448 env.fund(XRP(10'000), alice, bob, gw);
2449 env.close();
2450
2451 auto const mpt = xrpl::test::jtx::MPT(alice.name(), makeMptID(env.seq(alice), alice));
2452 json::Value jv = escrow::create(alice, bob, mpt(2));
2453 jv[jss::Amount][jss::mpt_issuance_id] =
2454 "00000004A407AF5856CCF3C42619DAA925813FC955C72983";
2455 env(jv,
2457 escrow::kFinishTime(env.now() + 1s),
2458 Fee(baseFee * 150),
2460 env.close();
2461 }
2462
2463 // tecNO_PERMISSION: tfMPTCanEscrow is not enabled
2464 {
2465 Env env{*this, features};
2466 auto const baseFee = env.current()->fees().base;
2467 auto const alice = Account("alice");
2468 auto const bob = Account("bob");
2469 auto const gw = Account("gw");
2470
2471 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2472 mptGw.create({.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanTransfer});
2473 mptGw.authorize({.account = alice});
2474 mptGw.authorize({.account = bob});
2475 auto const mpt = mptGw["MPT"];
2476 env(pay(gw, alice, mpt(10'000)));
2477 env(pay(gw, bob, mpt(10'000)));
2478 env.close();
2479
2480 env(escrow::create(alice, bob, mpt(3)),
2482 escrow::kFinishTime(env.now() + 1s),
2483 Fee(baseFee * 150),
2485 env.close();
2486 }
2487
2488 // tecOBJECT_NOT_FOUND: account does not have the mpt
2489 {
2490 Env env{*this, features};
2491 auto const baseFee = env.current()->fees().base;
2492 auto const alice = Account("alice");
2493 auto const bob = Account("bob");
2494 auto const gw = Account("gw");
2495
2496 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2497 mptGw.create(
2498 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2499 auto const mpt = mptGw["MPT"];
2500
2501 env(escrow::create(alice, bob, mpt(4)),
2503 escrow::kFinishTime(env.now() + 1s),
2504 Fee(baseFee * 150),
2506 env.close();
2507 }
2508
2509 // tecNO_AUTH: requireAuth set: account not authorized
2510 {
2511 Env env{*this, features};
2512 auto const baseFee = env.current()->fees().base;
2513 auto const alice = Account("alice");
2514 auto const bob = Account("bob");
2515 auto const gw = Account("gw");
2516
2517 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2518 mptGw.create({
2519 .ownerCount = 1,
2520 .holderCount = 0,
2521 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTRequireAuth,
2522 });
2523 mptGw.authorize({.account = alice});
2524 mptGw.authorize({.account = gw, .holder = alice});
2525 auto const mpt = mptGw["MPT"];
2526 env(pay(gw, alice, mpt(10'000)));
2527 env.close();
2528
2529 // unauthorize account
2530 mptGw.authorize({.account = gw, .holder = alice, .flags = tfMPTUnauthorize});
2531
2532 env(escrow::create(alice, bob, mpt(5)),
2534 escrow::kFinishTime(env.now() + 1s),
2535 Fee(baseFee * 150),
2536 Ter(tecNO_AUTH));
2537 env.close();
2538 }
2539
2540 // tecNO_AUTH: requireAuth set: dest not authorized
2541 {
2542 Env env{*this, features};
2543 auto const baseFee = env.current()->fees().base;
2544 auto const alice = Account("alice");
2545 auto const bob = Account("bob");
2546 auto const gw = Account("gw");
2547
2548 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2549 mptGw.create({
2550 .ownerCount = 1,
2551 .holderCount = 0,
2552 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTRequireAuth,
2553 });
2554 mptGw.authorize({.account = alice});
2555 mptGw.authorize({.account = gw, .holder = alice});
2556 mptGw.authorize({.account = bob});
2557 mptGw.authorize({.account = gw, .holder = bob});
2558 auto const mpt = mptGw["MPT"];
2559 env(pay(gw, alice, mpt(10'000)));
2560 env(pay(gw, bob, mpt(10'000)));
2561 env.close();
2562
2563 // unauthorize dest
2564 mptGw.authorize({.account = gw, .holder = bob, .flags = tfMPTUnauthorize});
2565
2566 env(escrow::create(alice, bob, mpt(6)),
2568 escrow::kFinishTime(env.now() + 1s),
2569 Fee(baseFee * 150),
2570 Ter(tecNO_AUTH));
2571 env.close();
2572 }
2573
2574 // tecLOCKED: issuer has locked the account
2575 {
2576 Env env{*this, features};
2577 auto const baseFee = env.current()->fees().base;
2578 auto const alice = Account("alice");
2579 auto const bob = Account("bob");
2580 auto const gw = Account("gw");
2581
2582 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2583 mptGw.create({
2584 .ownerCount = 1,
2585 .holderCount = 0,
2586 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTCanLock,
2587 });
2588 mptGw.authorize({.account = alice});
2589 mptGw.authorize({.account = bob});
2590 auto const mpt = mptGw["MPT"];
2591 env(pay(gw, alice, mpt(10'000)));
2592 env(pay(gw, bob, mpt(10'000)));
2593 env.close();
2594
2595 // lock account
2596 mptGw.set({.account = gw, .holder = alice, .flags = tfMPTLock});
2597
2598 env(escrow::create(alice, bob, mpt(7)),
2600 escrow::kFinishTime(env.now() + 1s),
2601 Fee(baseFee * 150),
2602 Ter(tecLOCKED));
2603 env.close();
2604 }
2605
2606 // tecLOCKED: issuer has locked the dest
2607 {
2608 Env env{*this, features};
2609 auto const baseFee = env.current()->fees().base;
2610 auto const alice = Account("alice");
2611 auto const bob = Account("bob");
2612 auto const gw = Account("gw");
2613
2614 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2615 mptGw.create({
2616 .ownerCount = 1,
2617 .holderCount = 0,
2618 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTCanLock,
2619 });
2620 mptGw.authorize({.account = alice});
2621 mptGw.authorize({.account = bob});
2622 auto const mpt = mptGw["MPT"];
2623 env(pay(gw, alice, mpt(10'000)));
2624 env(pay(gw, bob, mpt(10'000)));
2625 env.close();
2626
2627 // lock dest
2628 mptGw.set({.account = gw, .holder = bob, .flags = tfMPTLock});
2629
2630 env(escrow::create(alice, bob, mpt(8)),
2632 escrow::kFinishTime(env.now() + 1s),
2633 Fee(baseFee * 150),
2634 Ter(tecLOCKED));
2635 env.close();
2636 }
2637
2638 // tecNO_AUTH: mpt cannot be transferred
2639 {
2640 Env env{*this, features};
2641 auto const baseFee = env.current()->fees().base;
2642 auto const alice = Account("alice");
2643 auto const bob = Account("bob");
2644 auto const gw = Account("gw");
2645
2646 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2647 mptGw.create({.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow});
2648 mptGw.authorize({.account = alice});
2649 mptGw.authorize({.account = bob});
2650 auto const mpt = mptGw["MPT"];
2651 env(pay(gw, alice, mpt(10'000)));
2652 env(pay(gw, bob, mpt(10'000)));
2653 env.close();
2654
2655 env(escrow::create(alice, bob, mpt(9)),
2657 escrow::kFinishTime(env.now() + 1s),
2658 Fee(baseFee * 150),
2659 Ter(tecNO_AUTH));
2660 env.close();
2661 }
2662
2663 // tecINSUFFICIENT_FUNDS: spendable amount is zero
2664 {
2665 Env env{*this, features};
2666 auto const baseFee = env.current()->fees().base;
2667 auto const alice = Account("alice");
2668 auto const bob = Account("bob");
2669 auto const gw = Account("gw");
2670
2671 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2672 mptGw.create(
2673 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2674 mptGw.authorize({.account = alice});
2675 mptGw.authorize({.account = bob});
2676 auto const mpt = mptGw["MPT"];
2677 env(pay(gw, bob, mpt(10)));
2678 env.close();
2679
2680 env(escrow::create(alice, bob, mpt(11)),
2682 escrow::kFinishTime(env.now() + 1s),
2683 Fee(baseFee * 150),
2685 env.close();
2686 }
2687
2688 // tecINSUFFICIENT_FUNDS: spendable amount is less than the amount
2689 {
2690 Env env{*this, features};
2691 auto const baseFee = env.current()->fees().base;
2692 auto const alice = Account("alice");
2693 auto const bob = Account("bob");
2694 auto const gw = Account("gw");
2695
2696 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2697 mptGw.create(
2698 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2699 mptGw.authorize({.account = alice});
2700 mptGw.authorize({.account = bob});
2701 auto const mpt = mptGw["MPT"];
2702 env(pay(gw, alice, mpt(10)));
2703 env(pay(gw, bob, mpt(10)));
2704 env.close();
2705
2706 env(escrow::create(alice, bob, mpt(11)),
2708 escrow::kFinishTime(env.now() + 1s),
2709 Fee(baseFee * 150),
2711 env.close();
2712 }
2713 }
2714
2715 void
2717 {
2718 testcase("MPT Finish Preclaim");
2719 using namespace test::jtx;
2720 using namespace std::literals;
2721
2722 // tecNO_AUTH: requireAuth set: dest not authorized
2723 {
2724 Env env{*this, features};
2725 auto const baseFee = env.current()->fees().base;
2726 auto const alice = Account("alice");
2727 auto const bob = Account("bob");
2728 auto const gw = Account("gw");
2729
2730 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2731 mptGw.create({
2732 .ownerCount = 1,
2733 .holderCount = 0,
2734 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTRequireAuth,
2735 });
2736 mptGw.authorize({.account = alice});
2737 mptGw.authorize({.account = gw, .holder = alice});
2738 mptGw.authorize({.account = bob});
2739 mptGw.authorize({.account = gw, .holder = bob});
2740 auto const mpt = mptGw["MPT"];
2741 env(pay(gw, alice, mpt(10'000)));
2742 env(pay(gw, bob, mpt(10'000)));
2743 env.close();
2744
2745 auto const seq1 = env.seq(alice);
2746 env(escrow::create(alice, bob, mpt(10)),
2748 escrow::kFinishTime(env.now() + 1s),
2749 Fee(baseFee * 150),
2750 Ter(tesSUCCESS));
2751 env.close();
2752
2753 // unauthorize dest
2754 mptGw.authorize({.account = gw, .holder = bob, .flags = tfMPTUnauthorize});
2755
2756 env(escrow::finish(bob, alice, seq1),
2759 Fee(baseFee * 150),
2760 Ter(tecNO_AUTH));
2761 env.close();
2762 }
2763
2764 // tecOBJECT_NOT_FOUND: MPT issuance does not exist
2765 {
2766 Env env{*this, features};
2767 auto const baseFee = env.current()->fees().base;
2768 auto const alice = Account("alice");
2769 auto const bob = Account("bob");
2770 env.fund(XRP(10'000), alice, bob);
2771 env.close();
2772
2773 auto const seq1 = env.seq(alice);
2774 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
2775 Sandbox sb(&view, TapNone);
2776 auto const sleNew =
2778 MPTIssue const mpt{MPTIssue{makeMptID(1, AccountID(0x4985601))}};
2779 STAmount const amt(mpt, 10);
2780 sleNew->setAccountID(sfDestination, bob);
2781 sleNew->setFieldAmount(sfAmount, amt);
2782 sb.insert(sleNew);
2783 sb.apply(view);
2784 return true;
2785 });
2786
2787 env(escrow::finish(bob, alice, seq1),
2790 Fee(baseFee * 150),
2792 env.close();
2793 }
2794
2795 // tecLOCKED: issuer has locked the dest
2796 {
2797 Env env{*this, features};
2798 auto const baseFee = env.current()->fees().base;
2799 auto const alice = Account("alice");
2800 auto const bob = Account("bob");
2801 auto const gw = Account("gw");
2802
2803 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2804 mptGw.create({
2805 .ownerCount = 1,
2806 .holderCount = 0,
2807 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTCanLock,
2808 });
2809 mptGw.authorize({.account = alice});
2810 mptGw.authorize({.account = bob});
2811 auto const mpt = mptGw["MPT"];
2812 env(pay(gw, alice, mpt(10'000)));
2813 env(pay(gw, bob, mpt(10'000)));
2814 env.close();
2815
2816 auto const seq1 = env.seq(alice);
2817 env(escrow::create(alice, bob, mpt(8)),
2819 escrow::kFinishTime(env.now() + 1s),
2820 Fee(baseFee * 150),
2821 Ter(tesSUCCESS));
2822 env.close();
2823
2824 // lock dest
2825 mptGw.set({.account = gw, .holder = bob, .flags = tfMPTLock});
2826
2827 env(escrow::finish(bob, alice, seq1),
2830 Fee(baseFee * 150),
2831 Ter(tecLOCKED));
2832 env.close();
2833 }
2834 }
2835
2836 void
2838 {
2839 testcase("MPT Finish Do Apply");
2840 using namespace test::jtx;
2841 using namespace std::literals;
2842
2843 // tecINSUFFICIENT_RESERVE: insufficient reserve to create MPT
2844 {
2845 Env env{*this, features};
2846 auto const baseFee = env.current()->fees().base;
2847 auto const acctReserve = env.current()->fees().reserve;
2848 auto const incReserve = env.current()->fees().increment;
2849
2850 auto const alice = Account("alice");
2851 auto const bob = Account("bob");
2852 auto const gw = Account("gw");
2853 env.fund(acctReserve + (incReserve - 1), bob);
2854 env.close();
2855
2856 MPTTester mptGw(env, gw, {.holders = {alice}});
2857 mptGw.create(
2858 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2859 mptGw.authorize({.account = alice});
2860 auto const mpt = mptGw["MPT"];
2861 env(pay(gw, alice, mpt(10'000)));
2862 env.close();
2863
2864 auto const seq1 = env.seq(alice);
2865 env(escrow::create(alice, bob, mpt(10)),
2867 escrow::kFinishTime(env.now() + 1s),
2868 Fee(baseFee * 150),
2869 Ter(tesSUCCESS));
2870 env.close();
2871
2872 env(escrow::finish(bob, alice, seq1),
2875 Fee(baseFee * 150),
2877 env.close();
2878 }
2879
2880 // tesSUCCESS: bob submits; finish MPT created
2881 {
2882 Env env{*this, features};
2883 auto const baseFee = env.current()->fees().base;
2884 auto const alice = Account("alice");
2885 auto const bob = Account("bob");
2886 auto const gw = Account("gw");
2887 env.fund(XRP(10'000), bob);
2888 env.close();
2889
2890 MPTTester mptGw(env, gw, {.holders = {alice}});
2891 mptGw.create(
2892 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2893 mptGw.authorize({.account = alice});
2894 auto const mpt = mptGw["MPT"];
2895 env(pay(gw, alice, mpt(10'000)));
2896 env.close();
2897
2898 auto const seq1 = env.seq(alice);
2899 env(escrow::create(alice, bob, mpt(10)),
2901 escrow::kFinishTime(env.now() + 1s),
2902 Fee(baseFee * 150),
2903 Ter(tesSUCCESS));
2904 env.close();
2905
2906 env(escrow::finish(bob, alice, seq1),
2909 Fee(baseFee * 150),
2910 Ter(tesSUCCESS));
2911 env.close();
2912 }
2913
2914 // tecNO_PERMISSION: carol submits; finish MPT not created
2915 {
2916 Env env{*this, features};
2917 auto const baseFee = env.current()->fees().base;
2918 auto const alice = Account("alice");
2919 auto const bob = Account("bob");
2920 auto const carol = Account("carol");
2921 auto const gw = Account("gw");
2922 env.fund(XRP(10'000), bob, carol);
2923 env.close();
2924
2925 MPTTester mptGw(env, gw, {.holders = {alice}});
2926 mptGw.create(
2927 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
2928 mptGw.authorize({.account = alice});
2929 auto const mpt = mptGw["MPT"];
2930 env(pay(gw, alice, mpt(10'000)));
2931 env.close();
2932
2933 auto const seq1 = env.seq(alice);
2934 env(escrow::create(alice, bob, mpt(10)),
2936 escrow::kFinishTime(env.now() + 1s),
2937 Fee(baseFee * 150),
2938 Ter(tesSUCCESS));
2939 env.close();
2940
2941 env(escrow::finish(carol, alice, seq1),
2944 Fee(baseFee * 150),
2946 env.close();
2947 }
2948 }
2949
2950 void
2952 {
2953 testcase("MPT Cancel Preclaim");
2954 using namespace test::jtx;
2955 using namespace std::literals;
2956
2957 // tecNO_AUTH: requireAuth set: account not authorized
2958 {
2959 Env env{*this, features};
2960 auto const baseFee = env.current()->fees().base;
2961 auto const alice = Account("alice");
2962 auto const bob = Account("bob");
2963 auto const gw = Account("gw");
2964
2965 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
2966 mptGw.create({
2967 .ownerCount = 1,
2968 .holderCount = 0,
2969 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTRequireAuth,
2970 });
2971 mptGw.authorize({.account = alice});
2972 mptGw.authorize({.account = gw, .holder = alice});
2973 mptGw.authorize({.account = bob});
2974 mptGw.authorize({.account = gw, .holder = bob});
2975 auto const mpt = mptGw["MPT"];
2976 env(pay(gw, alice, mpt(10'000)));
2977 env(pay(gw, bob, mpt(10'000)));
2978 env.close();
2979
2980 auto const seq1 = env.seq(alice);
2981 env(escrow::create(alice, bob, mpt(10)),
2982 escrow::kCancelTime(env.now() + 2s),
2984 Fee(baseFee * 150),
2985 Ter(tesSUCCESS));
2986 env.close();
2987
2988 // unauthorize account
2989 mptGw.authorize({.account = gw, .holder = alice, .flags = tfMPTUnauthorize});
2990
2991 env(escrow::cancel(bob, alice, seq1), Ter(tecNO_AUTH));
2992 env.close();
2993 }
2994
2995 // tecOBJECT_NOT_FOUND: MPT issuance does not exist
2996 {
2997 Env env{*this, features};
2998 auto const baseFee = env.current()->fees().base;
2999 auto const alice = Account("alice");
3000 auto const bob = Account("bob");
3001 env.fund(XRP(10'000), alice, bob);
3002
3003 auto const seq1 = env.seq(alice);
3004 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
3005 Sandbox sb(&view, TapNone);
3006 auto const sleNew =
3008 MPTIssue const mpt{MPTIssue{makeMptID(1, AccountID(0x4985601))}};
3009 STAmount const amt(mpt, 10);
3010 sleNew->setAccountID(sfDestination, bob);
3011 sleNew->setFieldAmount(sfAmount, amt);
3012 sb.insert(sleNew);
3013 sb.apply(view);
3014 return true;
3015 });
3016
3017 env(escrow::cancel(bob, alice, seq1), Fee(baseFee), Ter(tecOBJECT_NOT_FOUND));
3018 env.close();
3019 }
3020 }
3021
3022 void
3024 {
3025 testcase("MPT Balances");
3026
3027 using namespace jtx;
3028 using namespace std::chrono;
3029
3030 Env env{*this, features};
3031 auto const baseFee = env.current()->fees().base;
3032 auto const alice = Account("alice");
3033 auto const bob = Account("bob");
3034 auto const carol = Account("carol");
3035 auto const gw = Account("gw");
3036 env.fund(XRP(5000), bob);
3037
3038 MPTTester mptGw(env, gw, {.holders = {alice, carol}});
3039 mptGw.create(
3040 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
3041 mptGw.authorize({.account = alice});
3042 mptGw.authorize({.account = carol});
3043 auto const mpt = mptGw["MPT"];
3044 env(pay(gw, alice, mpt(10'000)));
3045 env(pay(gw, carol, mpt(10'000)));
3046 env.close();
3047
3048 auto const outstandingMPT = env.balance(gw, mpt);
3049
3050 // Create & Finish Escrow
3051 auto const seq1 = env.seq(alice);
3052 {
3053 auto const preAliceMPT = env.balance(alice, mpt);
3054 auto const preBobMPT = env.balance(bob, mpt);
3055 env(escrow::create(alice, bob, mpt(1'000)),
3057 escrow::kFinishTime(env.now() + 1s),
3058 Fee(baseFee * 150),
3059 Ter(tesSUCCESS));
3060 env.close();
3061
3062 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3063 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1'000);
3064 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT);
3065 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3066 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3067 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 1'000);
3068 }
3069 {
3070 auto const preAliceMPT = env.balance(alice, mpt);
3071 auto const preBobMPT = env.balance(bob, mpt);
3072 env(escrow::finish(bob, alice, seq1),
3075 Fee(baseFee * 150),
3076 Ter(tesSUCCESS));
3077 env.close();
3078
3079 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT);
3080 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3081 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT + mpt(1'000));
3082 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3083 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3084 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3085 }
3086
3087 // Create & Cancel Escrow
3088 auto const seq2 = env.seq(alice);
3089 {
3090 auto const preAliceMPT = env.balance(alice, mpt);
3091 auto const preBobMPT = env.balance(bob, mpt);
3092 env(escrow::create(alice, bob, mpt(1'000)),
3094 escrow::kFinishTime(env.now() + 1s),
3095 escrow::kCancelTime(env.now() + 2s),
3096 Fee(baseFee * 150),
3097 Ter(tesSUCCESS));
3098 env.close();
3099
3100 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3101 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1'000);
3102 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT);
3103 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3104 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3105 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 1'000);
3106 }
3107 {
3108 auto const preAliceMPT = env.balance(alice, mpt);
3109 auto const preBobMPT = env.balance(bob, mpt);
3110 env(escrow::cancel(bob, alice, seq2), Ter(tesSUCCESS));
3111 env.close();
3112
3113 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT + mpt(1'000));
3114 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3115 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT);
3116 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3117 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3118 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3119 }
3120
3121 // Self Escrow Create & Finish
3122 {
3123 auto const seq = env.seq(alice);
3124 auto const preAliceMPT = env.balance(alice, mpt);
3125 env(escrow::create(alice, alice, mpt(1'000)),
3127 escrow::kFinishTime(env.now() + 1s),
3128 Fee(baseFee * 150),
3129 Ter(tesSUCCESS));
3130 env.close();
3131
3132 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3133 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1'000);
3134 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3135 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 1'000);
3136
3137 env(escrow::finish(alice, alice, seq),
3140 Fee(baseFee * 150),
3141 Ter(tesSUCCESS));
3142 env.close();
3143
3144 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT);
3145 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3146 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3147 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3148 }
3149
3150 // Self Escrow Create & Cancel
3151 {
3152 auto const seq = env.seq(alice);
3153 auto const preAliceMPT = env.balance(alice, mpt);
3154 env(escrow::create(alice, alice, mpt(1'000)),
3156 escrow::kFinishTime(env.now() + 1s),
3157 escrow::kCancelTime(env.now() + 2s),
3158 Fee(baseFee * 150),
3159 Ter(tesSUCCESS));
3160 env.close();
3161
3162 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3163 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1'000);
3164 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3165 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 1'000);
3166
3167 env(escrow::cancel(alice, alice, seq), Ter(tesSUCCESS));
3168 env.close();
3169
3170 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT);
3171 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3172 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3173 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3174 }
3175
3176 // Multiple Escrows
3177 {
3178 auto const preAliceMPT = env.balance(alice, mpt);
3179 auto const preBobMPT = env.balance(bob, mpt);
3180 auto const preCarolMPT = env.balance(carol, mpt);
3181 env(escrow::create(alice, bob, mpt(1'000)),
3183 escrow::kFinishTime(env.now() + 1s),
3184 Fee(baseFee * 150),
3185 Ter(tesSUCCESS));
3186 env.close();
3187
3188 env(escrow::create(carol, bob, mpt(1'000)),
3190 escrow::kFinishTime(env.now() + 1s),
3191 Fee(baseFee * 150),
3192 Ter(tesSUCCESS));
3193 env.close();
3194
3195 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3196 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1'000);
3197 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT);
3198 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3199 BEAST_EXPECT(env.balance(carol, mpt) == preCarolMPT - mpt(1'000));
3200 BEAST_EXPECT(mptEscrowed(env, carol, mpt) == 1'000);
3201 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3202 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 2'000);
3203 }
3204
3205 // Max MPT Amount Issued (Escrow 1 MPT)
3206 {
3207 Env env{*this, features};
3208 auto const baseFee = env.current()->fees().base;
3209 auto const alice = Account("alice");
3210 auto const bob = Account("bob");
3211 auto const gw = Account("gw");
3212
3213 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
3214 mptGw.create(
3215 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
3216 mptGw.authorize({.account = alice});
3217 mptGw.authorize({.account = bob});
3218 auto const mpt = mptGw["MPT"];
3219 env(pay(gw, alice, mpt(kMaxMpTokenAmount)));
3220 env.close();
3221
3222 auto const preAliceMPT = env.balance(alice, mpt);
3223 auto const preBobMPT = env.balance(bob, mpt);
3224 auto const outstandingMPT = env.balance(gw, mpt);
3225
3226 auto const seq1 = env.seq(alice);
3227 env(escrow::create(alice, bob, mpt(1)),
3229 escrow::kFinishTime(env.now() + 1s),
3230 Fee(baseFee * 150));
3231 env.close();
3232
3233 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1));
3234 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1);
3235 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT);
3236 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3237 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3238 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 1);
3239
3240 env(escrow::finish(bob, alice, seq1),
3243 Fee(baseFee * 150),
3244 Ter(tesSUCCESS));
3245 env.close();
3246
3247 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1));
3248 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3249 BEAST_EXPECT(
3250 !env.le(keylet::mptoken(mpt.mpt(), alice))->isFieldPresent(sfLockedAmount));
3251 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT + mpt(1));
3252 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3253 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3254 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3255 BEAST_EXPECT(
3256 !env.le(keylet::mptokenIssuance(mpt.mpt()))->isFieldPresent(sfLockedAmount));
3257 }
3258
3259 // Max MPT Amount Issued (Escrow Max MPT)
3260 {
3261 Env env{*this, features};
3262 auto const baseFee = env.current()->fees().base;
3263 auto const alice = Account("alice");
3264 auto const bob = Account("bob");
3265 auto const gw = Account("gw");
3266
3267 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
3268 mptGw.create(
3269 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
3270 mptGw.authorize({.account = alice});
3271 mptGw.authorize({.account = bob});
3272 auto const mpt = mptGw["MPT"];
3273 env(pay(gw, alice, mpt(kMaxMpTokenAmount)));
3274 env.close();
3275
3276 auto const preAliceMPT = env.balance(alice, mpt);
3277 auto const preBobMPT = env.balance(bob, mpt);
3278 auto const outstandingMPT = env.balance(gw, mpt);
3279
3280 // Escrow Max MPT - 10
3281 auto const seq1 = env.seq(alice);
3282 env(escrow::create(alice, bob, mpt(kMaxMpTokenAmount - 10)),
3284 escrow::kFinishTime(env.now() + 1s),
3285 Fee(baseFee * 150));
3286 env.close();
3287
3288 // Escrow 10 MPT
3289 auto const seq2 = env.seq(alice);
3290 env(escrow::create(alice, bob, mpt(10)),
3292 escrow::kFinishTime(env.now() + 1s),
3293 Fee(baseFee * 150));
3294 env.close();
3295
3296 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(kMaxMpTokenAmount));
3297 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == kMaxMpTokenAmount);
3298 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT);
3299 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3300 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3301 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == kMaxMpTokenAmount);
3302
3303 env(escrow::finish(bob, alice, seq1),
3306 Fee(baseFee * 150),
3307 Ter(tesSUCCESS));
3308 env.close();
3309
3310 env(escrow::finish(bob, alice, seq2),
3313 Fee(baseFee * 150),
3314 Ter(tesSUCCESS));
3315 env.close();
3316
3317 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(kMaxMpTokenAmount));
3318 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3319 BEAST_EXPECT(env.balance(bob, mpt) == preBobMPT + mpt(kMaxMpTokenAmount));
3320 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
3321 BEAST_EXPECT(env.balance(gw, mpt) == outstandingMPT);
3322 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3323 }
3324 }
3325
3326 void
3328 {
3329 using namespace jtx;
3330 using namespace std::chrono;
3331
3332 auto const alice = Account("alice");
3333 auto const bob = Account("bob");
3334 auto const carol = Account("carol");
3335 auto const gw = Account{"gateway"};
3336 {
3337 testcase("MPT Metadata to self");
3338
3339 Env env{*this, features};
3340 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
3341 mptGw.create(
3342 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
3343 mptGw.authorize({.account = alice});
3344 mptGw.authorize({.account = bob});
3345 auto const mpt = mptGw["MPT"];
3346 env(pay(gw, alice, mpt(10'000)));
3347 env(pay(gw, bob, mpt(10'000)));
3348 env.close();
3349 auto const aseq = env.seq(alice);
3350 auto const bseq = env.seq(bob);
3351
3352 env(escrow::create(alice, alice, mpt(1'000)),
3353 escrow::kFinishTime(env.now() + 1s),
3354 escrow::kCancelTime(env.now() + 500s));
3355 BEAST_EXPECT(
3356 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
3357 env.close(5s);
3358 auto const aa = env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq)));
3359 BEAST_EXPECT(aa);
3360 {
3361 auto const aod = ownerDirEntries(*env.current(), alice);
3362 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 2);
3363 BEAST_EXPECT(
3364 // NOLINTNEXTLINE(modernize-use-ranges)
3365 std::find(aod.begin(), aod.end(), aa) != aod.end());
3366 }
3367
3368 {
3369 auto const iod = ownerDirEntries(*env.current(), gw);
3370 BEAST_EXPECT(std::distance(iod.begin(), iod.end()) == 1);
3371 BEAST_EXPECT(
3372 // NOLINTNEXTLINE(modernize-use-ranges)
3373 std::find(iod.begin(), iod.end(), aa) == iod.end());
3374 }
3375
3376 env(escrow::create(bob, bob, mpt(1'000)),
3377 escrow::kFinishTime(env.now() + 1s),
3378 escrow::kCancelTime(env.now() + 2s));
3379 BEAST_EXPECT(
3380 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
3381 env.close(5s);
3382 auto const bb = env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq)));
3383 BEAST_EXPECT(bb);
3384
3385 {
3386 auto const bod = ownerDirEntries(*env.current(), bob);
3387 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 2);
3388 BEAST_EXPECT(
3389 // NOLINTNEXTLINE(modernize-use-ranges)
3390 std::find(bod.begin(), bod.end(), bb) != bod.end());
3391 }
3392
3393 env.close(5s);
3394 env(escrow::finish(alice, alice, aseq));
3395 {
3396 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
3397 BEAST_EXPECT(
3398 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
3399
3400 auto const aod = ownerDirEntries(*env.current(), alice);
3401 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
3402 BEAST_EXPECT(
3403 // NOLINTNEXTLINE(modernize-use-ranges)
3404 std::find(aod.begin(), aod.end(), aa) == aod.end());
3405
3406 auto const bod = ownerDirEntries(*env.current(), bob);
3407 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 2);
3408 BEAST_EXPECT(
3409 // NOLINTNEXTLINE(modernize-use-ranges)
3410 std::find(bod.begin(), bod.end(), bb) != bod.end());
3411 }
3412
3413 env.close(5s);
3414 env(escrow::cancel(bob, bob, bseq));
3415 {
3416 BEAST_EXPECT(!env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq))));
3417 BEAST_EXPECT(
3418 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
3419
3420 auto const bod = ownerDirEntries(*env.current(), bob);
3421 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 1);
3422 BEAST_EXPECT(
3423 // NOLINTNEXTLINE(modernize-use-ranges)
3424 std::find(bod.begin(), bod.end(), bb) == bod.end());
3425 }
3426 }
3427
3428 {
3429 testcase("MPT Metadata to other");
3430
3431 Env env{*this, features};
3432 MPTTester mptGw(env, gw, {.holders = {alice, bob, carol}});
3433 mptGw.create(
3434 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
3435 mptGw.authorize({.account = alice});
3436 mptGw.authorize({.account = bob});
3437 mptGw.authorize({.account = carol});
3438 auto const mpt = mptGw["MPT"];
3439 env(pay(gw, alice, mpt(10'000)));
3440 env(pay(gw, bob, mpt(10'000)));
3441 env(pay(gw, carol, mpt(10'000)));
3442 env.close();
3443 auto const aseq = env.seq(alice);
3444 auto const bseq = env.seq(bob);
3445
3446 env(escrow::create(alice, bob, mpt(1'000)), escrow::kFinishTime(env.now() + 1s));
3447 BEAST_EXPECT(
3448 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
3449 env.close(5s);
3450 env(escrow::create(bob, carol, mpt(1'000)),
3451 escrow::kFinishTime(env.now() + 1s),
3452 escrow::kCancelTime(env.now() + 2s));
3453 BEAST_EXPECT(
3454 (*env.meta())[sfTransactionResult] == static_cast<std::uint8_t>(tesSUCCESS));
3455 env.close(5s);
3456
3457 auto const ab = env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq)));
3458 BEAST_EXPECT(ab);
3459
3460 auto const bc = env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq)));
3461 BEAST_EXPECT(bc);
3462
3463 {
3464 auto const aod = ownerDirEntries(*env.current(), alice);
3465 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 2);
3466 BEAST_EXPECT(
3467 // NOLINTNEXTLINE(modernize-use-ranges)
3468 std::find(aod.begin(), aod.end(), ab) != aod.end());
3469
3470 auto const bod = ownerDirEntries(*env.current(), bob);
3471 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 3);
3472 BEAST_EXPECT(
3473 // NOLINTNEXTLINE(modernize-use-ranges)
3474 std::find(bod.begin(), bod.end(), ab) != bod.end());
3475 BEAST_EXPECT(
3476 // NOLINTNEXTLINE(modernize-use-ranges)
3477 std::find(bod.begin(), bod.end(), bc) != bod.end());
3478
3479 auto const cod = ownerDirEntries(*env.current(), carol);
3480 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 2);
3481 BEAST_EXPECT(
3482 // NOLINTNEXTLINE(modernize-use-ranges)
3483 std::find(cod.begin(), cod.end(), bc) != cod.end());
3484 }
3485
3486 env.close(5s);
3487 env(escrow::finish(alice, alice, aseq));
3488 {
3489 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
3490 BEAST_EXPECT(env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq))));
3491
3492 auto const aod = ownerDirEntries(*env.current(), alice);
3493 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
3494 BEAST_EXPECT(
3495 // NOLINTNEXTLINE(modernize-use-ranges)
3496 std::find(aod.begin(), aod.end(), ab) == aod.end());
3497
3498 auto const bod = ownerDirEntries(*env.current(), bob);
3499 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 2);
3500 BEAST_EXPECT(
3501 // NOLINTNEXTLINE(modernize-use-ranges)
3502 std::find(bod.begin(), bod.end(), ab) == bod.end());
3503 BEAST_EXPECT(
3504 // NOLINTNEXTLINE(modernize-use-ranges)
3505 std::find(bod.begin(), bod.end(), bc) != bod.end());
3506
3507 auto const cod = ownerDirEntries(*env.current(), carol);
3508 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 2);
3509 }
3510
3511 env.close(5s);
3512 env(escrow::cancel(bob, bob, bseq));
3513 {
3514 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(aseq))));
3515 BEAST_EXPECT(!env.le(keylet::escrow(bob.id(), SeqProxy::rawSequence(bseq))));
3516
3517 auto const aod = ownerDirEntries(*env.current(), alice);
3518 BEAST_EXPECT(std::distance(aod.begin(), aod.end()) == 1);
3519 BEAST_EXPECT(
3520 // NOLINTNEXTLINE(modernize-use-ranges)
3521 std::find(aod.begin(), aod.end(), ab) == aod.end());
3522
3523 auto const bod = ownerDirEntries(*env.current(), bob);
3524 BEAST_EXPECT(std::distance(bod.begin(), bod.end()) == 1);
3525 BEAST_EXPECT(
3526 // NOLINTNEXTLINE(modernize-use-ranges)
3527 std::find(bod.begin(), bod.end(), ab) == bod.end());
3528 BEAST_EXPECT(
3529 // NOLINTNEXTLINE(modernize-use-ranges)
3530 std::find(bod.begin(), bod.end(), bc) == bod.end());
3531
3532 auto const cod = ownerDirEntries(*env.current(), carol);
3533 BEAST_EXPECT(std::distance(cod.begin(), cod.end()) == 1);
3534 }
3535 }
3536 }
3537
3538 void
3540 {
3541 testcase("MPT Gateway Balances");
3542 using namespace test::jtx;
3543 using namespace std::literals;
3544
3545 // issuer is dest; alice w/ authorization
3546 {
3547 Env env{*this, features};
3548 auto const baseFee = env.current()->fees().base;
3549 auto const alice = Account("alice");
3550 auto const gw = Account("gw");
3551
3552 MPTTester mptGw(env, gw, {.holders = {alice}});
3553 mptGw.create(
3554 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
3555 mptGw.authorize({.account = alice});
3556 auto const mpt = mptGw["MPT"];
3557 env(pay(gw, alice, mpt(10'000)));
3558 env.close();
3559
3560 // issuer can be destination
3561 auto const seq1 = env.seq(alice);
3562 auto const preAliceMPT = env.balance(alice, mpt);
3563 auto const preOutstanding = env.balance(gw, mpt);
3564 auto const preEscrowed = issuerMPTEscrowed(env, mpt);
3565 BEAST_EXPECT(preOutstanding == mpt(-10'000));
3566 BEAST_EXPECT(preEscrowed == 0);
3567
3568 env(escrow::create(alice, gw, mpt(1'000)),
3570 escrow::kFinishTime(env.now() + 1s),
3571 Fee(baseFee * 150));
3572 env.close();
3573
3574 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3575 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 1'000);
3576 BEAST_EXPECT(env.balance(gw, mpt) == preOutstanding);
3577 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == preEscrowed + 1'000);
3578
3579 // issuer (dest) can finish escrow
3580 env(escrow::finish(gw, alice, seq1),
3583 Fee(baseFee * 150));
3584 env.close();
3585
3586 BEAST_EXPECT(env.balance(alice, mpt) == preAliceMPT - mpt(1'000));
3587 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3588 BEAST_EXPECT(env.balance(gw, mpt) == preOutstanding + mpt(1'000));
3589 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == preEscrowed);
3590 }
3591 }
3592
3593 void
3595 {
3596 testcase("MPT Locked Rate");
3597 using namespace test::jtx;
3598 using namespace std::literals;
3599
3600 auto const alice = Account("alice");
3601 auto const bob = Account("bob");
3602 auto const carol = Account("carol");
3603 auto const gw = Account{"gateway"};
3604 auto const usd = gw["USD"];
3605
3606 // test locked rate: finish
3607 {
3608 Env env{*this, features};
3609 auto const baseFee = env.current()->fees().base;
3610 auto const alice = Account("alice");
3611 auto const bob = Account("bob");
3612 auto const gw = Account("gw");
3613
3614 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
3615 mptGw.create({
3616 .transferFee = 25000,
3617 .ownerCount = 1,
3618 .holderCount = 0,
3619 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3620 });
3621 mptGw.authorize({.account = alice});
3622 mptGw.authorize({.account = bob});
3623 auto const mpt = mptGw["MPT"];
3624 env(pay(gw, alice, mpt(10'000)));
3625 env(pay(gw, bob, mpt(10'000)));
3626 env.close();
3627
3628 // alice can create escrow w/ xfer rate
3629 auto const preAlice = env.balance(alice, mpt);
3630 auto const seq1 = env.seq(alice);
3631 auto const delta = mpt(125);
3632 env(escrow::create(alice, bob, mpt(125)),
3634 escrow::kFinishTime(env.now() + 1s),
3635 Fee(baseFee * 150));
3636 env.close();
3637 auto const transferRate = escrow::rate(env, alice, seq1);
3638 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
3639
3640 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 125);
3641 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 125);
3642 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-20'000));
3643
3644 // bob can finish escrow
3645 env(escrow::finish(bob, alice, seq1),
3648 Fee(baseFee * 150));
3649 env.close();
3650
3651 BEAST_EXPECT(env.balance(alice, mpt) == preAlice - delta);
3652 BEAST_EXPECT(env.balance(bob, mpt) == mpt(10'100));
3653
3654 auto const escrowedWithFix = env.current()->rules().enabled(fixTokenEscrowV1) ? 0 : 25;
3655 auto const outstandingWithFix =
3656 env.current()->rules().enabled(fixTokenEscrowV1) ? mpt(19'975) : mpt(20'000);
3657 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == escrowedWithFix);
3658 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == escrowedWithFix);
3659 BEAST_EXPECT(env.balance(gw, mpt) == -outstandingWithFix);
3660 }
3661
3662 // test locked rate: cancel
3663 {
3664 Env env{*this, features};
3665 auto const baseFee = env.current()->fees().base;
3666 auto const alice = Account("alice");
3667 auto const bob = Account("bob");
3668 auto const gw = Account("gw");
3669
3670 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
3671 mptGw.create({
3672 .transferFee = 25000,
3673 .ownerCount = 1,
3674 .holderCount = 0,
3675 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3676 });
3677 mptGw.authorize({.account = alice});
3678 mptGw.authorize({.account = bob});
3679 auto const mpt = mptGw["MPT"];
3680 env(pay(gw, alice, mpt(10'000)));
3681 env(pay(gw, bob, mpt(10'000)));
3682 env.close();
3683
3684 // alice can create escrow w/ xfer rate
3685 auto const preAlice = env.balance(alice, mpt);
3686 auto const preBob = env.balance(bob, mpt);
3687 auto const seq1 = env.seq(alice);
3688 auto const delta = mpt(125);
3689 env(escrow::create(alice, bob, mpt(125)),
3691 escrow::kFinishTime(env.now() + 1s),
3692 escrow::kCancelTime(env.now() + 3s),
3693 Fee(baseFee * 150));
3694 env.close();
3695 auto const transferRate = escrow::rate(env, alice, seq1);
3696 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
3697
3698 // alice can cancel escrow
3699 env(escrow::cancel(alice, alice, seq1), Fee(baseFee));
3700 env.close();
3701
3702 BEAST_EXPECT(env.balance(alice, mpt) == preAlice);
3703 BEAST_EXPECT(env.balance(bob, mpt) == preBob);
3704 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-20'000));
3705 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3706 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3707 }
3708
3709 // test locked rate: issuer is destination
3710 {
3711 Env env{*this, features};
3712 auto const baseFee = env.current()->fees().base;
3713 auto const alice = Account("alice");
3714 auto const bob = Account("bob");
3715 auto const gw = Account("gw");
3716
3717 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
3718 mptGw.create({
3719 .transferFee = 25000,
3720 .ownerCount = 1,
3721 .holderCount = 0,
3722 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3723 });
3724 mptGw.authorize({.account = alice});
3725 mptGw.authorize({.account = bob});
3726 auto const mpt = mptGw["MPT"];
3727 env(pay(gw, alice, mpt(10'000)));
3728 env(pay(gw, bob, mpt(10'000)));
3729 env.close();
3730
3731 // alice can create escrow w/ xfer rate
3732 auto const preAlice = env.balance(alice, mpt);
3733 auto const seq1 = env.seq(alice);
3734 auto const delta = mpt(125);
3735 env(escrow::create(alice, gw, mpt(125)),
3737 escrow::kFinishTime(env.now() + 1s),
3738 Fee(baseFee * 150));
3739 env.close();
3740 auto const transferRate = escrow::rate(env, alice, seq1);
3741 BEAST_EXPECT(transferRate.value == std::uint32_t(1'000'000'000 * 1.25));
3742
3743 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 125);
3744 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 125);
3745 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-20'000));
3746
3747 // bob can finish escrow
3748 env(escrow::finish(gw, alice, seq1),
3751 Fee(baseFee * 150));
3752 env.close();
3753
3754 BEAST_EXPECT(env.balance(alice, mpt) == preAlice - delta);
3755 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3756 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3757 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-19'875));
3758 }
3759 }
3760
3761 void
3763 {
3764 using namespace test::jtx;
3765 using namespace std::literals;
3766
3767 bool const withCleanup340 = features[fixCleanup3_4_0];
3768 testcase(
3769 std::string("MPT Split Escrow Transfer Fee ") +
3770 (withCleanup340 ? "with Cleanup340" : "without Cleanup340"));
3771
3772 Env env{*this, features};
3773 auto const baseFee = env.current()->fees().base;
3774 auto const alice = Account("alice");
3775 auto const bob = Account("bob");
3776 auto const gw = Account("gw");
3777 env.fund(XRP(1'000), alice, bob, gw);
3778 env.close();
3779
3780 MPTTester const mpt({
3781 .env = env,
3782 .issuer = gw,
3783 .holders = {alice, bob},
3784 .transferFee = 1'000,
3785 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3786 });
3787 env(pay(gw, alice, mpt(10'000)));
3788 env.close();
3789
3790 static constexpr int escrowCount = 10;
3791 static constexpr int splitAmount = 10;
3792 static constexpr int totalLocked = escrowCount * splitAmount;
3794 for (auto& seq : seqs)
3795 {
3796 seq = env.seq(alice);
3797 env(escrow::create(alice, bob, mpt(splitAmount)),
3799 escrow::kFinishTime(env.now() + 1s),
3800 Fee(baseFee * 150));
3801 env.close();
3802 }
3803
3804 BEAST_EXPECT(env.balance(alice, mpt) == mpt(10'000 - totalLocked));
3805 BEAST_EXPECT(env.balance(bob, mpt) == mpt(0));
3806 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-10'000));
3807 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == totalLocked);
3808 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == totalLocked);
3809
3810 for (auto const seq : seqs)
3811 {
3812 env(escrow::finish(bob, alice, seq),
3815 Fee(baseFee * 150));
3816 env.close();
3817 }
3818
3819 auto const feeBurned = withCleanup340 ? escrowCount : 0;
3820 BEAST_EXPECT(env.balance(alice, mpt) == mpt(10'000 - totalLocked));
3821 BEAST_EXPECT(env.balance(bob, mpt) == mpt(totalLocked - feeBurned));
3822 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-10'000 + feeBurned));
3823 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
3824 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
3825 }
3826
3827 void
3829 {
3830 testcase("MPT large locked rate");
3831 using namespace test::jtx;
3832 using namespace std::literals;
3833
3834 auto constexpr escrowAmount = 200'000'000'000'000'000LL;
3835 auto constexpr noOverflowEscrowAmount = 186'000'000'000'000'000LL;
3836 auto const alice = Account("alice");
3837 auto const bob = Account("bob");
3838 auto const gw = Account("gw");
3839
3840 for (auto const testFeatures : {
3841 features - featureMPTokensV2 - fixCleanup3_4_0 - fixCleanup3_5_0,
3842 features - featureMPTokensV2 - fixCleanup3_4_0,
3843 features - featureMPTokensV2 - fixCleanup3_5_0,
3844 features - featureMPTokensV2,
3845 (features | featureMPTokensV2) - fixCleanup3_4_0 - fixCleanup3_5_0,
3846 (features | featureMPTokensV2) - fixCleanup3_4_0,
3847 (features | featureMPTokensV2) - fixCleanup3_5_0,
3848 features | featureMPTokensV2,
3849 features | fixCleanup3_5_0,
3850 })
3851 {
3852 bool const mptV2 = testFeatures[featureMPTokensV2];
3853 bool const tokenEscrowV1 = testFeatures[fixTokenEscrowV1];
3854 // The transfer-fee split in EscrowFinish only overflows on the
3855 // legacy divideRound(amount, lockedRate, ...) path, which runs when
3856 // fixCleanup3_4_0 is disabled. With fixCleanup3_4_0 the split uses
3857 // mulRatio (128-bit intermediate), which cannot overflow. Without
3858 // it, this large amount overflows unless divideRound takes the
3859 // Number path, which MPTokensV2 or fixCleanup3_5_0 enables. So the
3860 // finish succeeds when any of these amendments is enabled.
3861 bool const cleanup340 = testFeatures[fixCleanup3_4_0];
3862 bool const noOverflow = cleanup340 || mptV2 || testFeatures[fixCleanup3_5_0];
3863 auto const expectedErr = noOverflow ? Ter(tesSUCCESS) : Ter(tefEXCEPTION);
3864
3865 // Finish with a large MPT amount and non-zero transfer fee. When the
3866 // computation overflows (legacy divideRound path, no MPTokensV2) the
3867 // finish fails with tefEXCEPTION and the escrow is untouched;
3868 // otherwise it unlocks the escrow.
3869 {
3870 Env env{*this, testFeatures};
3871 env.fund(XRP(1'000), alice, bob, gw);
3872 auto const baseFee = env.current()->fees().base;
3873
3874 MPTTester const mpt({
3875 .env = env,
3876 .issuer = gw,
3877 .holders = {alice, bob},
3878 .transferFee = 1'000,
3879 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3880 });
3881 env(pay(gw, alice, mpt(escrowAmount)));
3882 env.close();
3883
3884 auto const preAlice = env.balance(alice, mpt);
3885 auto const preBob = env.balance(bob, mpt);
3886 auto const seq = env.seq(alice);
3887 env(escrow::create(alice, bob, mpt(escrowAmount)),
3889 escrow::kFinishTime(env.now() + 1s),
3890 escrow::kCancelTime(env.now() + 500s),
3891 Fee(baseFee * 150));
3892 env.close();
3893
3894 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == escrowAmount);
3895 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == escrowAmount);
3896
3897 env(escrow::finish(bob, alice, seq),
3900 Fee(baseFee * 150),
3901 expectedErr);
3902 env.close();
3903
3904 if (noOverflow)
3905 {
3906 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(seq))));
3907 BEAST_EXPECT(env.balance(alice, mpt) == preAlice - mpt(escrowAmount));
3908 auto const postBob = env.balance(bob, mpt);
3909 BEAST_EXPECT(postBob.value() > preBob.value());
3910 BEAST_EXPECT(postBob.value() < (preBob + mpt(escrowAmount)).value());
3911 auto const xferFee = escrowAmount - (postBob.value() - preBob.value());
3912 auto const expectedEscrow = tokenEscrowV1 ? 0 : xferFee;
3913 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == expectedEscrow);
3914 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == expectedEscrow);
3915 }
3916 else
3917 {
3918 BEAST_EXPECT(env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(seq))));
3919 BEAST_EXPECT(env.balance(alice, mpt) == preAlice - mpt(escrowAmount));
3920 BEAST_EXPECT(env.balance(bob, mpt) == preBob);
3921 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == escrowAmount);
3922 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == escrowAmount);
3923 }
3924 }
3925
3926 // Control: a still-large amount below the legacy overflow boundary
3927 // finishes successfully in both feature modes.
3928 {
3929 Env env{*this, testFeatures};
3930 env.fund(XRP(1'000), alice, bob, gw);
3931 auto const baseFee = env.current()->fees().base;
3932
3933 MPTTester const mpt({
3934 .env = env,
3935 .issuer = gw,
3936 .holders = {alice, bob},
3937 .transferFee = 1'000,
3938 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3939 });
3940 env(pay(gw, alice, mpt(noOverflowEscrowAmount)));
3941 env.close();
3942
3943 auto const preAlice = env.balance(alice, mpt);
3944 auto const preBob = env.balance(bob, mpt);
3945 auto const seq = env.seq(alice);
3946 env(escrow::create(alice, bob, mpt(noOverflowEscrowAmount)),
3948 escrow::kFinishTime(env.now() + 1s),
3949 escrow::kCancelTime(env.now() + 500s),
3950 Fee(baseFee * 150));
3951 env.close();
3952
3953 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == noOverflowEscrowAmount);
3954 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == noOverflowEscrowAmount);
3955
3956 env(escrow::finish(bob, alice, seq),
3959 Fee(baseFee * 150),
3960 Ter(tesSUCCESS));
3961 env.close();
3962
3963 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(seq))));
3964 BEAST_EXPECT(env.balance(alice, mpt) == preAlice - mpt(noOverflowEscrowAmount));
3965 auto const postBob = env.balance(bob, mpt);
3966 BEAST_EXPECT(postBob.value() > preBob.value());
3967 BEAST_EXPECT(postBob.value() < (preBob + mpt(noOverflowEscrowAmount)).value());
3968 auto const xferFee = noOverflowEscrowAmount - (postBob.value() - preBob.value());
3969 auto const expectedEscrow = tokenEscrowV1 ? 0 : xferFee;
3970 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == expectedEscrow);
3971 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == expectedEscrow);
3972 }
3973
3974 // Cancel returns the escrow to the owner using parity rate, so it
3975 // does not hit the transfer-rate division in either feature mode.
3976 {
3977 Env env{*this, testFeatures};
3978 env.fund(XRP(1'000), alice, bob, gw);
3979 auto const baseFee = env.current()->fees().base;
3980
3981 MPTTester const mpt({
3982 .env = env,
3983 .issuer = gw,
3984 .holders = {alice, bob},
3985 .transferFee = 1'000,
3986 .flags = tfMPTCanEscrow | tfMPTCanTransfer,
3987 });
3988 env(pay(gw, alice, mpt(escrowAmount)));
3989 env.close();
3990
3991 auto const preAlice = env.balance(alice, mpt);
3992 auto const preBob = env.balance(bob, mpt);
3993 auto const seq = env.seq(alice);
3994 env(escrow::create(alice, bob, mpt(escrowAmount)),
3996 escrow::kFinishTime(env.now() + 1s),
3997 escrow::kCancelTime(env.now() + 3s),
3998 Fee(baseFee * 150));
3999 env.close();
4000
4001 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == escrowAmount);
4002 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == escrowAmount);
4003
4004 env(escrow::cancel(alice, alice, seq), Fee(baseFee), Ter(tesSUCCESS));
4005 env.close();
4006
4007 BEAST_EXPECT(!env.le(keylet::escrow(alice.id(), SeqProxy::rawSequence(seq))));
4008 BEAST_EXPECT(env.balance(alice, mpt) == preAlice);
4009 BEAST_EXPECT(env.balance(bob, mpt) == preBob);
4010 BEAST_EXPECT(env.balance(gw, mpt) == -mpt(escrowAmount));
4011 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
4012 BEAST_EXPECT(issuerMPTEscrowed(env, mpt) == 0);
4013 }
4014 }
4015 }
4016
4017 void
4019 {
4020 testcase("MPT Require Auth");
4021 using namespace test::jtx;
4022 using namespace std::literals;
4023
4024 Env env{*this, features};
4025 auto const baseFee = env.current()->fees().base;
4026 auto const alice = Account("alice");
4027 auto const bob = Account("bob");
4028 auto const gw = Account("gw");
4029
4030 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
4031 mptGw.create({
4032 .ownerCount = 1,
4033 .holderCount = 0,
4034 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTRequireAuth,
4035 });
4036 mptGw.authorize({.account = alice});
4037 mptGw.authorize({.account = gw, .holder = alice});
4038 mptGw.authorize({.account = bob});
4039 mptGw.authorize({.account = gw, .holder = bob});
4040 auto const mpt = mptGw["MPT"];
4041 env(pay(gw, alice, mpt(10'000)));
4042 env.close();
4043
4044 auto seq = env.seq(alice);
4045 auto const delta = mpt(125);
4046 // alice can create escrow - is authorized
4047 env(escrow::create(alice, bob, mpt(100)),
4049 escrow::kFinishTime(env.now() + 1s),
4050 Fee(baseFee * 150));
4051 env.close();
4052
4053 // bob can finish escrow - is authorized
4054 env(escrow::finish(bob, alice, seq),
4057 Fee(baseFee * 150));
4058 env.close();
4059 }
4060
4061 void
4063 {
4064 testcase("MPT Lock");
4065 using namespace test::jtx;
4066 using namespace std::literals;
4067
4068 Env env{*this, features};
4069 auto const baseFee = env.current()->fees().base;
4070 auto const alice = Account("alice");
4071 auto const bob = Account("bob");
4072 auto const gw = Account("gw");
4073
4074 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
4075 mptGw.create({
4076 .ownerCount = 1,
4077 .holderCount = 0,
4078 .flags = tfMPTCanEscrow | tfMPTCanTransfer | tfMPTCanLock,
4079 });
4080 mptGw.authorize({.account = alice});
4081 mptGw.authorize({.account = bob});
4082 auto const mpt = mptGw["MPT"];
4083 env(pay(gw, alice, mpt(10'000)));
4084 env(pay(gw, bob, mpt(10'000)));
4085 env.close();
4086
4087 // alice create escrow
4088 auto seq1 = env.seq(alice);
4089 env(escrow::create(alice, bob, mpt(100)),
4091 escrow::kFinishTime(env.now() + 1s),
4092 escrow::kCancelTime(env.now() + 2s),
4093 Fee(baseFee * 150));
4094 env.close();
4095
4096 // lock account & dest
4097 mptGw.set({.account = gw, .holder = alice, .flags = tfMPTLock});
4098 mptGw.set({.account = gw, .holder = bob, .flags = tfMPTLock});
4099
4100 // bob cannot finish
4101 env(escrow::finish(bob, alice, seq1),
4104 Fee(baseFee * 150),
4105 Ter(tecLOCKED));
4106 env.close();
4107
4108 // bob can cancel
4109 env(escrow::cancel(bob, alice, seq1));
4110 env.close();
4111 }
4112
4113 void
4115 {
4116 testcase("MPT Can Transfer");
4117 using namespace test::jtx;
4118 using namespace std::literals;
4119
4120 Env env{*this, features};
4121 auto const baseFee = env.current()->fees().base;
4122 auto const alice = Account("alice");
4123 auto const bob = Account("bob");
4124 auto const gw = Account("gw");
4125
4126 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
4127 mptGw.create({.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow});
4128 mptGw.authorize({.account = alice});
4129 mptGw.authorize({.account = bob});
4130 auto const mpt = mptGw["MPT"];
4131 env(pay(gw, alice, mpt(10'000)));
4132 env(pay(gw, bob, mpt(10'000)));
4133 env.close();
4134
4135 // alice cannot create escrow to non issuer
4136 env(escrow::create(alice, bob, mpt(100)),
4138 escrow::kFinishTime(env.now() + 1s),
4139 escrow::kCancelTime(env.now() + 2s),
4140 Fee(baseFee * 150),
4141 Ter(tecNO_AUTH));
4142 env.close();
4143
4144 // Escrow Create & Finish
4145 {
4146 // alice an create escrow to issuer
4147 auto seq = env.seq(alice);
4148 env(escrow::create(alice, gw, mpt(100)),
4150 escrow::kFinishTime(env.now() + 1s),
4151 Fee(baseFee * 150));
4152 env.close();
4153
4154 // gw can finish
4155 env(escrow::finish(gw, alice, seq),
4158 Fee(baseFee * 150));
4159 env.close();
4160 }
4161
4162 // Escrow Create & Cancel
4163 {
4164 // alice an create escrow to issuer
4165 auto seq = env.seq(alice);
4166 env(escrow::create(alice, gw, mpt(100)),
4168 escrow::kFinishTime(env.now() + 1s),
4169 escrow::kCancelTime(env.now() + 2s),
4170 Fee(baseFee * 150));
4171 env.close();
4172
4173 // alice can cancel
4174 env(escrow::cancel(alice, alice, seq));
4175 env.close();
4176 }
4177 }
4178
4179 void
4181 {
4182 testcase("MPT Destroy");
4183 using namespace test::jtx;
4184 using namespace std::literals;
4185
4186 // tecHAS_OBLIGATIONS: issuer cannot destroy issuance
4187 {
4188 Env env{*this, features};
4189 auto const baseFee = env.current()->fees().base;
4190 auto const alice = Account("alice");
4191 auto const bob = Account("bob");
4192 auto const gw = Account("gw");
4193
4194 MPTTester mptGw(env, gw, {.holders = {alice, bob}});
4195 mptGw.create(
4196 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
4197 mptGw.authorize({.account = alice});
4198 mptGw.authorize({.account = bob});
4199 auto const mpt = mptGw["MPT"];
4200 env(pay(gw, alice, mpt(10'000)));
4201 env(pay(gw, bob, mpt(10'000)));
4202 env.close();
4203
4204 auto const seq1 = env.seq(alice);
4205 env(escrow::create(alice, bob, mpt(10)),
4207 escrow::kFinishTime(env.now() + 1s),
4208 Fee(baseFee * 150));
4209 env.close();
4210
4211 env(pay(alice, gw, mpt(10'000)), Ter(tecPATH_PARTIAL));
4212 env(pay(alice, gw, mpt(9'990)));
4213 env(pay(bob, gw, mpt(10'000)));
4214 BEAST_EXPECT(env.balance(alice, mpt) == mpt(0));
4215 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 10);
4216 BEAST_EXPECT(env.balance(bob, mpt) == mpt(0));
4217 BEAST_EXPECT(mptEscrowed(env, bob, mpt) == 0);
4218 BEAST_EXPECT(env.balance(gw, mpt) == mpt(-10));
4219 mptGw.authorize({.account = bob, .flags = tfMPTUnauthorize});
4220 mptGw.destroy({.id = mptGw.issuanceID(), .ownerCount = 1, .err = tecHAS_OBLIGATIONS});
4221
4222 env(escrow::finish(bob, alice, seq1),
4225 Fee(baseFee * 150),
4226 Ter(tesSUCCESS));
4227 env.close();
4228
4229 env(pay(bob, gw, mpt(10)));
4230 mptGw.destroy({.id = mptGw.issuanceID(), .ownerCount = 0});
4231 }
4232
4233 // tecHAS_OBLIGATIONS: holder cannot destroy mptoken
4234 {
4235 Env env{*this, features};
4236 auto const baseFee = env.current()->fees().base;
4237 auto const alice = Account("alice");
4238 auto const bob = Account("bob");
4239 auto const gw = Account("gw");
4240 env.fund(XRP(10'000), bob);
4241 env.close();
4242
4243 MPTTester mptGw(env, gw, {.holders = {alice}});
4244 mptGw.create(
4245 {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanEscrow | tfMPTCanTransfer});
4246 mptGw.authorize({.account = alice});
4247 auto const mpt = mptGw["MPT"];
4248 env(pay(gw, alice, mpt(10'000)));
4249 env.close();
4250
4251 auto const seq1 = env.seq(alice);
4252 env(escrow::create(alice, bob, mpt(10)),
4254 escrow::kFinishTime(env.now() + 1s),
4255 Fee(baseFee * 150),
4256 Ter(tesSUCCESS));
4257 env.close();
4258
4259 env(pay(alice, gw, mpt(9'990)));
4260 env.close();
4261
4262 BEAST_EXPECT(env.balance(alice, mpt) == mpt(0));
4263 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 10);
4264 mptGw.authorize(
4265 {.account = alice, .flags = tfMPTUnauthorize, .err = tecHAS_OBLIGATIONS});
4266
4267 env(escrow::finish(bob, alice, seq1),
4270 Fee(baseFee * 150),
4271 Ter(tesSUCCESS));
4272 env.close();
4273
4274 BEAST_EXPECT(env.balance(alice, mpt) == mpt(0));
4275 BEAST_EXPECT(mptEscrowed(env, alice, mpt) == 0);
4276 mptGw.authorize({.account = alice, .flags = tfMPTUnauthorize});
4277 BEAST_EXPECT(!env.le(keylet::mptoken(mpt.mpt(), alice)));
4278 }
4279 }
4280
4281 void
4283 {
4284 testIOUEnablement(features);
4285 testIOUAllowLockingFlag(features);
4286 testIOUCreatePreflight(features);
4287 testIOUCreatePreclaim(features);
4288 testIOUFinishPreclaim(features);
4289 testIOUFinishDoApply(features);
4290 testIOUCancelPreclaim(features);
4291 testIOUCancelDoApply(features);
4292 testIOUBalances(features);
4293 testIOUMetaAndOwnership(features);
4294 testIOURippleState(features);
4295 testIOUGateway(features);
4296 testIOULockedRate(features);
4297 testIOULimitAmount(features);
4298 testIOURequireAuth(features);
4299 testIOUFreeze(features);
4300 testIOUInsufficientFunds(features);
4301 testIOUPrecisionLoss(features);
4302 }
4303
4304 void
4306 {
4307 testMPTEnablement(features);
4308 testMPTCreatePreflight(features);
4309 testMPTCreatePreclaim(features);
4310 testMPTFinishPreclaim(features);
4311 testMPTFinishDoApply(features);
4312 testMPTCancelPreclaim(features);
4313 testMPTBalances(features);
4314 testMPTMetaAndOwnership(features);
4315 testMPTGateway(features);
4316 testMPTLockedRate(features);
4317 testMPTLargeLockedRate(features);
4318 testMPTRequireAuth(features);
4319 testMPTLock(features);
4320 testMPTCanTransfer(features);
4321 testMPTDestroy(features);
4322 }
4323
4324public:
4325 void
4326 run() override
4327 {
4328 using namespace test::jtx;
4329 FeatureBitset const all{testableAmendments()};
4330 for (FeatureBitset const& feats :
4331 {all - featureSingleAssetVault - featureLendingProtocol - featureMPTokensV2, all})
4332 {
4333 testIOUWithFeats(feats);
4334 testIOUWithFeats(feats - fixCleanup3_2_0);
4335 testMPTWithFeats(feats);
4336 testMPTWithFeats(feats - fixTokenEscrowV1);
4337 }
4338 testMPTSplitEscrowTransferFee(all - fixCleanup3_4_0);
4340 testIOUCancelReserveRecycle(all - fixCleanup3_4_0);
4342 }
4343};
4344
4345BEAST_DEFINE_TESTSUITE(EscrowToken, app, xrpl);
4346
4347} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:44
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Represents a JSON value.
Definition json_value.h:121
Value removeMember(char const *key)
Remove and return the named member.
bool modify(ModifyType const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
Discardable, editable view to a ledger.
Definition Sandbox.h:18
void apply(RawView &to)
Definition Sandbox.h:38
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
virtual OpenLedger & getOpenLedger()=0
constexpr value_type drops() const
Returns the number of drops.
Definition XRPAmount.h:163
void insert(SLE::Ref sle) override
Insert a new state SLE.
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
Definition Env.cpp:266
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
PrettyAmount limit(Account const &account, Issue const &issue) const
Returns the IOU limit on an account.
Definition Env.cpp:254
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:302
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
Definition Env.cpp:201
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:354
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
Definition Env.cpp:538
void memoize(Account const &account)
Associate AccountID with account.
Definition Env.cpp:174
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:766
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
NetClock::time_point now()
Returns the current network time.
Definition Env.h:326
Set the fee on a JTx.
Definition fee.h:20
Converts to IOU Issue or STAmount.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
Definition mpt.h:512
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:346
Converts to MPT Issue or STAmount.
Match clear account flags.
Definition flags.h:137
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
Set the flags on a JTx.
Definition txflags.h:14
T distance(T... args)
T find(T... args)
T make_shared(T... args)
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Definition Indexes.cpp:430
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Definition Indexes.cpp:547
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Definition Indexes.cpp:541
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:287
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition escrow.cpp:24
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition escrow.cpp:48
auto const kCondition
Definition escrow.h:100
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
Definition escrow.h:98
auto const kFinishTime
Set the "FinishAfter" time tag on a JTx.
Definition escrow.h:93
std::array< std::uint8_t, 39 > const kCb2
Definition escrow.h:71
auto const kFulfillment
Definition escrow.h:102
Rate rate(Env const &env, Account const &account, std::uint32_t const &seq)
Definition escrow.cpp:60
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition escrow.cpp:36
std::array< std::uint8_t, 4 > const kFb1
Definition escrow.h:58
std::array< std::uint8_t, 39 > const kCb1
Definition escrow.h:60
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
jtx::PrettyAmount issuerBalance(jtx::Env &env, jtx::Account const &account, Issue const &issue)
json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Definition flags.h:110
FeatureBitset testableAmendments()
Definition Env.h:92
uint64_t issuerMPTEscrowed(jtx::Env const &env, jtx::MPT const &mpt)
std::vector< SLE::const_pointer > ownerDirEntries(ReadView const &view, AccountID const &account)
Return the ledger entries in an account's owner directory.
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
Definition rate.cpp:15
uint64_t mptEscrowed(jtx::Env const &env, jtx::Account const &account, jtx::MPT const &mpt)
jtx::PrettyAmount issuerEscrowed(jtx::Env &env, jtx::Account const &account, Issue const &issue)
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:15
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefINTERNAL
Definition TER.h:167
@ tefEXCEPTION
Definition TER.h:166
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
Definition Indexes.cpp:219
@ TapNone
Definition ApplyView.h:28
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
@ temBAD_CURRENCY
Definition TER.h:78
@ temBAD_FEE
Definition TER.h:80
@ temDISABLED
Definition TER.h:102
@ temBAD_AMOUNT
Definition TER.h:77
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecLOCKED
Definition TER.h:369
@ tecNO_LINE_INSUF_RESERVE
Definition TER.h:303
@ tecPATH_PARTIAL
Definition TER.h:293
@ tecNO_TARGET
Definition TER.h:315
@ tecOBJECT_NOT_FOUND
Definition TER.h:337
@ tecNO_AUTH
Definition TER.h:311
@ tecFROZEN
Definition TER.h:314
@ tecINSUFFICIENT_FUNDS
Definition TER.h:336
@ tecNO_LINE
Definition TER.h:312
@ tecPRECISION_LOSS
Definition TER.h:374
@ tecINSUFFICIENT_RESERVE
Definition TER.h:318
@ tecLIMIT_EXCEEDED
Definition TER.h:372
@ tecNO_PERMISSION
Definition TER.h:316
@ tecNO_ISSUER
Definition TER.h:310
@ tecHAS_OBLIGATIONS
Definition TER.h:328
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
Definition Protocol.h:297
@ tesSUCCESS
Definition TER.h:253
void testMPTLargeLockedRate(FeatureBitset features)
void testMPTCreatePreclaim(FeatureBitset features)
void testMPTFinishDoApply(FeatureBitset features)
void testMPTMetaAndOwnership(FeatureBitset features)
void testIOUBalances(FeatureBitset features)
void testMPTSplitEscrowTransferFee(FeatureBitset features)
void testIOUCreatePreclaim(FeatureBitset features)
void testMPTGateway(FeatureBitset features)
void testMPTCanTransfer(FeatureBitset features)
void testIOUFinishPreclaim(FeatureBitset features)
void run() override
Runs the suite.
void testIOUMetaAndOwnership(FeatureBitset features)
void testIOUPrecisionLoss(FeatureBitset features)
void testMPTLock(FeatureBitset features)
void testMPTCancelPreclaim(FeatureBitset features)
void testIOUEnablement(FeatureBitset features)
void testMPTBalances(FeatureBitset features)
void testMPTRequireAuth(FeatureBitset features)
void testIOUFinishDoApply(FeatureBitset features)
void testIOUFreeze(FeatureBitset features)
void testMPTEnablement(FeatureBitset features)
void testIOUCancelPreclaim(FeatureBitset features)
void testIOUGateway(FeatureBitset features)
void testIOULimitAmount(FeatureBitset features)
void testIOUAllowLockingFlag(FeatureBitset features)
void testMPTCreatePreflight(FeatureBitset features)
void testIOULockedRate(FeatureBitset features)
void testMPTFinishPreclaim(FeatureBitset features)
void testIOUCancelDoApply(FeatureBitset features)
void testIOUInsufficientFunds(FeatureBitset features)
void testIOUWithFeats(FeatureBitset features)
void testIOUCancelReserveRecycle(FeatureBitset features)
void testMPTLockedRate(FeatureBitset features)
void testMPTWithFeats(FeatureBitset features)
void testIOUCreatePreflight(FeatureBitset features)
void testIOURequireAuth(FeatureBitset features)
void testMPTDestroy(FeatureBitset features)
void testIOURippleState(FeatureBitset features)
STAmount const & value() const