Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Jun 14, 2024
1 parent 7b69f42 commit 5a65a4d
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions src/test/rpc/AccountObjects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,37 +1033,84 @@ class AccountObjects_test : public beast::unit_test::suite
}

void
testNFTsWithInvalidMarker()
testNFTsMarker()
{
testcase("NFTsWithInvalidMarker");

using namespace jtx;
Env env(*this);

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

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

// save the NFTokenIDs to use later
std::vector<Json::Value> tokenIDs;
{
Json::Value params;
params[jss::account] = bob.human();
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];
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];
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::marker] = "00000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B9000000000000000000";
auto resp = env.rpc("json", "account_nfts", to_string(params));
std::cout << resp[jss::result][jss::error_message] << std::endl;
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::marker] = "00000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90FFFFFFFFFFFFFFFFF";
auto resp = env.rpc("json", "account_nfts", to_string(params));
std::cout << resp[jss::result][jss::error_message] << std::endl;
BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field \'marker\'.");
}
}
Expand All @@ -1075,7 +1122,7 @@ class AccountObjects_test : public beast::unit_test::suite
testUnsteppedThenStepped();
testUnsteppedThenSteppedWithNFTs();
testObjectTypes();
testNFTsWithInvalidMarker();
testNFTsMarker();
}
};

Expand Down

0 comments on commit 5a65a4d

Please sign in to comment.