xrpld
Loading...
Searching...
No Matches
EscrowSmart_test.cpp
1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/TestHelpers.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/envconfig.h>
6#include <test/jtx/escrow.h>
7#include <test/jtx/fee.h>
8#include <test/jtx/ter.h>
9
10#include <xrpld/core/Config.h>
11
12#include <xrpl/basics/strHex.h>
13#include <xrpl/beast/unit_test/suite.h>
14#include <xrpl/config/Constants.h>
15#include <xrpl/core/StartUpType.h>
16#include <xrpl/protocol/Feature.h>
17#include <xrpl/protocol/Fees.h>
18#include <xrpl/protocol/Indexes.h>
19#include <xrpl/protocol/Protocol.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/SeqProxy.h>
22#include <xrpl/protocol/TER.h>
23#include <xrpl/protocol/XRPAmount.h>
24
25#include <cstddef>
26#include <cstdint>
27#include <memory>
28#include <string>
29
30namespace xrpl::test {
31
47{
48 // A blob of `bytes` bytes, as hex. Opens with the WASM preamble - "\0asm"
49 // and version 1 - so a reader can see what the field is meant to carry,
50 // but nothing in this build parses it.
51 static std::string
53 {
54 static std::string const kPreamble = "0061736D01000000";
55 std::string hex = kPreamble;
56 hex.append((bytes * 2) - kPreamble.size(), 'A');
57 return hex;
58 }
59
60 // What EscrowCreate charges for `bytecodeHex`: ten base fees, plus five
61 // drops per byte.
62 static XRPAmount
63 createFeeFor(jtx::Env const& env, std::string const& bytecodeHex)
64 {
65 return env.current()->fees().base * 10 + bytecodeHex.size() / 2 * 5;
66 }
67
68 // A validator's config that votes for `value` on the fee setting `key`.
71 {
72 auto cfg = jtx::envconfig(jtx::validator, "");
73 cfg->section(Sections::kVoting).set(key, std::to_string(value));
74 return cfg;
75 }
76
77 // Close past the flag ledger, so the vote lands in FeeSettings.
78 static void
80 {
81 for (auto i = env.current()->seq(); i <= 257; ++i)
82 env.close();
83 }
84
85 // What EscrowFinish charges for `gas`: the gas cost rounded up to the drop.
86 static XRPAmount
88 {
89 return env.current()->fees().base +
90 ((gas * env.current()->fees().gasPrice) + microDropsPerDrop - 1) / microDropsPerDrop;
91 }
92
93 void
95 {
96 testcase("EscrowCreate preflight");
97
98 using namespace jtx;
99 using namespace std::chrono;
100
101 Account const alice{"alice"};
102 Account const carol{"carol"};
103
104 auto const bytecode = bytecodeOfSize(64);
105
106 {
107 // featureSmartEscrow disabled
108 Env env(*this, features - featureSmartEscrow);
109 env.fund(XRP(5000), alice, carol);
110 XRPAmount const txnFees = env.current()->fees().base + 1000;
111 auto const escrowCreate = escrow::create(alice, carol, XRP(1000));
112 env(escrowCreate,
113 escrow::Bytecode(bytecode),
114 escrow::kCancelTime(env.now() + 100s),
115 Fee(txnFees),
117 env.close();
118
119 env(escrowCreate,
120 escrow::Bytecode(bytecode),
121 escrow::kCancelTime(env.now() + 100s),
122 escrow::Data("00112233"),
123 Fee(txnFees),
125 env.close();
126
127 env(escrowCreate,
128 escrow::Data("00112233"),
129 escrow::kFinishTime(env.now() + 100s),
130 Fee(txnFees),
132 env.close();
133 }
134
135 {
136 // Bytecode > max length
137 Env env(*this, votingFor(Keys::kBytecodeSizeLimit, 10), features); // 10 bytes
139 XRPAmount const txnFees = env.current()->fees().base + 1000;
140 env.fund(XRP(5000), alice, carol);
141
142 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
143
144 // 11-byte string
145 std::string const longBytecode = "00112233445566778899AA";
146 env(escrowCreate,
147 escrow::Bytecode(longBytecode),
148 escrow::kCancelTime(env.now() + 100s),
149 Fee(txnFees),
151 env.close();
152 }
153
154 {
155 // gas limit set to 0
156 Env env(*this, votingFor(Keys::kGasLimit, 0), features); // WASM runtime disabled
158 XRPAmount const txnFees = env.current()->fees().base + 1000;
159 env.fund(XRP(5000), alice, carol);
160
161 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
162
163 env(escrowCreate,
164 escrow::Bytecode(bytecode),
165 escrow::kCancelTime(env.now() + 100s),
166 Fee(txnFees),
168 env.close();
169 }
170
171 {
172 // size limit set to 0
173 Env env(
174 *this, votingFor(Keys::kBytecodeSizeLimit, 0), features); // WASM upload disabled
176 XRPAmount const txnFees = env.current()->fees().base + 1000;
177 env.fund(XRP(5000), alice, carol);
178
179 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
180
181 // 1-byte string
182 env(escrowCreate,
183 escrow::Bytecode("AA"),
184 escrow::kCancelTime(env.now() + 100s),
185 Fee(txnFees),
187 env.close();
188
189 env(escrowCreate,
190 escrow::Bytecode(bytecode),
191 escrow::kCancelTime(env.now() + 100s),
192 Fee(txnFees),
194 env.close();
195 }
196
197 {
198 // Data without Bytecode
199 Env env(*this, features);
200 XRPAmount const txnFees = env.current()->fees().base + 100000;
201 env.fund(XRP(5000), alice, carol);
202
203 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
204
205 std::string const data(4, 'A');
206 env(escrowCreate,
208 escrow::kFinishTime(env.now() + 100s),
209 Fee(txnFees),
211 env.close();
212 }
213
214 {
215 // Data > max length
216 Env env(*this, features);
217 XRPAmount const txnFees = env.current()->fees().base + 100000;
218 env.fund(XRP(5000), alice, carol);
219
220 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
221
222 // string of length (kMaxWasmDataLength + 1) * 2
223 std::string const longData((kMaxWasmDataLength + 1) * 2, 'B');
224 env(escrowCreate,
225 escrow::Data(longData),
226 escrow::Bytecode(bytecode),
227 escrow::kCancelTime(env.now() + 100s),
228 Fee(txnFees),
230 env.close();
231 }
232
233 // Bytecode joins FinishAfter and Condition as a way to say how the
234 // escrow completes, but it always needs a CancelAfter: nothing else
235 // can free the funds if the contract never accepts.
236 Env env(
237 *this,
239 cfg->startUp = StartUpType::Fresh;
240 return cfg;
241 }),
242 features);
243 env.fund(XRP(5000), alice, carol);
244
245 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
246 XRPAmount const txnFees = createFeeFor(env, bytecode);
247
248 // Success situations
249 {
250 // Bytecode + CancelAfter
251 env(escrowCreate,
252 escrow::Bytecode(bytecode),
253 escrow::kCancelTime(env.now() + 20s),
254 Fee(txnFees));
255 env.close();
256 }
257 {
258 // Bytecode + Condition + CancelAfter
259 env(escrowCreate,
260 escrow::Bytecode(bytecode),
261 escrow::kCancelTime(env.now() + 30s),
263 Fee(txnFees));
264 env.close();
265 }
266 {
267 // Bytecode + FinishAfter + CancelAfter
268 env(escrowCreate,
269 escrow::Bytecode(bytecode),
270 escrow::kCancelTime(env.now() + 40s),
271 escrow::kFinishTime(env.now() + 2s),
272 Fee(txnFees));
273 env.close();
274 }
275 {
276 // Bytecode + Data + CancelAfter
277 env(escrowCreate,
278 escrow::Bytecode(bytecode),
279 escrow::Data("00112233"),
280 escrow::kCancelTime(env.now() + 50s),
281 Fee(txnFees));
282 env.close();
283 }
284
285 // Failure situations (i.e. all other combinations)
286 {
287 // only Bytecode
288 env(escrowCreate, escrow::Bytecode(bytecode), Fee(txnFees), Ter(temBAD_EXPIRATION));
289 env.close();
290 }
291 {
292 // Bytecode + FinishAfter
293 env(escrowCreate,
294 escrow::Bytecode(bytecode),
295 escrow::kFinishTime(env.now() + 2s),
296 Fee(txnFees),
298 env.close();
299 }
300 {
301 // Bytecode + Condition
302 env(escrowCreate,
303 escrow::Bytecode(bytecode),
305 Fee(txnFees),
307 env.close();
308 }
309 {
310 // Bytecode 0 length
311 env(escrowCreate,
313 escrow::kCancelTime(env.now() + 60s),
314 Fee(txnFees),
316 env.close();
317 }
318 {
319 // Not enough fees
320 env(escrowCreate,
321 escrow::Bytecode(bytecode),
322 escrow::kCancelTime(env.now() + 70s),
323 Fee(txnFees - 1),
325 env.close();
326 }
327 }
328
329 void
331 {
332 testcase("EscrowCreate fee and reserve");
333
334 using namespace jtx;
335 using namespace std::chrono;
336
337 Account const alice{"alice"};
338 Account const carol{"carol"};
339
340 {
341 // The fee scales with the bytecode: ten base fees plus five drops
342 // per byte, and a drop short of it is refused.
343 Env env(*this, features);
344 env.fund(XRP(5000), alice, carol);
345 env.close();
346
347 auto const bytecode = bytecodeOfSize(1'000);
348 auto const escrowCreate = escrow::create(alice, carol, XRP(500));
349 auto const fee = createFeeFor(env, bytecode);
350 BEAST_EXPECT(fee == env.current()->fees().base * 10 + 5'000);
351
352 env(escrowCreate,
353 escrow::Bytecode(bytecode),
354 escrow::kCancelTime(env.now() + 100s),
355 Fee(fee - 1),
357 env.close();
358
359 auto const seq = env.seq(alice);
360 env(escrowCreate,
361 escrow::Bytecode(bytecode),
362 escrow::Data("00112233"),
363 escrow::kCancelTime(env.now() + 100s),
364 Fee(fee));
365 env.close();
366
367 // The ledger entry carries both fields.
368 auto const sle = env.le(keylet::escrow(alice, SeqProxy::rawSequence(seq)));
369 if (BEAST_EXPECT(sle))
370 {
371 BEAST_EXPECT(sle->isFieldPresent(sfBytecode));
372 BEAST_EXPECT(strHex(sle->getFieldVL(sfBytecode)) == bytecode);
373 BEAST_EXPECT(strHex(sle->getFieldVL(sfData)) == "00112233");
374 }
375 }
376
377 {
378 // The reserve is one owner increment per started 500 bytes of
379 // bytecode.
380 Env env(*this, features);
381 env.fund(XRP(5000), alice, carol);
382 env.close();
383
384 std::uint32_t expectedOwnerCount = 0;
385 for (auto const size : {
386 std::size_t{64},
387 std::size_t{500},
388 std::size_t{501},
389 std::size_t{1'000},
390 std::size_t{1'001},
391 })
392 {
393 auto const bytecode = bytecodeOfSize(size);
394 env(escrow::create(alice, carol, XRP(100)),
395 escrow::Bytecode(bytecode),
396 escrow::kCancelTime(env.now() + 1000s),
397 Fee(createFeeFor(env, bytecode)));
398 env.close();
399
400 expectedOwnerCount += (size + 499) / 500;
401 BEAST_EXPECTS(
402 env.ownerCount(alice) == expectedOwnerCount,
403 std::to_string(size) + " bytes: " + std::to_string(env.ownerCount(alice)));
404 }
405 }
406
407 {
408 // A bytecode escrow the owner cannot reserve is refused, where the
409 // same escrow without bytecode would have been accepted.
410 Env env(*this, features);
411 // Base 200 XRP + 50 XRP per owner object, from the unit-test
412 // config. Enough for one owner object, not for two.
413 env.fund(XRP(300), alice, carol);
414 env.close();
415
416 auto const bytecode = bytecodeOfSize(1'000);
417 env(escrow::create(alice, carol, XRP(20)),
418 escrow::Bytecode(bytecode),
419 escrow::kCancelTime(env.now() + 100s),
420 Fee(createFeeFor(env, bytecode)),
422 env.close();
423 BEAST_EXPECT(env.ownerCount(alice) == 0);
424
425 // The same escrow without bytecode costs one increment and fits.
426 env(escrow::create(alice, carol, XRP(20)),
427 escrow::kFinishTime(env.now() + 10s),
428 escrow::kCancelTime(env.now() + 100s));
429 env.close();
430 BEAST_EXPECT(env.ownerCount(alice) == 1);
431 }
432
433 {
434 // After the lock, an XRP escrow's owner must still hold the
435 // reserve the bytecode costs, not the single increment a plain
436 // escrow costs.
437 Env env(*this, features);
438 Account const dave{"dave"};
439 Account const erin{"erin"};
440 env.fund(XRP(5000), carol);
441 env.close();
442
443 auto const bytecode = bytecodeOfSize(600); // two increments
444 auto const fee = createFeeFor(env, bytecode);
445 auto const amount = XRP(1'000);
446 auto const fees = env.current()->fees();
447
448 // One increment short after the lock.
449 env.fund(
450 STAmount{fees.accountReserve(1, 1) + amount.value().xrp() + fee}, noripple(dave));
451 // Exactly enough after the lock.
452 env.fund(
453 STAmount{fees.accountReserve(2, 1) + amount.value().xrp() + fee}, noripple(erin));
454 env.close();
455
456 env(escrow::create(dave, carol, amount),
457 escrow::Bytecode(bytecode),
458 escrow::kCancelTime(env.now() + 100s),
459 Fee(fee),
461 env(escrow::create(erin, carol, amount),
462 escrow::Bytecode(bytecode),
463 escrow::kCancelTime(env.now() + 100s),
464 Fee(fee));
465 env.close();
466 BEAST_EXPECT(env.ownerCount(dave) == 0);
467 BEAST_EXPECT(env.ownerCount(erin) == 2);
468 }
469 }
470
471 void
473 {
474 testcase("EscrowFinish preflight");
475
476 using namespace jtx;
477 using namespace std::chrono;
478
479 Account const alice{"alice"};
480 Account const carol{"carol"};
481
482 {
483 // featureSmartEscrow disabled
484 Env env(*this, features - featureSmartEscrow);
485 env.fund(XRP(5000), alice, carol);
486 env(escrow::finish(carol, alice, 1),
487 Fee(env.current()->fees().base + 1000),
488 escrow::Gas(4),
490 env.close();
491 }
492
493 {
494 // Gas > gas limit
495 Env env(*this, votingFor(Keys::kGasLimit, 1'000), features); // in gas
496 env.fund(XRP(5000), alice, carol);
497 env.close();
498
499 // Gas above the voted limit is checked against the escrow it
500 // would run, so there has to be one.
501 auto const bytecode = bytecodeOfSize(64);
502 auto const seq = env.seq(alice);
503 env(escrow::create(alice, carol, XRP(500)),
504 escrow::Bytecode(bytecode),
505 escrow::kCancelTime(env.now() + 100'000s),
506 Fee(createFeeFor(env, bytecode)));
508
509 auto const gas = 1'001;
510 env(escrow::finish(carol, alice, seq),
511 Fee(finishFeeFor(env, gas)),
512 escrow::Gas(gas),
514 }
515
516 {
517 // Gas of 0
518 Env env(*this, features);
519 env.fund(XRP(5000), alice, carol);
520 env.close();
521 env(escrow::finish(carol, alice, 1),
522 Fee(env.current()->fees().base + 1000),
523 escrow::Gas(0),
525 }
526
527 {
528 // Gas above the protocol ceiling, refused before any view is read
529 Env env(*this, features);
530 env.fund(XRP(5000), alice, carol);
531 env.close();
532 env(escrow::finish(carol, alice, 1),
533 Fee(env.current()->fees().base + 1000),
536 }
537
538 {
539 // WASM compute disabled after the escrow was created.
540 Env env(*this, votingFor(Keys::kGasLimit, 0), features);
541 env.fund(XRP(5000), alice, carol);
542 env.close();
543
544 auto const bytecode = bytecodeOfSize(64);
545 auto const seq = env.seq(alice);
546 env(escrow::create(alice, carol, XRP(500)),
547 escrow::Bytecode(bytecode),
548 escrow::kCancelTime(env.now() + 100'000s),
549 Fee(createFeeFor(env, bytecode)));
551
552 auto const gas = 1'000;
553 env(escrow::finish(carol, alice, seq),
554 escrow::Gas(gas),
555 Fee(finishFeeFor(env, gas)),
557 }
558 }
559
560 void
562 {
563 testcase("EscrowFinish Bytecode and Gas must agree");
564
565 using namespace jtx;
566 using namespace std::chrono;
567
568 Account const alice{"alice"};
569 Account const carol{"carol"};
570
571 Env env(*this, features);
572
573 // Run past the flag ledger so that a Fee change vote occurs and
574 // updates FeeSettings. (It also activates all supported amendments.)
575 for (auto i = env.current()->seq(); i <= 257; ++i)
576 env.close();
577
578 env.fund(XRP(5000), alice, carol);
579
580 auto const bytecode = bytecodeOfSize(64);
581 auto const seq = env.seq(alice);
582 env(escrow::create(alice, carol, XRP(500)),
583 escrow::Bytecode(bytecode),
584 escrow::kCancelTime(env.now() + 100s),
585 Fee(createFeeFor(env, bytecode)));
586 env.close();
587
588 {
589 // Bytecode on the escrow, no Gas on the finish
590 env(escrow::finish(carol, alice, seq), Ter(tefBYTECODE_NOT_INCLUDED));
591 }
592
593 {
594 // Gas on the finish, no Bytecode on the escrow
595 auto const plainSeq = env.seq(alice);
596 env(escrow::create(alice, carol, XRP(500)),
597 escrow::kFinishTime(env.now() + 10s),
598 escrow::kCancelTime(env.now() + 100s));
599 env.close();
600
601 auto const gas = 100;
602 env(escrow::finish(carol, alice, plainSeq),
603 Fee(finishFeeFor(env, gas)),
604 escrow::Gas(gas),
606 }
607 }
608
609 void
611 {
612 testcase("EscrowFinish fee");
613
614 using namespace jtx;
615 using namespace std::chrono;
616
617 Account const alice{"alice"};
618 Account const carol{"carol"};
619
620 Env env(
621 *this,
623 cfg->fees.gasPrice = 1'000'000; // 1 drop per gas
624 return cfg;
625 }),
626 features);
627 // Run past the flag ledger so that a Fee change vote occurs and
628 // updates FeeSettings. (It also activates all supported amendments.)
629 for (auto i = env.current()->seq(); i <= 257; ++i)
630 env.close();
631
632 env.fund(XRP(5000), alice, carol);
633
634 auto const bytecode = bytecodeOfSize(64);
635 auto const seq = env.seq(alice);
636 env(escrow::create(alice, carol, XRP(1000)),
637 escrow::Bytecode(bytecode),
638 escrow::kCancelTime(env.now() + 100s),
639 Fee(createFeeFor(env, bytecode)));
640 env.close();
641
642 // A large gas allowance costs more than the allowance itself, and does
643 // not wrap.
644 auto const gas = 996'433;
645 auto const fee = finishFeeFor(env, gas);
646 BEAST_EXPECT(fee.drops() > gas);
647 // At one drop per gas the cost divides evenly, so no drop is added.
648 BEAST_EXPECT(fee == env.current()->fees().base + gas);
649
650 // Intentional low value to test overflow handling
651 env(escrow::finish(carol, alice, seq),
652 Fee(drops(30)),
653 escrow::Gas(gas),
655
656 env(escrow::finish(carol, alice, seq), Fee(fee - 1), escrow::Gas(gas), Ter(telINSUF_FEE_P));
657
658 // TODO(SmartEscrow): tesSUCCESS once the WASM engine lands. Until then
659 // the fee is charged and the run reports that it could not happen.
660 env(escrow::finish(carol, alice, seq),
661 Fee(fee),
662 escrow::Gas(gas),
664
665 {
666 // A gas cost of a fraction of a drop rounds up to a whole drop:
667 // two gas at one micro-drop each costs one drop, not zero, and not
668 // one drop per gas.
669 Env env(*this, votingFor(Keys::kGasPrice, 1), features);
670 env.fund(XRP(5000), alice, carol);
671 env.close();
672
673 auto const seq = env.seq(alice);
674 env(escrow::create(alice, carol, XRP(1000)),
675 escrow::Bytecode(bytecode),
676 escrow::kCancelTime(env.now() + 100'000s),
677 Fee(createFeeFor(env, bytecode)));
679 BEAST_EXPECT(env.current()->fees().gasPrice == 1);
680
681 auto const base = env.current()->fees().base;
682 env(escrow::finish(carol, alice, seq), Fee(base), escrow::Gas(2), Ter(telINSUF_FEE_P));
683 env(escrow::finish(carol, alice, seq),
684 Fee(base + 1),
685 escrow::Gas(2),
687 }
688 }
689
690 void
692 {
693 testcase("EscrowFinish has no WASM engine");
694
695 using namespace jtx;
696 using namespace std::chrono;
697
698 Account const alice{"alice"};
699 Account const carol{"carol"};
700
701 Env env(*this, features);
702 env.fund(XRP(5000), alice, carol);
703 env.close();
704
705 auto const bytecode = bytecodeOfSize(1'000);
706 auto const seq = env.seq(alice);
707 env(escrow::create(alice, carol, XRP(500)),
708 escrow::Bytecode(bytecode),
709 escrow::kCancelTime(env.now() + 20s),
710 Fee(createFeeFor(env, bytecode)));
711 env.close();
712 BEAST_EXPECT(env.ownerCount(alice) == 2);
713
714 // TODO(SmartEscrow): the contract decides this once the WASM engine
715 // lands - tesSUCCESS on accept, tecBYTECODE_REJECTED on reject.
716 auto const gas = 1'000;
717 env(escrow::finish(carol, alice, seq),
718 Fee(finishFeeFor(env, gas)),
719 escrow::Gas(gas),
721 env.close();
722
723 // The escrow and its reserve survive.
724 BEAST_EXPECT(env.le(keylet::escrow(alice, SeqProxy::rawSequence(seq))));
725 BEAST_EXPECT(env.ownerCount(alice) == 2);
726
727 // Cancelling returns the whole reserve, not just one increment.
728 env.close(30s);
729 env(escrow::cancel(carol, alice, seq));
730 env.close();
731 BEAST_EXPECT(!env.le(keylet::escrow(alice, SeqProxy::rawSequence(seq))));
732 BEAST_EXPECT(env.ownerCount(alice) == 0);
733 }
734
735 void
737 {
738 testcase("EscrowFinish releases the reserve");
739
740 using namespace jtx;
741 using namespace std::chrono;
742
743 Account const alice{"alice"};
744 Account const carol{"carol"};
745
746 // Without featureSponsor and fixCleanup3_4_0, the reserve is released
747 // after delivery rather than before.
748 Env env(*this, features - featureSponsor - fixCleanup3_4_0);
749 env.fund(XRP(5000), alice, carol);
750 env.close();
751
752 auto const seq = env.seq(alice);
753 env(escrow::create(alice, carol, XRP(500)), escrow::kFinishTime(env.now() + 1s));
754 env.close();
755 BEAST_EXPECT(env.ownerCount(alice) == 1);
756
757 env(escrow::finish(carol, alice, seq));
758 env.close();
759 BEAST_EXPECT(!env.le(keylet::escrow(alice, SeqProxy::rawSequence(seq))));
760 BEAST_EXPECT(env.ownerCount(alice) == 0);
761 }
762
763 void
765 {
766 testCreatePreflight(features);
767 testCreateFeeAndReserve(features);
768 testFinishPreflight(features);
770 testFinishFee(features);
771 testFinishWithoutEngine(features);
773 }
774
775public:
776 void
777 run() override
778 {
779 using namespace test::jtx;
781 testWithFeats(all);
782 }
783};
784
785BEAST_DEFINE_TESTSUITE(EscrowSmart, app, xrpl);
786
787} // namespace xrpl::test
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
A transaction testing environment.
Definition Env.h:161
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
Definition Env.cpp:266
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:302
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
NetClock::time_point now()
Returns the current network time.
Definition Env.h:326
Set the fee on a JTx.
Definition fee.h:20
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
T data(T... args)
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Definition Indexes.cpp:430
HexBlobField< sfData > Data
Definition escrow.h:136
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition escrow.cpp:24
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition escrow.cpp:48
auto const kCondition
Definition escrow.h:100
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
Definition escrow.h:98
auto const kFinishTime
Set the "FinishAfter" time tag on a JTx.
Definition escrow.h:93
HexBlobField< sfBytecode > Bytecode
Definition escrow.h:135
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition escrow.cpp:36
std::array< std::uint8_t, 39 > const kCb1
Definition escrow.h:60
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
FeatureBitset testableAmendments()
Definition Env.h:92
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
Definition Env.h:86
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:53
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr std::uint32_t microDropsPerDrop
@ telINSUF_FEE_P
Definition TER.h:43
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
constexpr std::size_t kMaxWasmDataLength
Maximum length of a Data field in Escrow object that can be updated by WASM code.
Definition Protocol.h:404
@ tefTEMP_DISABLED
Definition TER.h:186
@ tefEXCEEDS_LIMIT
Definition TER.h:187
@ tefNO_BYTECODE
Definition TER.h:184
@ tefBYTECODE_NOT_INCLUDED
Definition TER.h:185
@ temBAD_EXPIRATION
Definition TER.h:79
@ temBAD_LIMIT
Definition TER.h:82
@ temMALFORMED
Definition TER.h:75
@ temDISABLED
Definition TER.h:102
@ tecFAILED_PROCESSING
Definition TER.h:297
@ tecINSUFFICIENT_RESERVE
Definition TER.h:318
@ tecUNFUNDED
Definition TER.h:306
constexpr std::uint32_t kMaxGasLimit
Hard protocol bounds on the Feature Extension fee settings.
T size(T... args)
static constexpr auto kGasLimit
Definition Constants.h:112
static constexpr auto kBytecodeSizeLimit
Definition Constants.h:97
static constexpr auto kGasPrice
Definition Constants.h:113
static constexpr auto kVoting
Definition Constants.h:78
Smart Escrow's Bytecode, Data and Gas fields.
void testCreateFeeAndReserve(FeatureBitset features)
void testFinishWithoutEngine(FeatureBitset features)
void testFinishReleasesReserve(FeatureBitset features)
static std::string bytecodeOfSize(std::size_t bytes)
static XRPAmount createFeeFor(jtx::Env const &env, std::string const &bytecodeHex)
void testFinishPreflight(FeatureBitset features)
static void closePastFlagLedger(jtx::Env &env)
void testFinishBytecodePairing(FeatureBitset features)
void run() override
Runs the suite.
static std::unique_ptr< Config > votingFor(std::string const &key, std::uint32_t value)
void testCreatePreflight(FeatureBitset features)
static XRPAmount finishFeeFor(jtx::Env const &env, std::uint64_t gas)
void testFinishFee(FeatureBitset features)
void testWithFeats(FeatureBitset features)
T to_string(T... args)