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