Change limit tests (#766)

Fixes #771
This commit is contained in:
cyan317
2023-07-14 13:08:08 +01:00
committed by GitHub
parent 50dbb51627
commit d195bdb66d
32 changed files with 1355 additions and 363 deletions

View File

@@ -42,6 +42,10 @@ class AccountChannelsHandler
std::shared_ptr<BackendInterface> const sharedPtrBackend_;
public:
static constexpr auto LIMIT_MIN = 10;
static constexpr auto LIMIT_MAX = 400;
static constexpr auto LIMIT_DEFAULT = 200;
// type align with SField.h
struct ChannelResponse
{
@@ -77,7 +81,7 @@ public:
std::optional<std::string> destinationAccount;
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 200;
uint32_t limit = LIMIT_DEFAULT;
std::optional<std::string> marker;
};
@@ -95,7 +99,7 @@ public:
{JS(account), validation::Required{}, validation::AccountValidator},
{JS(destination_account), validation::Type<std::string>{}, validation::AccountValidator},
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{10, 400}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(marker), validation::AccountMarkerValidator},
};

View File

@@ -51,7 +51,6 @@ public:
bool validated = true;
};
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
struct Input
{
std::string account;

View File

@@ -66,7 +66,6 @@ public:
// "queue" is not available in Reporting mode
// "ident" is deprecated, keep it for now, in line with rippled
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
struct Input
{
std::optional<std::string> account;

View File

@@ -42,6 +42,10 @@ class AccountLinesHandler
std::shared_ptr<BackendInterface> const sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 10;
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 200;
struct LineResponse
{
std::string account;
@@ -78,7 +82,7 @@ public:
std::optional<std::string> peer;
bool ignoreDefault = false; // TODO: document
// https://github.com/XRPLF/xrpl-dev-portal/issues/1839
uint32_t limit = 200;
uint32_t limit = LIMIT_DEFAULT;
std::optional<std::string> marker;
};
@@ -98,7 +102,7 @@ public:
{JS(peer), meta::WithCustomError{validation::AccountValidator, Status(RippledError::rpcACT_MALFORMED)}},
{JS(ignore_default), validation::Type<bool>{}},
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{10, 400}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(marker), validation::AccountMarkerValidator},
};

View File

@@ -37,6 +37,10 @@ class AccountNFTsHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 20;
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 100;
struct Output
{
std::string account;
@@ -54,7 +58,7 @@ public:
std::string account;
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 100; // Limit the number of token pages to retrieve. [20,400]
uint32_t limit = LIMIT_DEFAULT; // Limit the number of token pages to retrieve. [20,400]
std::optional<std::string> marker;
};
@@ -72,7 +76,7 @@ public:
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(marker), validation::Uint256HexStringValidator},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{20, 400}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
};
return rpcSpec;

View File

@@ -46,6 +46,10 @@ class AccountObjectsHandler
static std::unordered_map<std::string, ripple::LedgerEntryType> const TYPESMAP;
public:
static auto constexpr LIMIT_MIN = 10;
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 200;
struct Output
{
std::string account;
@@ -62,7 +66,7 @@ public:
std::string account;
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 200; // [10,400]
uint32_t limit = LIMIT_DEFAULT; // [10,400]
std::optional<std::string> marker;
std::optional<ripple::LedgerEntryType> type;
bool deletionBlockersOnly = false;
@@ -82,7 +86,7 @@ public:
{JS(account), validation::Required{}, validation::AccountValidator},
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>(10, 400)},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>(LIMIT_MIN, LIMIT_MAX)},
{JS(type),
validation::Type<std::string>{},
validation::OneOf<std::string>{

View File

@@ -38,6 +38,10 @@ class AccountOffersHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 10;
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 200;
struct Offer
{
uint32_t flags;
@@ -59,13 +63,12 @@ public:
bool validated = true;
};
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
struct Input
{
std::string account;
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 200;
uint32_t limit = LIMIT_DEFAULT;
std::optional<std::string> marker;
};
@@ -84,7 +87,7 @@ public:
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(marker), validation::AccountMarkerValidator},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{10, 400}}};
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}}};
return rpcSpec;
}

View File

