xrpld
Loading...
Searching...
No Matches
NFTokenBurn_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/acctdelete.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/fee.h>
8#include <test/jtx/owners.h> // IWYU pragma: keep
9#include <test/jtx/ter.h>
10#include <test/jtx/token.h>
11#include <test/jtx/txflags.h>
12#include <test/unit_test/SuiteJournal.h>
13
14#include <xrpl/basics/base_uint.h>
15#include <xrpl/beast/unit_test/suite.h>
16#include <xrpl/beast/utility/Journal.h>
17#include <xrpl/json/json_forwards.h>
18#include <xrpl/json/json_value.h>
19#include <xrpl/json/to_string.h>
20#include <xrpl/ledger/ApplyView.h>
21#include <xrpl/ledger/OpenView.h>
22#include <xrpl/protocol/Feature.h>
23#include <xrpl/protocol/Indexes.h>
24#include <xrpl/protocol/Protocol.h>
25#include <xrpl/protocol/SField.h>
26#include <xrpl/protocol/STObject.h>
27#include <xrpl/protocol/STTx.h>
28#include <xrpl/protocol/SeqProxy.h>
29#include <xrpl/protocol/TER.h>
30#include <xrpl/protocol/TxFlags.h>
31#include <xrpl/protocol/TxFormats.h>
32#include <xrpl/protocol/jss.h>
33#include <xrpl/protocol/nft.h>
34#include <xrpl/tx/ApplyContext.h>
35#include <xrpl/tx/invariants/InvariantRunner.h>
36
37#include <algorithm>
38#include <cstddef>
39#include <cstdint>
40#include <iostream>
41#include <ostream>
42#include <random>
43#include <vector>
44
45namespace xrpl {
46
48{
49 // Helper function that returns the number of nfts owned by an account.
50 static std::uint32_t
52 {
53 json::Value params;
54 params[jss::account] = acct.human();
55 params[jss::type] = "state";
56 json::Value nfts = env.rpc("json", "account_nfts", to_string(params));
57 return nfts[jss::result][jss::account_nfts].size();
58 };
59
60 // Helper function that returns new nft id for an account and create
61 // specified number of sell offers
62 static UInt256
64 test::jtx::Env& env,
65 test::jtx::Account const& owner,
66 std::vector<UInt256>& offerIndexes,
67 size_t const tokenCancelCount)
68 {
69 using namespace test::jtx;
70 UInt256 const nftokenID = token::getNextID(env, owner, 0, tfTransferable);
71 env(token::mint(owner, 0),
72 token::Uri(std::string(kMaxTokenUriLength, 'u')),
73 Txflags(tfTransferable));
74 env.close();
75
76 offerIndexes.reserve(tokenCancelCount);
77
78 for (uint32_t i = 0; i < tokenCancelCount; ++i)
79 {
80 // Create sell offer
81 offerIndexes.push_back(
82 keylet::nftokenOffer(owner, SeqProxy::rawSequence(env.seq(owner))).key);
83 env(token::createOffer(owner, nftokenID, drops(1)), Txflags(tfSellNFToken));
84 env.close();
85 }
86
87 return nftokenID;
88 };
89
90 // printNFTPages is a helper function that may be used for debugging.
91 //
92 // It uses the ledger RPC command to show the NFT pages in the ledger.
93 // This parameter controls how noisy the output is.
94 enum class Volume : bool {
95 Quiet = false,
96 Noisy = true,
97 };
98
99 static void
101 {
102 json::Value jvParams;
103 jvParams[jss::ledger_index] = "current";
104 jvParams[jss::binary] = false;
105 {
106 json::Value jrr = env.rpc("json", "ledger_data", to_string(jvParams));
107
108 // Iterate the state and print all NFTokenPages.
109 if (!jrr.isMember(jss::result) || !jrr[jss::result].isMember(jss::state))
110 {
111 std::cout << "No ledger state found!" << std::endl;
112 return;
113 }
114 json::Value& state = jrr[jss::result][jss::state];
115 if (!state.isArray())
116 {
117 std::cout << "Ledger state is not array!" << std::endl;
118 return;
119 }
120 for (auto& i : state)
121 {
122 if (i.isMember(sfNFTokens.jsonName) && i[sfNFTokens.jsonName].isArray())
123 {
124 std::uint32_t const tokenCount = i[sfNFTokens.jsonName].size();
125 std::cout << tokenCount << " NFtokens in page " << i[jss::index].asString()
126 << std::endl;
127
128 if (vol == Volume::Noisy)
129 {
130 std::cout << i.toStyledString() << std::endl;
131 }
132 else
133 {
134 if (tokenCount > 0)
135 {
136 std::cout << "first: " << i[sfNFTokens.jsonName][0u].toStyledString()
137 << std::endl;
138 }
139 if (tokenCount > 1)
140 {
141 std::cout << "last: "
142 << i[sfNFTokens.jsonName][tokenCount - 1].toStyledString()
143 << std::endl;
144 }
145 }
146 }
147 }
148 }
149 }
150
151 void
153 {
154 // Exercise a number of conditions with NFT burning.
155 testcase("Burn random");
156
157 using namespace test::jtx;
158
159 Env env{*this, features};
160
161 // Keep information associated with each account together.
162 struct AcctStat
163 {
164 test::jtx::Account const acct;
166
167 AcctStat(char const* name) : acct(name)
168 {
169 }
170
171 operator test::jtx::Account() const
172 {
173 return acct;
174 }
175 };
176 AcctStat alice{"alice"};
177 AcctStat becky{"becky"};
178 AcctStat minter{"minter"};
179
180 env.fund(XRP(10000), alice, becky, minter);
181 env.close();
182
183 // Both alice and minter mint nfts in case that makes any difference.
184 env(token::setMinter(alice, minter));
185 env.close();
186
187 // Create enough NFTs that alice, becky, and minter can all have
188 // at least three pages of NFTs. This will cause more activity in
189 // the page coalescing code. If we make 210 NFTs in total, we can
190 // have alice and minter each make 105. That will allow us to
191 // distribute 70 NFTs to our three participants.
192 //
193 // Give each NFT a pseudo-randomly chosen fee so the NFTs are
194 // distributed pseudo-randomly through the pages. This should
195 // prevent alice's and minter's NFTs from clustering together
196 // in becky's directory.
197 //
198 // Use a default initialized mersenne_twister because we want the
199 // effect of random numbers, but we want the test to run the same
200 // way each time.
201 // NOLINTNEXTLINE(bugprone-random-generator-seed): fixed seed for reproducible test
202 std::mt19937 engine;
204 decltype(kMaxTransferFee){}, kMaxTransferFee);
205
206 alice.nfts.reserve(105);
207 while (alice.nfts.size() < 105)
208 {
209 std::uint16_t const xferFee = feeDist(engine);
210 alice.nfts.push_back(
211 token::getNextID(env, alice, 0u, tfTransferable | tfBurnable, xferFee));
212 env(token::mint(alice), Txflags(tfTransferable | tfBurnable), token::XferFee(xferFee));
213 env.close();
214 }
215
216 minter.nfts.reserve(105);
217 while (minter.nfts.size() < 105)
218 {
219 std::uint16_t const xferFee = feeDist(engine);
220 minter.nfts.push_back(
221 token::getNextID(env, alice, 0u, tfTransferable | tfBurnable, xferFee));
222 env(token::mint(minter),
223 Txflags(tfTransferable | tfBurnable),
224 token::XferFee(xferFee),
225 token::Issuer(alice));
226 env.close();
227 }
228
229 // All of the NFTs are now minted. Transfer 35 each over to becky so
230 // we end up with 70 NFTs in each account.
231 becky.nfts.reserve(70);
232 {
233 auto aliceIter = alice.nfts.begin();
234 auto minterIter = minter.nfts.begin();
235 while (becky.nfts.size() < 70)
236 {
237 // We do the same work on alice and minter, so make a lambda.
238 auto const xferNFT = [&env, &becky](AcctStat& acct, auto& iter) {
239 UInt256 const offerIndex =
240 keylet::nftokenOffer(acct.acct, SeqProxy::rawSequence(env.seq(acct.acct)))
241 .key;
242 env(token::createOffer(acct, *iter, XRP(0)), Txflags(tfSellNFToken));
243 env.close();
244 env(token::acceptSellOffer(becky, offerIndex));
245 env.close();
246 becky.nfts.push_back(*iter);
247 iter = acct.nfts.erase(iter);
248 iter += 2;
249 };
250 xferNFT(alice, aliceIter);
251 xferNFT(minter, minterIter);
252 }
253 BEAST_EXPECT(aliceIter == alice.nfts.end());
254 BEAST_EXPECT(minterIter == minter.nfts.end());
255 }
256
257 // Now all three participants have 70 NFTs.
258 BEAST_EXPECT(nftCount(env, alice.acct) == 70);
259 BEAST_EXPECT(nftCount(env, becky.acct) == 70);
260 BEAST_EXPECT(nftCount(env, minter.acct) == 70);
261
262 // Next we'll create offers for all of those NFTs. This calls for
263 // another lambda.
264 auto const addOffers = [&env](AcctStat& owner, AcctStat& other1, AcctStat& other2) {
265 for (UInt256 const nft : owner.nfts)
266 {
267 // Create sell offers for owner.
268 env(token::createOffer(owner, nft, drops(1)),
269 Txflags(tfSellNFToken),
270 token::Destination(other1));
271 env(token::createOffer(owner, nft, drops(1)),
272 Txflags(tfSellNFToken),
273 token::Destination(other2));
274 env.close();
275
276 // Create buy offers for other1 and other2.
277 env(token::createOffer(other1, nft, drops(1)), token::Owner(owner));
278 env(token::createOffer(other2, nft, drops(1)), token::Owner(owner));
279 env.close();
280
281 env(token::createOffer(other2, nft, drops(2)), token::Owner(owner));
282 env(token::createOffer(other1, nft, drops(2)), token::Owner(owner));
283 env.close();
284 }
285 };
286 addOffers(alice, becky, minter);
287 addOffers(becky, minter, alice);
288 addOffers(minter, alice, becky);
289 BEAST_EXPECT(ownerCount(env, alice) == 424);
290 BEAST_EXPECT(ownerCount(env, becky) == 424);
291 BEAST_EXPECT(ownerCount(env, minter) == 424);
292
293 // Now each of the 270 NFTs has six offers associated with it.
294 // Randomly select an NFT out of the pile and burn it. Continue
295 // the process until all NFTs are burned.
296 AcctStat* const stats[3] = {&alice, &becky, &minter};
299
300 while (!stats[0]->nfts.empty() || !stats[1]->nfts.empty() || !stats[2]->nfts.empty())
301 {
302 // Pick an account to burn an nft. If there are no nfts left
303 // pick again.
304 AcctStat& owner = *stats[acctDist(engine)];
305 if (owner.nfts.empty())
306 continue;
307
308 // Pick one of the nfts.
309 std::uniform_int_distribution<std::size_t> nftDist(0lu, owner.nfts.size() - 1);
310 auto const nftIter = owner.nfts.begin() + nftDist(engine);
311 UInt256 const nft = *nftIter;
312 owner.nfts.erase(nftIter);
313
314 // Decide which of the accounts should burn the nft. If the
315 // owner is becky then any of the three accounts can burn.
316 // Otherwise either alice or minter can burn.
317 AcctStat const& burner = [&] -> AcctStat& {
318 if (owner.acct == becky.acct)
319 return *stats[acctDist(engine)];
320 return mintDist(engine) ? alice : minter;
321 }();
322
323 if (owner.acct == burner.acct)
324 {
325 env(token::burn(burner, nft));
326 }
327 else
328 {
329 env(token::burn(burner, nft), token::Owner(owner));
330 }
331 env.close();
332
333 // Every time we burn an nft, the number of nfts they hold should
334 // match the number of nfts we think they hold.
335 BEAST_EXPECT(nftCount(env, alice.acct) == alice.nfts.size());
336 BEAST_EXPECT(nftCount(env, becky.acct) == becky.nfts.size());
337 BEAST_EXPECT(nftCount(env, minter.acct) == minter.nfts.size());
338 }
339 BEAST_EXPECT(nftCount(env, alice.acct) == 0);
340 BEAST_EXPECT(nftCount(env, becky.acct) == 0);
341 BEAST_EXPECT(nftCount(env, minter.acct) == 0);
342
343 // When all nfts are burned kNone of the accounts should have
344 // an ownerCount.
345 BEAST_EXPECT(ownerCount(env, alice) == 0);
346 BEAST_EXPECT(ownerCount(env, becky) == 0);
347 BEAST_EXPECT(ownerCount(env, minter) == 0);
348 }
349
350 void
352 {
353 // The earlier burn test randomizes which nft is burned. There are
354 // a couple of directory merging scenarios that can only be tested by
355 // inserting and deleting in an ordered fashion. We do that testing
356 // now.
357 testcase("Burn sequential");
358
359 using namespace test::jtx;
360
361 Account const alice{"alice"};
362
363 Env env{*this, features};
364 env.fund(XRP(1000), alice);
365
366 // A lambda that generates 96 nfts packed into three pages of 32 each.
367 // Returns a sorted vector of the NFTokenIDs packed into the pages.
368 auto const genPackedTokens = [this, &env, &alice] {
370 nfts.reserve(96);
371
372 // We want to create fully packed NFT pages. This is a little
373 // tricky since the system currently in place is inclined to
374 // assign consecutive tokens to only 16 entries per page.
375 //
376 // By manipulating the internal form of the taxon we can force
377 // creation of NFT pages that are completely full. This lambda
378 // tells us the taxon value we should pass in in order for the
379 // internal representation to match the passed in value.
380 auto const internalTaxon =
381 [&env](Account const& acct, std::uint32_t taxon) -> std::uint32_t {
382 std::uint32_t tokenSeq = env.le(acct)->at(~sfMintedNFTokens).value_or(0);
383
384 // We must add FirstNFTokenSequence.
385 tokenSeq += env.le(acct)->at(~sfFirstNFTokenSequence).value_or(env.seq(acct));
386
387 return toUInt32(nft::cipheredTaxon(tokenSeq, nft::toTaxon(taxon)));
388 };
389
390 for (std::uint32_t i = 0; i < 96; ++i)
391 {
392 // In order to fill the pages we use the taxon to break them
393 // into groups of 16 entries. By having the internal
394 // representation of the taxon go...
395 // 0, 3, 2, 5, 4, 7...
396 // in sets of 16 NFTs we can get each page to be fully
397 // populated.
398 std::uint32_t const intTaxon = (i / 16) + (i & 0b10000 ? 2 : 0);
399 uint32_t const extTaxon = internalTaxon(alice, intTaxon);
400 nfts.push_back(token::getNextID(env, alice, extTaxon));
401 env(token::mint(alice, extTaxon));
402 env.close();
403 }
404
405 // Sort the NFTs so they are listed in storage order, not
406 // creation order.
407 std::ranges::sort(nfts);
408
409 // Verify that the ledger does indeed contain exactly three pages
410 // of NFTs with 32 entries in each page.
411 json::Value jvParams;
412 jvParams[jss::ledger_index] = "current";
413 jvParams[jss::binary] = false;
414 {
415 json::Value jrr = env.rpc("json", "ledger_data", to_string(jvParams));
416
417 json::Value& state = jrr[jss::result][jss::state];
418
419 int pageCount = 0;
420 for (auto& i : state)
421 {
422 if (i.isMember(sfNFTokens.jsonName) && i[sfNFTokens.jsonName].isArray())
423 {
424 BEAST_EXPECT(i[sfNFTokens.jsonName].size() == 32);
425 ++pageCount;
426 }
427 }
428 // If this check fails then the internal NFT directory logic
429 // has changed.
430 BEAST_EXPECT(pageCount == 3);
431 }
432 return nfts;
433 };
434 {
435 // Generate three packed pages. Then burn the tokens in order from
436 // first to last. This exercises specific cases where coalescing
437 // pages is not possible.
438 std::vector<UInt256> const nfts = genPackedTokens();
439 BEAST_EXPECT(nftCount(env, alice) == 96);
440 BEAST_EXPECT(ownerCount(env, alice) == 3);
441
442 for (UInt256 const& nft : nfts)
443 {
444 env(token::burn(alice, {nft}));
445 env.close();
446 }
447 BEAST_EXPECT(nftCount(env, alice) == 0);
448 BEAST_EXPECT(ownerCount(env, alice) == 0);
449 }
450
451 // A lambda verifies that the ledger no longer contains any NFT pages.
452 auto const checkNoTokenPages = [this, &env] {
453 json::Value jvParams;
454 jvParams[jss::ledger_index] = "current";
455 jvParams[jss::binary] = false;
456 {
457 json::Value jrr = env.rpc("json", "ledger_data", to_string(jvParams));
458
459 json::Value const& state = jrr[jss::result][jss::state];
460
461 for (auto const& i : state)
462 {
463 BEAST_EXPECT(!i.isMember(sfNFTokens.jsonName));
464 }
465 }
466 };
467 checkNoTokenPages();
468 {
469 // Generate three packed pages. Then burn the tokens in order from
470 // last to first. This exercises different specific cases where
471 // coalescing pages is not possible.
472 std::vector<UInt256> nfts = genPackedTokens();
473 BEAST_EXPECT(nftCount(env, alice) == 96);
474 BEAST_EXPECT(ownerCount(env, alice) == 3);
475
476 // Verify that that all three pages are present and remember the
477 // indexes.
478 auto lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
479 if (!BEAST_EXPECT(lastNFTokenPage))
480 return;
481
482 UInt256 const middleNFTokenPageIndex = lastNFTokenPage->at(sfPreviousPageMin);
483 auto middleNFTokenPage =
484 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
485 if (!BEAST_EXPECT(middleNFTokenPage))
486 return;
487
488 UInt256 const firstNFTokenPageIndex = middleNFTokenPage->at(sfPreviousPageMin);
489 auto firstNFTokenPage =
490 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
491 if (!BEAST_EXPECT(firstNFTokenPage))
492 return;
493
494 // Burn almost all the tokens in the very last page.
495 for (int i = 0; i < 31; ++i)
496 {
497 env(token::burn(alice, {nfts.back()}));
498 nfts.pop_back();
499 env.close();
500 }
501
502 // Verify that the last page is still present and contains just one
503 // NFT.
504 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
505 if (!BEAST_EXPECT(lastNFTokenPage))
506 return;
507
508 BEAST_EXPECT(lastNFTokenPage->getFieldArray(sfNFTokens).size() == 1);
509 BEAST_EXPECT(lastNFTokenPage->isFieldPresent(sfPreviousPageMin));
510 BEAST_EXPECT(!lastNFTokenPage->isFieldPresent(sfNextPageMin));
511
512 // Delete the last token from the last page.
513 env(token::burn(alice, {nfts.back()}));
514 nfts.pop_back();
515 env.close();
516
517 if (features[fixNFTokenPageLinks])
518 {
519 // Removing the last token from the last page deletes the
520 // _previous_ page because we need to preserve that last
521 // page as an anchor. The contents of the next-to-last page
522 // are moved into the last page.
523 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
524 BEAST_EXPECT(lastNFTokenPage);
525 BEAST_EXPECT(lastNFTokenPage->at(~sfPreviousPageMin) == firstNFTokenPageIndex);
526 BEAST_EXPECT(!lastNFTokenPage->isFieldPresent(sfNextPageMin));
527 BEAST_EXPECT(lastNFTokenPage->getFieldArray(sfNFTokens).size() == 32);
528
529 // The "middle" page should be gone.
530 middleNFTokenPage = env.le(
531 keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
532 BEAST_EXPECT(!middleNFTokenPage);
533
534 // The "first" page should still be present and linked to
535 // the last page.
536 firstNFTokenPage = env.le(
537 keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
538 BEAST_EXPECT(firstNFTokenPage);
539 BEAST_EXPECT(!firstNFTokenPage->isFieldPresent(sfPreviousPageMin));
540 BEAST_EXPECT(firstNFTokenPage->at(~sfNextPageMin) == lastNFTokenPage->key());
541 BEAST_EXPECT(lastNFTokenPage->getFieldArray(sfNFTokens).size() == 32);
542 }
543 else
544 {
545 // Removing the last token from the last page deletes the last
546 // page. This is a bug. The contents of the next-to-last page
547 // should have been moved into the last page.
548 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
549 BEAST_EXPECT(!lastNFTokenPage);
550
551 // The "middle" page is still present, but has lost the
552 // NextPageMin field.
553 middleNFTokenPage = env.le(
554 keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
555 if (!BEAST_EXPECT(middleNFTokenPage))
556 return;
557 BEAST_EXPECT(middleNFTokenPage->isFieldPresent(sfPreviousPageMin));
558 BEAST_EXPECT(!middleNFTokenPage->isFieldPresent(sfNextPageMin));
559 }
560
561 // Delete the rest of the NFTokens.
562 while (!nfts.empty())
563 {
564 env(token::burn(alice, {nfts.back()}));
565 nfts.pop_back();
566 env.close();
567 }
568 BEAST_EXPECT(nftCount(env, alice) == 0);
569 BEAST_EXPECT(ownerCount(env, alice) == 0);
570 }
571 checkNoTokenPages();
572 {
573 // Generate three packed pages. Then burn all tokens in the middle
574 // page. This exercises the case where a page is removed between
575 // two fully populated pages.
576 std::vector<UInt256> nfts = genPackedTokens();
577 BEAST_EXPECT(nftCount(env, alice) == 96);
578 BEAST_EXPECT(ownerCount(env, alice) == 3);
579
580 // Verify that that all three pages are present and remember the
581 // indexes.
582 auto lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
583 if (!BEAST_EXPECT(lastNFTokenPage))
584 return;
585
586 UInt256 const middleNFTokenPageIndex = lastNFTokenPage->at(sfPreviousPageMin);
587 auto middleNFTokenPage =
588 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
589 if (!BEAST_EXPECT(middleNFTokenPage))
590 return;
591
592 UInt256 const firstNFTokenPageIndex = middleNFTokenPage->at(sfPreviousPageMin);
593 auto firstNFTokenPage =
594 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
595 if (!BEAST_EXPECT(firstNFTokenPage))
596 return;
597
598 for (std::size_t i = 32; i < 64; ++i)
599 {
600 env(token::burn(alice, nfts[i]));
601 env.close();
602 }
603 nfts.erase(nfts.begin() + 32, nfts.begin() + 64);
604 BEAST_EXPECT(nftCount(env, alice) == 64);
605 BEAST_EXPECT(ownerCount(env, alice) == 2);
606
607 // Verify that middle page is gone and the links in the two
608 // remaining pages are correct.
609 middleNFTokenPage =
610 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
611 BEAST_EXPECT(!middleNFTokenPage);
612
613 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
614 BEAST_EXPECT(!lastNFTokenPage->isFieldPresent(sfNextPageMin));
615 BEAST_EXPECT(lastNFTokenPage->getFieldH256(sfPreviousPageMin) == firstNFTokenPageIndex);
616
617 firstNFTokenPage =
618 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
619 BEAST_EXPECT(
620 firstNFTokenPage->getFieldH256(sfNextPageMin) == keylet::nftokenPageMax(alice).key);
621 BEAST_EXPECT(!firstNFTokenPage->isFieldPresent(sfPreviousPageMin));
622
623 // Burn the remaining nfts.
624 for (UInt256 const& nft : nfts)
625 {
626 env(token::burn(alice, {nft}));
627 env.close();
628 }
629 BEAST_EXPECT(nftCount(env, alice) == 0);
630 BEAST_EXPECT(ownerCount(env, alice) == 0);
631 }
632 checkNoTokenPages();
633 {
634 // Generate three packed pages. Then burn all the tokens in the
635 // first page followed by all the tokens in the last page. This
636 // exercises a specific case where coalescing pages is not possible.
637 std::vector<UInt256> nfts = genPackedTokens();
638 BEAST_EXPECT(nftCount(env, alice) == 96);
639 BEAST_EXPECT(ownerCount(env, alice) == 3);
640
641 // Verify that that all three pages are present and remember the
642 // indexes.
643 auto lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
644 if (!BEAST_EXPECT(lastNFTokenPage))
645 return;
646
647 UInt256 const middleNFTokenPageIndex = lastNFTokenPage->at(sfPreviousPageMin);
648 auto middleNFTokenPage =
649 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
650 if (!BEAST_EXPECT(middleNFTokenPage))
651 return;
652
653 UInt256 const firstNFTokenPageIndex = middleNFTokenPage->at(sfPreviousPageMin);
654 auto firstNFTokenPage =
655 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
656 if (!BEAST_EXPECT(firstNFTokenPage))
657 return;
658
659 // Burn all the tokens in the first page.
661 for (int i = 0; i < 32; ++i)
662 {
663 env(token::burn(alice, {nfts.back()}));
664 nfts.pop_back();
665 env.close();
666 }
667
668 // Verify the first page is gone.
669 firstNFTokenPage =
670 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
671 BEAST_EXPECT(!firstNFTokenPage);
672
673 // Check the links in the other two pages.
674 middleNFTokenPage =
675 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
676 if (!BEAST_EXPECT(middleNFTokenPage))
677 return;
678 BEAST_EXPECT(!middleNFTokenPage->isFieldPresent(sfPreviousPageMin));
679 BEAST_EXPECT(middleNFTokenPage->isFieldPresent(sfNextPageMin));
680
681 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
682 if (!BEAST_EXPECT(lastNFTokenPage))
683 return;
684 BEAST_EXPECT(lastNFTokenPage->isFieldPresent(sfPreviousPageMin));
685 BEAST_EXPECT(!lastNFTokenPage->isFieldPresent(sfNextPageMin));
686
687 // Burn all the tokens in the last page.
689 for (int i = 0; i < 32; ++i)
690 {
691 env(token::burn(alice, {nfts.back()}));
692 nfts.pop_back();
693 env.close();
694 }
695
696 if (features[fixNFTokenPageLinks])
697 {
698 // Removing the last token from the last page deletes the
699 // _previous_ page because we need to preserve that last
700 // page as an anchor. The contents of the next-to-last page
701 // are moved into the last page.
702 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
703 BEAST_EXPECT(lastNFTokenPage);
704 BEAST_EXPECT(!lastNFTokenPage->isFieldPresent(sfPreviousPageMin));
705 BEAST_EXPECT(!lastNFTokenPage->isFieldPresent(sfNextPageMin));
706 BEAST_EXPECT(lastNFTokenPage->getFieldArray(sfNFTokens).size() == 32);
707
708 // The "middle" page should be gone.
709 middleNFTokenPage = env.le(
710 keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
711 BEAST_EXPECT(!middleNFTokenPage);
712
713 // The "first" page should still be gone.
714 firstNFTokenPage = env.le(
715 keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
716 BEAST_EXPECT(!firstNFTokenPage);
717 }
718 else
719 {
720 // Removing the last token from the last page deletes the last
721 // page. This is a bug. The contents of the next-to-last page
722 // should have been moved into the last page.
723 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
724 BEAST_EXPECT(!lastNFTokenPage);
725
726 // The "middle" page is still present, but has lost the
727 // NextPageMin field.
728 middleNFTokenPage = env.le(
729 keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
730 if (!BEAST_EXPECT(middleNFTokenPage))
731 return;
732 BEAST_EXPECT(!middleNFTokenPage->isFieldPresent(sfPreviousPageMin));
733 BEAST_EXPECT(!middleNFTokenPage->isFieldPresent(sfNextPageMin));
734 }
735
736 // Delete the rest of the NFTokens.
737 while (!nfts.empty())
738 {
739 env(token::burn(alice, {nfts.back()}));
740 nfts.pop_back();
741 env.close();
742 }
743 BEAST_EXPECT(nftCount(env, alice) == 0);
744 BEAST_EXPECT(ownerCount(env, alice) == 0);
745 }
746 checkNoTokenPages();
747
748 if (features[fixNFTokenPageLinks])
749 {
750 // Exercise the invariant that the final NFTokenPage of a directory
751 // may not be removed if there are NFTokens in other pages of the
752 // directory.
753 //
754 // We're going to fire an Invariant failure that is difficult to
755 // cause. We do it here because the tools are here.
756 //
757 // See InvariantsMisc_test.cpp for examples of other invariant
758 // tests that this one is modeled after.
759
760 // Generate three closely packed NFTokenPages.
761 std::vector<UInt256> nfts = genPackedTokens();
762 BEAST_EXPECT(nftCount(env, alice) == 96);
763 BEAST_EXPECT(ownerCount(env, alice) == 3);
764
765 // Burn almost all the tokens in the very last page.
766 for (int i = 0; i < 31; ++i)
767 {
768 env(token::burn(alice, {nfts.back()}));
769 nfts.pop_back();
770 env.close();
771 }
772 {
773 // Create an ApplyContext we can use to run the invariant
774 // checks. These variables must outlive the ApplyContext.
775 OpenView ov{*env.current()};
776 STTx const tx{ttACCOUNT_SET, [](STObject&) {}};
778 beast::Journal const jlog{sink};
779 ApplyContext ac{
780 env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, TapNone, jlog};
781
782 // Verify that the last page is present and contains one NFT.
783 auto const lastNFTokenPage = ac.view().peek(keylet::nftokenPageMax(alice));
784 if (!BEAST_EXPECT(lastNFTokenPage))
785 return;
786 BEAST_EXPECT(lastNFTokenPage->getFieldArray(sfNFTokens).size() == 1);
787
788 // Erase that last page.
789 ac.view().erase(lastNFTokenPage);
790
791 // Exercise the invariant.
792 TER terActual = tesSUCCESS;
793 for (TER const& terExpect : {TER(tecINVARIANT_FAILED), TER(tefINVARIANT_FAILED)})
794 {
795 terActual = xrpl::checkInvariants(ac, terActual, XRPAmount{});
796 BEAST_EXPECT(terExpect == terActual);
797 BEAST_EXPECT(sink.messages().str().starts_with("Invariant failed:"));
798 // uncomment to log the invariant failure message
799 // log << " --> " << sink.messages().str() << std::endl;
800 BEAST_EXPECT(sink.messages().str().contains(
801 "Last NFT page deleted with non-empty directory"));
802 }
803 }
804 {
805 // Create an ApplyContext we can use to run the invariant
806 // checks. These variables must outlive the ApplyContext.
807 OpenView ov{*env.current()};
808 STTx const tx{ttACCOUNT_SET, [](STObject&) {}};
810 beast::Journal const jlog{sink};
811 ApplyContext ac{
812 env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, TapNone, jlog};
813
814 // Verify that the middle page is present.
815 auto const lastNFTokenPage = ac.view().peek(keylet::nftokenPageMax(alice));
816 auto const middleNFTokenPage = ac.view().peek(
819 lastNFTokenPage->getFieldH256(sfPreviousPageMin)));
820 BEAST_EXPECT(middleNFTokenPage);
821
822 // Remove the NextMinPage link from the middle page to fire
823 // the invariant.
824 middleNFTokenPage->makeFieldAbsent(sfNextPageMin);
825 ac.view().update(middleNFTokenPage);
826
827 // Exercise the invariant.
828 TER terActual = tesSUCCESS;
829 for (TER const& terExpect : {TER(tecINVARIANT_FAILED), TER(tefINVARIANT_FAILED)})
830 {
831 terActual = xrpl::checkInvariants(ac, terActual, XRPAmount{});
832 BEAST_EXPECT(terExpect == terActual);
833 BEAST_EXPECT(sink.messages().str().starts_with("Invariant failed:"));
834 // uncomment to log the invariant failure message
835 // log << " --> " << sink.messages().str() << std::endl;
836 BEAST_EXPECT(sink.messages().str().contains("Lost NextMinPage link"));
837 }
838 }
839 }
840 }
841
842 void
844 {
845 // Look at the case where too many offers prevents burning a token.
846 testcase("Burn too many offers");
847
848 using namespace test::jtx;
849
850 // Test that up to 499 buy/sell offers will be removed when NFT is
851 // burned. This is to test that we can successfully remove all offers
852 // if the number of offers is less than 500.
853 {
854 Env env{*this, features};
855
856 Account const alice("alice");
857 Account const becky("becky");
858 env.fund(XRP(100000), alice, becky);
859 env.close();
860
861 // alice creates 498 sell offers and becky creates 1 buy offers.
862 // When the token is burned, 498 sell offers and 1 buy offer are
863 // removed. In total, 499 offers are removed
864 std::vector<UInt256> offerIndexes;
865 auto const nftokenID =
866 createNftAndOffers(env, alice, offerIndexes, kMaxDeletableTokenOfferEntries - 2);
867
868 // Verify all sell offers are present in the ledger.
869 for (UInt256 const& offerIndex : offerIndexes)
870 {
871 BEAST_EXPECT(env.le(keylet::nftokenOffer(offerIndex)));
872 }
873
874 // Becky creates a buy offer
875 UInt256 const beckyOfferIndex =
876 keylet::nftokenOffer(becky, SeqProxy::rawSequence(env.seq(becky))).key;
877 env(token::createOffer(becky, nftokenID, drops(1)), token::Owner(alice));
878 env.close();
879
880 // Burn the token
881 env(token::burn(alice, nftokenID));
882 env.close();
883
884 // Burning the token should remove all 498 sell offers
885 // that alice created
886 for (UInt256 const& offerIndex : offerIndexes)
887 {
888 BEAST_EXPECT(!env.le(keylet::nftokenOffer(offerIndex)));
889 }
890
891 // Burning the token should also remove the one buy offer
892 // that becky created
893 BEAST_EXPECT(!env.le(keylet::nftokenOffer(beckyOfferIndex)));
894
895 // alice and becky should have ownerCounts of zero
896 BEAST_EXPECT(ownerCount(env, alice) == 0);
897 BEAST_EXPECT(ownerCount(env, becky) == 0);
898 }
899
900 // Test that up to 500 buy offers are removed when NFT is burned.
901 {
902 Env env{*this, features};
903
904 Account const alice("alice");
905 Account const becky("becky");
906 env.fund(XRP(100000), alice, becky);
907 env.close();
908
909 // alice creates 501 sell offers for the token
910 // After we burn the token, 500 of the sell offers should be
911 // removed, and one is left over
912 std::vector<UInt256> offerIndexes;
913 auto const nftokenID =
914 createNftAndOffers(env, alice, offerIndexes, kMaxDeletableTokenOfferEntries + 1);
915
916 // Verify all sell offers are present in the ledger.
917 for (UInt256 const& offerIndex : offerIndexes)
918 {
919 BEAST_EXPECT(env.le(keylet::nftokenOffer(offerIndex)));
920 }
921
922 // Burn the token
923 env(token::burn(alice, nftokenID));
924 env.close();
925
926 uint32_t offerDeletedCount = 0;
927 // Count the number of sell offers that have been deleted
928 for (UInt256 const& offerIndex : offerIndexes)
929 {
930 if (!env.le(keylet::nftokenOffer(offerIndex)))
931 offerDeletedCount++;
932 }
933
934 BEAST_EXPECT(offerIndexes.size() == kMaxTokenOfferCancelCount + 1);
935
936 // 500 sell offers should be removed
937 BEAST_EXPECT(offerDeletedCount == kMaxTokenOfferCancelCount);
938
939 // alice should have ownerCounts of one for the orphaned sell offer
940 BEAST_EXPECT(ownerCount(env, alice) == 1);
941 }
942
943 // Test that up to 500 buy/sell offers are removed when NFT is burned.
944 {
945 Env env{*this, features};
946
947 Account const alice("alice");
948 Account const becky("becky");
949 env.fund(XRP(100000), alice, becky);
950 env.close();
951
952 // alice creates 499 sell offers and becky creates 2 buy offers.
953 // When the token is burned, 499 sell offers and 1 buy offer
954 // are removed.
955 // In total, 500 offers are removed
956 std::vector<UInt256> offerIndexes;
957 auto const nftokenID =
958 createNftAndOffers(env, alice, offerIndexes, kMaxDeletableTokenOfferEntries - 1);
959
960 // Verify all sell offers are present in the ledger.
961 for (UInt256 const& offerIndex : offerIndexes)
962 {
963 BEAST_EXPECT(env.le(keylet::nftokenOffer(offerIndex)));
964 }
965
966 // becky creates 2 buy offers
967 env(token::createOffer(becky, nftokenID, drops(1)), token::Owner(alice));
968 env.close();
969 env(token::createOffer(becky, nftokenID, drops(1)), token::Owner(alice));
970 env.close();
971
972 // Burn the token
973 env(token::burn(alice, nftokenID));
974 env.close();
975
976 // Burning the token should remove all 499 sell offers from the
977 // ledger.
978 for (UInt256 const& offerIndex : offerIndexes)
979 {
980 BEAST_EXPECT(!env.le(keylet::nftokenOffer(offerIndex)));
981 }
982
983 // alice should have ownerCount of zero because all her
984 // sell offers have been deleted
985 BEAST_EXPECT(ownerCount(env, alice) == 0);
986
987 // becky has ownerCount of one due to an orphaned buy offer
988 BEAST_EXPECT(ownerCount(env, becky) == 1);
989 }
990 }
991
992 void
994 {
995 // Amendment fixNFTokenPageLinks prevents the breakage we want
996 // to observe.
997 if (features[fixNFTokenPageLinks])
998 return;
999
1000 // a couple of directory merging scenarios that can only be tested by
1001 // inserting and deleting in an ordered fashion. We do that testing
1002 // now.
1003 testcase("Exercise broken links");
1004
1005 using namespace test::jtx;
1006
1007 Account const alice{"alice"};
1008 Account const minter{"minter"};
1009
1010 Env env{*this, features};
1011 env.fund(XRP(1000), alice, minter);
1012
1013 // A lambda that generates 96 nfts packed into three pages of 32 each.
1014 // Returns a sorted vector of the NFTokenIDs packed into the pages.
1015 auto const genPackedTokens = [this, &env, &alice, &minter] {
1017 nfts.reserve(96);
1018
1019 // We want to create fully packed NFT pages. This is a little
1020 // tricky since the system currently in place is inclined to
1021 // assign consecutive tokens to only 16 entries per page.
1022 //
1023 // By manipulating the internal form of the taxon we can force
1024 // creation of NFT pages that are completely full. This lambda
1025 // tells us the taxon value we should pass in in order for the
1026 // internal representation to match the passed in value.
1027 auto const internalTaxon =
1028 [&env](Account const& acct, std::uint32_t taxon) -> std::uint32_t {
1029 std::uint32_t tokenSeq = env.le(acct)->at(~sfMintedNFTokens).value_or(0);
1030
1031 // We must add FirstNFTokenSequence.
1032 tokenSeq += env.le(acct)->at(~sfFirstNFTokenSequence).value_or(env.seq(acct));
1033
1034 return toUInt32(nft::cipheredTaxon(tokenSeq, nft::toTaxon(taxon)));
1035 };
1036
1037 for (std::uint32_t i = 0; i < 96; ++i)
1038 {
1039 // In order to fill the pages we use the taxon to break them
1040 // into groups of 16 entries. By having the internal
1041 // representation of the taxon go...
1042 // 0, 3, 2, 5, 4, 7...
1043 // in sets of 16 NFTs we can get each page to be fully
1044 // populated.
1045 std::uint32_t const intTaxon = (i / 16) + (i & 0b10000 ? 2 : 0);
1046 uint32_t const extTaxon = internalTaxon(minter, intTaxon);
1047 nfts.push_back(token::getNextID(env, minter, extTaxon, tfTransferable));
1048 env(token::mint(minter, extTaxon), Txflags(tfTransferable));
1049 env.close();
1050
1051 // Minter creates an offer for the NFToken.
1052 UInt256 const minterOfferIndex =
1053 keylet::nftokenOffer(minter, SeqProxy::rawSequence(env.seq(minter))).key;
1054 env(token::createOffer(minter, nfts.back(), XRP(0)), Txflags(tfSellNFToken));
1055 env.close();
1056
1057 // alice accepts the offer.
1058 env(token::acceptSellOffer(alice, minterOfferIndex));
1059 env.close();
1060 }
1061
1062 // Sort the NFTs so they are listed in storage order, not
1063 // creation order.
1064 std::ranges::sort(nfts);
1065
1066 // Verify that the ledger does indeed contain exactly three pages
1067 // of NFTs with 32 entries in each page.
1068 json::Value jvParams;
1069 jvParams[jss::ledger_index] = "current";
1070 jvParams[jss::binary] = false;
1071 {
1072 json::Value jrr = env.rpc("json", "ledger_data", to_string(jvParams));
1073
1074 json::Value& state = jrr[jss::result][jss::state];
1075
1076 int pageCount = 0;
1077 for (auto& i : state)
1078 {
1079 if (i.isMember(sfNFTokens.jsonName) && i[sfNFTokens.jsonName].isArray())
1080 {
1081 BEAST_EXPECT(i[sfNFTokens.jsonName].size() == 32);
1082 ++pageCount;
1083 }
1084 }
1085 // If this check fails then the internal NFT directory logic
1086 // has changed.
1087 BEAST_EXPECT(pageCount == 3);
1088 }
1089 return nfts;
1090 };
1091
1092 // Generate three packed pages.
1093 std::vector<UInt256> nfts = genPackedTokens();
1094 BEAST_EXPECT(nftCount(env, alice) == 96);
1095 BEAST_EXPECT(ownerCount(env, alice) == 3);
1096
1097 // Verify that that all three pages are present and remember the
1098 // indexes.
1099 auto lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
1100 if (!BEAST_EXPECT(lastNFTokenPage))
1101 return;
1102
1103 UInt256 const middleNFTokenPageIndex = lastNFTokenPage->at(sfPreviousPageMin);
1104 auto middleNFTokenPage =
1105 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
1106 if (!BEAST_EXPECT(middleNFTokenPage))
1107 return;
1108
1109 UInt256 const firstNFTokenPageIndex = middleNFTokenPage->at(sfPreviousPageMin);
1110 auto const firstNFTokenPage =
1111 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), firstNFTokenPageIndex));
1112 if (!BEAST_EXPECT(firstNFTokenPage))
1113 return;
1114
1115 // Sell all the tokens in the very last page back to minter.
1116 std::vector<UInt256> last32NFTs;
1117 for (int i = 0; i < 32; ++i)
1118 {
1119 last32NFTs.push_back(nfts.back());
1120 nfts.pop_back();
1121
1122 // alice creates an offer for the NFToken.
1123 UInt256 const aliceOfferIndex =
1124 keylet::nftokenOffer(alice, SeqProxy::rawSequence(env.seq(alice))).key;
1125 env(token::createOffer(alice, last32NFTs.back(), XRP(0)), Txflags(tfSellNFToken));
1126 env.close();
1127
1128 // minter accepts the offer.
1129 env(token::acceptSellOffer(minter, aliceOfferIndex));
1130 env.close();
1131 }
1132
1133 // Removing the last token from the last page deletes alice's last
1134 // page. This is a bug. The contents of the next-to-last page
1135 // should have been moved into the last page.
1136 lastNFTokenPage = env.le(keylet::nftokenPageMax(alice));
1137 BEAST_EXPECT(!lastNFTokenPage);
1138 BEAST_EXPECT(ownerCount(env, alice) == 2);
1139
1140 // The "middle" page is still present, but has lost the
1141 // NextPageMin field.
1142 middleNFTokenPage =
1143 env.le(keylet::nftokenPage(keylet::nftokenPageMin(alice), middleNFTokenPageIndex));
1144 if (!BEAST_EXPECT(middleNFTokenPage))
1145 return;
1146 BEAST_EXPECT(middleNFTokenPage->isFieldPresent(sfPreviousPageMin));
1147 BEAST_EXPECT(!middleNFTokenPage->isFieldPresent(sfNextPageMin));
1148
1149 // Attempt to delete alice's account, but fail because she owns NFTs.
1150 auto const acctDelFee{drops(env.current()->fees().increment)};
1151 env(acctdelete(alice, minter), Fee(acctDelFee), Ter(tecHAS_OBLIGATIONS));
1152 env.close();
1153
1154 // minter sells the last 32 NFTs back to alice.
1155 for (UInt256 const nftID : last32NFTs)
1156 {
1157 // minter creates an offer for the NFToken.
1158 UInt256 const minterOfferIndex =
1159 keylet::nftokenOffer(minter, SeqProxy::rawSequence(env.seq(minter))).key;
1160 env(token::createOffer(minter, nftID, XRP(0)), Txflags(tfSellNFToken));
1161 env.close();
1162
1163 // alice accepts the offer.
1164 env(token::acceptSellOffer(alice, minterOfferIndex));
1165 env.close();
1166 }
1167 BEAST_EXPECT(ownerCount(env, alice) == 3); // Three NFTokenPages.
1168
1169 // alice has an NFToken directory with a broken link in the middle.
1170 {
1171 // Try the account_objects RPC command. Alice's account only shows
1172 // two NFT pages even though she owns more.
1173 json::Value acctObjs = [&env, &alice] {
1174 json::Value params;
1175 params[jss::account] = alice.human();
1176 return env.rpc("json", "account_objects", to_string(params));
1177 }();
1178 BEAST_EXPECT(!acctObjs.isMember(jss::marker));
1179 BEAST_EXPECT(acctObjs[jss::result][jss::account_objects].size() == 2);
1180 }
1181 {
1182 // Try the account_nfts RPC command. It only returns 64 NFTs
1183 // although alice owns 96.
1184 json::Value aliceNFTs = [&env, &alice] {
1185 json::Value params;
1186 params[jss::account] = alice.human();
1187 params[jss::type] = "state";
1188 return env.rpc("json", "account_nfts", to_string(params));
1189 }();
1190 BEAST_EXPECT(!aliceNFTs.isMember(jss::marker));
1191 BEAST_EXPECT(aliceNFTs[jss::result][jss::account_nfts].size() == 64);
1192 }
1193 }
1194
1195protected:
1197
1198 void
1200 {
1201 testBurnRandom(features);
1202 testBurnSequential(features);
1203 testBurnTooManyOffers(features);
1204 exerciseBrokenLinks(features);
1205 }
1206
1207public:
1208 void
1209 run() override
1210 {
1211 testWithFeats(allFeatures_ - fixNFTokenPageLinks);
1213 }
1214};
1215
1217
1218} // namespace xrpl
T back(T... args)
T begin(T... args)
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 isArray() const
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
State information when applying a tx.
ApplyView & view()
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(SLE::Ref sle)=0
Remove a peeked SLE.
virtual void update(SLE::Ref sle)=0
Indicate changes to a peeked SLE.
void run() override
Runs the suite.
static std::uint32_t nftCount(test::jtx::Env &env, test::jtx::Account const &acct)
void testBurnRandom(FeatureBitset features)
FeatureBitset const allFeatures_
static UInt256 createNftAndOffers(test::jtx::Env &env, test::jtx::Account const &owner, std::vector< UInt256 > &offerIndexes, size_t const tokenCancelCount)
static void printNFTPages(test::jtx::Env &env, Volume vol)
void testBurnSequential(FeatureBitset features)
void exerciseBrokenLinks(FeatureBitset features)
void testBurnTooManyOffers(FeatureBitset features)
void testWithFeats(FeatureBitset features)
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
std::stringstream const & messages() const
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
std::string const & human() const
Returns the human readable public key.
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
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
T empty(T... args)
T endl(T... args)
T erase(T... args)
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:465
Keylet nftokenPage(Keylet const &k, UInt256 const &token)
Definition Indexes.cpp:458
Keylet nftokenPageMin(AccountID const &owner)
NFT page keylets.
Definition Indexes.cpp:442
Keylet nftokenPageMax(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Definition Indexes.cpp:450
Taxon toTaxon(std::uint32_t i)
Definition nft.h:21
Taxon cipheredTaxon(std::uint32_t tokenSeq, Taxon taxon)
Definition nft.h:63
FeatureBitset testableAmendments()
Definition Env.h:92
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::uint32_t ownerCount(SLE::ConstRef sle, beast::Journal j, std::int32_t ownerCountAdj=0)
Return number of the objects which reserve is covered by the account(sle) (so called "ownercount").
constexpr std::size_t kMaxTokenUriLength
The maximum length of a URI inside an NFT.
Definition Protocol.h:246
@ tefINVARIANT_FAILED
Definition TER.h:177
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
TER checkInvariants(ApplyContext &ctx, TER result, XRPAmount fee, std::optional< std::reference_wrapper< TxInvariantCheck > > txCheck)
Run all protocol invariant checks plus the transaction-specific check in a single pass over the modif...
constexpr std::size_t kMaxDeletableTokenOfferEntries
The maximum number of offers in an offer directory for NFT to be burnable.
Definition Protocol.h:85
BaseUInt< 256 > UInt256
Definition base_uint.h:581
BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBaseUtil, app, xrpl, 2)
constexpr std::size_t kMaxTokenOfferCancelCount
The maximum number of token offers that can be canceled at once.
Definition Protocol.h:80
@ TapNone
Definition ApplyView.h:28
constexpr std::uint16_t kMaxTransferFee
The maximum token transfer fee allowed.
Definition Protocol.h:97
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecINVARIANT_FAILED
Definition TER.h:324
@ tecHAS_OBLIGATIONS
Definition TER.h:328
@ tesSUCCESS
Definition TER.h:253
T pop_back(T... args)
T push_back(T... args)
T reserve(T... args)
T reverse(T... args)
T size(T... args)
T sort(T... args)
T str(T... args)
UInt256 key
Definition Keylet.h:21