fix: account_objects returns error when filter does not make sense (#1579)

Fix #1488
This commit is contained in:
cyan317
2024-08-05 14:37:46 +01:00
committed by GitHub
parent 2a74a65b22
commit a7f34490b1
11 changed files with 233 additions and 130 deletions

View File

@@ -95,6 +95,12 @@ generateTestValuesForParametersTest()
"invalidParams",
"Invalid field 'type'."
},
AccountObjectsParamTestCaseBundle{
"TypeNotAccountOwned",
R"({"account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "type":"amendments"})",
"invalidParams",
"Invalid field 'type'."
},
AccountObjectsParamTestCaseBundle{
"LedgerHashInvalid",
R"({"account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "ledger_hash":"1"})",

View File

@@ -26,11 +26,12 @@
#include <algorithm>
#include <iterator>
#include <string_view>
TEST(LedgerUtilsTests, LedgerObjectTypeList)
{
auto const& types = util::getLedgerEntryTypeStrs();
static char const* typesList[] = {
auto constexpr types = util::LedgerTypes::GetLedgerEntryTypeStrList();
static constexpr char const* typesList[] = {
JS(account),
JS(amendments),
JS(check),
@@ -54,27 +55,63 @@ TEST(LedgerUtilsTests, LedgerObjectTypeList)
JS(oracle),
JS(nunl)
};
ASSERT_TRUE(std::size(typesList) == types.size());
EXPECT_TRUE(std::all_of(std::cbegin(typesList), std::cend(typesList), [&types](auto const& type) {
static_assert(std::size(typesList) == types.size());
static_assert(std::all_of(std::cbegin(typesList), std::cend(typesList), [&types](std::string_view type) {
return std::find(std::cbegin(types), std::cend(types), type) != std::cend(types);
}));
}
TEST(LedgerUtilsTests, AccountOwnedTypeList)
{
auto constexpr accountOwned = util::LedgerTypes::GetAccountOwnedLedgerTypeStrList();
static constexpr char const* correctTypes[] = {
JS(account),
JS(check),
JS(deposit_preauth),
JS(escrow),
JS(offer),
JS(payment_channel),
JS(signer_list),
JS(state),
JS(ticket),
JS(nft_offer),
JS(nft_page),
JS(amm),
JS(bridge),
JS(xchain_owned_claim_id),
JS(xchain_owned_create_account_claim_id),
JS(did),
JS(oracle)
};
static_assert(std::size(correctTypes) == accountOwned.size());
static_assert(std::all_of(
std::cbegin(correctTypes),
std::cend(correctTypes),
[&accountOwned](std::string_view type) {
return std::find(std::cbegin(accountOwned), std::cend(accountOwned), type) != std::cend(accountOwned);
}
));
}
TEST(LedgerUtilsTests, StrToType)
{
EXPECT_EQ(util::getLedgerEntryTypeFromStr("mess"), ripple::ltANY);
EXPECT_EQ(util::getLedgerEntryTypeFromStr("tomato"), ripple::ltANY);
EXPECT_EQ(util::getLedgerEntryTypeFromStr("account"), ripple::ltACCOUNT_ROOT);
EXPECT_EQ(util::LedgerTypes::GetLedgerEntryTypeFromStr("mess"), ripple::ltANY);
EXPECT_EQ(util::LedgerTypes::GetLedgerEntryTypeFromStr("tomato"), ripple::ltANY);
EXPECT_EQ(util::LedgerTypes::GetLedgerEntryTypeFromStr("account"), ripple::ltACCOUNT_ROOT);
auto const& types = util::getLedgerEntryTypeStrs();
auto constexpr types = util::LedgerTypes::GetLedgerEntryTypeStrList();
std::for_each(types.cbegin(), types.cend(), [](auto const& typeStr) {
EXPECT_NE(util::getLedgerEntryTypeFromStr(typeStr), ripple::ltANY);
EXPECT_NE(util::LedgerTypes::GetLedgerEntryTypeFromStr(typeStr), ripple::ltANY);
});
}
TEST(LedgerUtilsTests, DeletionBlockerTypes)
{
auto const& testedTypes = util::getDeletionBlockerLedgerTypes();
auto constexpr testedTypes = util::LedgerTypes::GetDeletionBlockerLedgerTypes();
static ripple::LedgerEntryType constexpr deletionBlockers[] = {
ripple::ltCHECK,
@@ -87,8 +124,8 @@ TEST(LedgerUtilsTests, DeletionBlockerTypes)
ripple::ltBRIDGE
};
ASSERT_TRUE(std::size(deletionBlockers) == testedTypes.size());
EXPECT_TRUE(std::any_of(testedTypes.cbegin(), testedTypes.cend(), [](auto const& type) {
static_assert(std::size(deletionBlockers) == testedTypes.size());
static_assert(std::any_of(testedTypes.cbegin(), testedTypes.cend(), [](auto const& type) {
return std::find(std::cbegin(deletionBlockers), std::cend(deletionBlockers), type) !=
std::cend(deletionBlockers);
}));