@@ -81,8 +81,7 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con
cursor = {maxIndex, std::numeric_limits<int32_t>::max()};
}
static auto constexpr limitDefault = 200;
auto const limit = input.limit.value_or(limitDefault);
auto const limit = input.limit.value_or(LIMIT_DEFAULT);
auto const accountID = accountFromStringStrict(input.account);
auto const [txnsAndCursor, timeDiff] = util::timed([&]() {
return sharedPtrBackend_->fetchAccountTransactions(*accountID, limit, input.forward, cursor, ctx.yield);

View File

@@ -40,6 +40,10 @@ class AccountTxHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
// no max limit
static auto constexpr LIMIT_MIN = 1;
static auto constexpr LIMIT_DEFAULT = 200;
struct Marker
{
uint32_t ledger;
@@ -94,7 +98,7 @@ public:
{JS(forward), validation::Type<bool>{}},
{JS(limit),
validation::Type<uint32_t>{},
modifiers::Clamp<int32_t>{1, std::numeric_limits<int32_t>::max()}},
modifiers::Clamp<int32_t>{LIMIT_MIN, std::numeric_limits<int32_t>::max()}},
{JS(marker),
meta::WithCustomError{
validation::Type<boost::json::object>{},

View File

@@ -37,6 +37,10 @@ class BookOffersHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 1;
static auto constexpr LIMIT_MAX = 100;
static auto constexpr LIMIT_DEFAULT = 60;
struct Output
{
std::string ledgerHash;
@@ -51,7 +55,7 @@ public:
{
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 60;
uint32_t limit = LIMIT_DEFAULT;
std::optional<ripple::AccountID> taker;
ripple::Currency paysCurrency;
ripple::Currency getsCurrency;
@@ -92,7 +96,7 @@ public:
{JS(taker),
meta::WithCustomError{
validation::AccountValidator, Status(RippledError::rpcINVALID_PARAMS, "Invalid field 'taker'")}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{1, 100}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
};

View File

@@ -52,7 +52,6 @@ public:
bool validated = true;
};
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
struct Input
{
std::string account;

View File

@@ -42,15 +42,15 @@ class LedgerDataHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
clio::Logger log_{"RPC"};
// constants
static uint32_t constexpr LIMITBINARY = 2048;
static uint32_t constexpr LIMITJSON = 256;
static const std::unordered_map<std::string, ripple::LedgerEntryType> TYPES_MAP;
static const std::unordered_set<std::string> TYPES_KEYS;
public:
// constants
static uint32_t constexpr LIMITBINARY = 2048;
static uint32_t constexpr LIMITJSON = 256;
struct Output
{
uint32_t ledgerIndex;

View File

@@ -81,9 +81,7 @@ NFTHistoryHandler::process(NFTHistoryHandler::Input input, Context const& ctx) c
cursor = {maxIndex, std::numeric_limits<int32_t>::max()};
}
static auto constexpr limitDefault = 50;
auto const limit = input.limit.value_or(limitDefault);
auto const limit = input.limit.value_or(LIMIT_DEFAULT);
auto const tokenID = ripple::uint256{input.nftID.c_str()};
auto const [txnsAndCursor, timeDiff] = util::timed(

View File

@@ -40,6 +40,10 @@ class NFTHistoryHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 1;
static auto constexpr LIMIT_MAX = 100;
static auto constexpr LIMIT_DEFAULT = 50;
// TODO: this marker is same as account_tx, reuse in future
struct Marker
{
@@ -92,7 +96,7 @@ public:
{JS(ledger_index_max), validation::Type<int32_t>{}},
{JS(binary), validation::Type<bool>{}},
{JS(forward), validation::Type<bool>{}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{1, 100}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
{JS(marker),
meta::WithCustomError{
validation::Type<boost::json::object>{}, Status{RippledError::rpcINVALID_PARAMS, "invalidMarker"}},

View File

@@ -32,6 +32,10 @@ class NFTOffersHandlerBase
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 50;
static auto constexpr LIMIT_MAX = 500;
static auto constexpr LIMIT_DEFAULT = 250;
struct Output
{
std::string nftID;
@@ -48,7 +52,7 @@ public:
std::string nftID;
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 250;
uint32_t limit = LIMIT_DEFAULT;
std::optional<std::string> marker;
};
@@ -66,7 +70,7 @@ public:
{JS(nft_id), validation::Required{}, validation::Uint256HexStringValidator},
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{50, 500}},
{JS(limit), validation::Type<uint32_t>{}, modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
{JS(marker), validation::Uint256HexStringValidator},
};

View File

@@ -41,6 +41,10 @@ class NoRippleCheckHandler
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
static auto constexpr LIMIT_MIN = 1;
static auto constexpr LIMIT_MAX = 500;
static auto constexpr LIMIT_DEFAULT = 300;
struct Output
{
std::string ledgerHash;
@@ -57,7 +61,7 @@ public:
bool roleGateway = false;
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
uint32_t limit = 300;
uint32_t limit = LIMIT_DEFAULT;
bool transactions = false;
};
@@ -80,7 +84,7 @@ public:
Status{RippledError::rpcINVALID_PARAMS, "role field is invalid"}}},
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
{JS(limit), validation::Type<uint32_t>(), modifiers::Clamp<int32_t>{1, 500}},
{JS(limit), validation::Type<uint32_t>(), modifiers::Clamp<int32_t>{LIMIT_MIN, LIMIT_MAX}},
{JS(transactions), validation::Type<bool>()},
};

View File

@@ -24,7 +24,7 @@ namespace RPC {
TxHandler::Result
TxHandler::process(Input input, Context const& ctx) const
{
constexpr static auto maxLedgerRange = 1000u;
static auto constexpr maxLedgerRange = 1000u;
auto const rangeSupplied = input.minLedger && input.maxLedger;
if (rangeSupplied)