Skip to content

Commit

Permalink
[FOLD] Suggestions for testing invalid account_objects types
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed Jul 3, 2024
1 parent b8b4e88 commit ad508ff
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/test/rpc/AccountObjects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,25 +580,12 @@ class AccountObjects_test : public beast::unit_test::suite
};

// Make a lambda that checks if the response has error for invalid type
auto acct_objs_type_is_invalid = [](Json::Value const& resp) {
auto acctObjsTypeIsInvalid = [](Json::Value const& resp) {
return resp[jss::result].isMember(jss::error) &&
resp[jss::result][jss::error_message] ==
"Invalid field \'type\'.";
};

// Make a lambda that checks if different filtering type is invalid
auto check_invalid_filter_types = [&](AccountID const& acct) {
// we expect invalid field type reported for the following types
if (!acct_objs_type_is_invalid(acct_objs(acct, jss::amendments)) ||
!acct_objs_type_is_invalid(acct_objs(acct, jss::directory)) ||
!acct_objs_type_is_invalid(acct_objs(acct, jss::fee)) ||
!acct_objs_type_is_invalid(acct_objs(acct, jss::hashes)) ||
!acct_objs_type_is_invalid(acct_objs(acct, jss::NegativeUNL)))
return false;

return true;
};

env.fund(XRP(10000), gw, alice);
env.close();

Expand All @@ -617,8 +604,12 @@ class AccountObjects_test : public beast::unit_test::suite
BEAST_EXPECT(acct_objs_is_size(acct_objs(gw, jss::amm), 0));
BEAST_EXPECT(acct_objs_is_size(acct_objs(gw, jss::did), 0));

// invalid filter type should get invalid type response
BEAST_EXPECT(check_invalid_filter_types(gw));
// we expect invalid field type reported for the following types
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::amendments)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::directory)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::fee)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::hashes)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::NegativeUNL)));

// gw mints an NFT so we can find it.
uint256 const nftID{token::getNextID(env, gw, 0u, tfTransferable)};
Expand Down Expand Up @@ -1035,9 +1026,12 @@ class AccountObjects_test : public beast::unit_test::suite
BEAST_EXPECT(acct_objs_is_size(acct_objs(gw, jss::amm), 0));
}

// check invalid filter type again which should get invalid type
// response
BEAST_EXPECT(check_invalid_filter_types(gw));
// we still expect invalid field type reported for the following types
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::amendments)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::directory)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::fee)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::hashes)));
BEAST_EXPECT(acctObjsTypeIsInvalid(acct_objs(gw, jss::NegativeUNL)));

// Run up the number of directory entries so gw has two
// directory nodes.
Expand Down

0 comments on commit ad508ff

Please sign in to comment.