xrpld
Loading...
Searching...
No Matches
NFTokenDir_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/envconfig.h>
6#include <test/jtx/owners.h> // IWYU pragma: keep
7#include <test/jtx/ter.h>
8#include <test/jtx/token.h>
9#include <test/jtx/txflags.h>
10
11#include <xrpl/basics/base_uint.h>
12#include <xrpl/beast/unit_test/suite.h>
13#include <xrpl/beast/utility/Journal.h>
14#include <xrpl/json/json_forwards.h>
15#include <xrpl/json/json_value.h>
16#include <xrpl/json/to_string.h>
17#include <xrpl/protocol/Feature.h>
18#include <xrpl/protocol/Indexes.h>
19#include <xrpl/protocol/SField.h>
20#include <xrpl/protocol/SeqProxy.h>
21#include <xrpl/protocol/TER.h>
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/jss.h>
24#include <xrpl/protocol/nft.h>
25#include <xrpl/protocol/nftPageMask.h>
26
27#include <algorithm>
28#include <array>
29#include <cstddef>
30#include <cstdint>
31#include <initializer_list>
32#include <iostream>
33#include <ostream>
34#include <set>
35#include <string_view>
36#include <vector>
37
38namespace xrpl {
39
41{
42 // printNFTPages is a helper function that may be used for debugging.
43 //
44 // It uses the ledger RPC command to show the NFT pages in the ledger.
45 // This parameter controls how noisy the output is.
46 enum class Volume : bool {
47 Quiet = false,
48 Noisy = true,
49 };
50
51 static void
53 {
54 json::Value jvParams;
55 jvParams[jss::ledger_index] = "current";
56 jvParams[jss::binary] = false;
57 {
58 json::Value jrr = env.rpc("json", "ledger_data", to_string(jvParams));
59
60 // Iterate the state and print all NFTokenPages.
61 if (!jrr.isMember(jss::result) || !jrr[jss::result].isMember(jss::state))
62 {
63 std::cout << "No ledger state found!" << std::endl;
64 return;
65 }
66 json::Value& state = jrr[jss::result][jss::state];
67 if (!state.isArray())
68 {
69 std::cout << "Ledger state is not array!" << std::endl;
70 return;
71 }
72 for (json::UInt i = 0; i < state.size(); ++i)
73 {
74 if (state[i].isMember(sfNFTokens.jsonName) &&
75 state[i][sfNFTokens.jsonName].isArray())
76 {
77 std::uint32_t const tokenCount = state[i][sfNFTokens.jsonName].size();
78 std::cout << tokenCount << " NFtokens in page "
79 << state[i][jss::index].asString() << std::endl;
80
81 if (vol == Volume::Noisy)
82 {
83 std::cout << state[i].toStyledString() << std::endl;
84 }
85 else
86 {
87 if (tokenCount > 0)
88 {
90 << "first: " << state[i][sfNFTokens.jsonName][0u].toStyledString()
91 << std::endl;
92 }
93 if (tokenCount > 1)
94 {
96 << "last: "
97 << state[i][sfNFTokens.jsonName][tokenCount - 1].toStyledString()
98 << std::endl;
99 }
100 }
101 }
102 }
103 }
104 }
105
106 void
108 {
109 // It should be possible to store many consecutive NFTs.
110 testcase("Sequential NFTs");
111
112 using namespace test::jtx;
113 Env env{*this, features};
114
115 // A single minter tends not to mint numerically sequential NFTokens
116 // because the taxon cipher mixes things up. We can override the
117 // cipher, however, and mint many sequential NFTokens with no gaps
118 // between them.
119 //
120 // Here we'll simply mint 100 sequential NFTs. Then we'll create
121 // offers for them to verify that the ledger can find them.
122
123 Account const issuer{"issuer"};
124 Account const buyer{"buyer"};
125 env.fund(XRP(10000), buyer, issuer);
126 env.close();
127
128 // Mint 100 sequential NFTs. Tweak the taxon so zero is always stored.
129 // That's what makes them sequential.
130 static constexpr std::size_t kNftCount = 100;
132 nftIDs.reserve(kNftCount);
133 for (int i = 0; i < kNftCount; ++i)
134 {
135 std::uint32_t const taxon = toUInt32(nft::cipheredTaxon(i, nft::toTaxon(0)));
136 nftIDs.emplace_back(token::getNextID(env, issuer, taxon, tfTransferable));
137 env(token::mint(issuer, taxon), Txflags(tfTransferable));
138 env.close();
139 }
140
141 // Create an offer for each of the NFTs. This verifies that the ledger
142 // can find all of the minted NFTs.
144 for (UInt256 const& nftID : nftIDs)
145 {
146 offers.emplace_back(
147 keylet::nftokenOffer(issuer, SeqProxy::rawSequence(env.seq(issuer))).key);
148 env(token::createOffer(issuer, nftID, XRP(0)), Txflags(tfSellNFToken));
149 env.close();
150 }
151
152 // Buyer accepts all of the offers in reverse order.
153 std::ranges::reverse(offers);
154 for (UInt256 const& offer : offers)
155 {
156 env(token::acceptSellOffer(buyer, offer));
157 env.close();
158 }
159 }
160
161 void
163 {
164 // All NFT IDs with the same low 96 bits must stay on the same NFT page.
165 testcase("Lopsided splits");
166
167 using namespace test::jtx;
168
169 // When a single NFT page exceeds 32 entries, the code is inclined
170 // to split that page into two equal pieces. That's fine, but
171 // the code also needs to keep NFTs with identical low 96-bits on
172 // the same page.
173 //
174 // Here we synthesize cases where there are several NFTs with
175 // identical 96-low-bits in the middle of a page. When that page
176 // is split because it overflows, we need to see that the NFTs
177 // with identical 96-low-bits are all kept on the same page.
178
179 // Lambda that exercises the lopsided splits.
180 auto const exerciseLopsided = [this, &features](
182 Env env{*this, features};
183
184 // Eventually all of the NFTokens will be owned by buyer.
185 Account const buyer{"buyer"};
186 env.fund(XRP(10000), buyer);
187 env.close();
188
189 // Create accounts for all of the seeds and fund those accounts.
190 std::vector<Account> accounts;
191 accounts.reserve(seeds.size());
192 for (std::string_view const seed : seeds)
193 {
194 Account const& account =
195 accounts.emplace_back(Account::AcctStringType::Base58Seed, std::string(seed));
196 env.fund(XRP(10000), account);
197
198 // Do not close the ledger inside the loop. If accounts are
199 // initialized at different ledgers, they will have
200 // different account sequences. That would cause the
201 // accounts to have different NFTokenID sequence numbers.
202 }
203 env.close();
204
205 // All of the accounts create one NFT and and offer that NFT to
206 // buyer.
209 offers.reserve(accounts.size());
210 for (Account const& account : accounts)
211 {
212 // Mint the NFT.
213 UInt256 const& nftID =
214 nftIDs.emplace_back(token::getNextID(env, account, 0, tfTransferable));
215 env(token::mint(account, 0), Txflags(tfTransferable));
216 env.close();
217
218 // Create an offer to give the NFT to buyer for free.
219 offers.emplace_back(
220 keylet::nftokenOffer(account, SeqProxy::rawSequence(env.seq(account))).key);
221 env(token::createOffer(account, nftID, XRP(0)),
222 token::Destination(buyer),
223 Txflags(tfSellNFToken));
224 }
225 env.close();
226
227 // buyer accepts all of the offers.
228 for (UInt256 const& offer : offers)
229 {
230 env(token::acceptSellOffer(buyer, offer));
231 env.close();
232 }
233
234 // This can be a good time to look at the NFT pages.
235 // printNFTPages(env, noisy);
236
237 // Verify that all NFTs are owned by buyer and findable in the
238 // ledger by having buyer create sell offers for all of their
239 // NFTs. Attempting to sell an offer that the ledger can't find
240 // generates a non-tesSUCCESS error code.
241 for (UInt256 const& nftID : nftIDs)
242 {
243 UInt256 const offerID =
244 keylet::nftokenOffer(buyer, SeqProxy::rawSequence(env.seq(buyer))).key;
245 env(token::createOffer(buyer, nftID, XRP(100)), Txflags(tfSellNFToken));
246 env.close();
247
248 env(token::cancelOffer(buyer, {offerID}));
249 }
250
251 // Verify that all the NFTs are owned by buyer.
252 json::Value buyerNFTs = [&env, &buyer] {
253 json::Value params;
254 params[jss::account] = buyer.human();
255 params[jss::type] = "state";
256 return env.rpc("json", "account_nfts", to_string(params));
257 }();
258
259 BEAST_EXPECT(buyerNFTs[jss::result][jss::account_nfts].size() == nftIDs.size());
260 for (json::Value const& ownedNFT : buyerNFTs[jss::result][jss::account_nfts])
261 {
262 UInt256 ownedID;
263 BEAST_EXPECT(ownedID.parseHex(ownedNFT[sfNFTokenID.jsonName].asString()));
264 auto const foundIter = std::ranges::find(nftIDs, ownedID);
265
266 // Assuming we find the NFT, erase it so we know it's been
267 // found and can't be found again.
268 if (BEAST_EXPECT(foundIter != nftIDs.end()))
269 nftIDs.erase(foundIter);
270 }
271
272 // All NFTs should now be accounted for, so nftIDs should be
273 // empty.
274 BEAST_EXPECT(nftIDs.empty());
275 };
276
277 // These seeds cause a lopsided split where the new NFT is added
278 // to the upper page.
279 static std::initializer_list<std::string_view const> const kSplitAndAddToHi{
280 "sp6JS7f14BuwFY8Mw5p3b8jjQBBTK", // 0. 0x1d2932ea
281 "sp6JS7f14BuwFY8Mw6F7X3EiGKazu", // 1. 0x1d2932ea
282 "sp6JS7f14BuwFY8Mw6FxjntJJfKXq", // 2. 0x1d2932ea
283 "sp6JS7f14BuwFY8Mw6eSF1ydEozJg", // 3. 0x1d2932ea
284 "sp6JS7f14BuwFY8Mw6koPB91um2ej", // 4. 0x1d2932ea
285 "sp6JS7f14BuwFY8Mw6m6D64iwquSe", // 5. 0x1d2932ea
286
287 "sp6JS7f14BuwFY8Mw5rC43sN4adC2", // 6. 0x208dbc24
288 "sp6JS7f14BuwFY8Mw65L9DDQqgebz", // 7. 0x208dbc24
289 "sp6JS7f14BuwFY8Mw65nKvU8pPQNn", // 8. 0x208dbc24
290 "sp6JS7f14BuwFY8Mw6bxZLyTrdipw", // 9. 0x208dbc24
291 "sp6JS7f14BuwFY8Mw6d5abucntSoX", // 10. 0x208dbc24
292 "sp6JS7f14BuwFY8Mw6qXK5awrRRP8", // 11. 0x208dbc24
293
294 // These eight need to be kept together by the implementation.
295 "sp6JS7f14BuwFY8Mw66EBtMxoMcCa", // 12. 0x309b67ed
296 "sp6JS7f14BuwFY8Mw66dGfE9jVfGv", // 13. 0x309b67ed
297 "sp6JS7f14BuwFY8Mw6APdZa7PH566", // 14. 0x309b67ed
298 "sp6JS7f14BuwFY8Mw6C3QX5CZyET5", // 15. 0x309b67ed
299 "sp6JS7f14BuwFY8Mw6CSysFf8GvaR", // 16. 0x309b67ed
300 "sp6JS7f14BuwFY8Mw6c7QSDmoAeRV", // 17. 0x309b67ed
301 "sp6JS7f14BuwFY8Mw6mvonveaZhW7", // 18. 0x309b67ed
302 "sp6JS7f14BuwFY8Mw6vtHHG7dYcXi", // 19. 0x309b67ed
303
304 "sp6JS7f14BuwFY8Mw66yppUNxESaw", // 20. 0x40d4b96f
305 "sp6JS7f14BuwFY8Mw6ATYQvobXiDT", // 21. 0x40d4b96f
306 "sp6JS7f14BuwFY8Mw6bis8D1Wa9Uy", // 22. 0x40d4b96f
307 "sp6JS7f14BuwFY8Mw6cTiGCWA8Wfa", // 23. 0x40d4b96f
308 "sp6JS7f14BuwFY8Mw6eAy2fpXmyYf", // 24. 0x40d4b96f
309 "sp6JS7f14BuwFY8Mw6icn58TRs8YG", // 25. 0x40d4b96f
310
311 "sp6JS7f14BuwFY8Mw68tj2eQEWoJt", // 26. 0x503b6ba9
312 "sp6JS7f14BuwFY8Mw6AjnAinNnMHT", // 27. 0x503b6ba9
313 "sp6JS7f14BuwFY8Mw6CKDUwB4LrhL", // 28. 0x503b6ba9
314 "sp6JS7f14BuwFY8Mw6d2yPszEFA6J", // 29. 0x503b6ba9
315 "sp6JS7f14BuwFY8Mw6jcBQBH3PfnB", // 30. 0x503b6ba9
316 "sp6JS7f14BuwFY8Mw6qxx19KSnN1w", // 31. 0x503b6ba9
317
318 // Adding this NFT splits the page. It is added to the upper
319 // page.
320 "sp6JS7f14BuwFY8Mw6ut1hFrqWoY5", // 32. 0x503b6ba9
321 };
322
323 // These seeds cause a lopsided split where the new NFT is added
324 // to the lower page.
325 static std::initializer_list<std::string_view const> const kSplitAndAddToLo{
326 "sp6JS7f14BuwFY8Mw5p3b8jjQBBTK", // 0. 0x1d2932ea
327 "sp6JS7f14BuwFY8Mw6F7X3EiGKazu", // 1. 0x1d2932ea
328 "sp6JS7f14BuwFY8Mw6FxjntJJfKXq", // 2. 0x1d2932ea
329 "sp6JS7f14BuwFY8Mw6eSF1ydEozJg", // 3. 0x1d2932ea
330 "sp6JS7f14BuwFY8Mw6koPB91um2ej", // 4. 0x1d2932ea
331 "sp6JS7f14BuwFY8Mw6m6D64iwquSe", // 5. 0x1d2932ea
332
333 "sp6JS7f14BuwFY8Mw5rC43sN4adC2", // 6. 0x208dbc24
334 "sp6JS7f14BuwFY8Mw65L9DDQqgebz", // 7. 0x208dbc24
335 "sp6JS7f14BuwFY8Mw65nKvU8pPQNn", // 8. 0x208dbc24
336 "sp6JS7f14BuwFY8Mw6bxZLyTrdipw", // 9. 0x208dbc24
337 "sp6JS7f14BuwFY8Mw6d5abucntSoX", // 10. 0x208dbc24
338 "sp6JS7f14BuwFY8Mw6qXK5awrRRP8", // 11. 0x208dbc24
339
340 // These eight need to be kept together by the implementation.
341 "sp6JS7f14BuwFY8Mw66EBtMxoMcCa", // 12. 0x309b67ed
342 "sp6JS7f14BuwFY8Mw66dGfE9jVfGv", // 13. 0x309b67ed
343 "sp6JS7f14BuwFY8Mw6APdZa7PH566", // 14. 0x309b67ed
344 "sp6JS7f14BuwFY8Mw6C3QX5CZyET5", // 15. 0x309b67ed
345 "sp6JS7f14BuwFY8Mw6CSysFf8GvaR", // 16. 0x309b67ed
346 "sp6JS7f14BuwFY8Mw6c7QSDmoAeRV", // 17. 0x309b67ed
347 "sp6JS7f14BuwFY8Mw6mvonveaZhW7", // 18. 0x309b67ed
348 "sp6JS7f14BuwFY8Mw6vtHHG7dYcXi", // 19. 0x309b67ed
349
350 "sp6JS7f14BuwFY8Mw66yppUNxESaw", // 20. 0x40d4b96f
351 "sp6JS7f14BuwFY8Mw6ATYQvobXiDT", // 21. 0x40d4b96f
352 "sp6JS7f14BuwFY8Mw6bis8D1Wa9Uy", // 22. 0x40d4b96f
353 "sp6JS7f14BuwFY8Mw6cTiGCWA8Wfa", // 23. 0x40d4b96f
354 "sp6JS7f14BuwFY8Mw6eAy2fpXmyYf", // 24. 0x40d4b96f
355 "sp6JS7f14BuwFY8Mw6icn58TRs8YG", // 25. 0x40d4b96f
356
357 "sp6JS7f14BuwFY8Mw68tj2eQEWoJt", // 26. 0x503b6ba9
358 "sp6JS7f14BuwFY8Mw6AjnAinNnMHT", // 27. 0x503b6ba9
359 "sp6JS7f14BuwFY8Mw6CKDUwB4LrhL", // 28. 0x503b6ba9
360 "sp6JS7f14BuwFY8Mw6d2yPszEFA6J", // 29. 0x503b6ba9
361 "sp6JS7f14BuwFY8Mw6jcBQBH3PfnB", // 30. 0x503b6ba9
362 "sp6JS7f14BuwFY8Mw6qxx19KSnN1w", // 31. 0x503b6ba9
363
364 // Adding this NFT splits the page. It is added to the lower
365 // page.
366 "sp6JS7f14BuwFY8Mw6xCigaMwC6Dp", // 32. 0x309b67ed
367 };
368
369 // Run the test cases.
370 exerciseLopsided(kSplitAndAddToHi);
371 exerciseLopsided(kSplitAndAddToLo);
372 }
373
374 void
376 {
377 testcase("NFTokenDir");
378
379 using namespace test::jtx;
380
381 // When a single NFT page exceeds 32 entries, the code is inclined
382 // to split that page into two equal pieces. The new page is lower
383 // than the original. There was an off-by-one in the selection of
384 // the index for the new page. This test recreates the problem.
385
386 // Lambda that exercises the split.
387 auto const exercise = [this,
389 Env env{*this, envconfig(), features, nullptr, beast::Severity::Disabled};
390
391 // Eventually all of the NFTokens will be owned by buyer.
392 Account const buyer{"buyer"};
393 env.fund(XRP(10000), buyer);
394 env.close();
395
396 // Create accounts for all of the seeds and fund those accounts.
397 std::vector<Account> accounts;
398 accounts.reserve(seeds.size());
399 for (std::string_view const seed : seeds)
400 {
401 Account const& account =
402 accounts.emplace_back(Account::AcctStringType::Base58Seed, std::string(seed));
403 env.fund(XRP(10000), account);
404
405 // Do not close the ledger inside the loop. If accounts are
406 // initialized at different ledgers, they will have
407 // different account sequences. That would cause the
408 // accounts to have different NFTokenID sequence numbers.
409 }
410 env.close();
411
412 // All of the accounts create one NFT and and offer that NFT to
413 // buyer.
416 offers.reserve(accounts.size());
417 for (Account const& account : accounts)
418 {
419 // Mint the NFT.
420 UInt256 const& nftID =
421 nftIDs.emplace_back(token::getNextID(env, account, 0, tfTransferable));
422 env(token::mint(account, 0), Txflags(tfTransferable));
423 env.close();
424
425 // Create an offer to give the NFT to buyer for free.
426 offers.emplace_back(
427 keylet::nftokenOffer(account, SeqProxy::rawSequence(env.seq(account))).key);
428 env(token::createOffer(account, nftID, XRP(0)),
429 token::Destination(buyer),
430 Txflags(tfSellNFToken));
431 }
432 env.close();
433
434 // buyer accepts all of the but the last. The last offer
435 // causes the page to split.
436 for (std::size_t i = 0; i < offers.size() - 1; ++i)
437 {
438 env(token::acceptSellOffer(buyer, offers[i]));
439 env.close();
440 }
441
442 env(token::acceptSellOffer(buyer, offers.back()));
443 env.close();
444
445 // This can be a good time to look at the NFT pages.
446 // printNFTPages(env, noisy);
447
448 // Verify that all NFTs are owned by buyer and findable in the
449 // ledger by having buyer create sell offers for all of their
450 // NFTs. Attempting to sell an offer that the ledger can't find
451 // generates a non-tesSUCCESS error code.
452 for (UInt256 const& nftID : nftIDs)
453 {
454 UInt256 const offerID =
455 keylet::nftokenOffer(buyer, SeqProxy::rawSequence(env.seq(buyer))).key;
456 env(token::createOffer(buyer, nftID, XRP(100)), Txflags(tfSellNFToken));
457 env.close();
458
459 env(token::cancelOffer(buyer, {offerID}));
460 }
461
462 // Verify that all the NFTs are owned by buyer.
463 json::Value buyerNFTs = [&env, &buyer] {
464 json::Value params;
465 params[jss::account] = buyer.human();
466 params[jss::type] = "state";
467 return env.rpc("json", "account_nfts", to_string(params));
468 }();
469
470 BEAST_EXPECT(buyerNFTs[jss::result][jss::account_nfts].size() == nftIDs.size());
471 for (json::Value const& ownedNFT : buyerNFTs[jss::result][jss::account_nfts])
472 {
473 UInt256 ownedID;
474 BEAST_EXPECT(ownedID.parseHex(ownedNFT[sfNFTokenID.jsonName].asString()));
475 auto const foundIter = std::ranges::find(nftIDs, ownedID);
476
477 // Assuming we find the NFT, erase it so we know it's been
478 // found and can't be found again.
479 if (BEAST_EXPECT(foundIter != nftIDs.end()))
480 nftIDs.erase(foundIter);
481 }
482
483 // All NFTs should now be accounted for, so nftIDs should be
484 // empty.
485 BEAST_EXPECT(nftIDs.empty());
486 };
487
488 // These seeds fill the last 17 entries of the initial page with
489 // equivalent NFTs. The split should keep these together.
490 static std::initializer_list<std::string_view const> const kSeventeenHi{
491 // These 16 need to be kept together by the implementation.
492 "sp6JS7f14BuwFY8Mw5EYu5z86hKDL", // 0. 0x399187e9
493 "sp6JS7f14BuwFY8Mw5PUAMwc5ygd7", // 1. 0x399187e9
494 "sp6JS7f14BuwFY8Mw5R3xUBcLSeTs", // 2. 0x399187e9
495 "sp6JS7f14BuwFY8Mw5W6oS5sdC3oF", // 3. 0x399187e9
496 "sp6JS7f14BuwFY8Mw5pYc3D9iuLcw", // 4. 0x399187e9
497 "sp6JS7f14BuwFY8Mw5pfGVnhcdp3b", // 5. 0x399187e9
498 "sp6JS7f14BuwFY8Mw6jS6RdEqXqrN", // 6. 0x399187e9
499 "sp6JS7f14BuwFY8Mw6krt6AKbvRXW", // 7. 0x399187e9
500 "sp6JS7f14BuwFY8Mw6mnVBQq7cAN2", // 8. 0x399187e9
501 "sp6JS7f14BuwFY8Mw8ECJxPjmkufQ", // 9. 0x399187e9
502 "sp6JS7f14BuwFY8Mw8asgzcceGWYm", // 10. 0x399187e9
503 "sp6JS7f14BuwFY8MwF6J3FXnPCgL8", // 11. 0x399187e9
504 "sp6JS7f14BuwFY8MwFEud2w5czv5q", // 12. 0x399187e9
505 "sp6JS7f14BuwFY8MwFNxKVqJnx8P5", // 13. 0x399187e9
506 "sp6JS7f14BuwFY8MwFnTCXg3eRidL", // 14. 0x399187e9
507 "sp6JS7f14BuwFY8Mwj47hv1vrDge6", // 15. 0x399187e9
508
509 // These 17 need to be kept together by the implementation.
510 "sp6JS7f14BuwFY8MwjJCwYr9zSfAv", // 16. 0xabb11898
511 "sp6JS7f14BuwFY8MwjYa5yLkgCLuT", // 17. 0xabb11898
512 "sp6JS7f14BuwFY8MwjenxuJ3TH2Bc", // 18. 0xabb11898
513 "sp6JS7f14BuwFY8MwjriN7Ui11NzB", // 19. 0xabb11898
514 "sp6JS7f14BuwFY8Mwk3AuoJNSEo34", // 20. 0xabb11898
515 "sp6JS7f14BuwFY8MwkT36hnRv8hTo", // 21. 0xabb11898
516 "sp6JS7f14BuwFY8MwkTQixEXfi1Cr", // 22. 0xabb11898
517 "sp6JS7f14BuwFY8MwkYJaZM1yTJBF", // 23. 0xabb11898
518 "sp6JS7f14BuwFY8Mwkc4k1uo85qp2", // 24. 0xabb11898
519 "sp6JS7f14BuwFY8Mwkf7cFhF1uuxx", // 25. 0xabb11898
520 "sp6JS7f14BuwFY8MwmCK2un99wb4e", // 26. 0xabb11898
521 "sp6JS7f14BuwFY8MwmETztNHYu2Bx", // 27. 0xabb11898
522 "sp6JS7f14BuwFY8MwmJws9UwRASfR", // 28. 0xabb11898
523 "sp6JS7f14BuwFY8MwoH5PQkGK8tEb", // 29. 0xabb11898
524 "sp6JS7f14BuwFY8MwoVXtP2yCzjJV", // 30. 0xabb11898
525 "sp6JS7f14BuwFY8MwobxRXA9vsTeX", // 31. 0xabb11898
526 "sp6JS7f14BuwFY8Mwos3pc5Gb3ihU", // 32. 0xabb11898
527 };
528
529 // These seeds fill the first entries of the initial page with
530 // equivalent NFTs. The split should keep these together.
531 static std::initializer_list<std::string_view const> const kSeventeenLo{
532 // These 17 need to be kept together by the implementation.
533 "sp6JS7f14BuwFY8Mw5EYu5z86hKDL", // 0. 0x399187e9
534 "sp6JS7f14BuwFY8Mw5PUAMwc5ygd7", // 1. 0x399187e9
535 "sp6JS7f14BuwFY8Mw5R3xUBcLSeTs", // 2. 0x399187e9
536 "sp6JS7f14BuwFY8Mw5W6oS5sdC3oF", // 3. 0x399187e9
537 "sp6JS7f14BuwFY8Mw5pYc3D9iuLcw", // 4. 0x399187e9
538 "sp6JS7f14BuwFY8Mw5pfGVnhcdp3b", // 5. 0x399187e9
539 "sp6JS7f14BuwFY8Mw6jS6RdEqXqrN", // 6. 0x399187e9
540 "sp6JS7f14BuwFY8Mw6krt6AKbvRXW", // 7. 0x399187e9
541 "sp6JS7f14BuwFY8Mw6mnVBQq7cAN2", // 8. 0x399187e9
542 "sp6JS7f14BuwFY8Mw8ECJxPjmkufQ", // 9. 0x399187e9
543 "sp6JS7f14BuwFY8Mw8asgzcceGWYm", // 10. 0x399187e9
544 "sp6JS7f14BuwFY8MwF6J3FXnPCgL8", // 11. 0x399187e9
545 "sp6JS7f14BuwFY8MwFEud2w5czv5q", // 12. 0x399187e9
546 "sp6JS7f14BuwFY8MwFNxKVqJnx8P5", // 13. 0x399187e9
547 "sp6JS7f14BuwFY8MwFnTCXg3eRidL", // 14. 0x399187e9
548 "sp6JS7f14BuwFY8Mwj47hv1vrDge6", // 15. 0x399187e9
549 "sp6JS7f14BuwFY8Mwj6TYekeeyukh", // 16. 0x399187e9
550
551 // These 16 need to be kept together by the implementation.
552 "sp6JS7f14BuwFY8MwjYa5yLkgCLuT", // 17. 0xabb11898
553 "sp6JS7f14BuwFY8MwjenxuJ3TH2Bc", // 18. 0xabb11898
554 "sp6JS7f14BuwFY8MwjriN7Ui11NzB", // 19. 0xabb11898
555 "sp6JS7f14BuwFY8Mwk3AuoJNSEo34", // 20. 0xabb11898
556 "sp6JS7f14BuwFY8MwkT36hnRv8hTo", // 21. 0xabb11898
557 "sp6JS7f14BuwFY8MwkTQixEXfi1Cr", // 22. 0xabb11898
558 "sp6JS7f14BuwFY8MwkYJaZM1yTJBF", // 23. 0xabb11898
559 "sp6JS7f14BuwFY8Mwkc4k1uo85qp2", // 24. 0xabb11898
560 "sp6JS7f14BuwFY8Mwkf7cFhF1uuxx", // 25. 0xabb11898
561 "sp6JS7f14BuwFY8MwmCK2un99wb4e", // 26. 0xabb11898
562 "sp6JS7f14BuwFY8MwmETztNHYu2Bx", // 27. 0xabb11898
563 "sp6JS7f14BuwFY8MwmJws9UwRASfR", // 28. 0xabb11898
564 "sp6JS7f14BuwFY8MwoH5PQkGK8tEb", // 29. 0xabb11898
565 "sp6JS7f14BuwFY8MwoVXtP2yCzjJV", // 30. 0xabb11898
566 "sp6JS7f14BuwFY8MwobxRXA9vsTeX", // 31. 0xabb11898
567 "sp6JS7f14BuwFY8Mwos3pc5Gb3ihU", // 32. 0xabb11898
568 };
569
570 // Run the test cases.
571 exercise(kSeventeenHi);
572 exercise(kSeventeenLo);
573 }
574
575 void
577 {
578 // Exercise the case where 33 NFTs with identical sort
579 // characteristics are owned by the same account.
580 testcase("NFToken too many same");
581
582 using namespace test::jtx;
583
584 Env env{*this, features};
585
586 // Eventually all of the NFTokens will be owned by buyer.
587 Account const buyer{"buyer"};
588 env.fund(XRP(10000), buyer);
589 env.close();
590
591 // Here are 33 seeds that produce identical low 32-bits in their
592 // corresponding AccountIDs.
594 "sp6JS7f14BuwFY8Mw5FnqmbciPvH6", // 0. 0x9a8ebed3
595 "sp6JS7f14BuwFY8Mw5MBGbyMSsXLp", // 1. 0x9a8ebed3
596 "sp6JS7f14BuwFY8Mw5S4PnDyBdKKm", // 2. 0x9a8ebed3
597 "sp6JS7f14BuwFY8Mw6kcXpM2enE35", // 3. 0x9a8ebed3
598 "sp6JS7f14BuwFY8Mw6tuuSMMwyJ44", // 4. 0x9a8ebed3
599 "sp6JS7f14BuwFY8Mw8E8JWLQ1P8pt", // 5. 0x9a8ebed3
600 "sp6JS7f14BuwFY8Mw8WwdgWkCHhEx", // 6. 0x9a8ebed3
601 "sp6JS7f14BuwFY8Mw8XDUYvU6oGhQ", // 7. 0x9a8ebed3
602 "sp6JS7f14BuwFY8Mw8ceVGL4M1zLQ", // 8. 0x9a8ebed3
603 "sp6JS7f14BuwFY8Mw8fdSwLCZWDFd", // 9. 0x9a8ebed3
604 "sp6JS7f14BuwFY8Mw8zuF6Fg65i1E", // 10. 0x9a8ebed3
605 "sp6JS7f14BuwFY8MwF2k7bihVfqes", // 11. 0x9a8ebed3
606 "sp6JS7f14BuwFY8MwF6X24WXGn557", // 12. 0x9a8ebed3
607 "sp6JS7f14BuwFY8MwFMpn7strjekg", // 13. 0x9a8ebed3
608 "sp6JS7f14BuwFY8MwFSdy9sYVrwJs", // 14. 0x9a8ebed3
609 "sp6JS7f14BuwFY8MwFdMcLy9UkrXn", // 15. 0x9a8ebed3
610 "sp6JS7f14BuwFY8MwFdbwFm1AAboa", // 16. 0x9a8ebed3
611 "sp6JS7f14BuwFY8MwFdr5AhKThVtU", // 17. 0x9a8ebed3
612 "sp6JS7f14BuwFY8MwjFc3Q9YatvAw", // 18. 0x9a8ebed3
613 "sp6JS7f14BuwFY8MwjRXcNs1ozEXn", // 19. 0x9a8ebed3
614 "sp6JS7f14BuwFY8MwkQGUKL7v1FBt", // 20. 0x9a8ebed3
615 "sp6JS7f14BuwFY8Mwkamsoxx1wECt", // 21. 0x9a8ebed3
616 "sp6JS7f14BuwFY8Mwm3hus1dG6U8y", // 22. 0x9a8ebed3
617 "sp6JS7f14BuwFY8Mwm589M8vMRpXF", // 23. 0x9a8ebed3
618 "sp6JS7f14BuwFY8MwmJTRJ4Fqz1A3", // 24. 0x9a8ebed3
619 "sp6JS7f14BuwFY8MwmRfy8fer4QbL", // 25. 0x9a8ebed3
620 "sp6JS7f14BuwFY8MwmkkFx1HtgWRx", // 26. 0x9a8ebed3
621 "sp6JS7f14BuwFY8MwmwP9JFdKa4PS", // 27. 0x9a8ebed3
622 "sp6JS7f14BuwFY8MwoXWJLB3ciHfo", // 28. 0x9a8ebed3
623 "sp6JS7f14BuwFY8MwoYc1gTtT2mWL", // 29. 0x9a8ebed3
624 "sp6JS7f14BuwFY8MwogXtHH7FNVoo", // 30. 0x9a8ebed3
625 "sp6JS7f14BuwFY8MwoqYoA9P8gf3r", // 31. 0x9a8ebed3
626 "sp6JS7f14BuwFY8MwoujwMJofGnsA", // 32. 0x9a8ebed3
627 };
628
629 // Create accounts for all of the seeds and fund those accounts.
630 std::vector<Account> accounts;
631 accounts.reserve(kSeeds.size());
632 for (std::string_view const seed : kSeeds)
633 {
634 Account const& account =
635 accounts.emplace_back(Account::AcctStringType::Base58Seed, std::string(seed));
636 env.fund(XRP(10000), account);
637
638 // Do not close the ledger inside the loop. If accounts are
639 // initialized at different ledgers, they will have different
640 // account sequences. That would cause the accounts to have
641 // different NFTokenID sequence numbers.
642 }
643 env.close();
644
645 // All of the accounts create one NFT and and offer that NFT to buyer.
648 offers.reserve(accounts.size());
649 for (Account const& account : accounts)
650 {
651 // Mint the NFT.
652 UInt256 const& nftID =
653 nftIDs.emplace_back(token::getNextID(env, account, 0, tfTransferable));
654 env(token::mint(account, 0), Txflags(tfTransferable));
655 env.close();
656
657 // Create an offer to give the NFT to buyer for free.
658 offers.emplace_back(
659 keylet::nftokenOffer(account, SeqProxy::rawSequence(env.seq(account))).key);
660 env(token::createOffer(account, nftID, XRP(0)),
661 token::Destination(buyer),
662 Txflags(tfSellNFToken));
663 }
664 env.close();
665
666 // Verify that the low 96 bits of all generated NFTs is identical.
667 UInt256 const expectLowBits = nftIDs.front() & nft::kPageMask;
668 for (UInt256 const& nftID : nftIDs)
669 {
670 BEAST_EXPECT(expectLowBits == (nftID & nft::kPageMask));
671 }
672
673 // Remove one NFT and offer from the vectors. This offer is the one
674 // that will overflow the page.
675 nftIDs.pop_back();
676 UInt256 const offerForPageOverflow = offers.back();
677 offers.pop_back();
678
679 // buyer accepts all of the offers but one.
680 for (UInt256 const& offer : offers)
681 {
682 env(token::acceptSellOffer(buyer, offer));
683 env.close();
684 }
685
686 // buyer accepts the last offer which causes a page overflow.
687 env(token::acceptSellOffer(buyer, offerForPageOverflow), Ter(tecNO_SUITABLE_NFTOKEN_PAGE));
688
689 // Verify that all expected NFTs are owned by buyer and findable in
690 // the ledger by having buyer create sell offers for all of their NFTs.
691 // Attempting to sell an offer that the ledger can't find generates
692 // a non-tesSUCCESS error code.
693 for (UInt256 const& nftID : nftIDs)
694 {
695 UInt256 const offerID =
696 keylet::nftokenOffer(buyer, SeqProxy::rawSequence(env.seq(buyer))).key;
697 env(token::createOffer(buyer, nftID, XRP(100)), Txflags(tfSellNFToken));
698 env.close();
699
700 env(token::cancelOffer(buyer, {offerID}));
701 }
702
703 // Verify that all the NFTs are owned by buyer.
704 json::Value buyerNFTs = [&env, &buyer] {
705 json::Value params;
706 params[jss::account] = buyer.human();
707 params[jss::type] = "state";
708 return env.rpc("json", "account_nfts", to_string(params));
709 }();
710
711 BEAST_EXPECT(buyerNFTs[jss::result][jss::account_nfts].size() == nftIDs.size());
712 for (json::Value const& ownedNFT : buyerNFTs[jss::result][jss::account_nfts])
713 {
714 UInt256 ownedID;
715 BEAST_EXPECT(ownedID.parseHex(ownedNFT[sfNFTokenID.jsonName].asString()));
716 auto const foundIter = std::ranges::find(nftIDs, ownedID);
717
718 // Assuming we find the NFT, erase it so we know it's been found
719 // and can't be found again.
720 if (BEAST_EXPECT(foundIter != nftIDs.end()))
721 nftIDs.erase(foundIter);
722 }
723
724 // All NFTs should now be accounted for, so nftIDs should be empty.
725 BEAST_EXPECT(nftIDs.empty());
726
727 TER const expect = tesSUCCESS;
728 env(token::mint(buyer, 0), Txflags(tfTransferable), Ter(expect));
729 env.close();
730 }
731
732 void
734 {
735 // We'll make a worst case scenario for NFT packing:
736 //
737 // 1. 33 accounts with identical low-32 bits mint 7 consecutive NFTs.
738 // 2. The taxon is manipulated to always be stored as zero.
739 // 3. A single account buys all 7x32 of the 33 NFTs.
740 //
741 // All of the NFTs should be acquired by the buyer.
742 //
743 // Lastly, kNone of the remaining NFTs should be acquirable by the
744 // buyer. They would cause page overflow.
745
746 testcase("NFToken consecutive packing");
747
748 using namespace test::jtx;
749
750 Env env{*this, features};
751
752 // Eventually all of the NFTokens will be owned by buyer.
753 Account const buyer{"buyer"};
754 env.fund(XRP(10000), buyer);
755 env.close();
756
757 // Here are 33 seeds that produce identical low 32-bits in their
758 // corresponding AccountIDs.
760 "sp6JS7f14BuwFY8Mw56vZeiBuhePx", // 0. 0x115d0525
761 "sp6JS7f14BuwFY8Mw5BodF9tGuTUe", // 1. 0x115d0525
762 "sp6JS7f14BuwFY8Mw5EnhC1cg84J7", // 2. 0x115d0525
763 "sp6JS7f14BuwFY8Mw5P913Cunr2BK", // 3. 0x115d0525
764 "sp6JS7f14BuwFY8Mw5Pru7eLo1XzT", // 4. 0x115d0525
765 "sp6JS7f14BuwFY8Mw61SLUC8UX2m8", // 5. 0x115d0525
766 "sp6JS7f14BuwFY8Mw6AsBF9TpeMpq", // 6. 0x115d0525
767 "sp6JS7f14BuwFY8Mw84XqrBZkU2vE", // 7. 0x115d0525
768 "sp6JS7f14BuwFY8Mw89oSU6dBk3KB", // 8. 0x115d0525
769 "sp6JS7f14BuwFY8Mw89qUKCyDmyzj", // 9. 0x115d0525
770 "sp6JS7f14BuwFY8Mw8GfqQ9VRZ8tm", // 10. 0x115d0525
771 "sp6JS7f14BuwFY8Mw8LtW3VqrqMks", // 11. 0x115d0525
772 "sp6JS7f14BuwFY8Mw8ZrAkJc2sHew", // 12. 0x115d0525
773 "sp6JS7f14BuwFY8Mw8jpkYSNrD3ah", // 13. 0x115d0525
774 "sp6JS7f14BuwFY8MwF2mshd786m3V", // 14. 0x115d0525
775 "sp6JS7f14BuwFY8MwFHfXq9x5NbPY", // 15. 0x115d0525
776 "sp6JS7f14BuwFY8MwFrjWq5LAB8NT", // 16. 0x115d0525
777 "sp6JS7f14BuwFY8Mwj4asgSh6hQZd", // 17. 0x115d0525
778 "sp6JS7f14BuwFY8Mwj7ipFfqBSRrE", // 18. 0x115d0525
779 "sp6JS7f14BuwFY8MwjHqtcvGav8uW", // 19. 0x115d0525
780 "sp6JS7f14BuwFY8MwjLp4sk5fmzki", // 20. 0x115d0525
781 "sp6JS7f14BuwFY8MwjioHuYb3Ytkx", // 21. 0x115d0525
782 "sp6JS7f14BuwFY8MwkRjHPXWi7fGN", // 22. 0x115d0525
783 "sp6JS7f14BuwFY8MwkdVdPV3LjNN1", // 23. 0x115d0525
784 "sp6JS7f14BuwFY8MwkxUtVY5AXZFk", // 24. 0x115d0525
785 "sp6JS7f14BuwFY8Mwm4jQzdfTbY9F", // 25. 0x115d0525
786 "sp6JS7f14BuwFY8MwmCucYAqNp4iF", // 26. 0x115d0525
787 "sp6JS7f14BuwFY8Mwo2bgdFtxBzpF", // 27. 0x115d0525
788 "sp6JS7f14BuwFY8MwoGwD7v4U6qBh", // 28. 0x115d0525
789 "sp6JS7f14BuwFY8MwoUczqFADMoXi", // 29. 0x115d0525
790 "sp6JS7f14BuwFY8MwoY1xZeGd3gAr", // 30. 0x115d0525
791 "sp6JS7f14BuwFY8MwomVCbfkv4kYZ", // 31. 0x115d0525
792 "sp6JS7f14BuwFY8MwoqbrPSr4z13F", // 32. 0x115d0525
793 };
794
795 // Create accounts for all of the seeds and fund those accounts.
796 std::vector<Account> accounts;
797 accounts.reserve(kSeeds.size());
798 for (std::string_view const seed : kSeeds)
799 {
800 Account const& account =
801 accounts.emplace_back(Account::AcctStringType::Base58Seed, std::string(seed));
802 env.fund(XRP(10000), account);
803
804 // Do not close the ledger inside the loop. If accounts are
805 // initialized at different ledgers, they will have different
806 // account sequences. That would cause the accounts to have
807 // different NFTokenID sequence numbers.
808 }
809 env.close();
810
811 // All of the accounts create seven consecutive NFTs and and offer
812 // those NFTs to buyer.
813 std::array<std::vector<UInt256>, 7> nftIDsByPage;
814 for (auto& vec : nftIDsByPage)
815 vec.reserve(accounts.size());
817 for (auto& vec : offers)
818 vec.reserve(accounts.size());
819 for (std::size_t i = 0; i < nftIDsByPage.size(); ++i)
820 {
821 for (Account const& account : accounts)
822 {
823 // Mint the NFT. Tweak the taxon so zero is always stored.
824 std::uint32_t const taxon = toUInt32(nft::cipheredTaxon(i, nft::toTaxon(0)));
825
826 UInt256 const& nftID = nftIDsByPage[i].emplace_back(
827 token::getNextID(env, account, taxon, tfTransferable));
828 env(token::mint(account, taxon), Txflags(tfTransferable));
829 env.close();
830
831 // Create an offer to give the NFT to buyer for free.
832 offers[i].emplace_back(
833 keylet::nftokenOffer(account, SeqProxy::rawSequence(env.seq(account))).key);
834 env(token::createOffer(account, nftID, XRP(0)),
835 token::Destination(buyer),
836 Txflags(tfSellNFToken));
837 }
838 }
839 env.close();
840
841 // Verify that the low 96 bits of all generated NFTs of the same
842 // sequence is identical.
843 for (auto const& vec : nftIDsByPage)
844 {
845 UInt256 const expectLowBits = vec.front() & nft::kPageMask;
846 for (UInt256 const& nftID : vec)
847 {
848 BEAST_EXPECT(expectLowBits == (nftID & nft::kPageMask));
849 }
850 }
851
852 // Remove one NFT and offer from each of the vectors. These offers
853 // are the ones that will overflow the page.
854 std::vector<UInt256> overflowNFTs;
855 overflowNFTs.reserve(nftIDsByPage.size());
856 std::vector<UInt256> overflowOffers;
857 overflowOffers.reserve(nftIDsByPage.size());
858
859 for (std::size_t i = 0; i < nftIDsByPage.size(); ++i)
860 {
861 overflowNFTs.push_back(nftIDsByPage[i].back());
862 nftIDsByPage[i].pop_back();
863 BEAST_EXPECT(nftIDsByPage[i].size() == kSeeds.size() - 1);
864
865 overflowOffers.push_back(offers[i].back());
866 offers[i].pop_back();
867 BEAST_EXPECT(offers[i].size() == kSeeds.size() - 1);
868 }
869
870 // buyer accepts all of the offers that won't cause an overflow.
871 // Fill the center and outsides first to exercise different boundary
872 // cases.
873 for (int const i : std::initializer_list<int>{3, 6, 0, 1, 2, 5, 4})
874 {
875 for (UInt256 const& offer : offers[i])
876 {
877 env(token::acceptSellOffer(buyer, offer));
878 env.close();
879 }
880 }
881
882 // buyer accepts the seven offers that would cause page overflows if
883 // the transaction succeeded.
884 for (UInt256 const& offer : overflowOffers)
885 {
886 env(token::acceptSellOffer(buyer, offer), Ter(tecNO_SUITABLE_NFTOKEN_PAGE));
887 env.close();
888 }
889
890 // Verify that all expected NFTs are owned by buyer and findable in
891 // the ledger by having buyer create sell offers for all of their NFTs.
892 // Attempting to sell an offer that the ledger can't find generates
893 // a non-tesSUCCESS error code.
894 for (auto const& vec : nftIDsByPage)
895 {
896 for (UInt256 const& nftID : vec)
897 {
898 env(token::createOffer(buyer, nftID, XRP(100)), Txflags(tfSellNFToken));
899 env.close();
900 }
901 }
902
903 // See what the account_objects command does with "nft_offer".
904 {
905 json::Value ownedNftOffers(json::ValueType::Array);
906 std::string marker;
907 do
908 {
909 json::Value buyerOffers = [&env, &buyer, &marker] {
910 json::Value params;
911 params[jss::account] = buyer.human();
912 params[jss::type] = jss::nft_offer;
913
914 if (!marker.empty())
915 params[jss::marker] = marker;
916 return env.rpc("json", "account_objects", to_string(params));
917 }();
918
919 marker.clear();
920 if (buyerOffers.isMember(jss::result))
921 {
922 json::Value& result = buyerOffers[jss::result];
923
924 if (result.isMember(jss::marker))
925 marker = result[jss::marker].asString();
926
927 if (result.isMember(jss::account_objects))
928 {
929 json::Value& someOffers = result[jss::account_objects];
930 for (std::size_t i = 0; i < someOffers.size(); ++i)
931 ownedNftOffers.append(someOffers[i]);
932 }
933 }
934 } while (!marker.empty());
935
936 // Verify there are as many offers are there are NFTs.
937 {
938 std::size_t totalOwnedNFTs = 0;
939 for (auto const& vec : nftIDsByPage)
940 totalOwnedNFTs += vec.size();
941 BEAST_EXPECT(ownedNftOffers.size() == totalOwnedNFTs);
942 }
943
944 // Cancel all the offers.
945 {
946 std::vector<UInt256> cancelOffers;
947 cancelOffers.reserve(ownedNftOffers.size());
948
949 for (auto const& offer : ownedNftOffers)
950 {
951 if (offer.isMember(jss::index))
952 {
953 UInt256 offerIndex;
954 if (offerIndex.parseHex(offer[jss::index].asString()))
955 cancelOffers.push_back(offerIndex);
956 }
957 }
958 env(token::cancelOffer(buyer, cancelOffers));
959 env.close();
960 }
961
962 // account_objects should no longer return any "nft_offer"s.
963 json::Value remainingOffers = [&env, &buyer] {
964 json::Value params;
965 params[jss::account] = buyer.human();
966 params[jss::type] = jss::nft_offer;
967
968 return env.rpc("json", "account_objects", to_string(params));
969 }();
970 BEAST_EXPECT(
971 remainingOffers.isMember(jss::result) &&
972 remainingOffers[jss::result].isMember(jss::account_objects) &&
973 remainingOffers[jss::result][jss::account_objects].size() == 0);
974 }
975
976 // Verify that the ledger reports all of the NFTs owned by buyer.
977 // Use the account_nfts rpc call to get the values.
979 std::string marker;
980 do
981 {
982 json::Value buyerNFTs = [&env, &buyer, &marker] {
983 json::Value params;
984 params[jss::account] = buyer.human();
985 params[jss::type] = "state";
986
987 if (!marker.empty())
988 params[jss::marker] = marker;
989 return env.rpc("json", "account_nfts", to_string(params));
990 }();
991
992 marker.clear();
993 if (buyerNFTs.isMember(jss::result))
994 {
995 json::Value& result = buyerNFTs[jss::result];
996
997 if (result.isMember(jss::marker))
998 marker = result[jss::marker].asString();
999
1000 if (result.isMember(jss::account_nfts))
1001 {
1002 json::Value& someNFTs = result[jss::account_nfts];
1003 for (std::size_t i = 0; i < someNFTs.size(); ++i)
1004 ownedNFTs.append(someNFTs[i]);
1005 }
1006 }
1007 } while (!marker.empty());
1008
1009 // Copy all of the nftIDs into a set to make validation easier.
1010 std::set<UInt256> allNftIDs;
1011 for (auto& vec : nftIDsByPage)
1012 allNftIDs.insert(vec.begin(), vec.end());
1013
1014 BEAST_EXPECT(ownedNFTs.size() == allNftIDs.size());
1015
1016 for (json::Value const& ownedNFT : ownedNFTs)
1017 {
1018 if (ownedNFT.isMember(sfNFTokenID.jsonName))
1019 {
1020 UInt256 ownedID;
1021 BEAST_EXPECT(ownedID.parseHex(ownedNFT[sfNFTokenID.jsonName].asString()));
1022 auto const foundIter = allNftIDs.find(ownedID);
1023
1024 // Assuming we find the NFT, erase it so we know it's been found
1025 // and can't be found again.
1026 if (BEAST_EXPECT(foundIter != allNftIDs.end()))
1027 allNftIDs.erase(foundIter);
1028 }
1029 }
1030
1031 // All NFTs should now be accounted for, so allNftIDs should be empty.
1032 BEAST_EXPECT(allNftIDs.empty());
1033 }
1034
1035 void
1037 {
1038 testConsecutiveNFTs(features);
1039 testLopsidedSplits(features);
1040 testNFTokenDir(features);
1041 testTooManyEquivalent(features);
1042 testConsecutivePacking(features);
1043 }
1044
1045public:
1046 void
1047 run() override
1048 {
1049 using namespace test::jtx;
1050 FeatureBitset const all{testableAmendments()};
1051
1052 testWithFeats(all);
1053 }
1054};
1055
1057
1058} // namespace xrpl
1059
1060// Seed that produces an account with the low-32 bits == 0xFFFFFFFF in
1061// case it is needed for future testing:
1062//
1063// sp6JS7f14BuwFY8MwFe95Vpi9Znjs
1064//
T back(T... args)
A testsuite class.
Definition suite.h:52
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:235
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Represents a JSON value.
Definition json_value.h:121
std::string toStyledString() const
bool isArray() const
Value & append(Value const &value)
Append value to array at the end.
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.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:526
void testLopsidedSplits(FeatureBitset features)
void run() override
Runs the suite.
void testWithFeats(FeatureBitset features)
static void printNFTPages(test::jtx::Env &env, Volume vol)
void testNFTokenDir(FeatureBitset features)
void testConsecutivePacking(FeatureBitset features)
void testTooManyEquivalent(FeatureBitset features)
void testConsecutiveNFTs(FeatureBitset features)
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
A transaction testing environment.
Definition Env.h:161
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 clear(T... args)
T emplace_back(T... args)
T empty(T... args)
T end(T... args)
T endl(T... args)
T erase(T... args)
T find(T... args)
T front(T... args)
T insert(T... args)
unsigned int UInt
@ Array
array value (ordered list)
Definition json_value.h:32
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:465
Taxon toTaxon(std::uint32_t i)
Definition nft.h:21
Taxon cipheredTaxon(std::uint32_t tokenSeq, Taxon taxon)
Definition nft.h:63
constexpr UInt256 kPageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
BaseUInt< 256 > UInt256
Definition base_uint.h:581
BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBaseUtil, app, xrpl, 2)
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecNO_SUITABLE_NFTOKEN_PAGE
Definition TER.h:332
@ 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)
UInt256 key
Definition Keylet.h:21