Skip to content

Commit

Permalink
create unit test for fixing nft page invalid marker not returning error
Browse files Browse the repository at this point in the history
add more test

change test name

create unit test
  • Loading branch information
yinyiqian1 committed Jun 17, 2024
1 parent 9bf62f7 commit 7cfe5b2
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ripple/rpc/handlers/AccountObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ doAccountNFTs(RPC::JsonContext& context)
continue;
}

if (markerSet && !markerFound) {
if (markerSet && !markerFound)
{
return RPC::invalid_field_error(jss::marker);
}

Expand Down Expand Up @@ -168,6 +169,11 @@ doAccountNFTs(RPC::JsonContext& context)
cp = nullptr;
}

if (markerSet && !markerFound)
{
return RPC::invalid_field_error(jss::marker);
}

result[jss::account] = toBase58(accountID);
context.loadType = Resource::feeMediumBurdenRPC;
return result;
Expand Down
91 changes: 91 additions & 0 deletions src/test/rpc/AccountObjects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,13 +1032,104 @@ class AccountObjects_test : public beast::unit_test::suite
BEAST_EXPECT(acct_objs_is_size(acct_objs(gw, jss::hashes), 0));
}

void
testNFTsMarker()
{
testcase("NFTsMarker");

using namespace jtx;
Env env(*this);

Account const bob{"bob"};
env.fund(XRP(10000), bob);

unsigned nftsSize = 10;
for (unsigned i = 0; i < nftsSize; i++)
{
env(token::mint(bob, 0));
}

env.close();

// save the NFTokenIDs to use later
std::vector<Json::Value> tokenIDs;
{
Json::Value params;
params[jss::account] = bob.human();
params[jss::ledger_index] = "validated";
auto resp = env.rpc("json", "account_nfts", to_string(params));
auto& nfts = resp[jss::result][jss::account_nfts];
for (auto& nft : nfts)
tokenIDs.push_back(nft["NFTokenID"]);
}

// test a valid marker which is equal to the third tokenID
{
unsigned limit = 4;
unsigned lastIndex = 2;
Json::Value params;
params[jss::account] = bob.human();
params[jss::limit] = limit;
params[jss::marker] = tokenIDs[lastIndex];
params[jss::ledger_index] = "validated";
auto resp = env.rpc("json", "account_nfts", to_string(params));
BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
auto& nfts = resp[jss::result][jss::account_nfts];
auto nftsCount = nftsSize - lastIndex - 1 < limit ? nftsSize - lastIndex - 1: limit;
BEAST_EXPECT(nfts.size() == nftsCount);
for (unsigned i = 0; i < nftsCount; i++)
BEAST_EXPECT(nfts[i]["NFTokenID"] == tokenIDs[lastIndex + 1 + i]);
}

// test a valid marker which is equal to the 8th tokenID
{
unsigned limit = 4;
unsigned lastIndex = 7;
Json::Value params;
params[jss::account] = bob.human();
params[jss::limit] = limit;
params[jss::marker] = tokenIDs[lastIndex];
params[jss::ledger_index] = "validated";
auto resp = env.rpc("json", "account_nfts", to_string(params));
BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
auto& nfts = resp[jss::result][jss::account_nfts];
auto nftsCount = nftsSize - lastIndex - 1 < limit ? nftsSize - lastIndex - 1 : limit;
BEAST_EXPECT(nfts.size() == nftsCount);
for (unsigned i = 0; i < nftsCount; i++)
BEAST_EXPECT(nfts[i]["NFTokenID"] == tokenIDs[lastIndex + 1 + i]);
}

// test an invalid marker which does not exist in the NFTokenIDs
{
Json::Value params;
params[jss::account] = bob.human();
params[jss::limit] = 4;
params[jss::ledger_index] = "validated";
params[jss::marker] = "00000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B9000000000000000000";
auto resp = env.rpc("json", "account_nfts", to_string(params));
BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field \'marker\'.");
}

// test an invalid marker which exceeds the maximum value of the existing NFTokenID
{
Json::Value params;
params[jss::account] = bob.human();
params[jss::limit] = 4;
params[jss::ledger_index] = "validated";
params[jss::marker] = "00000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90FFFFFFFFFFFFFFFFF";
auto resp = env.rpc("json", "account_nfts", to_string(params));
BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field \'marker\'.");
}
}

void
run() override
{
testErrors();
testUnsteppedThenStepped();
testUnsteppedThenSteppedWithNFTs();
testObjectTypes();
testNFTsMarker();
}
};

Expand Down

0 comments on commit 7cfe5b2

Please sign in to comment.