rippled
Loading...
Searching...
No Matches
Freeze_test.cpp
1#include <test/jtx.h>
2#include <test/jtx/AMM.h>
3
4#include <xrpl/protocol/AccountID.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/SField.h>
7#include <xrpl/protocol/TxFlags.h>
8#include <xrpl/protocol/jss.h>
9
10namespace ripple {
11
13{
14 void
16 {
17 testcase("RippleState Freeze");
18
19 using namespace test::jtx;
20 Env env(*this, features);
21
22 Account G1{"G1"};
23 Account alice{"alice"};
24 Account bob{"bob"};
25
26 env.fund(XRP(1000), G1, alice, bob);
27 env.close();
28
29 env.trust(G1["USD"](100), bob);
30 env.trust(G1["USD"](100), alice);
31 env.close();
32
33 env(pay(G1, bob, G1["USD"](10)));
34 env(pay(G1, alice, G1["USD"](100)));
35 env.close();
36
37 env(offer(alice, XRP(500), G1["USD"](100)));
38 env.close();
39
40 {
41 auto lines = getAccountLines(env, bob);
42 if (!BEAST_EXPECT(checkArraySize(lines[jss::lines], 1u)))
43 return;
44 BEAST_EXPECT(lines[jss::lines][0u][jss::account] == G1.human());
45 BEAST_EXPECT(lines[jss::lines][0u][jss::limit] == "100");
46 BEAST_EXPECT(lines[jss::lines][0u][jss::balance] == "10");
47 }
48
49 {
50 auto lines = getAccountLines(env, alice);
51 if (!BEAST_EXPECT(checkArraySize(lines[jss::lines], 1u)))
52 return;
53 BEAST_EXPECT(lines[jss::lines][0u][jss::account] == G1.human());
54 BEAST_EXPECT(lines[jss::lines][0u][jss::limit] == "100");
55 BEAST_EXPECT(lines[jss::lines][0u][jss::balance] == "100");
56 }
57
58 {
59 // Account with line unfrozen (proving operations normally work)
60 // test: can make Payment on that line
61 env(pay(alice, bob, G1["USD"](1)));
62
63 // test: can receive Payment on that line
64 env(pay(bob, alice, G1["USD"](1)));
65 env.close();
66 }
67
68 {
69 // Is created via a TrustSet with SetFreeze flag
70 // test: sets LowFreeze | HighFreeze flags
71 env(trust(G1, bob["USD"](0), tfSetFreeze));
72 auto affected = env.meta()->getJson(
73 JsonOptions::none)[sfAffectedNodes.fieldName];
74 if (!BEAST_EXPECT(checkArraySize(affected, 2u)))
75 return;
76 auto ff =
77 affected[1u][sfModifiedNode.fieldName][sfFinalFields.fieldName];
78 BEAST_EXPECT(
79 ff[sfLowLimit.fieldName] ==
80 G1["USD"](0).value().getJson(JsonOptions::none));
81 BEAST_EXPECT(ff[jss::Flags].asUInt() & lsfLowFreeze);
82 BEAST_EXPECT(!(ff[jss::Flags].asUInt() & lsfHighFreeze));
83 env.close();
84 }
85
86 {
87 // Account with line frozen by issuer
88 // test: can buy more assets on that line
89 env(offer(bob, G1["USD"](5), XRP(25)));
90 auto affected = env.meta()->getJson(
91 JsonOptions::none)[sfAffectedNodes.fieldName];
92 if (!BEAST_EXPECT(checkArraySize(affected, 5u)))
93 return;
94 auto ff =
95 affected[3u][sfModifiedNode.fieldName][sfFinalFields.fieldName];
96 BEAST_EXPECT(
97 ff[sfHighLimit.fieldName] ==
98 bob["USD"](100).value().getJson(JsonOptions::none));
99 auto amt = STAmount{Issue{to_currency("USD"), noAccount()}, -15}
100 .value()
101 .getJson(JsonOptions::none);
102 BEAST_EXPECT(ff[sfBalance.fieldName] == amt);
103 env.close();
104 }
105
106 {
107 // test: can not sell assets from that line
108 env(offer(bob, XRP(1), G1["USD"](5)), ter(tecUNFUNDED_OFFER));
109
110 // test: can receive Payment on that line
111 env(pay(alice, bob, G1["USD"](1)));
112
113 // test: can not make Payment from that line
114 env(pay(bob, alice, G1["USD"](1)), ter(tecPATH_DRY));
115 }
116
117 {
118 // check G1 account lines
119 // test: shows freeze
120 auto lines = getAccountLines(env, G1);
121 Json::Value bobLine;
122 for (auto const& it : lines[jss::lines])
123 {
124 if (it[jss::account] == bob.human())
125 {
126 bobLine = it;
127 break;
128 }
129 }
130 if (!BEAST_EXPECT(bobLine))
131 return;
132 BEAST_EXPECT(bobLine[jss::freeze] == true);
133 BEAST_EXPECT(bobLine[jss::balance] == "-16");
134 }
135
136 {
137 // test: shows freeze peer
138 auto lines = getAccountLines(env, bob);
139 Json::Value g1Line;
140 for (auto const& it : lines[jss::lines])
141 {
142 if (it[jss::account] == G1.human())
143 {
144 g1Line = it;
145 break;
146 }
147 }
148 if (!BEAST_EXPECT(g1Line))
149 return;
150 BEAST_EXPECT(g1Line[jss::freeze_peer] == true);
151 BEAST_EXPECT(g1Line[jss::balance] == "16");
152 }
153
154 {
155 // Is cleared via a TrustSet with ClearFreeze flag
156 // test: sets LowFreeze | HighFreeze flags
157 env(trust(G1, bob["USD"](0), tfClearFreeze));
158 auto affected = env.meta()->getJson(
159 JsonOptions::none)[sfAffectedNodes.fieldName];
160 if (!BEAST_EXPECT(checkArraySize(affected, 2u)))
161 return;
162 auto ff =
163 affected[1u][sfModifiedNode.fieldName][sfFinalFields.fieldName];
164 BEAST_EXPECT(
165 ff[sfLowLimit.fieldName] ==
166 G1["USD"](0).value().getJson(JsonOptions::none));
167 BEAST_EXPECT(!(ff[jss::Flags].asUInt() & lsfLowFreeze));
168 BEAST_EXPECT(!(ff[jss::Flags].asUInt() & lsfHighFreeze));
169 env.close();
170 }
171 }
172
173 void
175 {
176 testcase("Deep Freeze");
177
178 using namespace test::jtx;
179 Env env(*this, features);
180
181 Account G1{"G1"};
182 Account A1{"A1"};
183
184 env.fund(XRP(10000), G1, A1);
185 env.close();
186
187 env.trust(G1["USD"](1000), A1);
188 env.close();
189
190 if (features[featureDeepFreeze])
191 {
192 // test: Issuer deep freezing the trust line in a single
193 // transaction
194 env(trust(G1, A1["USD"](0), tfSetFreeze | tfSetDeepFreeze));
195 {
196 auto const flags = getTrustlineFlags(env, 2u, 1u);
197 BEAST_EXPECT(flags & lsfLowFreeze);
198 BEAST_EXPECT(flags & lsfLowDeepFreeze);
199 BEAST_EXPECT(!(flags & (lsfHighFreeze | lsfHighDeepFreeze)));
200 env.close();
201 }
202
203 // test: Issuer clearing deep freeze and normal freeze in a single
204 // transaction
205 env(trust(G1, A1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
206 {
207 auto const flags = getTrustlineFlags(env, 2u, 1u);
208 BEAST_EXPECT(!(flags & (lsfLowFreeze | lsfLowDeepFreeze)));
209 BEAST_EXPECT(!(flags & (lsfHighFreeze | lsfHighDeepFreeze)));
210 env.close();
211 }
212
213 // test: Issuer deep freezing not already frozen line must fail
214 env(trust(G1, A1["USD"](0), tfSetDeepFreeze),
215 ter(tecNO_PERMISSION));
216
217 env(trust(G1, A1["USD"](0), tfSetFreeze));
218 env.close();
219
220 // test: Issuer deep freezing already frozen trust line
221 env(trust(G1, A1["USD"](0), tfSetDeepFreeze));
222 {
223 auto const flags = getTrustlineFlags(env, 2u, 1u);
224 BEAST_EXPECT(flags & lsfLowFreeze);
225 BEAST_EXPECT(flags & lsfLowDeepFreeze);
226 BEAST_EXPECT(!(flags & (lsfHighFreeze | lsfHighDeepFreeze)));
227 env.close();
228 }
229
230 // test: Holder clearing freeze flags has no effect. Each sides'
231 // flags are independent
232 env(trust(A1, G1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
233 {
234 auto const flags = getTrustlineFlags(env, 2u, 1u);
235 BEAST_EXPECT(flags & lsfLowFreeze);
236 BEAST_EXPECT(flags & lsfLowDeepFreeze);
237 BEAST_EXPECT(!(flags & (lsfHighFreeze | lsfHighDeepFreeze)));
238 env.close();
239 }
240
241 // test: Issuer can't clear normal freeze when line is deep frozen
242 env(trust(G1, A1["USD"](0), tfClearFreeze), ter(tecNO_PERMISSION));
243
244 // test: Issuer clearing deep freeze but normal freeze is still in
245 // effect
246 env(trust(G1, A1["USD"](0), tfClearDeepFreeze));
247 {
248 auto const flags = getTrustlineFlags(env, 2u, 1u);
249 BEAST_EXPECT(flags & lsfLowFreeze);
250 BEAST_EXPECT(!(flags & lsfLowDeepFreeze));
251 BEAST_EXPECT(!(flags & (lsfHighFreeze | lsfHighDeepFreeze)));
252 env.close();
253 }
254 }
255 else
256 {
257 // test: applying deep freeze before amendment fails
258 env(trust(G1, A1["USD"](0), tfSetDeepFreeze), ter(temINVALID_FLAG));
259
260 // test: clearing deep freeze before amendment fails
261 env(trust(G1, A1["USD"](0), tfClearDeepFreeze),
262 ter(temINVALID_FLAG));
263 }
264 }
265
266 void
268 {
269 testcase("Create Frozen Trustline");
270
271 using namespace test::jtx;
272 Env env(*this, features);
273
274 Account G1{"G1"};
275 Account A1{"A1"};
276
277 env.fund(XRP(10000), G1, A1);
278 env.close();
279
280 // test: can create frozen trustline
281 {
282 env(trust(G1, A1["USD"](1000), tfSetFreeze));
283 auto const flags = getTrustlineFlags(env, 5u, 3u, false);
284 BEAST_EXPECT(flags & lsfLowFreeze);
285 env.close();
286 env.require(lines(A1, 1));
287 }
288
289 // Cleanup
290 env(trust(G1, A1["USD"](0), tfClearFreeze));
291 env.close();
292 env.require(lines(G1, 0));
293 env.require(lines(A1, 0));
294
295 // test: cannot create deep frozen trustline without normal freeze
296 if (features[featureDeepFreeze])
297 {
298 env(trust(G1, A1["USD"](1000), tfSetDeepFreeze),
299 ter(tecNO_PERMISSION));
300 env.close();
301 env.require(lines(A1, 0));
302 }
303
304 // test: can create deep frozen trustline together with normal freeze
305 if (features[featureDeepFreeze])
306 {
307 env(trust(G1, A1["USD"](1000), tfSetFreeze | tfSetDeepFreeze));
308 auto const flags = getTrustlineFlags(env, 5u, 3u, false);
309 BEAST_EXPECT(flags & lsfLowFreeze);
310 BEAST_EXPECT(flags & lsfLowDeepFreeze);
311 env.close();
312 env.require(lines(A1, 1));
313 }
314 }
315
316 void
318 {
319 testcase("Freeze Set and Clear");
320
321 using namespace test::jtx;
322 Env env(*this, features);
323
324 Account G1{"G1"};
325 Account A1{"A1"};
326
327 env.fund(XRP(10000), G1, A1);
328 env.close();
329
330 env.trust(G1["USD"](1000), A1);
331 env.close();
332
333 if (features[featureDeepFreeze])
334 {
335 // test: can't have both set and clear flag families in the same
336 // transaction
337 env(trust(G1, A1["USD"](0), tfSetFreeze | tfClearFreeze),
338 ter(tecNO_PERMISSION));
339 env(trust(G1, A1["USD"](0), tfSetFreeze | tfClearDeepFreeze),
340 ter(tecNO_PERMISSION));
341 env(trust(G1, A1["USD"](0), tfSetDeepFreeze | tfClearFreeze),
342 ter(tecNO_PERMISSION));
343 env(trust(G1, A1["USD"](0), tfSetDeepFreeze | tfClearDeepFreeze),
344 ter(tecNO_PERMISSION));
345 }
346 else
347 {
348 // test: old behavior, transaction succeed with no effect on a
349 // trust line
350 env(trust(G1, A1["USD"](0), tfSetFreeze | tfClearFreeze));
351 {
352 auto affected = env.meta()->getJson(
353 JsonOptions::none)[sfAffectedNodes.fieldName];
354 BEAST_EXPECT(checkArraySize(
355 affected, 1u)); // means no trustline changes
356 }
357 }
358 }
359
360 void
362 {
363 testcase("Global Freeze");
364
365 using namespace test::jtx;
366 Env env(*this, features);
367
368 Account G1{"G1"};
369 Account A1{"A1"};
370 Account A2{"A2"};
371 Account A3{"A3"};
372 Account A4{"A4"};
373
374 env.fund(XRP(12000), G1);
375 env.fund(XRP(1000), A1);
376 env.fund(XRP(20000), A2, A3, A4);
377 env.close();
378
379 env.trust(G1["USD"](1200), A1);
380 env.trust(G1["USD"](200), A2);
381 env.trust(G1["BTC"](100), A3);
382 env.trust(G1["BTC"](100), A4);
383 env.close();
384
385 env(pay(G1, A1, G1["USD"](1000)));
386 env(pay(G1, A2, G1["USD"](100)));
387 env(pay(G1, A3, G1["BTC"](100)));
388 env(pay(G1, A4, G1["BTC"](100)));
389 env.close();
390
391 env(offer(G1, XRP(10000), G1["USD"](100)), txflags(tfPassive));
392 env(offer(G1, G1["USD"](100), XRP(10000)), txflags(tfPassive));
393 env(offer(A1, XRP(10000), G1["USD"](100)), txflags(tfPassive));
394 env(offer(A2, G1["USD"](100), XRP(10000)), txflags(tfPassive));
395 env.close();
396
397 {
398 // Is toggled via AccountSet using SetFlag and ClearFlag
399 // test: SetFlag GlobalFreeze
400 env.require(nflags(G1, asfGlobalFreeze));
401 env(fset(G1, asfGlobalFreeze));
402 env.require(flags(G1, asfGlobalFreeze));
403 env.require(nflags(G1, asfNoFreeze));
404
405 // test: ClearFlag GlobalFreeze
406 env(fclear(G1, asfGlobalFreeze));
407 env.require(nflags(G1, asfGlobalFreeze));
408 env.require(nflags(G1, asfNoFreeze));
409 }
410
411 {
412 // Account without GlobalFreeze (proving operations normally work)
413 // test: visible offers where taker_pays is unfrozen issuer
414 auto offers = env.rpc(
415 "book_offers",
416 std::string("USD/") + G1.human(),
417 "XRP")[jss::result][jss::offers];
418 if (!BEAST_EXPECT(checkArraySize(offers, 2u)))
419 return;
420 std::set<std::string> accounts;
421 for (auto const& offer : offers)
422 {
423 accounts.insert(offer[jss::Account].asString());
424 }
425 BEAST_EXPECT(accounts.find(A2.human()) != std::end(accounts));
426 BEAST_EXPECT(accounts.find(G1.human()) != std::end(accounts));
427
428 // test: visible offers where taker_gets is unfrozen issuer
429 offers = env.rpc(
430 "book_offers",
431 "XRP",
432 std::string("USD/") + G1.human())[jss::result][jss::offers];
433 if (!BEAST_EXPECT(checkArraySize(offers, 2u)))
434 return;
435 accounts.clear();
436 for (auto const& offer : offers)
437 {
438 accounts.insert(offer[jss::Account].asString());
439 }
440 BEAST_EXPECT(accounts.find(A1.human()) != std::end(accounts));
441 BEAST_EXPECT(accounts.find(G1.human()) != std::end(accounts));
442 }
443
444 {
445 // Offers/Payments
446 // test: assets can be bought on the market
447 env(offer(A3, G1["BTC"](1), XRP(1)));
448
449 // test: assets can be sold on the market
450 env(offer(A4, XRP(1), G1["BTC"](1)));
451
452 // test: direct issues can be sent
453 env(pay(G1, A2, G1["USD"](1)));
454
455 // test: direct redemptions can be sent
456 env(pay(A2, G1, G1["USD"](1)));
457
458 // test: via rippling can be sent
459 env(pay(A2, A1, G1["USD"](1)));
460
461 // test: via rippling can be sent back
462 env(pay(A1, A2, G1["USD"](1)));
463 }
464
465 {
466 // Account with GlobalFreeze
467 // set GlobalFreeze first
468 // test: SetFlag GlobalFreeze will toggle back to freeze
469 env.require(nflags(G1, asfGlobalFreeze));
470 env(fset(G1, asfGlobalFreeze));
471 env.require(flags(G1, asfGlobalFreeze));
472 env.require(nflags(G1, asfNoFreeze));
473
474 // test: assets can't be bought on the market
475 env(offer(A3, G1["BTC"](1), XRP(1)), ter(tecFROZEN));
476
477 // test: assets can't be sold on the market
478 env(offer(A4, XRP(1), G1["BTC"](1)), ter(tecFROZEN));
479 }
480
481 {
482 // offers are filtered (seems to be broken?)
483 // test: account_offers always shows own offers
484 auto offers = getAccountOffers(env, G1)[jss::offers];
485 if (!BEAST_EXPECT(checkArraySize(offers, 2u)))
486 return;
487
488 // test: book_offers shows offers
489 // (should these actually be filtered?)
490 offers = env.rpc(
491 "book_offers",
492 "XRP",
493 std::string("USD/") + G1.human())[jss::result][jss::offers];
494 if (!BEAST_EXPECT(checkArraySize(offers, 2u)))
495 return;
496
497 offers = env.rpc(
498 "book_offers",
499 std::string("USD/") + G1.human(),
500 "XRP")[jss::result][jss::offers];
501 if (!BEAST_EXPECT(checkArraySize(offers, 2u)))
502 return;
503 }
504
505 {
506 // Payments
507 // test: direct issues can be sent
508 env(pay(G1, A2, G1["USD"](1)));
509
510 // test: direct redemptions can be sent
511 env(pay(A2, G1, G1["USD"](1)));
512
513 // test: via rippling cant be sent
514 env(pay(A2, A1, G1["USD"](1)), ter(tecPATH_DRY));
515 }
516 }
517
518 void
520 {
521 testcase("No Freeze");
522
523 using namespace test::jtx;
524 Env env(*this, features);
525
526 Account G1{"G1"};
527 Account A1{"A1"};
528 Account frozenAcc{"A2"};
529 Account deepFrozenAcc{"A3"};
530
531 env.fund(XRP(12000), G1);
532 env.fund(XRP(1000), A1);
533 env.fund(XRP(1000), frozenAcc);
534 env.fund(XRP(1000), deepFrozenAcc);
535 env.close();
536
537 env.trust(G1["USD"](1000), A1);
538 env.trust(G1["USD"](1000), frozenAcc);
539 env.trust(G1["USD"](1000), deepFrozenAcc);
540 env.close();
541
542 env(pay(G1, A1, G1["USD"](1000)));
543 env(pay(G1, frozenAcc, G1["USD"](1000)));
544 env(pay(G1, deepFrozenAcc, G1["USD"](1000)));
545
546 // Freezing and deep freezing some of the trust lines to check deep
547 // freeze and clearing of freeze separately
548 env(trust(G1, frozenAcc["USD"](0), tfSetFreeze));
549 {
550 auto const flags = getTrustlineFlags(env, 2u, 1u);
551 BEAST_EXPECT(flags & lsfLowFreeze);
552 BEAST_EXPECT(!(flags & lsfHighFreeze));
553 }
554 if (features[featureDeepFreeze])
555 {
556 env(trust(
557 G1, deepFrozenAcc["USD"](0), tfSetFreeze | tfSetDeepFreeze));
558 {
559 auto const flags = getTrustlineFlags(env, 2u, 1u);
560 BEAST_EXPECT(!(flags & (lsfLowFreeze | lsfLowDeepFreeze)));
561 BEAST_EXPECT(flags & lsfHighFreeze);
562 BEAST_EXPECT(flags & lsfHighDeepFreeze);
563 }
564 }
565 env.close();
566
567 // TrustSet NoFreeze
568 // test: should set NoFreeze in Flags
569 env.require(nflags(G1, asfNoFreeze));
570 env(fset(G1, asfNoFreeze));
571 env.require(flags(G1, asfNoFreeze));
572 env.require(nflags(G1, asfGlobalFreeze));
573
574 // test: cannot be cleared
575 env(fclear(G1, asfNoFreeze));
576 env.require(flags(G1, asfNoFreeze));
577 env.require(nflags(G1, asfGlobalFreeze));
578
579 // test: can set GlobalFreeze
580 env(fset(G1, asfGlobalFreeze));
581 env.require(flags(G1, asfNoFreeze));
582 env.require(flags(G1, asfGlobalFreeze));
583
584 // test: cannot unset GlobalFreeze
585 env(fclear(G1, asfGlobalFreeze));
586 env.require(flags(G1, asfNoFreeze));
587 env.require(flags(G1, asfGlobalFreeze));
588
589 // test: trustlines can't be frozen when no freeze enacted
590 if (features[featureDeepFreeze])
591 {
592 env(trust(G1, A1["USD"](0), tfSetFreeze), ter(tecNO_PERMISSION));
593
594 // test: cannot deep freeze already frozen line when no freeze
595 // enacted
596 env(trust(G1, frozenAcc["USD"](0), tfSetDeepFreeze),
597 ter(tecNO_PERMISSION));
598 }
599 else
600 {
601 // test: previous functionality, checking there's no changes to a
602 // trust line
603 env(trust(G1, A1["USD"](0), tfSetFreeze));
604 auto affected = env.meta()->getJson(
605 JsonOptions::none)[sfAffectedNodes.fieldName];
606 if (!BEAST_EXPECT(checkArraySize(affected, 1u)))
607 return;
608
609 auto let = affected[0u][sfModifiedNode.fieldName]
610 [sfLedgerEntryType.fieldName];
611 BEAST_EXPECT(let == jss::AccountRoot);
612 }
613
614 // test: can clear freeze on account
615 env(trust(G1, frozenAcc["USD"](0), tfClearFreeze));
616 {
617 auto const flags = getTrustlineFlags(env, 2u, 1u);
618 BEAST_EXPECT(!(flags & lsfLowFreeze));
619 }
620
621 if (features[featureDeepFreeze])
622 {
623 // test: can clear deep freeze on account
624 env(trust(G1, deepFrozenAcc["USD"](0), tfClearDeepFreeze));
625 {
626 auto const flags = getTrustlineFlags(env, 2u, 1u);
627 BEAST_EXPECT(flags & lsfHighFreeze);
628 BEAST_EXPECT(!(flags & lsfHighDeepFreeze));
629 }
630 }
631 }
632
633 void
635 {
636 testcase("Offers for Frozen Trust Lines");
637
638 using namespace test::jtx;
639 Env env(*this, features);
640
641 Account G1{"G1"};
642 Account A2{"A2"};
643 Account A3{"A3"};
644 Account A4{"A4"};
645
646 env.fund(XRP(1000), G1, A3, A4);
647 env.fund(XRP(2000), A2);
648 env.close();
649
650 env.trust(G1["USD"](1000), A2);
651 env.trust(G1["USD"](2000), A3);
652 env.trust(G1["USD"](2000), A4);
653 env.close();
654
655 env(pay(G1, A3, G1["USD"](2000)));
656 env(pay(G1, A4, G1["USD"](2000)));
657 env.close();
658
659 env(offer(A3, XRP(1000), G1["USD"](1000)), txflags(tfPassive));
660 env.close();
661
662 // removal after successful payment
663 // test: make a payment with partially consuming offer
664 env(pay(A2, G1, G1["USD"](1)), paths(G1["USD"]), sendmax(XRP(1)));
665 env.close();
666
667 // test: offer was only partially consumed
668 auto offers = getAccountOffers(env, A3)[jss::offers];
669 if (!BEAST_EXPECT(checkArraySize(offers, 1u)))
670 return;
671 BEAST_EXPECT(
672 offers[0u][jss::taker_gets] ==
673 G1["USD"](999).value().getJson(JsonOptions::none));
674
675 // test: someone else creates an offer providing liquidity
676 env(offer(A4, XRP(999), G1["USD"](999)));
677 env.close();
678
679 // test: owner of partially consumed offers line is frozen
680 env(trust(G1, A3["USD"](0), tfSetFreeze));
681 auto affected =
682 env.meta()->getJson(JsonOptions::none)[sfAffectedNodes.fieldName];
683 if (!BEAST_EXPECT(checkArraySize(affected, 2u)))
684 return;
685 auto ff =
686 affected[1u][sfModifiedNode.fieldName][sfFinalFields.fieldName];
687 BEAST_EXPECT(
688 ff[sfHighLimit.fieldName] ==
689 G1["USD"](0).value().getJson(JsonOptions::none));
690 BEAST_EXPECT(!(ff[jss::Flags].asUInt() & lsfLowFreeze));
691 BEAST_EXPECT(ff[jss::Flags].asUInt() & lsfHighFreeze);
692 env.close();
693
694 // verify offer on the books
695 offers = getAccountOffers(env, A3)[jss::offers];
696 if (!BEAST_EXPECT(checkArraySize(offers, 1u)))
697 return;
698
699 // test: Can make a payment via the new offer
700 env(pay(A2, G1, G1["USD"](1)), paths(G1["USD"]), sendmax(XRP(1)));
701 env.close();
702
703 // test: Partially consumed offer was removed by tes* payment
704 offers = getAccountOffers(env, A3)[jss::offers];
705 if (!BEAST_EXPECT(checkArraySize(offers, 0u)))
706 return;
707
708 // removal buy successful OfferCreate
709 // test: freeze the new offer
710 env(trust(G1, A4["USD"](0), tfSetFreeze));
711 affected =
712 env.meta()->getJson(JsonOptions::none)[sfAffectedNodes.fieldName];
713 if (!BEAST_EXPECT(checkArraySize(affected, 2u)))
714 return;
715 ff = affected[0u][sfModifiedNode.fieldName][sfFinalFields.fieldName];
716 BEAST_EXPECT(
717 ff[sfLowLimit.fieldName] ==
718 G1["USD"](0).value().getJson(JsonOptions::none));
719 BEAST_EXPECT(ff[jss::Flags].asUInt() & lsfLowFreeze);
720 BEAST_EXPECT(!(ff[jss::Flags].asUInt() & lsfHighFreeze));
721 env.close();
722
723 // test: can no longer create a crossing offer
724 env(offer(A2, G1["USD"](999), XRP(999)));
725 affected =
726 env.meta()->getJson(JsonOptions::none)[sfAffectedNodes.fieldName];
727 if (!BEAST_EXPECT(checkArraySize(affected, 8u)))
728 return;
729 auto created = affected[0u][sfCreatedNode.fieldName];
730 BEAST_EXPECT(
731 created[sfNewFields.fieldName][jss::Account] == A2.human());
732 env.close();
733
734 // test: offer was removed by offer_create
735 offers = getAccountOffers(env, A4)[jss::offers];
736 if (!BEAST_EXPECT(checkArraySize(offers, 0u)))
737 return;
738 }
739
740 void
742 {
743 testcase("Offers on frozen trust lines");
744
745 using namespace test::jtx;
746 Env env(*this, features);
747
748 Account G1{"G1"};
749 Account A1{"A1"};
750 Account A2{"A2"};
751 Account A3{"A3"};
752 auto const USD{G1["USD"]};
753
754 env.fund(XRP(10000), G1, A1, A2, A3);
755 env.close();
756
757 auto const limit = USD(10000);
758 env.trust(limit, A1, A2, A3);
759 env.close();
760
761 env(pay(G1, A1, USD(1000)));
762 env(pay(G1, A2, USD(1000)));
763 env.close();
764
765 // Making large passive sell offer
766 // Wants to sell 50 USD for 100 XRP
767 env(offer(A2, XRP(100), USD(50)), txflags(tfPassive));
768 env.close();
769 // Making large passive buy offer
770 // Wants to buy 100 USD for 100 XRP
771 env(offer(A3, USD(100), XRP(100)), txflags(tfPassive));
772 env.close();
773 env.require(offers(A2, 1), offers(A3, 1));
774
775 // Checking A1 can buy from A2 by crossing it's offer
776 env(offer(A1, USD(1), XRP(2)), txflags(tfFillOrKill));
777 env.close();
778 env.require(balance(A1, USD(1001)), balance(A2, USD(999)));
779
780 // Checking A1 can sell to A3 by crossing it's offer
781 env(offer(A1, XRP(1), USD(1)), txflags(tfFillOrKill));
782 env.close();
783 env.require(balance(A1, USD(1000)), balance(A3, USD(1)));
784
785 // Testing aggressive and passive offer placing, trustline frozen by
786 // the issuer
787 {
788 env(trust(G1, A1["USD"](0), tfSetFreeze));
789 env.close();
790
791 // test: can still make passive buy offer
792 env(offer(A1, USD(1), XRP(0.5)), txflags(tfPassive));
793 env.close();
794 env.require(balance(A1, USD(1000)), offers(A1, 1));
795 // Cleanup
796 env(offer_cancel(A1, env.seq(A1) - 1));
797 env.require(offers(A1, 0));
798 env.close();
799
800 // test: can still buy from A2
801 env(offer(A1, USD(1), XRP(2)), txflags(tfFillOrKill));
802 env.close();
803 env.require(
804 balance(A1, USD(1001)), balance(A2, USD(998)), offers(A1, 0));
805
806 // test: cannot create passive sell offer
807 env(offer(A1, XRP(2), USD(1)),
808 txflags(tfPassive),
809 ter(tecUNFUNDED_OFFER));
810 env.close();
811 env.require(balance(A1, USD(1001)), offers(A1, 0));
812
813 // test: cannot sell to A3
814 env(offer(A1, XRP(1), USD(1)),
815 txflags(tfFillOrKill),
816 ter(tecUNFUNDED_OFFER));
817 env.close();
818 env.require(balance(A1, USD(1001)), offers(A1, 0));
819
820 env(trust(G1, A1["USD"](0), tfClearFreeze));
821 env.close();
822 }
823
824 // Testing aggressive and passive offer placing, trustline deep frozen
825 // by the issuer
826 if (features[featureDeepFreeze])
827 {
828 env(trust(G1, A1["USD"](0), tfSetFreeze | tfSetDeepFreeze));
829 env.close();
830
831 // test: cannot create passive buy offer
832 env(offer(A1, USD(1), XRP(0.5)),
833 txflags(tfPassive),
834 ter(tecFROZEN));
835 env.close();
836
837 // test: cannot buy from A2
838 env(offer(A1, USD(1), XRP(2)),
839 txflags(tfFillOrKill),
840 ter(tecFROZEN));
841 env.close();
842
843 // test: cannot create passive sell offer
844 env(offer(A1, XRP(2), USD(1)),
845 txflags(tfPassive),
846 ter(tecUNFUNDED_OFFER));
847 env.close();
848
849 // test: cannot sell to A3
850 env(offer(A1, XRP(1), USD(1)),
851 txflags(tfFillOrKill),
852 ter(tecUNFUNDED_OFFER));
853 env.close();
854
855 env(trust(G1, A1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
856 env.close();
857 env.require(balance(A1, USD(1001)), offers(A1, 0));
858 }
859
860 // Testing already existing offers behavior after trustline is frozen by
861 // the issuer
862 {
863 env.require(balance(A1, USD(1001)));
864 env(offer(A1, XRP(1.9), USD(1)));
865 env(offer(A1, USD(1), XRP(1.1)));
866 env.close();
867 env.require(balance(A1, USD(1001)), offers(A1, 2));
868
869 env(trust(G1, A1["USD"](0), tfSetFreeze));
870 env.close();
871
872 // test: A2 wants to sell to A1, must succeed
873 env.require(balance(A1, USD(1001)), balance(A2, USD(998)));
874 env(offer(A2, XRP(1.1), USD(1)), txflags(tfFillOrKill));
875 env.close();
876 env.require(
877 balance(A1, USD(1002)), balance(A2, USD(997)), offers(A1, 1));
878
879 // test: A3 wants to buy from A1, must fail
880 env.require(
881 balance(A1, USD(1002)), balance(A3, USD(1)), offers(A1, 1));
882 env(offer(A3, USD(1), XRP(1.9)),
883 txflags(tfFillOrKill),
884 ter(tecKILLED));
885 env.close();
886 env.require(
887 balance(A1, USD(1002)), balance(A3, USD(1)), offers(A1, 0));
888
889 env(trust(G1, A1["USD"](0), tfClearFreeze));
890 env.close();
891 }
892
893 // Testing existing offers behavior after trustline is deep frozen by
894 // the issuer
895 if (features[featureDeepFreeze])
896 {
897 env.require(balance(A1, USD(1002)));
898 env(offer(A1, XRP(1.9), USD(1)));
899 env(offer(A1, USD(1), XRP(1.1)));
900 env.close();
901 env.require(balance(A1, USD(1002)), offers(A1, 2));
902
903 env(trust(G1, A1["USD"](0), tfSetFreeze | tfSetDeepFreeze));
904 env.close();
905
906 // test: A2 wants to sell to A1, must fail
907 env.require(balance(A1, USD(1002)), balance(A2, USD(997)));
908 env(offer(A2, XRP(1.1), USD(1)),
909 txflags(tfFillOrKill),
910 ter(tecKILLED));
911 env.close();
912 env.require(
913 balance(A1, USD(1002)), balance(A2, USD(997)), offers(A1, 1));
914
915 // test: A3 wants to buy from A1, must fail
916 env.require(
917 balance(A1, USD(1002)), balance(A3, USD(1)), offers(A1, 1));
918 env(offer(A3, USD(1), XRP(1.9)),
919 txflags(tfFillOrKill),
920 ter(tecKILLED));
921 env.close();
922 env.require(
923 balance(A1, USD(1002)), balance(A3, USD(1)), offers(A1, 0));
924
925 env(trust(G1, A1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
926 env.close();
927 }
928
929 // Testing aggressive and passive offer placing, trustline frozen by
930 // the holder
931 {
932 env(trust(A1, limit, tfSetFreeze));
933 env.close();
934
935 // test: A1 can make passive buy offer
936 env(offer(A1, USD(1), XRP(0.5)), txflags(tfPassive));
937 env.close();
938 env.require(balance(A1, USD(1002)), offers(A1, 1));
939 // Cleanup
940 env(offer_cancel(A1, env.seq(A1) - 1));
941 env.require(offers(A1, 0));
942 env.close();
943
944 // test: A1 wants to buy, must fail
945 env(offer(A1, USD(1), XRP(2)),
946 txflags(tfFillOrKill),
947 ter(tecKILLED));
948 env.close();
949 env.require(
950 balance(A1, USD(1002)), balance(A2, USD(997)), offers(A1, 0));
951
952 // test: A1 can create passive sell offer
953 env(offer(A1, XRP(2), USD(1)), txflags(tfPassive));
954 env.close();
955 env.require(balance(A1, USD(1002)), offers(A1, 1));
956 // Cleanup
957 env(offer_cancel(A1, env.seq(A1) - 1));
958 env.require(offers(A1, 0));
959 env.close();
960
961 // test: A1 can sell to A3
962 env(offer(A1, XRP(1), USD(1)), txflags(tfFillOrKill));
963 env.close();
964 env.require(balance(A1, USD(1001)), offers(A1, 0));
965
966 env(trust(A1, limit, tfClearFreeze));
967 env.close();
968 }
969
970 // Testing aggressive and passive offer placing, trustline deep frozen
971 // by the holder
972 if (features[featureDeepFreeze])
973 {
974 env(trust(A1, limit, tfSetFreeze | tfSetDeepFreeze));
975 env.close();
976
977 // test: A1 cannot create passive buy offer
978 env(offer(A1, USD(1), XRP(0.5)),
979 txflags(tfPassive),
980 ter(tecFROZEN));
981 env.close();
982
983 // test: A1 cannot buy, must fail
984 env(offer(A1, USD(1), XRP(2)),
985 txflags(tfFillOrKill),
986 ter(tecFROZEN));
987 env.close();
988
989 // test: A1 cannot create passive sell offer
990 env(offer(A1, XRP(2), USD(1)),
991 txflags(tfPassive),
992 ter(tecUNFUNDED_OFFER));
993 env.close();
994
995 // test: A1 cannot sell to A3
996 env(offer(A1, XRP(1), USD(1)),
997 txflags(tfFillOrKill),
998 ter(tecUNFUNDED_OFFER));
999 env.close();
1000
1001 env(trust(A1, limit, tfClearFreeze | tfClearDeepFreeze));
1002 env.close();
1003 }
1004 }
1005
1006 void
1008 {
1009 testcase("Longer paths payment on frozen trust lines");
1010 using namespace test::jtx;
1011 using path = test::jtx::path;
1012
1013 Env env(*this, features);
1014 Account G1{"G1"};
1015 Account A1{"A1"};
1016 Account A2{"A2"};
1017 auto const USD{G1["USD"]};
1018
1019 env.fund(XRP(10000), G1, A1, A2);
1020 env.close();
1021
1022 auto const limit = USD(10000);
1023 env.trust(limit, A1, A2);
1024 env.close();
1025
1026 env(pay(G1, A1, USD(1000)));
1027 env(pay(G1, A2, USD(1000)));
1028 env.close();
1029
1030 env(offer(A2, XRP(100), USD(100)), txflags(tfPassive));
1031 env.close();
1032
1033 // Testing payments A1 <-> G1 using offer from A2 frozen by issuer.
1034 {
1035 env(trust(G1, A2["USD"](0), tfSetFreeze));
1036 env.close();
1037
1038 // test: A1 cannot send USD using XRP through A2 offer
1039 env(pay(A1, G1, USD(10)),
1040 path(~USD),
1041 sendmax(XRP(11)),
1042 txflags(tfNoRippleDirect),
1043 ter(tecPATH_PARTIAL));
1044 env.close();
1045
1046 // test: G1 cannot send USD using XRP through A2 offer
1047 env(pay(G1, A1, USD(10)),
1048 path(~USD),
1049 sendmax(XRP(11)),
1050 txflags(tfNoRippleDirect),
1051 ter(tecPATH_PARTIAL));
1052 env.close();
1053
1054 env(trust(G1, A2["USD"](0), tfClearFreeze));
1055 env.close();
1056 }
1057
1058 // Testing payments A1 <-> G1 using offer from A2 deep frozen by issuer.
1059 if (features[featureDeepFreeze])
1060 {
1061 env(trust(G1, A2["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1062 env.close();
1063
1064 // test: A1 cannot send USD using XRP through A2 offer
1065 env(pay(A1, G1, USD(10)),
1066 path(~USD),
1067 sendmax(XRP(11)),
1068 txflags(tfNoRippleDirect),
1069 ter(tecPATH_PARTIAL));
1070 env.close();
1071
1072 // test: G1 cannot send USD using XRP through A2 offer
1073 env(pay(G1, A1, USD(10)),
1074 path(~USD),
1075 sendmax(XRP(11)),
1076 txflags(tfNoRippleDirect),
1077 ter(tecPATH_PARTIAL));
1078 env.close();
1079
1080 env(trust(G1, A2["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1081 env.close();
1082 }
1083
1084 // Testing payments A1 <-> G1 using offer from A2 frozen by currency
1085 // holder.
1086 {
1087 env(trust(A2, limit, tfSetFreeze));
1088 env.close();
1089
1090 // test: A1 can send USD using XRP through A2 offer
1091 env(pay(A1, G1, USD(10)),
1092 path(~USD),
1093 sendmax(XRP(11)),
1094 txflags(tfNoRippleDirect));
1095 env.close();
1096
1097 // test: G1 can send USD using XRP through A2 offer
1098 env(pay(G1, A1, USD(10)),
1099 path(~USD),
1100 sendmax(XRP(11)),
1101 txflags(tfNoRippleDirect));
1102 env.close();
1103
1104 env(trust(A2, limit, tfClearFreeze));
1105 env.close();
1106 }
1107
1108 // Testing payments A1 <-> G1 using offer from A2 deep frozen by
1109 // currency holder.
1110 if (features[featureDeepFreeze])
1111 {
1112 env(trust(A2, limit, tfSetFreeze | tfSetDeepFreeze));
1113 env.close();
1114
1115 // test: A1 cannot send USD using XRP through A2 offer
1116 env(pay(A1, G1, USD(10)),
1117 path(~USD),
1118 sendmax(XRP(11)),
1119 txflags(tfNoRippleDirect),
1120 ter(tecPATH_PARTIAL));
1121 env.close();
1122
1123 // test: G1 cannot send USD using XRP through A2 offer
1124 env(pay(G1, A1, USD(10)),
1125 path(~USD),
1126 sendmax(XRP(11)),
1127 txflags(tfNoRippleDirect),
1128 ter(tecPATH_PARTIAL));
1129 env.close();
1130
1131 env(trust(A2, limit, tfClearFreeze | tfClearDeepFreeze));
1132 env.close();
1133 }
1134
1135 // Cleanup
1136 env(offer_cancel(A1, env.seq(A1) - 1));
1137 env.require(offers(A1, 0));
1138 env.close();
1139
1140 env(offer(A2, USD(100), XRP(100)), txflags(tfPassive));
1141 env.close();
1142
1143 // Testing payments A1 <-> G1 using offer from A2 frozen by issuer.
1144 {
1145 env(trust(G1, A2["USD"](0), tfSetFreeze));
1146 env.close();
1147
1148 // test: A1 can send XRP using USD through A2 offer
1149 env(pay(A1, G1, XRP(10)),
1150 path(~XRP),
1151 sendmax(USD(11)),
1152 txflags(tfNoRippleDirect));
1153 env.close();
1154
1155 // test: G1 can send XRP using USD through A2 offer
1156 env(pay(G1, A1, XRP(10)),
1157 path(~XRP),
1158 sendmax(USD(11)),
1159 txflags(tfNoRippleDirect));
1160 env.close();
1161
1162 env(trust(G1, A2["USD"](0), tfClearFreeze));
1163 env.close();
1164 }
1165
1166 // Testing payments A1 <-> G1 using offer from A2 deep frozen by
1167 // issuer.
1168 if (features[featureDeepFreeze])
1169 {
1170 env(trust(G1, A2["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1171 env.close();
1172
1173 // test: A1 cannot send XRP using USD through A2 offer
1174 env(pay(A1, G1, XRP(10)),
1175 path(~XRP),
1176 sendmax(USD(11)),
1177 txflags(tfNoRippleDirect),
1178 ter(tecPATH_PARTIAL));
1179 env.close();
1180
1181 // test: G1 cannot send XRP using USD through A2 offer
1182 env(pay(G1, A1, XRP(10)),
1183 path(~XRP),
1184 sendmax(USD(11)),
1185 txflags(tfNoRippleDirect),
1186 ter(tecPATH_PARTIAL));
1187 env.close();
1188
1189 env(trust(G1, A2["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1190 env.close();
1191 }
1192
1193 // Testing payments A1 <-> G1 using offer from A2 frozen by currency
1194 // holder.
1195 {
1196 env(trust(A2, limit, tfSetFreeze));
1197 env.close();
1198
1199 // test: A1 can send XRP using USD through A2 offer
1200 env(pay(A1, G1, XRP(10)),
1201 path(~XRP),
1202 sendmax(USD(11)),
1203 txflags(tfNoRippleDirect));
1204 env.close();
1205
1206 // test: G1 can send XRP using USD through A2 offer
1207 env(pay(G1, A1, XRP(10)),
1208 path(~XRP),
1209 sendmax(USD(11)),
1210 txflags(tfNoRippleDirect));
1211 env.close();
1212
1213 env(trust(A2, limit, tfClearFreeze));
1214 env.close();
1215 }
1216
1217 // Testing payments A1 <-> G1 using offer from A2 deep frozen by
1218 // currency holder.
1219 if (features[featureDeepFreeze])
1220 {
1221 env(trust(A2, limit, tfSetFreeze | tfSetDeepFreeze));
1222 env.close();
1223
1224 // test: A1 cannot send XRP using USD through A2 offer
1225 env(pay(A1, G1, XRP(10)),
1226 path(~XRP),
1227 sendmax(USD(11)),
1228 txflags(tfNoRippleDirect),
1229 ter(tecPATH_PARTIAL));
1230 env.close();
1231
1232 // test: G1 cannot send XRP using USD through A2 offer
1233 env(pay(G1, A1, XRP(10)),
1234 path(~XRP),
1235 sendmax(USD(11)),
1236 txflags(tfNoRippleDirect),
1237 ter(tecPATH_PARTIAL));
1238 env.close();
1239
1240 env(trust(A2, limit, tfClearFreeze | tfClearDeepFreeze));
1241 env.close();
1242 }
1243
1244 // Cleanup
1245 env(offer_cancel(A1, env.seq(A1) - 1));
1246 env.require(offers(A1, 0));
1247 env.close();
1248 }
1249
1250 void
1252 {
1253 testcase("Direct payments on frozen trust lines");
1254
1255 using namespace test::jtx;
1256 Env env(*this, features);
1257
1258 Account G1{"G1"};
1259 Account A1{"A1"};
1260 Account A2{"A2"};
1261 auto const USD{G1["USD"]};
1262
1263 env.fund(XRP(10000), G1, A1, A2);
1264 env.close();
1265
1266 auto const limit = USD(10000);
1267 env.trust(limit, A1, A2);
1268 env.close();
1269
1270 env(pay(G1, A1, USD(1000)));
1271 env(pay(G1, A2, USD(1000)));
1272 env.close();
1273
1274 // Checking payments before freeze
1275 // To issuer:
1276 env(pay(A1, G1, USD(1)));
1277 env(pay(A2, G1, USD(1)));
1278 env.close();
1279
1280 // To each other:
1281 env(pay(A1, A2, USD(1)));
1282 env(pay(A2, A1, USD(1)));
1283 env.close();
1284
1285 // Freeze A1
1286 env(trust(G1, A1["USD"](0), tfSetFreeze));
1287 env.close();
1288
1289 // Issuer and A1 can send payments to each other
1290 env(pay(A1, G1, USD(1)));
1291 env(pay(G1, A1, USD(1)));
1292 env.close();
1293
1294 // A1 cannot send tokens to A2
1295 env(pay(A1, A2, USD(1)), ter(tecPATH_DRY));
1296
1297 // A2 can still send to A1
1298 env(pay(A2, A1, USD(1)));
1299 env.close();
1300
1301 if (features[featureDeepFreeze])
1302 {
1303 // Deep freeze A1
1304 env(trust(G1, A1["USD"](0), tfSetDeepFreeze));
1305 env.close();
1306
1307 // Issuer and A1 can send payments to each other
1308 env(pay(A1, G1, USD(1)));
1309 env(pay(G1, A1, USD(1)));
1310 env.close();
1311
1312 // A1 cannot send tokens to A2
1313 env(pay(A1, A2, USD(1)), ter(tecPATH_DRY));
1314
1315 // A2 cannot send tokens to A1
1316 env(pay(A2, A1, USD(1)), ter(tecPATH_DRY));
1317
1318 // Clear deep freeze on A1
1319 env(trust(G1, A1["USD"](0), tfClearDeepFreeze));
1320 env.close();
1321 }
1322
1323 // Clear freeze on A1
1324 env(trust(G1, A1["USD"](0), tfClearFreeze));
1325 env.close();
1326
1327 // A1 freezes trust line
1328 env(trust(A1, limit, tfSetFreeze));
1329 env.close();
1330
1331 // Issuer and A2 must not be affected
1332 env(pay(A2, G1, USD(1)));
1333 env(pay(G1, A2, USD(1)));
1334 env.close();
1335
1336 // A1 can send tokens to the issuer
1337 env(pay(A1, G1, USD(1)));
1338 env.close();
1339 // A1 can send tokens to A2
1340 env(pay(A1, A2, USD(1)));
1341 env.close();
1342
1343 // Issuer can sent tokens to A1
1344 env(pay(G1, A1, USD(1)));
1345 // A2 cannot send tokens to A1
1346 env(pay(A2, A1, USD(1)), ter(tecPATH_DRY));
1347
1348 if (features[featureDeepFreeze])
1349 {
1350 // A1 deep freezes trust line
1351 env(trust(A1, limit, tfSetDeepFreeze));
1352 env.close();
1353
1354 // Issuer and A2 must not be affected
1355 env(pay(A2, G1, USD(1)));
1356 env(pay(G1, A2, USD(1)));
1357 env.close();
1358
1359 // A1 can still send token to issuer
1360 env(pay(A1, G1, USD(1)));
1361 env.close();
1362
1363 // Issuer can send tokens to A1
1364 env(pay(G1, A1, USD(1)));
1365 // A2 cannot send tokens to A1
1366 env(pay(A2, A1, USD(1)), ter(tecPATH_DRY));
1367 // A1 cannot send tokens to A2
1368 env(pay(A1, A2, USD(1)), ter(tecPATH_DRY));
1369 }
1370 }
1371
1372 void
1374 {
1375 testcase("Checks on frozen trust lines");
1376
1377 using namespace test::jtx;
1378 Env env(*this, features);
1379
1380 Account G1{"G1"};
1381 Account A1{"A1"};
1382 Account A2{"A2"};
1383 auto const USD{G1["USD"]};
1384
1385 env.fund(XRP(10000), G1, A1, A2);
1386 env.close();
1387
1388 auto const limit = USD(10000);
1389 env.trust(limit, A1, A2);
1390 env.close();
1391
1392 env(pay(G1, A1, USD(1000)));
1393 env(pay(G1, A2, USD(1000)));
1394 env.close();
1395
1396 // Confirming we can write and cash checks
1397 {
1398 uint256 const checkId{getCheckIndex(G1, env.seq(G1))};
1399 env(check::create(G1, A1, USD(10)));
1400 env.close();
1401 env(check::cash(A1, checkId, USD(10)));
1402 env.close();
1403 }
1404
1405 {
1406 uint256 const checkId{getCheckIndex(G1, env.seq(G1))};
1407 env(check::create(G1, A2, USD(10)));
1408 env.close();
1409 env(check::cash(A2, checkId, USD(10)));
1410 env.close();
1411 }
1412
1413 {
1414 uint256 const checkId{getCheckIndex(A1, env.seq(A1))};
1415 env(check::create(A1, G1, USD(10)));
1416 env.close();
1417 env(check::cash(G1, checkId, USD(10)));
1418 env.close();
1419 }
1420
1421 {
1422 uint256 const checkId{getCheckIndex(A1, env.seq(A1))};
1423 env(check::create(A1, A2, USD(10)));
1424 env.close();
1425 env(check::cash(A2, checkId, USD(10)));
1426 env.close();
1427 }
1428
1429 {
1430 uint256 const checkId{getCheckIndex(A2, env.seq(A2))};
1431 env(check::create(A2, G1, USD(10)));
1432 env.close();
1433 env(check::cash(G1, checkId, USD(10)));
1434 env.close();
1435 }
1436
1437 {
1438 uint256 const checkId{getCheckIndex(A2, env.seq(A2))};
1439 env(check::create(A2, A1, USD(10)));
1440 env.close();
1441 env(check::cash(A1, checkId, USD(10)));
1442 env.close();
1443 }
1444
1445 // Testing creation and cashing of checks on a trustline frozen by
1446 // issuer
1447 {
1448 env(trust(G1, A1["USD"](0), tfSetFreeze));
1449 env.close();
1450
1451 // test: issuer writes check to A1.
1452 {
1453 uint256 const checkId{getCheckIndex(G1, env.seq(G1))};
1454 env(check::create(G1, A1, USD(10)));
1455 env.close();
1456 env(check::cash(A1, checkId, USD(10)), ter(tecFROZEN));
1457 env.close();
1458 }
1459
1460 // test: A2 writes check to A1.
1461 {
1462 uint256 const checkId{getCheckIndex(A2, env.seq(A2))};
1463 env(check::create(A2, A1, USD(10)));
1464 env.close();
1465 // Same as previous test
1466 env(check::cash(A1, checkId, USD(10)), ter(tecFROZEN));
1467 env.close();
1468 }
1469
1470 // test: A1 writes check to issuer
1471 {
1472 env(check::create(A1, G1, USD(10)), ter(tecFROZEN));
1473 env.close();
1474 }
1475
1476 // test: A1 writes check to A2
1477 {
1478 // Same as previous test
1479 env(check::create(A1, A2, USD(10)), ter(tecFROZEN));
1480 env.close();
1481 }
1482
1483 // Unfreeze the trustline to create a couple of checks so that we
1484 // could try to cash them later when the trustline is frozen again.
1485 env(trust(G1, A1["USD"](0), tfClearFreeze));
1486 env.close();
1487
1488 uint256 const checkId1{getCheckIndex(A1, env.seq(A1))};
1489 env(check::create(A1, G1, USD(10)));
1490 env.close();
1491 uint256 const checkId2{getCheckIndex(A1, env.seq(A1))};
1492 env(check::create(A1, A2, USD(10)));
1493 env.close();
1494
1495 env(trust(G1, A1["USD"](0), tfSetFreeze));
1496 env.close();
1497
1498 // test: issuer tries to cash the check from A1
1499 {
1500 env(check::cash(G1, checkId1, USD(10)), ter(tecPATH_PARTIAL));
1501 env.close();
1502 }
1503
1504 // test: A2 tries to cash the check from A1
1505 {
1506 env(check::cash(A2, checkId2, USD(10)), ter(tecPATH_PARTIAL));
1507 env.close();
1508 }
1509
1510 env(trust(G1, A1["USD"](0), tfClearFreeze));
1511 env.close();
1512 }
1513
1514 // Testing creation and cashing of checks on a trustline deep frozen by
1515 // issuer
1516 if (features[featureDeepFreeze])
1517 {
1518 env(trust(G1, A1["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1519 env.close();
1520
1521 // test: issuer writes check to A1.
1522 {
1523 uint256 const checkId{getCheckIndex(G1, env.seq(G1))};
1524 env(check::create(G1, A1, USD(10)));
1525 env.close();
1526
1527 env(check::cash(A1, checkId, USD(10)), ter(tecFROZEN));
1528 env.close();
1529 }
1530
1531 // test: A2 writes check to A1.
1532 {
1533 uint256 const checkId{getCheckIndex(A2, env.seq(A2))};
1534 env(check::create(A2, A1, USD(10)));
1535 env.close();
1536 // Same as previous test
1537 env(check::cash(A1, checkId, USD(10)), ter(tecFROZEN));
1538 env.close();
1539 }
1540
1541 // test: A1 writes check to issuer
1542 {
1543 env(check::create(A1, G1, USD(10)), ter(tecFROZEN));
1544 env.close();
1545 }
1546
1547 // test: A1 writes check to A2
1548 {
1549 // Same as previous test
1550 env(check::create(A1, A2, USD(10)), ter(tecFROZEN));
1551 env.close();
1552 }
1553
1554 // Unfreeze the trustline to create a couple of checks so that we
1555 // could try to cash them later when the trustline is frozen again.
1556 env(trust(G1, A1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1557 env.close();
1558
1559 uint256 const checkId1{getCheckIndex(A1, env.seq(A1))};
1560 env(check::create(A1, G1, USD(10)));
1561 env.close();
1562 uint256 const checkId2{getCheckIndex(A1, env.seq(A1))};
1563 env(check::create(A1, A2, USD(10)));
1564 env.close();
1565
1566 env(trust(G1, A1["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1567 env.close();
1568
1569 // test: issuer tries to cash the check from A1
1570 {
1571 env(check::cash(G1, checkId1, USD(10)), ter(tecPATH_PARTIAL));
1572 env.close();
1573 }
1574
1575 // test: A2 tries to cash the check from A1
1576 {
1577 env(check::cash(A2, checkId2, USD(10)), ter(tecPATH_PARTIAL));
1578 env.close();
1579 }
1580
1581 env(trust(G1, A1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1582 env.close();
1583 }
1584
1585 // Testing creation and cashing of checks on a trustline frozen by
1586 // a currency holder
1587 {
1588 env(trust(A1, limit, tfSetFreeze));
1589 env.close();
1590
1591 // test: issuer writes check to A1.
1592 {
1593 env(check::create(G1, A1, USD(10)), ter(tecFROZEN));
1594 env.close();
1595 }
1596
1597 // test: A2 writes check to A1.
1598 {
1599 env(check::create(A2, A1, USD(10)), ter(tecFROZEN));
1600 env.close();
1601 }
1602
1603 // test: A1 writes check to issuer
1604 {
1605 uint256 const checkId{getCheckIndex(A1, env.seq(A1))};
1606 env(check::create(A1, G1, USD(10)));
1607 env.close();
1608 env(check::cash(G1, checkId, USD(10)));
1609 env.close();
1610 }
1611
1612 // test: A1 writes check to A2
1613 {
1614 uint256 const checkId{getCheckIndex(A1, env.seq(A1))};
1615 env(check::create(A1, A2, USD(10)));
1616 env.close();
1617 env(check::cash(A2, checkId, USD(10)));
1618 env.close();
1619 }
1620
1621 env(trust(A1, limit, tfClearFreeze));
1622 env.close();
1623 }
1624
1625 // Testing creation and cashing of checks on a trustline deep frozen by
1626 // a currency holder
1627 if (features[featureDeepFreeze])
1628 {
1629 env(trust(A1, limit, tfSetFreeze | tfSetDeepFreeze));
1630 env.close();
1631
1632 // test: issuer writes check to A1.
1633 {
1634 env(check::create(G1, A1, USD(10)), ter(tecFROZEN));
1635 env.close();
1636 }
1637
1638 // test: A2 writes check to A1.
1639 {
1640 env(check::create(A2, A1, USD(10)), ter(tecFROZEN));
1641 env.close();
1642 }
1643
1644 // test: A1 writes check to issuer
1645 {
1646 uint256 const checkId{getCheckIndex(A1, env.seq(A1))};
1647 env(check::create(A1, G1, USD(10)));
1648 env.close();
1649 env(check::cash(G1, checkId, USD(10)), ter(tecPATH_PARTIAL));
1650 env.close();
1651 }
1652
1653 // test: A1 writes check to A2
1654 {
1655 uint256 const checkId{getCheckIndex(A1, env.seq(A1))};
1656 env(check::create(A1, A2, USD(10)));
1657 env.close();
1658 env(check::cash(A2, checkId, USD(10)), ter(tecPATH_PARTIAL));
1659 env.close();
1660 }
1661
1662 env(trust(A1, limit, tfClearFreeze | tfClearDeepFreeze));
1663 env.close();
1664 }
1665 }
1666
1667 void
1669 {
1670 testcase("AMM payments on frozen trust lines");
1671 using namespace test::jtx;
1672 using path = test::jtx::path;
1673
1674 Env env(*this, features);
1675 Account G1{"G1"};
1676 Account A1{"A1"};
1677 Account A2{"A2"};
1678 auto const USD{G1["USD"]};
1679
1680 env.fund(XRP(10000), G1, A1, A2);
1681 env.close();
1682
1683 env.trust(G1["USD"](10000), A1, A2);
1684 env.close();
1685
1686 env(pay(G1, A1, USD(1000)));
1687 env(pay(G1, A2, USD(1000)));
1688 env.close();
1689
1690 AMM ammG1(env, G1, XRP(1'000), USD(1'000));
1691 env.close();
1692
1693 // Testing basic payment using AMM when freezing one of the trust lines.
1694 {
1695 env(trust(G1, A1["USD"](0), tfSetFreeze));
1696 env.close();
1697
1698 // test: can still use XRP to make payment
1699 env(pay(A1, A2, USD(10)),
1700 path(~USD),
1701 sendmax(XRP(11)),
1702 txflags(tfNoRippleDirect));
1703 env.close();
1704
1705 // test: cannot use USD to make payment
1706 env(pay(A1, A2, XRP(10)),
1707 path(~XRP),
1708 sendmax(USD(11)),
1709 txflags(tfNoRippleDirect),
1710 ter(tecPATH_DRY));
1711 env.close();
1712
1713 // test: can still receive USD payments.
1714 env(pay(A2, A1, USD(10)),
1715 path(~USD),
1716 sendmax(XRP(11)),
1717 txflags(tfNoRippleDirect));
1718 env.close();
1719
1720 // test: can still receive XRP payments.
1721 env(pay(A2, A1, XRP(10)),
1722 path(~XRP),
1723 sendmax(USD(11)),
1724 txflags(tfNoRippleDirect));
1725 env.close();
1726
1727 env(trust(G1, A1["USD"](0), tfClearFreeze));
1728 env.close();
1729 }
1730
1731 // Testing basic payment using AMM when deep freezing one of the trust
1732 // lines.
1733 if (features[featureDeepFreeze])
1734 {
1735 env(trust(G1, A1["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1736 env.close();
1737
1738 // test: can still use XRP to make payment
1739 env(pay(A1, A2, USD(10)),
1740 path(~USD),
1741 sendmax(XRP(11)),
1742 txflags(tfNoRippleDirect));
1743 env.close();
1744
1745 // test: cannot use USD to make payment
1746 env(pay(A1, A2, XRP(10)),
1747 path(~XRP),
1748 sendmax(USD(11)),
1749 txflags(tfNoRippleDirect),
1750 ter(tecPATH_DRY));
1751 env.close();
1752
1753 // test: cannot receive USD payments.
1754 env(pay(A2, A1, USD(10)),
1755 path(~USD),
1756 sendmax(XRP(11)),
1757 txflags(tfNoRippleDirect),
1758 ter(tecPATH_DRY));
1759 env.close();
1760
1761 // test: can still receive XRP payments.
1762 env(pay(A2, A1, XRP(10)),
1763 path(~XRP),
1764 sendmax(USD(11)),
1765 txflags(tfNoRippleDirect));
1766 env.close();
1767
1768 env(trust(G1, A1["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1769 env.close();
1770 }
1771 }
1772
1773 void
1775 {
1776 testcase("NFT offers on frozen trust lines");
1777 using namespace test::jtx;
1778
1779 Env env(*this, features);
1780 Account G1{"G1"};
1781 Account A1{"A1"};
1782 Account A2{"A2"};
1783 auto const USD{G1["USD"]};
1784
1785 env.fund(XRP(10000), G1, A1, A2);
1786 env.close();
1787
1788 auto const limit = USD(10000);
1789 env.trust(limit, A1, A2);
1790 env.close();
1791
1792 env(pay(G1, A1, USD(1000)));
1793 env(pay(G1, A2, USD(1000)));
1794 env.close();
1795
1796 // Testing A2 nft offer sell when A2 frozen by issuer
1797 {
1798 auto const sellOfferIndex = createNFTSellOffer(env, A2, USD(10));
1799 env(trust(G1, A2["USD"](0), tfSetFreeze));
1800 env.close();
1801
1802 // test: A2 can still receive USD for his NFT
1803 env(token::acceptSellOffer(A1, sellOfferIndex));
1804 env.close();
1805
1806 env(trust(G1, A2["USD"](0), tfClearFreeze));
1807 env.close();
1808 }
1809
1810 // Testing A2 nft offer sell when A2 deep frozen by issuer
1811 if (features[featureDeepFreeze])
1812 {
1813 auto const sellOfferIndex = createNFTSellOffer(env, A2, USD(10));
1814
1815 env(trust(G1, A2["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1816 env.close();
1817
1818 // test: A2 cannot receive USD for his NFT
1819 env(token::acceptSellOffer(A1, sellOfferIndex), ter(tecFROZEN));
1820 env.close();
1821
1822 env(trust(G1, A2["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1823 env.close();
1824 }
1825
1826 // Testing A1 nft offer sell when A2 frozen by issuer
1827 {
1828 auto const sellOfferIndex = createNFTSellOffer(env, A1, USD(10));
1829 env(trust(G1, A2["USD"](0), tfSetFreeze));
1830 env.close();
1831
1832 // test: A2 cannot send USD for NFT
1833 env(token::acceptSellOffer(A2, sellOfferIndex),
1835 env.close();
1836
1837 env(trust(G1, A2["USD"](0), tfClearFreeze));
1838 env.close();
1839 }
1840
1841 // Testing A1 nft offer sell when A2 deep frozen by issuer
1842 if (features[featureDeepFreeze])
1843 {
1844 auto const sellOfferIndex = createNFTSellOffer(env, A1, USD(10));
1845 env(trust(G1, A2["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1846 env.close();
1847
1848 // test: A2 cannot send USD for NFT
1849 env(token::acceptSellOffer(A2, sellOfferIndex),
1851 env.close();
1852
1853 env(trust(G1, A2["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1854 env.close();
1855 }
1856
1857 // Testing A1 nft buy offer when A2 deep frozen by issuer
1858 if (features[featureDeepFreeze] &&
1859 features[fixEnforceNFTokenTrustlineV2])
1860 {
1861 env(trust(G1, A2["USD"](0), tfSetFreeze | tfSetDeepFreeze));
1862 env.close();
1863
1864 uint256 const nftID{token::getNextID(env, A2, 0u, tfTransferable)};
1865 env(token::mint(A2, 0), txflags(tfTransferable));
1866 env.close();
1867
1868 auto const buyIdx = keylet::nftoffer(A1, env.seq(A1)).key;
1869 env(token::createOffer(A1, nftID, USD(10)), token::owner(A2));
1870 env.close();
1871
1872 env(token::acceptBuyOffer(A2, buyIdx), ter(tecFROZEN));
1873 env.close();
1874
1875 env(trust(G1, A2["USD"](0), tfClearFreeze | tfClearDeepFreeze));
1876 env.close();
1877
1878 env(token::acceptBuyOffer(A2, buyIdx));
1879 env.close();
1880 }
1881
1882 // Testing A2 nft offer sell when A2 frozen by currency holder
1883 {
1884 auto const sellOfferIndex = createNFTSellOffer(env, A2, USD(10));
1885 env(trust(A2, limit, tfSetFreeze));
1886 env.close();
1887
1888 // test: offer can still be accepted.
1889 env(token::acceptSellOffer(A1, sellOfferIndex));
1890 env.close();
1891
1892 env(trust(A2, limit, tfClearFreeze));
1893 env.close();
1894 }
1895
1896 // Testing A2 nft offer sell when A2 deep frozen by currency holder
1897 if (features[featureDeepFreeze])
1898 {
1899 auto const sellOfferIndex = createNFTSellOffer(env, A2, USD(10));
1900
1901 env(trust(A2, limit, tfSetFreeze | tfSetDeepFreeze));
1902 env.close();
1903
1904 // test: A2 cannot receive USD for his NFT
1905 env(token::acceptSellOffer(A1, sellOfferIndex), ter(tecFROZEN));
1906 env.close();
1907
1908 env(trust(A2, limit, tfClearFreeze | tfClearDeepFreeze));
1909 env.close();
1910 }
1911
1912 // Testing A1 nft offer sell when A2 frozen by currency holder
1913 {
1914 auto const sellOfferIndex = createNFTSellOffer(env, A1, USD(10));
1915 env(trust(A2, limit, tfSetFreeze));
1916 env.close();
1917
1918 // test: A2 cannot send USD for NFT
1919 env(token::acceptSellOffer(A2, sellOfferIndex));
1920 env.close();
1921
1922 env(trust(A2, limit, tfClearFreeze));
1923 env.close();
1924 }
1925
1926 // Testing A1 nft offer sell when A2 deep frozen by currency holder
1927 if (features[featureDeepFreeze])
1928 {
1929 auto const sellOfferIndex = createNFTSellOffer(env, A1, USD(10));
1930 env(trust(A2, limit, tfSetFreeze | tfSetDeepFreeze));
1931 env.close();
1932
1933 // test: A2 cannot send USD for NFT
1934 env(token::acceptSellOffer(A2, sellOfferIndex),
1936 env.close();
1937
1938 env(trust(A2, limit, tfClearFreeze | tfClearDeepFreeze));
1939 env.close();
1940 }
1941
1942 // Testing brokered offer acceptance
1943 if (features[featureDeepFreeze] &&
1944 features[fixEnforceNFTokenTrustlineV2])
1945 {
1946 Account broker{"broker"};
1947 env.fund(XRP(10000), broker);
1948 env.close();
1949 env(trust(G1, broker["USD"](1000), tfSetFreeze | tfSetDeepFreeze));
1950 env.close();
1951
1952 uint256 const nftID{token::getNextID(env, A2, 0u, tfTransferable)};
1953 env(token::mint(A2, 0), txflags(tfTransferable));
1954 env.close();
1955
1956 uint256 const sellIdx = keylet::nftoffer(A2, env.seq(A2)).key;
1957 env(token::createOffer(A2, nftID, USD(10)), txflags(tfSellNFToken));
1958 env.close();
1959 auto const buyIdx = keylet::nftoffer(A1, env.seq(A1)).key;
1960 env(token::createOffer(A1, nftID, USD(11)), token::owner(A2));
1961 env.close();
1962
1963 env(token::brokerOffers(broker, buyIdx, sellIdx),
1964 token::brokerFee(USD(1)),
1965 ter(tecFROZEN));
1966 env.close();
1967 }
1968
1969 // Testing transfer fee
1970 if (features[featureDeepFreeze] &&
1971 features[fixEnforceNFTokenTrustlineV2])
1972 {
1973 Account minter{"minter"};
1974 env.fund(XRP(10000), minter);
1975 env.close();
1976 env(trust(G1, minter["USD"](1000)));
1977 env.close();
1978
1979 uint256 const nftID{
1980 token::getNextID(env, minter, 0u, tfTransferable, 1u)};
1981 env(token::mint(minter, 0),
1982 token::xferFee(1u),
1983 txflags(tfTransferable));
1984 env.close();
1985
1986 uint256 const minterSellIdx =
1987 keylet::nftoffer(minter, env.seq(minter)).key;
1988 env(token::createOffer(minter, nftID, drops(1)),
1989 txflags(tfSellNFToken));
1990 env.close();
1991 env(token::acceptSellOffer(A2, minterSellIdx));
1992 env.close();
1993
1994 uint256 const sellIdx = keylet::nftoffer(A2, env.seq(A2)).key;
1995 env(token::createOffer(A2, nftID, USD(100)),
1996 txflags(tfSellNFToken));
1997 env.close();
1998 env(trust(G1, minter["USD"](1000), tfSetFreeze | tfSetDeepFreeze));
1999 env.close();
2000 env(token::acceptSellOffer(A1, sellIdx), ter(tecFROZEN));
2001 env.close();
2002 }
2003 }
2004
2005 // Helper function to extract trustline flags from open ledger
2006 uint32_t
2008 test::jtx::Env& env,
2009 size_t expectedArraySize,
2010 size_t expectedArrayIndex,
2011 bool modified = true)
2012 {
2013 using namespace test::jtx;
2014 auto const affected =
2015 env.meta()->getJson(JsonOptions::none)[sfAffectedNodes.fieldName];
2016 if (!BEAST_EXPECT(checkArraySize(affected, expectedArraySize)))
2017 return 0;
2018
2019 if (modified)
2020 {
2021 return affected[expectedArrayIndex][sfModifiedNode.fieldName]
2022 [sfFinalFields.fieldName][jss::Flags]
2023 .asUInt();
2024 }
2025
2026 return affected[expectedArrayIndex][sfCreatedNode.fieldName]
2027 [sfNewFields.fieldName][jss::Flags]
2028 .asUInt();
2029 }
2030
2031 // Helper function that returns the index of the next check on account
2032 uint256
2033 getCheckIndex(AccountID const& account, std::uint32_t uSequence)
2034 {
2035 return keylet::check(account, uSequence).key;
2036 }
2037
2038 uint256
2040 test::jtx::Env& env,
2041 test::jtx::Account const& account,
2042 test::jtx::PrettyAmount const& currency)
2043 {
2044 using namespace test::jtx;
2045 uint256 const nftID{token::getNextID(env, account, 0u, tfTransferable)};
2046 env(token::mint(account, 0), txflags(tfTransferable));
2047 env.close();
2048
2049 uint256 const sellOfferIndex =
2050 keylet::nftoffer(account, env.seq(account)).key;
2051 env(token::createOffer(account, nftID, currency),
2052 txflags(tfSellNFToken));
2053 env.close();
2054
2055 return sellOfferIndex;
2056 }
2057
2058public:
2059 void
2060 run() override
2061 {
2062 auto testAll = [this](FeatureBitset features) {
2063 testRippleState(features);
2064 testDeepFreeze(features);
2065 testCreateFrozenTrustline(features);
2066 testSetAndClear(features);
2067 testGlobalFreeze(features);
2068 testNoFreeze(features);
2069 testOffersWhenFrozen(features);
2070 testOffersWhenDeepFrozen(features);
2072 testChecksWhenFrozen(features);
2073 testAMMWhenFreeze(features);
2074 testPathsWhenFrozen(features);
2075 testNFTOffersWhenFreeze(features);
2076 };
2077 using namespace test::jtx;
2078 auto const sa = testable_amendments();
2079 testAll(
2080 sa - featureDeepFreeze - featurePermissionedDEX -
2081 fixEnforceNFTokenTrustlineV2);
2082 testAll(sa - featurePermissionedDEX - fixEnforceNFTokenTrustlineV2);
2083 testAll(sa - featureDeepFreeze - featurePermissionedDEX);
2084 testAll(sa - featurePermissionedDEX);
2085 testAll(sa - fixEnforceNFTokenTrustlineV2);
2086 testAll(sa - featureDeepFreeze);
2087 testAll(sa);
2088 }
2089};
2090
2091BEAST_DEFINE_TESTSUITE(Freeze, app, ripple);
2092} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
void testOffersWhenDeepFrozen(FeatureBitset features)
uint256 createNFTSellOffer(test::jtx::Env &env, test::jtx::Account const &account, test::jtx::PrettyAmount const &currency)
uint32_t getTrustlineFlags(test::jtx::Env &env, size_t expectedArraySize, size_t expectedArrayIndex, bool modified=true)
void testGlobalFreeze(FeatureBitset features)
void testDeepFreeze(FeatureBitset features)
void testPaymentsWhenDeepFrozen(FeatureBitset features)
void testNoFreeze(FeatureBitset features)
void testNFTOffersWhenFreeze(FeatureBitset features)
void testAMMWhenFreeze(FeatureBitset features)
void testPathsWhenFrozen(FeatureBitset features)
void run() override
Runs the suite.
uint256 getCheckIndex(AccountID const &account, std::uint32_t uSequence)
void testCreateFrozenTrustline(FeatureBitset features)
void testRippleState(FeatureBitset features)
void testSetAndClear(FeatureBitset features)
void testOffersWhenFrozen(FeatureBitset features)
void testChecksWhenFrozen(FeatureBitset features)
A currency issued by an account.
Definition Issue.h:14
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:102
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:250
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:103
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
Definition Env.cpp:485
Add a path.
Definition paths.h:39
T clear(T... args)
T end(T... args)
T find(T... args)
T insert(T... args)
Keylet nftoffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:408
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Definition Indexes.cpp:317
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
AccountID const & noAccount()
A placeholder for empty accounts.
constexpr std::uint32_t asfGlobalFreeze
Definition TxFlags.h:64
constexpr std::uint32_t tfSetDeepFreeze
Definition TxFlags.h:101
constexpr std::uint32_t const tfSellNFToken
Definition TxFlags.h:211
@ lsfHighDeepFreeze
@ lsfLowDeepFreeze
constexpr std::uint32_t asfNoFreeze
Definition TxFlags.h:63
constexpr std::uint32_t tfFillOrKill
Definition TxFlags.h:81
constexpr std::uint32_t tfPassive
Definition TxFlags.h:79
constexpr std::uint32_t tfClearFreeze
Definition TxFlags.h:100
@ tecUNFUNDED_OFFER
Definition TER.h:266
@ tecFROZEN
Definition TER.h:285
@ tecKILLED
Definition TER.h:298
@ tecINSUFFICIENT_FUNDS
Definition TER.h:307
@ tecNO_PERMISSION
Definition TER.h:287
@ tecPATH_PARTIAL
Definition TER.h:264
@ tecPATH_DRY
Definition TER.h:276
constexpr std::uint32_t tfNoRippleDirect
Definition TxFlags.h:88
constexpr std::uint32_t tfClearDeepFreeze
Definition TxFlags.h:102
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
constexpr std::uint32_t tfSetFreeze
Definition TxFlags.h:99
constexpr std::uint32_t const tfTransferable
Definition TxFlags.h:123
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition UintTypes.cpp:65
@ temINVALID_FLAG
Definition TER.h:92
uint256 key
Definition Keylet.h:21
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...