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