xrpld
Loading...
Searching...
No Matches
TransactionProposalReservedTicket_test.cpp
1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/TestHelpers.h>
4#include <test/jtx/acctdelete.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/batch.h>
7#include <test/jtx/envconfig.h>
8#include <test/jtx/fee.h>
9#include <test/jtx/flags.h>
10#include <test/jtx/multisign.h>
11#include <test/jtx/noop.h>
12#include <test/jtx/pay.h>
13#include <test/jtx/proposal.h>
14#include <test/jtx/regkey.h>
15#include <test/jtx/sig.h>
16#include <test/jtx/sponsor.h>
17#include <test/jtx/ter.h>
18#include <test/jtx/ticket.h>
19
20#include <xrpld/app/misc/TxQ.h>
21#include <xrpld/core/Config.h>
22
23#include <xrpl/basics/Blob.h>
24#include <xrpl/basics/Slice.h>
25#include <xrpl/basics/base_uint.h>
26#include <xrpl/beast/unit_test/suite.h>
27#include <xrpl/beast/utility/Journal.h>
28#include <xrpl/config/Constants.h>
29#include <xrpl/json/json_value.h>
30#include <xrpl/json/to_string.h>
31#include <xrpl/ledger/ApplyView.h>
32#include <xrpl/ledger/OpenView.h>
33#include <xrpl/ledger/helpers/ProposalHelpers.h>
34#include <xrpl/protocol/Feature.h>
35#include <xrpl/protocol/Indexes.h>
36#include <xrpl/protocol/SField.h>
37#include <xrpl/protocol/STObject.h>
38#include <xrpl/protocol/STTx.h>
39#include <xrpl/protocol/SeqProxy.h>
40#include <xrpl/protocol/Serializer.h>
41#include <xrpl/protocol/TER.h>
42#include <xrpl/protocol/TxFlags.h>
43#include <xrpl/protocol/jss.h>
44#include <xrpl/tx/apply.h>
45
46#include <cstdint>
47#include <memory>
48#include <string>
49#include <utility>
50
51namespace xrpl::test {
52
53// While a TransactionProposal exists, the Ticket it is keyed to is reserved
54// (On-Chain Cosigner spec §4.2.1): a transaction may consume it only if its payload matches
55// the stored ProposedTransaction, so unrelated target-account activity cannot
56// invalidate the proposal while signatures are being collected. When the
57// matching transaction does consume the ticket, the ledger deletes the
58// now-stale proposal and releases the reserve it holds against its Owner
59// (On-Chain Cosigner spec §4.5).
61{
62 // Create a live proposal owned by proposer holding the given payload.
63 static void
64 makeProposal(jtx::Env& env, jtx::Account const& proposer, json::Value const& payload)
65 {
66 using namespace jtx;
67 using namespace std::chrono_literals;
68
69 Account const target = env.lookup(payload[jss::Account].asString());
70 if (proposer.id() != target.id() && !env.le(keylet::signerList(target.id())))
71 proposal::authorizeProposer(env, target, proposer);
72
73 env(proposal::create(proposer, payload, proposal::expiration(env, 1000s)));
74 env.close();
75 }
76
77 // Rebuild a transaction from a copy of it whose fields have been edited.
78 // Editing an STTx in place would leave getTransactionID — and the
79 // signature verdict the HashRouter caches under it — describing the
80 // transaction before the edit. Going through the bytes rather than
81 // STTx{STObject&&} is what makes this work on a copy of an already
82 // templated transaction: applyTemplate refuses a defaulted field that is
83 // explicitly present, which such a copy carries, and serializing omits it.
85 rebuilt(STObject const& tx)
86 {
87 Serializer s;
88 tx.add(s);
90 }
91
92 // A transaction that is not the proposed transaction cannot consume the
93 // reserved ticket: it fails with terTICKET_RESERVED and neither the
94 // ticket nor the proposal is touched. The target's sequence, and its
95 // other tickets, stay freely spendable.
96 void
98 {
99 testcase("unrelated spend of a reserved ticket is blocked");
100
101 using namespace jtx;
102 using namespace std::chrono_literals;
103
104 Env env{*this, features};
105
106 Account const alice{"alice"}; // the proposer
107 Account const target{"target"}; // the account the proposal is for
108 Account const bob{"bob"};
109 env.fund(XRP(10000), alice, target, bob);
110 env.close();
111
112 std::uint32_t const ticketSeq = proposal::createTicket(env, target, 2);
113 json::Value const payload =
114 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
115 makeProposal(env, alice, payload);
116
117 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
118 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
119 BEAST_EXPECT(ownerCount(env, target) == 3);
120
121 // A different transaction type.
122 env(noop(target), ticket::Use(ticketSeq), Ter(terTICKET_RESERVED));
123 // The proposed transaction with one payload field off: the amount,
124 // the destination, or the fee. Signature fields are the only
125 // latitude a submitter has (On-Chain Cosigner spec §4.2.1).
126 env(pay(target, bob, XRP(2)), ticket::Use(ticketSeq), Ter(terTICKET_RESERVED));
127 env(pay(target, alice, XRP(1)), ticket::Use(ticketSeq), Ter(terTICKET_RESERVED));
128 env(pay(target, bob, XRP(1)),
129 ticket::Use(ticketSeq),
130 Fee(env.current()->fees().base * 2),
132 env.close();
133
134 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
135 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
136 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
137 BEAST_EXPECT(ownerCount(env, target) == 3);
138
139 // The reservation binds one ticket, not the account: its sequence
140 // and its other tickets spend freely, and the proposal survives.
141 env(noop(target));
142 env(noop(target), ticket::Use(ticketSeq + 1));
143 env.close();
144
145 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
146 BEAST_EXPECT(ownerCount(env, target) == 2);
147 }
148
149 // The proposal's own transaction consumes the reserved ticket through
150 // the ordinary submission path (On-Chain Cosigner spec §6.5). How it is signed is
151 // irrelevant to the match — signature fields are excluded — and applying
152 // it auto-deletes the proposal and refunds the Owner (On-Chain Cosigner spec §4.5).
153 void
155 {
156 testcase("matching payload consumes the ticket and cleans up");
157
158 using namespace jtx;
159 using namespace std::chrono_literals;
160
161 Env env{*this, features};
162
163 Account const alice{"alice"};
164 Account const target{"target"};
165 Account const bob{"bob"};
166 Account const carol{"carol"};
167 env.fund(XRP(10000), alice, target, bob, carol);
168 env.close();
169
170 // Single-signed with the target's own key: the stored payload has an
171 // empty SigningPubKey, the submission a populated one plus a
172 // TxnSignature. Both are signature fields, so they still match.
173 {
174 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
176 env, alice, proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq));
177
178 auto const bobBefore = env.balance(bob);
179 env(pay(target, bob, XRP(1)), ticket::Use(ticketSeq));
180 env.close();
181
182 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
183 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
184 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
185 BEAST_EXPECT(ownerCount(env, alice) == 0);
186 BEAST_EXPECT(ownerCount(env, target) == 1);
187 }
188
189 // Multi-signed under the target's SignerList: the Signers array the
190 // submission carries is a signature field too. The payload's Fee was
191 // fixed at creation, so a proposer expecting multi-signed submission
192 // must budget for the signatures then (On-Chain Cosigner spec §4.2.1).
193 {
194 env(signers(target, 2, {{alice, 1}, {bob, 1}, {carol, 1}}));
195 env.close();
196
197 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
198 auto const msigFee = env.current()->fees().base * 3;
199 json::Value proposedTx = pay(target, bob, XRP(1));
200 proposedTx[jss::Fee] = std::to_string(msigFee.drops());
201 makeProposal(env, alice, proposal::unsignedPayload(env, proposedTx, ticketSeq));
202
203 auto const bobBefore = env.balance(bob);
204 env(pay(target, bob, XRP(1)), ticket::Use(ticketSeq), Msig(bob, carol), Fee(msigFee));
205 env.close();
206
207 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
208 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
209 BEAST_EXPECT(ownerCount(env, alice) == 0);
210 // The consumed ticket's count is released; the SignerList set up
211 // above remains the target's only owned object.
212 BEAST_EXPECT(ownerCount(env, target) == 1);
213 }
214 }
215
216 // Cancelling the proposal removes the reservation. terTICKET_RESERVED is
217 // a retry: the very transaction the reservation blocked is held and
218 // applies on its own once a Cancel frees the ticket.
219 void
221 {
222 testcase("cancelling the proposal frees the ticket");
223
224 using namespace jtx;
225 using namespace std::chrono_literals;
226
227 Env env{*this, features};
228
229 Account const alice{"alice"};
230 Account const target{"target"};
231 Account const bob{"bob"};
232 env.fund(XRP(10000), alice, target, bob);
233 env.close();
234
235 // After a Cancel, the ticket spends freely.
236 {
237 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
239 env, alice, proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq));
240
241 env(proposal::cancel(alice, keylet::txProposal(target.id(), ticketSeq).key));
242 env.close();
243
244 env(noop(target), ticket::Use(ticketSeq));
245 env.close();
246 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
247 }
248
249 // A blocked transaction is held for retry, and consumes the ticket
250 // by itself once the proposal is gone. Two closes: the held
251 // transaction and the Cancel land in the same ledger in salted
252 // canonical order, so the retry may run before the Cancel once more.
253 {
254 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
256 env, alice, proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq));
257
258 env(noop(target), ticket::Use(ticketSeq), Ter(terTICKET_RESERVED));
259
260 env(proposal::cancel(alice, keylet::txProposal(target.id(), ticketSeq).key));
261 env.close();
262 env.close();
263
264 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
265 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
266 }
267 }
268
269 // A ticket is consumed even when its transaction fails with a tec. The
270 // reservation lets only the matching payload get that far, and once the
271 // ticket is durably gone the proposal is cleaned up all the same.
272 void
274 {
275 testcase("matching payload failing with tec still cleans up");
276
277 using namespace jtx;
278 using namespace std::chrono_literals;
279
280 Env env{*this, features};
281
282 Account const alice{"alice"};
283 Account const target{"target"};
284 Account const bob{"bob"};
285 env.fund(XRP(10000), alice, target, bob);
286 env.close();
287
288 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
289 // A proposed payment the target cannot fund. Creation only runs the
290 // payload's stateless checks, so the proposal stores it happily.
292 env,
293 alice,
294 proposal::unsignedPayload(env, pay(target, bob, XRP(1'000'000)), ticketSeq));
295
296 env(pay(target, bob, XRP(1'000'000)), ticket::Use(ticketSeq), Ter(tecUNFUNDED_PAYMENT));
297 env.close();
298
299 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
300 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
301 BEAST_EXPECT(ownerCount(env, alice) == 0);
302 BEAST_EXPECT(ownerCount(env, target) == 1);
303 }
304
305 // The reservation is keyed by target account and ticket, so another
306 // account spending its own ticket of the same numeric sequence is
307 // neither blocked nor does it touch the proposal.
308 void
310 {
311 testcase("other account's same-numbered ticket is unaffected");
312
313 using namespace jtx;
314 using namespace std::chrono_literals;
315
316 Env env{*this, features};
317
318 Account const alice{"alice"};
319 Account const target{"target"};
320 Account const bob{"bob"};
321 env.fund(XRP(10000), alice, target, bob);
322 env.close();
323
324 // target and bob were funded together, so creating one ticket each
325 // in the same ledger gives their tickets the same numeric sequence.
326 std::uint32_t const targetTicketSeq = env.seq(target) + 1;
327 std::uint32_t const bobTicketSeq = env.seq(bob) + 1;
328 env(ticket::create(target, 1));
329 env(ticket::create(bob, 1));
330 env.close();
331 BEAST_EXPECT(targetTicketSeq == bobTicketSeq);
332
334 env, alice, proposal::unsignedPayload(env, pay(target, bob, XRP(1)), targetTicketSeq));
335
336 env(noop(bob), ticket::Use(bobTicketSeq));
337 env.close();
338
339 BEAST_EXPECT(proposal::entry(env, target, targetTicketSeq));
340 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(targetTicketSeq))));
341 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
342 }
343
344 // The proposer may be the target itself. The reservation still binds it
345 // — its own unrelated spend is blocked — and the matching execution
346 // lands the ticket bookkeeping and the reserve release on the same
347 // account-root SLE within one ticketDelete call, pinning that aliasing.
348 void
350 {
351 testcase("proposer is the target account");
352
353 using namespace jtx;
354 using namespace std::chrono_literals;
355
356 Env env{*this, features};
357
358 Account const alice{"alice"};
359 Account const bob{"bob"};
360 env.fund(XRP(10000), alice, bob);
361 env.close();
362
363 std::uint32_t const ticketSeq = proposal::createTicket(env, alice);
365 env, alice, proposal::unsignedPayload(env, pay(alice, bob, XRP(1)), ticketSeq));
366
367 auto const sle = proposal::entry(env, alice, ticketSeq);
368 BEAST_EXPECT(sle && sle->getAccountID(sfOwner) == alice.id());
369 // One Ticket plus the proposal's increments, all against alice.
370 BEAST_EXPECT(ownerCount(env, alice) == 1 + proposal::kProposalOwnerCount);
371
372 env(noop(alice), ticket::Use(ticketSeq), Ter(terTICKET_RESERVED));
373 env.close();
374 BEAST_EXPECT(proposal::entry(env, alice, ticketSeq));
375
376 env(pay(alice, bob, XRP(1)), ticket::Use(ticketSeq));
377 env.close();
378
379 BEAST_EXPECT(!proposal::entry(env, alice, ticketSeq));
380 BEAST_EXPECT(ownerCount(env, alice) == 0);
381 }
382
383 // A proposed Batch: the reservation covers its outer ticket, only the
384 // identical Batch consumes it, and its deletion must release the larger
385 // reserve a Batch proposal holds (On-Chain Cosigner spec §4.4).
386 void
388 {
389 testcase("proposed Batch: only the identical Batch spends the ticket");
390
391 using namespace jtx;
392 using namespace std::chrono_literals;
393
394 Env env{*this, features};
395
396 Account const alice{"alice"};
397 Account const target{"target"};
398 Account const bob{"bob"};
399 env.fund(XRP(10000), alice, target, bob);
400 env.close();
401 proposal::authorizeProposer(env, target, alice);
402
403 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
404
405 // Build the payload once; the same JSON is stored in the proposal
406 // and later submitted, differing only by the signature env() adds.
407 auto const innerSeq = env.seq(target);
408 json::Value const payload = proposal::unsignedBatch(
409 env,
410 target,
411 ticketSeq,
412 tfAllOrNothing,
413 {
414 proposal::innerTx(pay(target, bob, XRP(1)), innerSeq),
415 proposal::innerTx(pay(target, bob, XRP(1)), innerSeq + 1),
416 });
417 makeProposal(env, alice, payload);
418 BEAST_EXPECT(ownerCount(env, alice) == proposal::kBatchProposalOwnerCount);
419
420 // A different Batch spending the reserved outer ticket is blocked.
421 env(batch::outer(target, 0, batch::calcBatchFee(env, 0, 2), tfAllOrNothing),
422 batch::Inner(pay(target, bob, XRP(5)), innerSeq),
423 batch::Inner(pay(target, bob, XRP(5)), innerSeq + 1),
424 ticket::Use(ticketSeq),
426 env.close();
427 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
428
429 // The proposed Batch itself executes: outer ticket consumed, both
430 // inner payments applied, proposal deleted, larger reserve released.
431 auto const bobBefore = env.balance(bob);
432 env(payload);
433 env.close();
434
435 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(2));
436 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
437 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
438 BEAST_EXPECT(ownerCount(env, alice) == 0);
439 }
440
441 // An inner Batch transaction validates its ticket through the same path
442 // as a standalone one, so a reserved ticket blocks it too — an inner
443 // transaction carries tfInnerBatchTxn and a zero fee, so it can never
444 // match a stored payload, which may not carry that flag (On-Chain Cosigner spec
445 // §4.2.1). Under tfAllOrNothing the whole Batch is discarded.
446 void
448 {
449 testcase("inner batch transaction cannot spend a reserved ticket");
450
451 using namespace jtx;
452 using namespace std::chrono_literals;
453
454 Env env{*this, features};
455
456 Account const alice{"alice"};
457 Account const target{"target"};
458 Account const bob{"bob"};
459 env.fund(XRP(10000), alice, target, bob);
460 env.close();
461
462 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
463 json::Value const payload =
464 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
465 makeProposal(env, alice, payload);
466
467 // The second inner transaction spends the reserved ticket — even
468 // carrying the very payment the proposal holds, its flag and fee
469 // make it a different payload, so it fails and tfAllOrNothing
470 // discards its sibling too.
471 auto const bobBefore = env.balance(bob);
472 auto const seq = env.seq(target);
473 env(batch::outer(target, seq, batch::calcBatchFee(env, 0, 2), tfAllOrNothing),
474 batch::Inner(pay(target, bob, XRP(1)), seq + 1),
475 batch::Inner(pay(target, bob, XRP(1)), 0, ticketSeq));
476 env.close();
477
478 BEAST_EXPECT(env.balance(bob) == bobBefore);
479 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
480 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
481 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
482
483 // The standalone matching payment still goes through.
484 env(pay(target, bob, XRP(1)), ticket::Use(ticketSeq));
485 env.close();
486 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
487 BEAST_EXPECT(ownerCount(env, alice) == 0);
488 }
489
490 // A proposed multi-account Batch is stored with no BatchSigners: the
491 // participants' signatures are collected afterwards, and the submission
492 // that completes it carries them. BatchSigners is one of the containers
493 // payloadMatches excludes, which is exactly what lets the completed Batch
494 // still match what was stored.
495 void
497 {
498 testcase("proposed multi-account Batch completes with BatchSigners");
499
500 using namespace jtx;
501 using namespace std::chrono_literals;
502
503 Env env{*this, features};
504
505 Account const alice{"alice"};
506 Account const target{"target"};
507 Account const bob{"bob"};
508 Account const carol{"carol"};
509 env.fund(XRP(10000), alice, target, bob, carol);
510 env.close();
511 proposal::authorizeProposer(env, target, alice);
512
513 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
514
515 // One inner from each of two accounts, so the Batch is unsubmittable
516 // without bob's BatchSigners entry. The second inner moves funds bob
517 // holds to a third account, so each inner is separately observable.
518 json::Value const payload = proposal::unsignedBatch(
519 env,
520 target,
521 ticketSeq,
522 tfAllOrNothing,
523 {
524 proposal::innerTx(pay(target, bob, XRP(1)), env.seq(target)),
525 proposal::innerTx(pay(bob, carol, XRP(2)), env.seq(bob)),
526 });
527 makeProposal(env, alice, payload);
528
529 auto const sle = proposal::entry(env, target, ticketSeq);
530 BEAST_EXPECT(
531 sle && !sle->getFieldObject(sfProposedTransaction).isFieldPresent(sfBatchSigners));
532 BEAST_EXPECT(ownerCount(env, alice) == proposal::kBatchProposalOwnerCount);
533
534 // Submitted exactly as stored, the Batch cannot even preflight: a
535 // multi-account Batch demands an entry per participant. So excluding
536 // BatchSigners from the match is load-bearing rather than incidental —
537 // without it this proposal could never be completed at all.
538 env(payload, Ter(temBAD_SIGNER));
539 env.close();
540 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
541
542 auto const bobBefore = env.balance(bob);
543 auto const carolBefore = env.balance(carol);
544 env(payload, batch::Sig(bob));
545 env.close();
546
547 // Both inners applied: bob took XRP(1) from the target and paid
548 // XRP(2) out, and inner transactions carry no fee of their own.
549 BEAST_EXPECT(env.balance(carol) == carolBefore + XRP(2));
550 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1) - XRP(2));
551 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
552 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
553 BEAST_EXPECT(ownerCount(env, alice) == 0);
554 }
555
556 // A proposed LoanSet stores no CounterpartySignature — that is collected
557 // afterwards too — and the completed submission carrying one still
558 // matches. The payload's Fee is fixed at creation, so it has to budget for
559 // that signature up front: LoanSet charges an extra base fee per
560 // counterparty signature, and nothing can raise the fee later.
561 void
563 {
564 testcase("proposed LoanSet completes with a CounterpartySignature");
565
566 using namespace jtx;
567 using namespace std::chrono_literals;
568
569 Env env{*this, features};
570
571 Account const alice{"alice"};
572 Account const target{"target"}; // the borrower
573 Account const lender{"lender"}; // the LoanSet's Counterparty
574 env.fund(XRP(10000), alice, target, lender);
575 env.close();
576 proposal::authorizeProposer(env, target, alice);
577
578 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
579
580 json::Value tx = loan::set(target, uint256{1}, 1'000);
581 tx[sfCounterparty.getJsonName()] = lender.human();
582 tx[jss::Fee] = std::to_string((env.current()->fees().base * 2).drops());
583 json::Value const payload = proposal::unsignedPayload(env, tx, ticketSeq);
584 makeProposal(env, alice, payload);
585
586 // The named LoanBroker does not exist, so this fails at preclaim —
587 // which is the point: getting as far as preclaim proves the added
588 // CounterpartySignature did not break the payload match, and a tec
589 // consumes the ticket and cleans the proposal up all the same.
590 env(payload, Sig(sfCounterpartySignature, lender), Ter(tecNO_ENTRY));
591 env.close();
592
593 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
594 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
595 BEAST_EXPECT(ownerCount(env, alice) == 0);
596 }
597
598 // The last of the co-signature containers: a payload may name a fee
599 // sponsor at creation and collect that sponsor's signature later. Sponsor
600 // and SponsorFlags are ordinary payload fields, fixed from the start;
601 // only the SponsorSignature itself arrives at submission.
602 void
604 {
605 testcase("proposed payload completes with a SponsorSignature");
606
607 using namespace jtx;
608 using namespace std::chrono_literals;
609
610 Env env{*this, features};
611
612 Account const alice{"alice"};
613 Account const target{"target"};
614 Account const bob{"bob"};
615 Account const backer{"backer"}; // pays the payload's fee
616 env.fund(XRP(10000), alice, target, bob, backer);
617 env.close();
618 proposal::authorizeProposer(env, target, alice);
619
620 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
621
622 json::Value tx = pay(target, bob, XRP(1));
623 tx[sfSponsor.getJsonName()] = backer.human();
624 tx[sfSponsorFlags.getJsonName()] = spfSponsorFee;
625 json::Value const payload = proposal::unsignedPayload(env, tx, ticketSeq);
626 makeProposal(env, alice, payload);
627
628 auto const sle = proposal::entry(env, target, ticketSeq);
629 BEAST_EXPECT(
630 sle && !sle->getFieldObject(sfProposedTransaction).isFieldPresent(sfSponsorSignature));
631
632 auto const fee = env.current()->fees().base;
633 auto const bobBefore = env.balance(bob);
634 auto const targetBefore = env.balance(target);
635 auto const backerBefore = env.balance(backer);
636
637 env(payload, Sig(sfSponsorSignature, backer));
638 env.close();
639
640 // The sponsor covered the fee, so the target parted with the payment
641 // amount and nothing beyond it.
642 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
643 BEAST_EXPECT(env.balance(target) == targetBefore - XRP(1));
644 BEAST_EXPECT(env.balance(backer) == backerBefore - fee);
645 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
646 BEAST_EXPECT(ownerCount(env, alice) == 0);
647 }
648
649 // A terminal proposal — expired, or past its payload's LastLedgerSequence
650 // — still reserves its ticket. canConsumeTicket never consults
651 // isTerminal: going terminal widens who may cancel a proposal, but it
652 // releases nothing, because the ticket is reserved for as long as the
653 // proposal exists (On-Chain Cosigner spec §4.2.1). Freeing the ticket
654 // takes a Cancel, which anyone may now send.
655 void
657 {
658 testcase("a terminal proposal still reserves its ticket");
659
660 using namespace jtx;
661 using namespace std::chrono_literals;
662
663 // An unrelated spend stays blocked after the proposal expires.
664 {
665 Env env{*this, features};
666
667 Account const alice{"alice"};
668 Account const target{"target"};
669 Account const bob{"bob"};
670 env.fund(XRP(10000), alice, target, bob);
671 env.close();
672 proposal::authorizeProposer(env, target, alice);
673
674 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
675
676 // A far-future LastLedgerSequence keeps that arm of the terminal
677 // rule inert, so the expiry alone makes the proposal terminal.
678 json::Value payload =
679 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
680 payload[sfLastLedgerSequence.getJsonName()] = env.current()->seq() + 1000;
681
682 env(proposal::create(alice, payload, proposal::expiration(env, 100s)));
683 env.close();
684
685 env.close(env.now() + 200s);
686
687 env(noop(target), ticket::Use(ticketSeq), Ter(terTICKET_RESERVED));
688 env.close();
689
690 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
691 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
692 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
693 }
694
695 // The same indifference to isTerminal in the other direction: the
696 // proposal's own payload still consumes the ticket after the proposal
697 // expires. An expired proposal is closed to new signatures, not to
698 // the transaction it already holds. A separate environment keeps the
699 // held retry from the block above out of this one.
700 {
701 Env env{*this, features};
702
703 Account const alice{"alice"};
704 Account const target{"target"};
705 Account const bob{"bob"};
706 env.fund(XRP(10000), alice, target, bob);
707 env.close();
708 proposal::authorizeProposer(env, target, alice);
709
710 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
711 json::Value const payload =
712 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
713
714 env(proposal::create(alice, payload, proposal::expiration(env, 100s)));
715 env.close();
716
717 env.close(env.now() + 200s);
718
719 auto const bobBefore = env.balance(bob);
720 env(payload);
721 env.close();
722
723 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
724 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
725 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
726 BEAST_EXPECT(ownerCount(env, alice) == 0);
727 }
728 }
729
730 // A reserve-sponsored proposal cleaned up by its own payload consuming the
731 // ticket releases the reserve against the sponsor. deleteProposal follows
732 // the Sponsor recorded on the entry, so this path and the Cancel path land
733 // in the same place.
734 void
736 {
737 testcase("auto-deleting a sponsored proposal releases its sponsor");
738
739 using namespace jtx;
740 using namespace std::chrono_literals;
741
742 Env env{*this, features};
743
744 Account const alice{"alice"};
745 Account const target{"target"};
746 Account const bob{"bob"};
747 Account const backer{"backer"}; // sponsors alice's proposal reserve
748 env.fund(XRP(10000), alice, target, bob, backer);
749 env.close();
750 proposal::authorizeProposer(env, target, alice);
751
752 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
753 json::Value const payload =
754 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
755
756 env(proposal::create(alice, payload, proposal::expiration(env, 1000s)),
758 Sig(sfSponsorSignature, backer),
760 env.close();
761
762 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
763 BEAST_EXPECT(sponsoredOwnerCount(env, alice) == proposal::kProposalOwnerCount);
764 BEAST_EXPECT(sponsoringOwnerCount(env, backer) == proposal::kProposalOwnerCount);
765
766 env(payload);
767 env.close();
768
769 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
770 BEAST_EXPECT(ownerCount(env, alice) == 0);
771 BEAST_EXPECT(sponsoredOwnerCount(env, alice) == 0);
772 BEAST_EXPECT(sponsoringOwnerCount(env, backer) == 0);
773 BEAST_EXPECT(ownerCount(env, backer) == 0);
774 }
775
776 // Deleting the target account sweeps its Tickets without consuming them
777 // as a sequence proxy, so the reservation does not block it. A proposal
778 // keyed to a swept ticket can never execute and is cleaned up with it,
779 // refunding the proposer (On-Chain Cosigner spec §4.5).
780 void
782 {
783 testcase("deleting the target account deletes the proposal");
784
785 using namespace jtx;
786 using namespace std::chrono_literals;
787
788 Env env{*this, features};
789
790 Account const alice{"alice"};
791 Account const target{"target"};
792 Account const bob{"bob"};
793 env.fund(XRP(10000), alice, target, bob);
794 env.close();
795
796 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
798 env, alice, proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq));
799 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
800
801 incLgrSeqForAccDel(env, target);
802 env(acctdelete(target, bob), Fee(env.current()->fees().increment));
803 env.close();
804
805 BEAST_EXPECT(!env.le(keylet::account(target.id())));
806 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
807 BEAST_EXPECT(ownerCount(env, alice) == 0);
808 }
809
810 // The sweep above, with more than one proposal and more than one Owner.
811 // Each reserve has to return to the account that put it up, which means the
812 // sweep cannot stop at the first proposal it reaches and cannot settle the
813 // refunds against a single account. Two Owners also make the directory
814 // separation concrete: the sweep walks the target's owner directory while
815 // each deletion mutates a different one.
816 void
818 {
819 testcase("target deletion refunds each proposal's own owner");
820
821 using namespace jtx;
822 using namespace std::chrono_literals;
823
824 Env env{*this, features};
825
826 Account const alice{"alice"}; // Owner of the proposal on the first ticket
827 Account const bob{"bob"}; // Owner of the one on the second
828 Account const target{"target"};
829 Account const dest{"dest"};
830 env.fund(XRP(10000), alice, bob, target, dest);
831 env.close();
832
833 // Both proposers on one SignerList. makeProposal's own authorization
834 // step adds a list for the first proposer only and then finds one
835 // present, so the second proposer would be unauthorized without this.
836 env(signers(target, 1, {{alice, 1}, {bob, 1}}));
837 env.close();
838
839 std::uint32_t const firstTicket = proposal::createTicket(env, target, 2);
840 std::uint32_t const secondTicket = firstTicket + 1;
841
843 env, alice, proposal::unsignedPayload(env, pay(target, dest, XRP(1)), firstTicket));
845 env, bob, proposal::unsignedPayload(env, pay(target, dest, XRP(2)), secondTicket));
846
847 BEAST_EXPECT(proposal::entry(env, target, firstTicket));
848 BEAST_EXPECT(proposal::entry(env, target, secondTicket));
849 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
850 BEAST_EXPECT(ownerCount(env, bob) == proposal::kProposalOwnerCount);
851
852 incLgrSeqForAccDel(env, target);
853 env(acctdelete(target, dest), Fee(env.current()->fees().increment));
854 env.close();
855
856 BEAST_EXPECT(!env.le(keylet::account(target.id())));
857 BEAST_EXPECT(!proposal::entry(env, target, firstTicket));
858 BEAST_EXPECT(!proposal::entry(env, target, secondTicket));
859 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(firstTicket))));
860 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(secondTicket))));
861
862 // Each Owner got its own reserve back, and only its own.
863 BEAST_EXPECT(ownerCount(env, alice) == 0);
864 BEAST_EXPECT(ownerCount(env, bob) == 0);
865 }
866
867 // A TransactionProposal blocks its Owner's account deletion (On-Chain Cosigner spec
868 // §4.5). Beyond the spec requirement, this blocker is what guarantees
869 // the AccountDelete ticket sweep never deletes a proposal out of the
870 // very owner directory it is iterating: any proposal reached through a
871 // swept ticket is necessarily owned by an account other than the one
872 // being deleted.
873 void
875 {
876 testcase("proposal blocks its owner's account deletion");
877
878 using namespace jtx;
879 using namespace std::chrono_literals;
880
881 Env env{*this, features};
882
883 Account const alice{"alice"}; // proposer, tries to delete itself
884 Account const target{"target"};
885 Account const bob{"bob"};
886 env.fund(XRP(10000), alice, target, bob);
887 env.close();
888
889 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
891 env, alice, proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq));
892
893 incLgrSeqForAccDel(env, alice);
894 env(acctdelete(alice, bob), Fee(env.current()->fees().increment), Ter(tecHAS_OBLIGATIONS));
895 env.close();
896
897 BEAST_EXPECT(env.le(keylet::account(alice.id())));
898 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
899 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
900
901 // An account holding a blocker needs to be able to find out why its
902 // deletion failed, so account_objects has to agree with the transactor
903 // about what counts as one.
904 json::Value params;
905 params[jss::account] = alice.human();
906 params[jss::deletion_blockers_only] = true;
907 auto const jrr = env.rpc("json", "account_objects", to_string(params))[jss::result];
908 BEAST_EXPECT(jrr[jss::account_objects].size() == 1);
909 BEAST_EXPECT(
910 jrr[jss::account_objects][0u][sfLedgerEntryType.getJsonName()] ==
911 jss::TransactionProposal);
912 }
913
914 // A proposal reserves a ticket, not the target's signing authority: the
915 // target stays free to rewrite its SignerList while signatures are being
916 // collected. Signatures gathered against the old list then no longer
917 // authorize the payload, and the payload's Fee was fixed at creation, so
918 // it cannot buy more of them. None of these failures claims a fee or
919 // applies anything, so the ticket stays reserved and the payload keeps
920 // whatever signing routes the rewritten list still leaves it
921 // (On-Chain Cosigner spec §4.2.1).
922 void
924 {
925 testcase("target's SignerList changes under a stored proposal");
926
927 using namespace jtx;
928 using namespace std::chrono_literals;
929
930 // A signer dropped from the list can no longer contribute.
931 {
932 Env env{*this, features};
933
934 Account const alice{"alice"};
935 Account const target{"target"};
936 Account const bob{"bob"};
937 Account const carol{"carol"};
938 env.fund(XRP(10000), alice, target, bob, carol);
939 env.close();
940
941 env(signers(target, 2, {{alice, 1}, {bob, 1}, {carol, 1}}));
942 env.close();
943
944 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
945 auto const msigFee = env.current()->fees().base * 3;
946 json::Value proposedTx = pay(target, bob, XRP(1));
947 proposedTx[jss::Fee] = std::to_string(msigFee.drops());
948 json::Value const payload = proposal::unsignedPayload(env, proposedTx, ticketSeq);
949 makeProposal(env, alice, payload);
950
951 // The target drops carol after the proposal is stored.
952 env(signers(target, 2, {{alice, 1}, {bob, 1}}));
953 env.close();
954
955 env(payload, Msig(bob, carol), Ter(tefBAD_SIGNATURE));
956 env.close();
957
958 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
959 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
960 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
961
962 // Only the dropped signer is gone, not the route: the signers
963 // still on the list meet the unchanged quorum, and because two
964 // signatures is what the Fee budgeted for, the payload completes.
965 env(payload, Msig(alice, bob));
966 env.close();
967
968 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
969 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
970 BEAST_EXPECT(ownerCount(env, alice) == 0);
971 }
972
973 // A quorum raised beyond what the fixed Fee can pay for. That closes
974 // the multisign route the Fee was budgeted for, but not the proposal:
975 // a SignerList does not revoke the master key, and signing singly
976 // costs less than the Fee already covers.
977 {
978 Env env{*this, features};
979
980 Account const alice{"alice"};
981 Account const target{"target"};
982 Account const bob{"bob"};
983 Account const carol{"carol"};
984 env.fund(XRP(10000), alice, target, bob, carol);
985 env.close();
986
987 env(signers(target, 1, {{alice, 1}, {bob, 1}, {carol, 1}}));
988 env.close();
989
990 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
991 auto const msigFee = env.current()->fees().base * 2;
992 json::Value proposedTx = pay(target, bob, XRP(1));
993 proposedTx[jss::Fee] = std::to_string(msigFee.drops());
994 json::Value const payload = proposal::unsignedPayload(env, proposedTx, ticketSeq);
995 makeProposal(env, alice, payload);
996
997 env(signers(target, 3, {{alice, 1}, {bob, 1}, {carol, 1}}));
998 env.close();
999
1000 // The single signature the Fee paid for no longer reaches quorum.
1001 env(payload, Msig(bob), Ter(tefBAD_QUORUM));
1002 env.close();
1003
1004 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1005 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1006
1007 // And the three signatures that would reach it cost more than the
1008 // Fee fixed at creation. They do satisfy the raised quorum, and
1009 // checkSign runs ahead of checkFee, so nothing is masked here: a
1010 // three-signer multisign is priced at four base fees against the
1011 // two the payload fixed, and checkFee is what rejects it.
1012 env(payload, Msig(alice, bob, carol), Ter(telINSUF_FEE_P));
1013 env.close();
1014
1015 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1016 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1017 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1018
1019 // What closed is the multisign route, not the proposal. Raising a
1020 // quorum does not revoke the master key, and one signature is
1021 // priced at a single base fee, well inside what the Fee covers.
1022 auto const bobBefore = env.balance(bob);
1023 env(payload, Sig(target));
1024 env.close();
1025
1026 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
1027 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
1028 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1029 BEAST_EXPECT(ownerCount(env, alice) == 0);
1030 }
1031 }
1032
1033 // The signature-presence checks that TapProposal skips at creation time
1034 // are not skipped at submission (On-Chain Cosigner spec §5.3.1.2). Each is
1035 // a tem, so the submission claims no fee: the ticket keeps its
1036 // reservation and the proposal stays put.
1037 void
1039 {
1040 testcase("deferred signature-presence checks fire at submission");
1041
1042 using namespace jtx;
1043 using namespace std::chrono_literals;
1044
1045 // LoanSet's CounterpartySignature. testCounterpartySignatureMatches
1046 // covers the completed submission; this covers its absence, which is
1047 // what LoanSet::preflight stops checking under TapProposal.
1048 {
1049 Env env{*this, features};
1050
1051 Account const alice{"alice"};
1052 Account const target{"target"}; // the borrower
1053 Account const lender{"lender"};
1054 env.fund(XRP(10000), alice, target, lender);
1055 env.close();
1056 proposal::authorizeProposer(env, target, alice);
1057
1058 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1059
1060 json::Value tx = loan::set(target, uint256{1}, 1'000);
1061 tx[sfCounterparty.getJsonName()] = lender.human();
1062 json::Value const payload = proposal::unsignedPayload(env, tx, ticketSeq);
1063 makeProposal(env, alice, payload);
1064
1065 env(payload, Ter(temBAD_SIGNER));
1066 env.close();
1067
1068 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1069 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1070 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1071 }
1072
1073 // An account-level SponsorshipTransfer's SponsorSignature. Only the
1074 // account-level form defers this: it needs no ObjectID, which is what
1075 // distinguishes it from object-level sponsorship.
1076 {
1077 Env env{*this, features};
1078
1079 Account const alice{"alice"};
1080 Account const target{"target"};
1081 Account const backer{"backer"};
1082 env.fund(XRP(10000), alice, target, backer);
1083 env.close();
1084 proposal::authorizeProposer(env, target, alice);
1085
1086 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1087
1088 json::Value tx = sponsor::transfer(target, tfSponsorshipCreate);
1089 tx[sfSponsor.getJsonName()] = backer.human();
1090 tx[sfSponsorFlags.getJsonName()] = spfSponsorReserve;
1091 json::Value const payload = proposal::unsignedPayload(env, tx, ticketSeq);
1092 makeProposal(env, alice, payload);
1093
1094 env(payload, Ter(temMALFORMED));
1095 env.close();
1096
1097 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1098 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1099 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1100 }
1101
1102 // Reassignment is the other way into that check: creating and
1103 // reassigning are gated by one account-level condition, so this pins
1104 // the flags the check answers for rather than a second code path.
1105 {
1106 Env env{*this, features};
1107
1108 Account const alice{"alice"};
1109 Account const target{"target"};
1110 Account const backer{"backer"};
1111 env.fund(XRP(10000), alice, target, backer);
1112 env.close();
1113 proposal::authorizeProposer(env, target, alice);
1114
1115 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1116
1117 json::Value tx = sponsor::transfer(target, tfSponsorshipReassign);
1118 tx[sfSponsor.getJsonName()] = backer.human();
1119 tx[sfSponsorFlags.getJsonName()] = spfSponsorReserve;
1120 json::Value const payload = proposal::unsignedPayload(env, tx, ticketSeq);
1121 makeProposal(env, alice, payload);
1122
1123 env(payload, Ter(temMALFORMED));
1124 env.close();
1125
1126 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1127 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1128 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1129 }
1130 }
1131
1132 // What a tem submission costs the proposal. Creation cannot store a
1133 // payload that fails its own preflight, so the only payload rejected
1134 // unaltered is one whose check creation defers: here a multi-account
1135 // Batch, submitted without the BatchSigners entry it will eventually be
1136 // given. payloadMatches is asserted first, so the rejection cannot be read
1137 // as the test having submitted something else.
1138 void
1140 {
1141 testcase("a tem submission consumes neither ticket nor proposal");
1142
1143 using namespace jtx;
1144 using namespace std::chrono_literals;
1145
1146 Env env{*this, features};
1147
1148 Account const alice{"alice"};
1149 Account const target{"target"};
1150 Account const bob{"bob"};
1151 Account const carol{"carol"};
1152 env.fund(XRP(10000), alice, target, bob, carol);
1153 env.close();
1154 proposal::authorizeProposer(env, target, alice);
1155
1156 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1157 json::Value const payload = proposal::unsignedBatch(
1158 env,
1159 target,
1160 ticketSeq,
1161 tfAllOrNothing,
1162 {
1163 proposal::innerTx(pay(target, bob, XRP(1)), env.seq(target)),
1164 proposal::innerTx(pay(bob, carol, XRP(2)), env.seq(bob)),
1165 });
1166 makeProposal(env, alice, payload);
1167
1168 auto const sle = proposal::entry(env, target, ticketSeq);
1169 if (!BEAST_EXPECT(sle))
1170 return;
1171
1172 // The transaction about to be rejected is the proposal's own payload.
1173 auto const jt = env.jt(payload);
1174 if (!BEAST_EXPECT(jt.stx))
1175 return;
1176 BEAST_EXPECT(
1177 xrpl::proposal::payloadMatches(sle->getFieldObject(sfProposedTransaction), *jt.stx));
1178
1179 auto const targetBefore = env.balance(target);
1180 auto const bobBefore = env.balance(bob);
1181 auto const carolBefore = env.balance(carol);
1182
1183 env(payload, Ter(temBAD_SIGNER));
1184 env.close();
1185
1186 // A tem is rejected before it can claim a fee, so the target paid
1187 // nothing for the attempt and no inner transaction ran.
1188 BEAST_EXPECT(env.balance(target) == targetBefore);
1189 BEAST_EXPECT(env.balance(bob) == bobBefore);
1190 BEAST_EXPECT(env.balance(carol) == carolBefore);
1191
1192 // The proposal is still stored, still holding its reserve, and the
1193 // ticket still exists.
1194 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1195 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1196 BEAST_EXPECT(ownerCount(env, alice) == proposal::kBatchProposalOwnerCount);
1197
1198 // And the proposal still completes on that same ticket once the
1199 // signatures it was waiting for arrive, which is what makes the
1200 // rejection above a no-op rather than a loss.
1201 env(payload, batch::Sig(bob));
1202 env.close();
1203
1204 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1) - XRP(2));
1205 BEAST_EXPECT(env.balance(carol) == carolBefore + XRP(2));
1206 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
1207 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1208 BEAST_EXPECT(ownerCount(env, alice) == 0);
1209 }
1210
1211 // Skipping Batch::preflightSigValidated at creation defers every shape of
1212 // BatchSigners error, not just an absent array.
1213 // testMultiAccountBatchCompletes covers the absent case; these are the
1214 // malformed ones, each rejected at submission with the ticket and the
1215 // proposal untouched.
1216 void
1218 {
1219 testcase("malformed BatchSigners rejected at submission");
1220
1221 using namespace jtx;
1222 using namespace std::chrono_literals;
1223
1224 Env env{*this, features};
1225
1226 Account const alice{"alice"};
1227 Account const target{"target"};
1228 Account const bob{"bob"};
1229 Account const carol{"carol"};
1230 env.fund(XRP(10000), alice, target, bob, carol);
1231 env.close();
1232 proposal::authorizeProposer(env, target, alice);
1233
1234 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1235
1236 // Inners from three accounts, so the completed Batch needs an entry
1237 // from each of bob and carol.
1238 json::Value const payload = proposal::unsignedBatch(
1239 env,
1240 target,
1241 ticketSeq,
1242 tfAllOrNothing,
1243 {
1244 proposal::innerTx(pay(target, bob, XRP(1)), env.seq(target)),
1245 proposal::innerTx(pay(bob, carol, XRP(2)), env.seq(bob)),
1246 proposal::innerTx(pay(carol, bob, XRP(1)), env.seq(carol)),
1247 });
1248 makeProposal(env, alice, payload);
1249
1250 auto const stillTicketReservedForProposal = [&] {
1251 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1252 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1253 BEAST_EXPECT(ownerCount(env, alice) == proposal::kBatchProposalOwnerCount);
1254 };
1255
1256 // Batch signers are checked against the required signers positionally,
1257 // both sorted by account ID, so which malformation a given array trips
1258 // depends on this ordering. Pin it: if these fixed jtx accounts ever
1259 // sort differently, that should fail here rather than quietly move the
1260 // cases below onto a different branch. The outer account is included
1261 // because the first case below relies on it sorting ahead of bob.
1262 BEAST_EXPECT(target.id() < alice.id() && alice.id() < carol.id() && carol.id() < bob.id());
1263
1264 // The outer account may not sign for itself.
1265 env(payload, batch::Sig(target, bob), Ter(temBAD_SIGNER));
1266 env.close();
1267 stillTicketReservedForProposal();
1268
1269 // A duplicated signer. It has to be carol, the first required signer:
1270 // a duplicated bob would be rejected as a mismatch against carol
1271 // before the array's second entry is ever examined.
1272 env(payload, batch::Sig(carol, carol), Ter(temBAD_SIGNER));
1273 env.close();
1274 stillTicketReservedForProposal();
1275
1276 // An unsorted pair. batch::Sig sorts what it is given, so the array
1277 // has to be swapped after the fact to express this. Swapping the two
1278 // required signers would not reach the sort check either, so the pair
1279 // is carol and alice: carol matches, then alice sorts below her.
1280 {
1281 auto jt = env.jt(payload, batch::Sig(alice, carol));
1282 auto const first = jt.jv[sfBatchSigners.jsonName][0u];
1283 auto const second = jt.jv[sfBatchSigners.jsonName][1u];
1284 jt.jv[sfBatchSigners.jsonName][0u] = second;
1285 jt.jv[sfBatchSigners.jsonName][1u] = first;
1286
1287 env(jt.jv, Ter(temBAD_SIGNER));
1288 env.close();
1289 stillTicketReservedForProposal();
1290 }
1291
1292 // Correctly formed, the same proposal still completes: the rejections
1293 // above are about the signers array, not the stored payload.
1294 env(payload, batch::Sig(bob, carol));
1295 env.close();
1296
1297 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
1298 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1299 BEAST_EXPECT(ownerCount(env, alice) == 0);
1300 }
1301
1302 // Create rejects a payload whose LastLedgerSequence is at or before the
1303 // ledger Create itself applies in (tecEXPIRED). A bound that passes after
1304 // the proposal exists is a different matter: at view.seq() ==
1305 // LastLedgerSequence the payload still submits
1306 // (the transactor's tefMAX_LEDGER rule is view.seq() > bound), and the
1307 // proposal's own terminal rule uses the same boundary, so the proposal
1308 // is live in that same ledger. Only once view.seq() has advanced past
1309 // the bound does the payload become unsubmittable — as a tef it leaves
1310 // the ticket and the proposal in place, and Cancel is the only exit.
1311 void
1313 {
1314 testcase("payload's LastLedgerSequence passes while the proposal waits");
1315
1316 using namespace jtx;
1317 using namespace std::chrono_literals;
1318
1319 // One ledger past the bound: the payload can no longer be submitted,
1320 // and being a tef it takes neither the ticket nor the proposal with
1321 // it. Cancel is the only exit left.
1322 {
1323 Env env{*this, features};
1324
1325 Account const alice{"alice"};
1326 Account const target{"target"};
1327 Account const bob{"bob"};
1328 env.fund(XRP(10000), alice, target, bob);
1329 env.close();
1330 proposal::authorizeProposer(env, target, alice);
1331
1332 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1333
1334 std::uint32_t const lastLedgerSeq = env.current()->seq() + 5;
1335 json::Value payload =
1336 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
1337 payload[sfLastLedgerSequence.getJsonName()] = lastLedgerSeq;
1338 makeProposal(env, alice, payload);
1339
1340 while (env.current()->seq() <= lastLedgerSeq)
1341 env.close();
1342
1343 env(payload, Ter(tefMAX_LEDGER));
1344 env.close();
1345
1346 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1347 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1348 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1349 }
1350
1351 // Exactly at the bound: still live and still submittable — the
1352 // proposal's terminal rule and the transactor's tefMAX_LEDGER rule
1353 // both trigger only strictly past the bound, so the payload applies
1354 // in this last valid ledger and cleans up as usual.
1355 {
1356 Env env{*this, features};
1357
1358 Account const alice{"alice"};
1359 Account const target{"target"};
1360 Account const bob{"bob"};
1361 env.fund(XRP(10000), alice, target, bob);
1362 env.close();
1363 proposal::authorizeProposer(env, target, alice);
1364
1365 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1366
1367 std::uint32_t const lastLedgerSeq = env.current()->seq() + 5;
1368 json::Value payload =
1369 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
1370 payload[sfLastLedgerSequence.getJsonName()] = lastLedgerSeq;
1371 makeProposal(env, alice, payload);
1372
1373 while (env.current()->seq() < lastLedgerSeq)
1374 env.close();
1375
1376 auto const bobBefore = env.balance(bob);
1377 env(payload);
1378 env.close();
1379
1380 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
1381 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
1382 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1383 BEAST_EXPECT(ownerCount(env, alice) == 0);
1384 }
1385 }
1386
1387 // Matching the stored payload is not authority to submit it. SigningPubKey
1388 // and TxnSignature are excluded from the match, so the submission's key is
1389 // checked on its own terms — and the target may change which keys count
1390 // after the proposal is stored.
1391 void
1393 {
1394 testcase("submission signed by an unauthorized or disabled key");
1395
1396 using namespace jtx;
1397 using namespace std::chrono_literals;
1398
1399 // A key with no authority over the target. The payload still matches;
1400 // it is the authority that is missing.
1401 {
1402 Env env{*this, features};
1403
1404 Account const alice{"alice"};
1405 Account const target{"target"};
1406 Account const bob{"bob"};
1407 env.fund(XRP(10000), alice, target, bob);
1408 env.close();
1409 proposal::authorizeProposer(env, target, alice);
1410
1411 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1412 json::Value const payload =
1413 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
1414 makeProposal(env, alice, payload);
1415
1416 env(payload, Sig(bob), Ter(tefBAD_AUTH));
1417 env.close();
1418
1419 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1420 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1421 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1422 }
1423
1424 // The target disables its master key after the proposal is stored. The
1425 // key that would have submitted the payload no longer can.
1426 {
1427 Env env{*this, features};
1428
1429 Account const alice{"alice"};
1430 Account const target{"target"};
1431 Account const bob{"bob"};
1432 env.fund(XRP(10000), alice, target, bob);
1433 env.close();
1434 proposal::authorizeProposer(env, target, alice);
1435
1436 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1437 json::Value const payload =
1438 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
1439 makeProposal(env, alice, payload);
1440
1441 // Disabling the master key requires another way in first.
1442 env(regkey(target, bob));
1443 env(fset(target, asfDisableMaster), Sig(target));
1444 env.close();
1445 // Signed with the master key the proposal was made under, the
1446 // payload is now refused. The key has to be named explicitly:
1447 // left to autofill, the submission would take the regular key
1448 // set above and succeed, proving nothing.
1449 env(payload, Sig(target), Ter(tefMASTER_DISABLED));
1450 env.close();
1451
1452 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1453 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1454
1455 // The regular key set above is a route the payload can still take,
1456 // so this proposal is stalled rather than dead.
1457 auto const bobBefore = env.balance(bob);
1458 env(payload, Sig(bob));
1459 env.close();
1460
1461 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
1462 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
1463 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1464 BEAST_EXPECT(ownerCount(env, alice) == 0);
1465 }
1466 }
1467
1468 // The payload's Fee is chosen at creation and is part of what a submission
1469 // must match, so it can never be raised. A proposal that under-budgets the
1470 // signatures it will need is therefore permanently unsubmittable. Both
1471 // unsignedBatch's numSigners parameter and the LoanSet Fee multiplier
1472 // exist to avoid this; these are the cases that walk into it.
1473 void
1475 {
1476 testcase("fee fixed at creation cannot cover the signatures needed");
1477
1478 using namespace jtx;
1479 using namespace std::chrono_literals;
1480
1481 // A multi-account Batch that budgeted for no BatchSigners at all.
1482 {
1483 Env env{*this, features};
1484
1485 Account const alice{"alice"};
1486 Account const target{"target"};
1487 Account const bob{"bob"};
1488 Account const carol{"carol"};
1489 env.fund(XRP(10000), alice, target, bob, carol);
1490 env.close();
1491 proposal::authorizeProposer(env, target, alice);
1492
1493 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1494
1495 json::Value const payload = proposal::unsignedBatch(
1496 env,
1497 target,
1498 ticketSeq,
1499 tfAllOrNothing,
1500 {
1501 proposal::innerTx(pay(target, bob, XRP(1)), env.seq(target)),
1502 proposal::innerTx(pay(bob, carol, XRP(2)), env.seq(bob)),
1503 },
1504 0u);
1505 makeProposal(env, alice, payload);
1506
1507 // Bare, it cannot preflight: the signer entry is still required.
1508 env(payload, Ter(temBAD_SIGNER));
1509 env.close();
1510
1511 // With the entry it preflights, and then cannot pay for it.
1512 env(payload, batch::Sig(bob), Ter(telINSUF_FEE_P));
1513 env.close();
1514
1515 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1516 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1517 BEAST_EXPECT(ownerCount(env, alice) == proposal::kBatchProposalOwnerCount);
1518 }
1519
1520 // A proposed LoanSet left at the single base fee, which cannot cover
1521 // the CounterpartySignature it is going to need. unsignedPayload
1522 // stamps the single base fee when the caller does not choose one,
1523 // while LoanSet prices each counterparty signer at one further base
1524 // fee, so the payload is short by exactly one.
1525 {
1526 Env env{*this, features};
1527
1528 Account const alice{"alice"};
1529 Account const target{"target"}; // the borrower
1530 Account const lender{"lender"};
1531 env.fund(XRP(10000), alice, target, lender);
1532 env.close();
1533 proposal::authorizeProposer(env, target, alice);
1534
1535 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1536
1537 json::Value tx = loan::set(target, uint256{1}, 1'000);
1538 tx[sfCounterparty.getJsonName()] = lender.human();
1539 json::Value const payload = proposal::unsignedPayload(env, tx, ticketSeq);
1540 makeProposal(env, alice, payload);
1541
1542 // The shortfall is what the case turns on, so pin it — read off
1543 // the stored proposal rather than the JSON built above.
1544 auto const sle = proposal::entry(env, target, ticketSeq);
1545 if (!BEAST_EXPECT(sle))
1546 return;
1547 BEAST_EXPECT(
1548 sle->getFieldObject(sfProposedTransaction).getFieldAmount(sfFee).xrp() ==
1549 env.current()->fees().base);
1550
1551 env(payload, Sig(sfCounterpartySignature, lender), Ter(telINSUF_FEE_P));
1552 env.close();
1553
1554 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1555 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1556 BEAST_EXPECT(ownerCount(env, alice) == proposal::kProposalOwnerCount);
1557 }
1558 }
1559
1560 // SigningPubKey and TxnSignature are excluded from the payload match, so a
1561 // submission may carry whatever it likes in them and still match. Nothing
1562 // about holding a proposal excuses the content of those fields: a key that
1563 // is not a key is refused in preflight, and a well-formed signature that
1564 // does not verify in preflight2.
1565 //
1566 // These go through xrpl::apply because jtx would overwrite the signature
1567 // fields when it signs, and the submit path rejects a bad signature itself
1568 // before a transactor sees it. The OpenView is discarded either way, so
1569 // only the returned ter and applied flag are evidence here; the
1570 // reservation surviving a tem is covered by
1571 // testTemSubmissionConsumesNothing.
1572 void
1574 {
1575 testcase("submission carrying malformed signature content");
1576
1577 using namespace jtx;
1578 using namespace std::chrono_literals;
1579
1580 // A SigningPubKey that is not a public key at all.
1581 {
1582 Env env{*this, features};
1583
1584 Account const alice{"alice"};
1585 Account const target{"target"};
1586 Account const bob{"bob"};
1587 env.fund(XRP(10000), alice, target, bob);
1588 env.close();
1589 proposal::authorizeProposer(env, target, alice);
1590
1591 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1592 json::Value const payload =
1593 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
1594 makeProposal(env, alice, payload);
1595
1596 auto const jt = env.jt(payload);
1597 if (!BEAST_EXPECT(jt.stx))
1598 return;
1599
1600 STObject mutated{*jt.stx};
1601 std::string const badKey{"badkey"};
1602 mutated.at(sfSigningPubKey) = makeSlice(badKey);
1603 auto const stx = rebuilt(mutated);
1604
1605 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
1606 auto const result = xrpl::apply(env.app(), view, *stx, TapNone, j);
1607 BEAST_EXPECT(result.ter == temBAD_SIGNATURE);
1608 BEAST_EXPECT(!result.applied);
1609 return result.applied;
1610 });
1611 }
1612
1613 // A signature that is structurally fine but was made over a different
1614 // key's identity: bob's signature presented under the target's
1615 // SigningPubKey. This is the case a malformed-key check cannot catch.
1616 {
1617 Env env{*this, features};
1618
1619 Account const alice{"alice"};
1620 Account const target{"target"};
1621 Account const bob{"bob"};
1622 env.fund(XRP(10000), alice, target, bob);
1623 env.close();
1624 proposal::authorizeProposer(env, target, alice);
1625
1626 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1627 json::Value const payload =
1628 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq);
1629 makeProposal(env, alice, payload);
1630
1631 auto const jt = env.jt(payload);
1632 auto const jtOther = env.jt(payload, Sig(bob));
1633 if (!BEAST_EXPECT(jt.stx && jtOther.stx))
1634 return;
1635
1636 STObject mutated{*jt.stx};
1637 Blob const otherSig = jtOther.stx->getFieldVL(sfTxnSignature);
1638 mutated.at(sfTxnSignature) = makeSlice(otherSig);
1639 auto const stx = rebuilt(mutated);
1640
1641 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
1642 auto const result = xrpl::apply(env.app(), view, *stx, TapNone, j);
1643 BEAST_EXPECT(result.ter == temINVALID);
1644 BEAST_EXPECT(!result.applied);
1645 return result.applied;
1646 });
1647 }
1648 }
1649
1650 // The other way a fixed Fee stops being enough: the Fee does not change,
1651 // the ledger's price does. This one is not fatal, and it is not
1652 // telINSUF_FEE_P either — the queue holds the payload at terQUEUED rather
1653 // than rejecting it, and applies it once the escalated fee drops. So an
1654 // expensive ledger delays a completed proposal; it does not strand one.
1655 void
1657 {
1658 testcase("open-ledger fee escalation only delays the payload");
1659
1660 using namespace jtx;
1661 using namespace std::chrono_literals;
1662
1663 auto cfg = envconfig([](std::unique_ptr<Config> cfg) {
1664 auto& section = cfg->section(Sections::kTransactionQueue);
1665 // Price above two transactions per ledger, not the standalone
1666 // default of 1000, so the three fillers below escalate the fee.
1667 section.set(Keys::kMinimumTxnInLedgerStandalone, "2");
1668 return cfg;
1669 });
1670 Env env{*this, std::move(cfg), features};
1671
1672 Account const alice{"alice"};
1673 Account const target{"target"};
1674 Account const bob{"bob"};
1675
1676 // Funded one at a time: with a target of two transactions per ledger,
1677 // funding them together would itself escalate the fee.
1678 env.fund(XRP(10000), alice);
1679 env.close();
1680 env.fund(XRP(10000), target);
1681 env.close();
1682 env.fund(XRP(10000), bob);
1683 env.close();
1684
1685 proposal::authorizeProposer(env, target, alice);
1686
1687 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
1688
1689 // Name the Fee rather than letting fillFee supply it: the whole case
1690 // turns on the payload being priced at the base fee while the ledger
1691 // around it is not.
1692 auto const baseFee = env.current()->fees().base;
1693 json::Value proposedTx = pay(target, bob, XRP(1));
1694 proposedTx[jss::Fee] = std::to_string(baseFee.drops());
1695 json::Value const payload = proposal::unsignedPayload(env, proposedTx, ticketSeq);
1696 makeProposal(env, alice, payload);
1697
1698 // Fill the open ledger past its target so the next transaction is
1699 // priced above the base fee the payload was created with.
1700 env(noop(alice));
1701 env(noop(alice));
1702 env(noop(alice));
1703
1704 // Both sides of the shortfall, so terQUEUED below rests on asserted
1705 // facts rather than on the tuning above having worked: the stored
1706 // payload is priced at the base fee, and the open ledger now charges
1707 // more than that.
1708 auto const sleProposal = proposal::entry(env, target, ticketSeq);
1709 if (!BEAST_EXPECT(sleProposal))
1710 return;
1711 BEAST_EXPECT(
1712 sleProposal->getFieldObject(sfProposedTransaction).getFieldAmount(sfFee).xrp() ==
1713 baseFee);
1714 BEAST_EXPECT(
1715 toDrops(env.app().getTxQ().getMetrics(*env.current()).openLedgerFeeLevel, baseFee) >
1716 baseFee);
1717
1718 auto const bobBefore = env.balance(bob);
1719 env(payload, Ter(terQUEUED));
1720
1721 // Still intact while queued: nothing has been applied yet.
1722 BEAST_EXPECT(proposal::entry(env, target, ticketSeq));
1723 BEAST_EXPECT(env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1724
1725 // Closing the ledger returns the price to the base fee, and that is
1726 // what lets the queue apply a payload whose Fee was fixed there: it
1727 // goes in unchanged, resolving the proposal as any match would.
1728 env.close();
1729
1730 BEAST_EXPECT(
1731 toDrops(env.app().getTxQ().getMetrics(*env.current()).openLedgerFeeLevel, baseFee) ==
1732 baseFee);
1733
1734 BEAST_EXPECT(env.balance(bob) == bobBefore + XRP(1));
1735 BEAST_EXPECT(!proposal::entry(env, target, ticketSeq));
1736 BEAST_EXPECT(!env.le(keylet::ticket(target.id(), SeqProxy::rawTicket(ticketSeq))));
1737 BEAST_EXPECT(ownerCount(env, alice) == 0);
1738 }
1739
1740 void
1771};
1772
1773BEAST_DEFINE_TESTSUITE(TransactionProposalReservedTicket, app, xrpl);
1774
1775} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:44
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Represents a JSON value.
Definition json_value.h:121
bool modify(ModifyType const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1077
void add(Serializer &s) const override
Definition STObject.cpp:123
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
Definition SeqProxy.h:74
Slice slice() const noexcept
Definition Serializer.h:141
virtual OpenLedger & getOpenLedger()=0
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
std::string const & human() const
Returns the human readable public key.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition Env.cpp:180
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
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1058
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:723
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
Definition Env.cpp:201
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 a multisignature on a JTx.
Definition multisign.h:53
Set the regular signature on a JTx.
Definition sig.h:19
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
Adds an inner Batch transaction to a JTx and autofills it.
Definition batch.h:91
Sets the Batch transaction signers on a JTx.
Definition batch.h:142
Set a ticket sequence on a JTx.
Definition ticket.h:36
T make_shared(T... args)
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:360
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Definition Indexes.cpp:378
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Definition Indexes.cpp:344
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
bool payloadMatches(STObject const &proposedTx, STObject const &tx)
Whether tx carries the same payload as a proposal's stored ProposedTransaction (On-Chain Cosigner spe...
json::Value outer(jtx::Account const &account, uint32_t seq, STAmount const &fee, std::uint32_t flags)
Build an outer Batch transaction JSON object.
Definition batch.cpp:55
XRPAmount calcBatchFee(jtx::Env const &env, uint32_t const &numSigners, uint32_t const &txns=0)
Calculate the expected outer Batch transaction fee.
Definition batch.cpp:37
json::Value set(AccountID const &account, UInt256 const &loanBrokerID, Number principalRequested, std::uint32_t flags)
Create create()
Check the ledger effects a TransactionProposalCreate must have, whatever its outcome: on tesSUCCESS a...
Definition proposal.h:89
json::Value innerTx(json::Value tx, std::uint32_t seq)
Put a transaction into the form an inner transaction of a proposed Batch takes, as batch::Inner does ...
Definition proposal.cpp:80
std::uint32_t createTicket(Env &env, Account const &account, std::uint32_t count)
Create tickets for a proposal to be built against, and close the ledger.
Definition proposal.cpp:128
json::Value unsignedPayload(Env const &env, json::Value tx, std::uint32_t ticketSeq)
Put a transaction of any type into the form a proposal stores it in: unsigned and ticket-based,...
Definition proposal.cpp:61
constexpr std::uint32_t kBatchProposalOwnerCount
Owner-reserve increments held by a proposal of a Batch transaction.
constexpr std::uint32_t kProposalOwnerCount
Owner-reserve increments held by a proposal of an ordinary transaction.
SLE::const_pointer entry(Env const &env, AccountID const &target, std::uint32_t ticketSeq)
The proposal stored against a target account's ticket.
Definition proposal.cpp:145
json::Value create(Account const &proposer, json::Value const &proposedTx, std::uint32_t expiration)
Build a TransactionProposalCreate carrying an unsigned proposed transaction.
Definition proposal.cpp:40
void authorizeProposer(Env &env, Account const &target, Account const &proposer)
Give proposer a place on target's SignerList, so it may create proposals against target.
Definition proposal.cpp:121
json::Value unsignedBatch(Env const &env, Account const &target, std::uint32_t ticketSeq, std::uint32_t flags, std::vector< json::Value > const &inners, std::optional< std::uint32_t > numSigners)
An unsigned outer Batch payload holding inners.
Definition proposal.cpp:86
std::uint32_t expiration(Env &env, NetClock::duration delta)
An absolute expiration delta past the environment's current time.
Definition proposal.cpp:139
json::Value cancel(Account const &account, uint256 const &proposalID)
Build a TransactionProposalCancel naming the proposal to delete.
Definition proposal.cpp:51
json::Value transfer(jtx::Account const &account, uint32_t flags, std::optional< UInt256 > const &index)
Definition sponsor.cpp:52
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
Definition ticket.cpp:16
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
json::Value regkey(Account const &account, DisabledT)
Disable the regular key.
Definition regkey.cpp:13
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
json::Value noop(Account const &account)
The null transaction.
Definition noop.h:14
std::uint32_t ownerCount(Env const &env, Account const &account)
std::uint32_t sponsoringOwnerCount(Env const &env, Account const &account)
FeatureBitset testableAmendments()
Definition Env.h:92
json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
void incLgrSeqForAccDel(jtx::Env &env, jtx::Account const &acc, std::uint32_t margin=0)
std::uint32_t sponsoredOwnerCount(Env const &env, Account const &account)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
json::Value signers(Account const &account, std::uint32_t quorum, std::vector< Signer > const &v)
Definition multisign.cpp:31
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:15
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr FlagValue spfSponsorFee
Definition TxFlags.h:467
@ telINSUF_FEE_P
Definition TER.h:43
@ terTICKET_RESERVED
Definition TER.h:235
@ terQUEUED
Definition TER.h:227
ApplyResult apply(ServiceRegistry &registry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition apply.cpp:181
@ tefBAD_QUORUM
Definition TER.h:174
@ tefMAX_LEDGER
Definition TER.h:172
@ tefMASTER_DISABLED
Definition TER.h:171
@ tefBAD_SIGNATURE
Definition TER.h:173
@ tefBAD_AUTH
Definition TER.h:163
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
Definition TxQ.h:1011
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
@ TapNone
Definition ApplyView.h:28
@ temINVALID
Definition TER.h:98
@ temMALFORMED
Definition TER.h:75
@ temBAD_SIGNATURE
Definition TER.h:93
@ temBAD_SIGNER
Definition TER.h:103
@ tecUNFUNDED_PAYMENT
Definition TER.h:296
@ tecNO_ENTRY
Definition TER.h:317
@ tecHAS_OBLIGATIONS
Definition TER.h:328
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
constexpr FlagValue spfSponsorReserve
Definition TxFlags.h:468
UInt256 uint256
Definition base_uint.h:587
static constexpr auto kMinimumTxnInLedgerStandalone
Definition Constants.h:137
static constexpr auto kTransactionQueue
Definition Constants.h:66
static std::shared_ptr< STTx const > rebuilt(STObject const &tx)
static void makeProposal(jtx::Env &env, jtx::Account const &proposer, json::Value const &payload)
json::Value jv
Definition JTx.h:28
T to_string(T... args)