Skip to content

Commit

Permalink
[FOLD] add test cases to ensure the NFT page links are correct:
Browse files Browse the repository at this point in the history
* This is from suggestions I made on the review, so someone else will
  have to review these changes.
  • Loading branch information
ximinez committed Aug 2, 2024
1 parent 943ff24 commit c85ddf0
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/test/app/FixNFTokenPageLinks_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ class FixNFTokenPageLinks_test : public beast::unit_test::suite
// bob's last page should now be present and include a previous
// link but no next link.
{
auto bobLastNFTokenPage = env.le(keylet::nftpage_max(bob));
auto const lastPageKeylet = keylet::nftpage_max(bob);
auto const bobLastNFTokenPage = env.le(lastPageKeylet);
if (!BEAST_EXPECT(bobLastNFTokenPage))
return;

Expand All @@ -561,6 +562,19 @@ class FixNFTokenPageLinks_test : public beast::unit_test::suite
bobLastNFTokenPage->at(sfPreviousPageMin) !=
bobMiddleNFTokenPageIndex);
BEAST_EXPECT(!bobLastNFTokenPage->isFieldPresent(sfNextPageMin));

auto const bobNewFirstNFTokenPage = env.le(keylet::nftpage(
keylet::nftpage_min(bob),
bobLastNFTokenPage->at(sfPreviousPageMin)));
if (!BEAST_EXPECT(bobNewFirstNFTokenPage))
return;

BEAST_EXPECT(
bobNewFirstNFTokenPage->isFieldPresent(sfNextPageMin) &&
bobNewFirstNFTokenPage->at(sfNextPageMin) ==
lastPageKeylet.key);
BEAST_EXPECT(
!bobNewFirstNFTokenPage->isFieldPresent(sfPreviousPageMin));
}

// bob's middle page should be gone.
Expand Down Expand Up @@ -601,24 +615,43 @@ class FixNFTokenPageLinks_test : public beast::unit_test::suite
env(ledgerStateFix::nftPageLinks(carol, carol), fee(linkFixFee));
env.close();

// carol's "middle" page is present and now has a NextPageMin field.
{
// carol's "middle" page is present and now has a NextPageMin field.
auto const lastPageKeylet = keylet::nftpage_max(carol);
auto carolMiddleNFTokenPage = env.le(keylet::nftpage(
keylet::nftpage_min(carol), carolMiddleNFTokenPageIndex));
if (!BEAST_EXPECT(carolMiddleNFTokenPage))
return;

BEAST_EXPECT(
carolMiddleNFTokenPage->isFieldPresent(sfPreviousPageMin));
BEAST_EXPECT(carolMiddleNFTokenPage->isFieldPresent(sfNextPageMin));
}
// carol has a "last" page that includes a PreviousPageMin field.
{
auto carolLastNFTokenPage = env.le(keylet::nftpage_max(carol));
BEAST_EXPECT(
carolMiddleNFTokenPage->isFieldPresent(sfNextPageMin) &&
carolMiddleNFTokenPage->at(sfNextPageMin) == lastPageKeylet.key);

// carol has a "last" page that includes a PreviousPageMin field.
auto carolLastNFTokenPage = env.le(lastPageKeylet);
if (!BEAST_EXPECT(carolLastNFTokenPage))
return;

BEAST_EXPECT(
carolLastNFTokenPage->isFieldPresent(sfPreviousPageMin));
carolLastNFTokenPage->isFieldPresent(sfPreviousPageMin) &&
carolLastNFTokenPage->at(sfPreviousPageMin) ==
carolMiddleNFTokenPageIndex);
BEAST_EXPECT(!carolLastNFTokenPage->isFieldPresent(sfNextPageMin));

// carol also has a "first" page that includes a NextPageMin field.
auto carolFirstNFTokenPage = env.le(keylet::nftpage(
keylet::nftpage_min(carol),
carolMiddleNFTokenPage->at(sfPreviousPageMin)));
if (!BEAST_EXPECT(carolFirstNFTokenPage))
return;

BEAST_EXPECT(
carolFirstNFTokenPage->isFieldPresent(sfNextPageMin) &&
carolFirstNFTokenPage->at(sfNextPageMin) ==
carolMiddleNFTokenPageIndex);
BEAST_EXPECT(!carolFirstNFTokenPage->isFieldPresent(sfPreviousPageMin));
}

// With the link repair, the server knows that carol has 96 NFTs.
Expand Down

0 comments on commit c85ddf0

Please sign in to comment.