mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-27 15:15:52 +00:00
@@ -42,6 +42,10 @@ class AccountChannelsHandler
|
|||||||
std::shared_ptr<BackendInterface> const sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> const sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static constexpr auto LIMIT_MIN = 10;
|
||||||
|
static constexpr auto LIMIT_MAX = 400;
|
||||||
|
static constexpr auto LIMIT_DEFAULT = 200;
|
||||||
|
|
||||||
// type align with SField.h
|
// type align with SField.h
|
||||||
struct ChannelResponse
|
struct ChannelResponse
|
||||||
{
|
{
|
||||||
@@ -77,7 +81,7 @@ public:
|
|||||||
std::optional<std::string> destinationAccount;
|
std::optional<std::string> destinationAccount;
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
std::optional<uint32_t> ledgerIndex;
|
||||||
uint32_t limit = 200;
|
uint32_t limit = LIMIT_DEFAULT;
|
||||||
std::optional<std::string> marker;
|
std::optional<std::string> marker;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,7 +99,7 @@ public:
|
|||||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||||
{JS(destination_account), validation::Type<std::string>{}, validation::AccountValidator},
|
{JS(destination_account), validation::Type<std::string>{}, validation::AccountValidator},
|
||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{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(ledger_index), validation::LedgerIndexValidator},
|
||||||
{JS(marker), validation::AccountMarkerValidator},
|
{JS(marker), validation::AccountMarkerValidator},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public:
|
|||||||
bool validated = true;
|
bool validated = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
|
|
||||||
struct Input
|
struct Input
|
||||||
{
|
{
|
||||||
std::string account;
|
std::string account;
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ public:
|
|||||||
|
|
||||||
// "queue" is not available in Reporting mode
|
// "queue" is not available in Reporting mode
|
||||||
// "ident" is deprecated, keep it for now, in line with rippled
|
// "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
|
struct Input
|
||||||
{
|
{
|
||||||
std::optional<std::string> account;
|
std::optional<std::string> account;
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ class AccountLinesHandler
|
|||||||
std::shared_ptr<BackendInterface> const sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> const sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 10;
|
||||||
|
static auto constexpr LIMIT_MAX = 400;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 200;
|
||||||
|
|
||||||
struct LineResponse
|
struct LineResponse
|
||||||
{
|
{
|
||||||
std::string account;
|
std::string account;
|
||||||
@@ -78,7 +82,7 @@ public:
|
|||||||
std::optional<std::string> peer;
|
std::optional<std::string> peer;
|
||||||
bool ignoreDefault = false; // TODO: document
|
bool ignoreDefault = false; // TODO: document
|
||||||
// https://github.com/XRPLF/xrpl-dev-portal/issues/1839
|
// https://github.com/XRPLF/xrpl-dev-portal/issues/1839
|
||||||
uint32_t limit = 200;
|
uint32_t limit = LIMIT_DEFAULT;
|
||||||
std::optional<std::string> marker;
|
std::optional<std::string> marker;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,7 +102,7 @@ public:
|
|||||||
{JS(peer), meta::WithCustomError{validation::AccountValidator, Status(RippledError::rpcACT_MALFORMED)}},
|
{JS(peer), meta::WithCustomError{validation::AccountValidator, Status(RippledError::rpcACT_MALFORMED)}},
|
||||||
{JS(ignore_default), validation::Type<bool>{}},
|
{JS(ignore_default), validation::Type<bool>{}},
|
||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{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(ledger_index), validation::LedgerIndexValidator},
|
||||||
{JS(marker), validation::AccountMarkerValidator},
|
{JS(marker), validation::AccountMarkerValidator},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class AccountNFTsHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 20;
|
||||||
|
static auto constexpr LIMIT_MAX = 400;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 100;
|
||||||
|
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
std::string account;
|
std::string account;
|
||||||
@@ -54,7 +58,7 @@ public:
|
|||||||
std::string account;
|
std::string account;
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
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;
|
std::optional<std::string> marker;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ public:
|
|||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||||
{JS(marker), validation::Uint256HexStringValidator},
|
{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;
|
return rpcSpec;
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ class AccountObjectsHandler
|
|||||||
static std::unordered_map<std::string, ripple::LedgerEntryType> const TYPESMAP;
|
static std::unordered_map<std::string, ripple::LedgerEntryType> const TYPESMAP;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 10;
|
||||||
|
static auto constexpr LIMIT_MAX = 400;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 200;
|
||||||
|
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
std::string account;
|
std::string account;
|
||||||
@@ -62,7 +66,7 @@ public:
|
|||||||
std::string account;
|
std::string account;
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
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<std::string> marker;
|
||||||
std::optional<ripple::LedgerEntryType> type;
|
std::optional<ripple::LedgerEntryType> type;
|
||||||
bool deletionBlockersOnly = false;
|
bool deletionBlockersOnly = false;
|
||||||
@@ -82,7 +86,7 @@ public:
|
|||||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{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),
|
{JS(type),
|
||||||
validation::Type<std::string>{},
|
validation::Type<std::string>{},
|
||||||
validation::OneOf<std::string>{
|
validation::OneOf<std::string>{
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ class AccountOffersHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 10;
|
||||||
|
static auto constexpr LIMIT_MAX = 400;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 200;
|
||||||
|
|
||||||
struct Offer
|
struct Offer
|
||||||
{
|
{
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
@@ -59,13 +63,12 @@ public:
|
|||||||
bool validated = true;
|
bool validated = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
|
|
||||||
struct Input
|
struct Input
|
||||||
{
|
{
|
||||||
std::string account;
|
std::string account;
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
std::optional<uint32_t> ledgerIndex;
|
||||||
uint32_t limit = 200;
|
uint32_t limit = LIMIT_DEFAULT;
|
||||||
std::optional<std::string> marker;
|
std::optional<std::string> marker;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -84,7 +87,7 @@ public:
|
|||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||||
{JS(marker), validation::AccountMarkerValidator},
|
{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;
|
return rpcSpec;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con
|
|||||||
cursor = {maxIndex, std::numeric_limits<int32_t>::max()};
|
cursor = {maxIndex, std::numeric_limits<int32_t>::max()};
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto constexpr limitDefault = 200;
|
auto const limit = input.limit.value_or(LIMIT_DEFAULT);
|
||||||
auto const limit = input.limit.value_or(limitDefault);
|
|
||||||
auto const accountID = accountFromStringStrict(input.account);
|
auto const accountID = accountFromStringStrict(input.account);
|
||||||
auto const [txnsAndCursor, timeDiff] = util::timed([&]() {
|
auto const [txnsAndCursor, timeDiff] = util::timed([&]() {
|
||||||
return sharedPtrBackend_->fetchAccountTransactions(*accountID, limit, input.forward, cursor, ctx.yield);
|
return sharedPtrBackend_->fetchAccountTransactions(*accountID, limit, input.forward, cursor, ctx.yield);
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ class AccountTxHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// no max limit
|
||||||
|
static auto constexpr LIMIT_MIN = 1;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 200;
|
||||||
|
|
||||||
struct Marker
|
struct Marker
|
||||||
{
|
{
|
||||||
uint32_t ledger;
|
uint32_t ledger;
|
||||||
@@ -94,7 +98,7 @@ public:
|
|||||||
{JS(forward), validation::Type<bool>{}},
|
{JS(forward), validation::Type<bool>{}},
|
||||||
{JS(limit),
|
{JS(limit),
|
||||||
validation::Type<uint32_t>{},
|
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),
|
{JS(marker),
|
||||||
meta::WithCustomError{
|
meta::WithCustomError{
|
||||||
validation::Type<boost::json::object>{},
|
validation::Type<boost::json::object>{},
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class BookOffersHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 1;
|
||||||
|
static auto constexpr LIMIT_MAX = 100;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 60;
|
||||||
|
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
std::string ledgerHash;
|
std::string ledgerHash;
|
||||||
@@ -51,7 +55,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
std::optional<uint32_t> ledgerIndex;
|
||||||
uint32_t limit = 60;
|
uint32_t limit = LIMIT_DEFAULT;
|
||||||
std::optional<ripple::AccountID> taker;
|
std::optional<ripple::AccountID> taker;
|
||||||
ripple::Currency paysCurrency;
|
ripple::Currency paysCurrency;
|
||||||
ripple::Currency getsCurrency;
|
ripple::Currency getsCurrency;
|
||||||
@@ -92,7 +96,7 @@ public:
|
|||||||
{JS(taker),
|
{JS(taker),
|
||||||
meta::WithCustomError{
|
meta::WithCustomError{
|
||||||
validation::AccountValidator, Status(RippledError::rpcINVALID_PARAMS, "Invalid field 'taker'")}},
|
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_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public:
|
|||||||
bool validated = true;
|
bool validated = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: clio only supports XRP Ledger addresses (i.e. `strict` is unsupported for `false`)
|
|
||||||
struct Input
|
struct Input
|
||||||
{
|
{
|
||||||
std::string account;
|
std::string account;
|
||||||
|
|||||||
@@ -42,15 +42,15 @@ class LedgerDataHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
clio::Logger log_{"RPC"};
|
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_map<std::string, ripple::LedgerEntryType> TYPES_MAP;
|
||||||
|
|
||||||
static const std::unordered_set<std::string> TYPES_KEYS;
|
static const std::unordered_set<std::string> TYPES_KEYS;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// constants
|
||||||
|
static uint32_t constexpr LIMITBINARY = 2048;
|
||||||
|
static uint32_t constexpr LIMITJSON = 256;
|
||||||
|
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
uint32_t ledgerIndex;
|
uint32_t ledgerIndex;
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ NFTHistoryHandler::process(NFTHistoryHandler::Input input, Context const& ctx) c
|
|||||||
cursor = {maxIndex, std::numeric_limits<int32_t>::max()};
|
cursor = {maxIndex, std::numeric_limits<int32_t>::max()};
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto constexpr limitDefault = 50;
|
auto const limit = input.limit.value_or(LIMIT_DEFAULT);
|
||||||
|
|
||||||
auto const limit = input.limit.value_or(limitDefault);
|
|
||||||
auto const tokenID = ripple::uint256{input.nftID.c_str()};
|
auto const tokenID = ripple::uint256{input.nftID.c_str()};
|
||||||
|
|
||||||
auto const [txnsAndCursor, timeDiff] = util::timed(
|
auto const [txnsAndCursor, timeDiff] = util::timed(
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ class NFTHistoryHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
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
|
// TODO: this marker is same as account_tx, reuse in future
|
||||||
struct Marker
|
struct Marker
|
||||||
{
|
{
|
||||||
@@ -92,7 +96,7 @@ public:
|
|||||||
{JS(ledger_index_max), validation::Type<int32_t>{}},
|
{JS(ledger_index_max), validation::Type<int32_t>{}},
|
||||||
{JS(binary), validation::Type<bool>{}},
|
{JS(binary), validation::Type<bool>{}},
|
||||||
{JS(forward), 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),
|
{JS(marker),
|
||||||
meta::WithCustomError{
|
meta::WithCustomError{
|
||||||
validation::Type<boost::json::object>{}, Status{RippledError::rpcINVALID_PARAMS, "invalidMarker"}},
|
validation::Type<boost::json::object>{}, Status{RippledError::rpcINVALID_PARAMS, "invalidMarker"}},
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ class NFTOffersHandlerBase
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 50;
|
||||||
|
static auto constexpr LIMIT_MAX = 500;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 250;
|
||||||
|
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
std::string nftID;
|
std::string nftID;
|
||||||
@@ -48,7 +52,7 @@ public:
|
|||||||
std::string nftID;
|
std::string nftID;
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
std::optional<uint32_t> ledgerIndex;
|
||||||
uint32_t limit = 250;
|
uint32_t limit = LIMIT_DEFAULT;
|
||||||
std::optional<std::string> marker;
|
std::optional<std::string> marker;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,7 +70,7 @@ public:
|
|||||||
{JS(nft_id), validation::Required{}, validation::Uint256HexStringValidator},
|
{JS(nft_id), validation::Required{}, validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{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},
|
{JS(marker), validation::Uint256HexStringValidator},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ class NoRippleCheckHandler
|
|||||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static auto constexpr LIMIT_MIN = 1;
|
||||||
|
static auto constexpr LIMIT_MAX = 500;
|
||||||
|
static auto constexpr LIMIT_DEFAULT = 300;
|
||||||
|
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
std::string ledgerHash;
|
std::string ledgerHash;
|
||||||
@@ -57,7 +61,7 @@ public:
|
|||||||
bool roleGateway = false;
|
bool roleGateway = false;
|
||||||
std::optional<std::string> ledgerHash;
|
std::optional<std::string> ledgerHash;
|
||||||
std::optional<uint32_t> ledgerIndex;
|
std::optional<uint32_t> ledgerIndex;
|
||||||
uint32_t limit = 300;
|
uint32_t limit = LIMIT_DEFAULT;
|
||||||
bool transactions = false;
|
bool transactions = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,7 +84,7 @@ public:
|
|||||||
Status{RippledError::rpcINVALID_PARAMS, "role field is invalid"}}},
|
Status{RippledError::rpcINVALID_PARAMS, "role field is invalid"}}},
|
||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{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>()},
|
{JS(transactions), validation::Type<bool>()},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace RPC {
|
|||||||
TxHandler::Result
|
TxHandler::Result
|
||||||
TxHandler::process(Input input, Context const& ctx) const
|
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;
|
auto const rangeSupplied = input.minLedger && input.maxLedger;
|
||||||
|
|
||||||
if (rangeSupplied)
|
if (rangeSupplied)
|
||||||
|
|||||||
@@ -810,3 +810,97 @@ TEST_F(RPCAccountChannelsHandlerTest, MarkerInput)
|
|||||||
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), limit - 1);
|
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), limit - 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountChannelsHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
// fetch account object return something
|
||||||
|
auto account = GetAccountIDWithString(ACCOUNT);
|
||||||
|
auto accountKk = ripple::keylet::account(account).key;
|
||||||
|
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||||
|
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||||
|
// return a non empty account
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
// return two payment channel objects
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||||
|
bbs.push_back(channel1.getSerializer().peekData());
|
||||||
|
bbs.push_back(channel1.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountChannelsHandler::LIMIT_MIN - 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto handler = AnyHandler{AccountChannelsHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), 2);
|
||||||
|
EXPECT_EQ((*output).as_object().at("limit").as_uint64(), AccountChannelsHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountChannelsHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
// fetch account object return something
|
||||||
|
auto account = GetAccountIDWithString(ACCOUNT);
|
||||||
|
auto accountKk = ripple::keylet::account(account).key;
|
||||||
|
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||||
|
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||||
|
// return a non empty account
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
// return two payment channel objects
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||||
|
bbs.push_back(channel1.getSerializer().peekData());
|
||||||
|
bbs.push_back(channel1.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountChannelsHandler::LIMIT_MAX + 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto handler = AnyHandler{AccountChannelsHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), 2);
|
||||||
|
EXPECT_EQ((*output).as_object().at("limit").as_uint64(), AccountChannelsHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -290,89 +290,3 @@ TEST_F(RPCAccountCurrenciesHandlerTest, RequestViaLegderSeq)
|
|||||||
EXPECT_EQ((*output).as_object().at("ledger_index").as_uint64(), ledgerSeq);
|
EXPECT_EQ((*output).as_object().at("ledger_index").as_uint64(), ledgerSeq);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RPCAccountCurrenciesHandlerTest, RequestViaLegderSeqWithStrictTrue)
|
|
||||||
{
|
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
|
||||||
mockBackendPtr->updateRange(10); // min
|
|
||||||
mockBackendPtr->updateRange(30); // max
|
|
||||||
auto const ledgerSeq = 29;
|
|
||||||
// return valid ledgerinfo
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, ledgerSeq);
|
|
||||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
|
||||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(ledgerSeq, _)).WillByDefault(Return(ledgerinfo));
|
|
||||||
// return valid account
|
|
||||||
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
|
||||||
|
|
||||||
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}}, INDEX1);
|
|
||||||
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
|
||||||
std::vector<Blob> bbs;
|
|
||||||
auto const line1 =
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, 0);
|
|
||||||
bbs.push_back(line1.getSerializer().peekData());
|
|
||||||
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
|
||||||
auto const static input = boost::json::parse(fmt::format(
|
|
||||||
R"({{
|
|
||||||
"account": "{}",
|
|
||||||
"ledger_index": {},
|
|
||||||
"strict": true
|
|
||||||
}})",
|
|
||||||
ACCOUNT,
|
|
||||||
ledgerSeq));
|
|
||||||
auto const handler = AnyHandler{AccountCurrenciesHandler{mockBackendPtr}};
|
|
||||||
runSpawn([&](auto& yield) {
|
|
||||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
|
||||||
ASSERT_TRUE(output);
|
|
||||||
EXPECT_EQ((*output).as_object().at("ledger_index").as_uint64(), ledgerSeq);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCAccountCurrenciesHandlerTest, RequestViaLegderSeqWithStrictOfInvalidType)
|
|
||||||
{
|
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
|
||||||
mockBackendPtr->updateRange(10); // min
|
|
||||||
mockBackendPtr->updateRange(30); // max
|
|
||||||
auto const ledgerSeq = 29;
|
|
||||||
// return valid ledgerinfo
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, ledgerSeq);
|
|
||||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
|
||||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(ledgerSeq, _)).WillByDefault(Return(ledgerinfo));
|
|
||||||
// return valid account
|
|
||||||
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
|
||||||
|
|
||||||
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}}, INDEX1);
|
|
||||||
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
|
||||||
std::vector<Blob> bbs;
|
|
||||||
auto const line1 =
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, 0);
|
|
||||||
bbs.push_back(line1.getSerializer().peekData());
|
|
||||||
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
|
||||||
auto const static input = boost::json::parse(fmt::format(
|
|
||||||
R"({{
|
|
||||||
"account": "{}",
|
|
||||||
"ledger_index": {},
|
|
||||||
"strict": "test"
|
|
||||||
}})",
|
|
||||||
ACCOUNT,
|
|
||||||
ledgerSeq));
|
|
||||||
auto const handler = AnyHandler{AccountCurrenciesHandler{mockBackendPtr}};
|
|
||||||
runSpawn([&](auto& yield) {
|
|
||||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
|
||||||
ASSERT_TRUE(output);
|
|
||||||
EXPECT_EQ((*output).as_object().at("ledger_index").as_uint64(), ledgerSeq);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -449,72 +449,6 @@ TEST_F(RPCAccountInfoHandlerTest, Flags)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RPCAccountInfoHandlerTest, StrictTrue)
|
|
||||||
{
|
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
|
||||||
|
|
||||||
mockBackendPtr->updateRange(10); // min
|
|
||||||
mockBackendPtr->updateRange(30); // max
|
|
||||||
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
|
||||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
|
||||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
|
||||||
|
|
||||||
auto const account = GetAccountIDWithString(ACCOUNT);
|
|
||||||
auto const accountKk = ripple::keylet::account(account).key;
|
|
||||||
auto const accountRoot = CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2);
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, 30, _))
|
|
||||||
.WillByDefault(Return(accountRoot.getSerializer().peekData()));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(1);
|
|
||||||
|
|
||||||
auto const static input = boost::json::parse(fmt::format(
|
|
||||||
R"({{
|
|
||||||
"account": "{}",
|
|
||||||
"strict": true
|
|
||||||
}})",
|
|
||||||
ACCOUNT));
|
|
||||||
|
|
||||||
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
|
|
||||||
|
|
||||||
runSpawn([&](auto& yield) {
|
|
||||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
|
||||||
ASSERT_TRUE(output);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCAccountInfoHandlerTest, StrictInvalidTypeHasNoEffect)
|
|
||||||
{
|
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
|
||||||
|
|
||||||
mockBackendPtr->updateRange(10); // min
|
|
||||||
mockBackendPtr->updateRange(30); // max
|
|
||||||
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
|
||||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
|
||||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
|
||||||
|
|
||||||
auto const account = GetAccountIDWithString(ACCOUNT);
|
|
||||||
auto const accountKk = ripple::keylet::account(account).key;
|
|
||||||
auto const accountRoot = CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2);
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, 30, _))
|
|
||||||
.WillByDefault(Return(accountRoot.getSerializer().peekData()));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(1);
|
|
||||||
|
|
||||||
auto const static input = boost::json::parse(fmt::format(
|
|
||||||
R"({{
|
|
||||||
"account": "{}",
|
|
||||||
"strict": "test"
|
|
||||||
}})",
|
|
||||||
ACCOUNT));
|
|
||||||
|
|
||||||
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
|
|
||||||
|
|
||||||
runSpawn([&](auto& yield) {
|
|
||||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
|
||||||
ASSERT_TRUE(output);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCAccountInfoHandlerTest, IdentAndSignerListsFalse)
|
TEST_F(RPCAccountInfoHandlerTest, IdentAndSignerListsFalse)
|
||||||
{
|
{
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
|||||||
@@ -867,3 +867,169 @@ TEST_F(RPCAccountLinesHandlerTest, MarkerInput)
|
|||||||
EXPECT_EQ((*output).as_object().at("lines").as_array().size(), limit - 1);
|
EXPECT_EQ((*output).as_object().at("lines").as_array().size(), limit - 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountLinesHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
// fetch account object return something
|
||||||
|
auto account = GetAccountIDWithString(ACCOUNT);
|
||||||
|
auto accountKk = ripple::keylet::account(account).key;
|
||||||
|
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||||
|
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||||
|
// return a non empty account
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
// return two trust lines
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const line1 =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT, "USD", ACCOUNT2, 10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123);
|
||||||
|
auto const line2 =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT2, "USD", ACCOUNT, 10, ACCOUNT2, 100, ACCOUNT, 200, TXNID, 123);
|
||||||
|
bbs.push_back(line1.getSerializer().peekData());
|
||||||
|
bbs.push_back(line2.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
runSpawn([this](auto& yield) {
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountLinesHandler::LIMIT_MIN - 1));
|
||||||
|
auto const correctOutput = fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"ledger_hash": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652",
|
||||||
|
"ledger_index": 30,
|
||||||
|
"validated": true,
|
||||||
|
"limit": {},
|
||||||
|
"lines": [
|
||||||
|
{{
|
||||||
|
"account": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||||
|
"balance": "10",
|
||||||
|
"currency": "USD",
|
||||||
|
"limit": "100",
|
||||||
|
"limit_peer": "200",
|
||||||
|
"quality_in": 0,
|
||||||
|
"quality_out": 0,
|
||||||
|
"no_ripple": false,
|
||||||
|
"no_ripple_peer": false
|
||||||
|
}},
|
||||||
|
{{
|
||||||
|
"account": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||||
|
"balance": "-10",
|
||||||
|
"currency": "USD",
|
||||||
|
"limit": "200",
|
||||||
|
"limit_peer": "100",
|
||||||
|
"quality_in": 0,
|
||||||
|
"quality_out": 0,
|
||||||
|
"no_ripple": false,
|
||||||
|
"no_ripple_peer": false
|
||||||
|
}}
|
||||||
|
]
|
||||||
|
}})",
|
||||||
|
AccountLinesHandler::LIMIT_MIN);
|
||||||
|
|
||||||
|
auto handler = AnyHandler{AccountLinesHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(json::parse(correctOutput), *output);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountLinesHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
// fetch account object return something
|
||||||
|
auto account = GetAccountIDWithString(ACCOUNT);
|
||||||
|
auto accountKk = ripple::keylet::account(account).key;
|
||||||
|
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||||
|
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||||
|
// return a non empty account
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
// return two trust lines
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const line1 =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT, "USD", ACCOUNT2, 10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123);
|
||||||
|
auto const line2 =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT2, "USD", ACCOUNT, 10, ACCOUNT2, 100, ACCOUNT, 200, TXNID, 123);
|
||||||
|
bbs.push_back(line1.getSerializer().peekData());
|
||||||
|
bbs.push_back(line2.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
runSpawn([this](auto& yield) {
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountLinesHandler::LIMIT_MAX + 1));
|
||||||
|
auto const correctOutput = fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"ledger_hash": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652",
|
||||||
|
"ledger_index": 30,
|
||||||
|
"validated": true,
|
||||||
|
"limit": {},
|
||||||
|
"lines": [
|
||||||
|
{{
|
||||||
|
"account": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||||
|
"balance": "10",
|
||||||
|
"currency": "USD",
|
||||||
|
"limit": "100",
|
||||||
|
"limit_peer": "200",
|
||||||
|
"quality_in": 0,
|
||||||
|
"quality_out": 0,
|
||||||
|
"no_ripple": false,
|
||||||
|
"no_ripple_peer": false
|
||||||
|
}},
|
||||||
|
{{
|
||||||
|
"account": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||||
|
"balance": "-10",
|
||||||
|
"currency": "USD",
|
||||||
|
"limit": "200",
|
||||||
|
"limit_peer": "100",
|
||||||
|
"quality_in": 0,
|
||||||
|
"quality_out": 0,
|
||||||
|
"no_ripple": false,
|
||||||
|
"no_ripple_peer": false
|
||||||
|
}}
|
||||||
|
]
|
||||||
|
}})",
|
||||||
|
AccountLinesHandler::LIMIT_MAX);
|
||||||
|
|
||||||
|
auto handler = AnyHandler{AccountLinesHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(json::parse(correctOutput), *output);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -389,3 +389,129 @@ TEST_F(RPCAccountNFTsHandlerTest, Marker)
|
|||||||
EXPECT_EQ(output->as_object().at("account_nfts").as_array().size(), 1);
|
EXPECT_EQ(output->as_object().at("account_nfts").as_array().size(), 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountNFTsHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
static auto const expectedOutput = fmt::format(
|
||||||
|
R"({{
|
||||||
|
"ledger_hash":"{}",
|
||||||
|
"ledger_index":30,
|
||||||
|
"validated":true,
|
||||||
|
"account":"{}",
|
||||||
|
"account_nfts":[
|
||||||
|
{{
|
||||||
|
"NFTokenID":"{}",
|
||||||
|
"URI":"7777772E6F6B2E636F6D",
|
||||||
|
"Flags":{},
|
||||||
|
"Issuer":"{}",
|
||||||
|
"NFTokenTaxon":{},
|
||||||
|
"nft_serial":{},
|
||||||
|
"TransferFee":10000
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"limit":{}
|
||||||
|
}})",
|
||||||
|
LEDGERHASH,
|
||||||
|
ACCOUNT,
|
||||||
|
TOKENID,
|
||||||
|
FLAG,
|
||||||
|
ISSUER,
|
||||||
|
TAXON,
|
||||||
|
SERIAL,
|
||||||
|
AccountNFTsHandler::LIMIT_MIN);
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(MINSEQ);
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ);
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, MAXSEQ);
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
|
||||||
|
auto const accountObject = CreateAccountRootObject(ACCOUNT, 0, 1, 10, 2, TXNID, 3);
|
||||||
|
auto const accountID = GetAccountIDWithString(ACCOUNT);
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(accountID).key, 30, _))
|
||||||
|
.WillByDefault(Return(accountObject.getSerializer().peekData()));
|
||||||
|
|
||||||
|
auto const firstPage = ripple::keylet::nftpage_max(accountID).key;
|
||||||
|
auto const pageObject =
|
||||||
|
CreateNFTTokenPage(std::vector{std::make_pair<std::string, std::string>(TOKENID, "www.ok.com")}, std::nullopt);
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(firstPage, 30, _))
|
||||||
|
.WillByDefault(Return(pageObject.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"limit":{}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountNFTsHandler::LIMIT_MIN - 1));
|
||||||
|
auto const handler = AnyHandler{AccountNFTsHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](auto& yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(*output, json::parse(expectedOutput));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountNFTsHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
static auto const expectedOutput = fmt::format(
|
||||||
|
R"({{
|
||||||
|
"ledger_hash":"{}",
|
||||||
|
"ledger_index":30,
|
||||||
|
"validated":true,
|
||||||
|
"account":"{}",
|
||||||
|
"account_nfts":[
|
||||||
|
{{
|
||||||
|
"NFTokenID":"{}",
|
||||||
|
"URI":"7777772E6F6B2E636F6D",
|
||||||
|
"Flags":{},
|
||||||
|
"Issuer":"{}",
|
||||||
|
"NFTokenTaxon":{},
|
||||||
|
"nft_serial":{},
|
||||||
|
"TransferFee":10000
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"limit":{}
|
||||||
|
}})",
|
||||||
|
LEDGERHASH,
|
||||||
|
ACCOUNT,
|
||||||
|
TOKENID,
|
||||||
|
FLAG,
|
||||||
|
ISSUER,
|
||||||
|
TAXON,
|
||||||
|
SERIAL,
|
||||||
|
AccountNFTsHandler::LIMIT_MAX);
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(MINSEQ);
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ);
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, MAXSEQ);
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
|
||||||
|
auto const accountObject = CreateAccountRootObject(ACCOUNT, 0, 1, 10, 2, TXNID, 3);
|
||||||
|
auto const accountID = GetAccountIDWithString(ACCOUNT);
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(accountID).key, 30, _))
|
||||||
|
.WillByDefault(Return(accountObject.getSerializer().peekData()));
|
||||||
|
|
||||||
|
auto const firstPage = ripple::keylet::nftpage_max(accountID).key;
|
||||||
|
auto const pageObject =
|
||||||
|
CreateNFTTokenPage(std::vector{std::make_pair<std::string, std::string>(TOKENID, "www.ok.com")}, std::nullopt);
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(firstPage, 30, _))
|
||||||
|
.WillByDefault(Return(pageObject.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"limit":{}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountNFTsHandler::LIMIT_MAX + 1));
|
||||||
|
auto const handler = AnyHandler{AccountNFTsHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](auto& yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(*output, json::parse(expectedOutput));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1526,3 +1526,165 @@ TEST_F(RPCAccountObjectsHandlerTest, NFTZeroMarkerNotAffectOtherMarker)
|
|||||||
EXPECT_EQ(output->as_object().at("marker").as_string(), fmt::format("{},{}", INDEX1, 0));
|
EXPECT_EQ(output->as_object().at("marker").as_string(), fmt::format("{},{}", INDEX1, 0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountObjectsHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
static auto const expectedOut = fmt::format(
|
||||||
|
R"({{
|
||||||
|
"ledger_hash":"4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652",
|
||||||
|
"ledger_index":30,
|
||||||
|
"validated":true,
|
||||||
|
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"limit": {},
|
||||||
|
"account_objects":[
|
||||||
|
{{
|
||||||
|
"Balance":{{
|
||||||
|
"currency":"USD",
|
||||||
|
"issuer":"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
|
||||||
|
"value":"100"
|
||||||
|
}},
|
||||||
|
"Flags":0,
|
||||||
|
"HighLimit":{{
|
||||||
|
"currency":"USD",
|
||||||
|
"issuer":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||||
|
"value":"20"
|
||||||
|
}},
|
||||||
|
"LedgerEntryType":"RippleState",
|
||||||
|
"LowLimit":{{
|
||||||
|
"currency":"USD",
|
||||||
|
"issuer":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"value":"10"
|
||||||
|
}},
|
||||||
|
"PreviousTxnID":"E3FE6EA3D48F0C2B639448020EA4F03D4F4F8FFDB243A852A0F59177921B4879",
|
||||||
|
"PreviousTxnLgrSeq":123,
|
||||||
|
"index":"1B8590C01B0006EDFA9ED60296DD052DC5E90F99659B25014D08E1BC983515BC"
|
||||||
|
}}
|
||||||
|
]
|
||||||
|
}})",
|
||||||
|
AccountObjectsHandler::LIMIT_MIN);
|
||||||
|
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(MINSEQ); // min
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ); // max
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, MAXSEQ);
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
|
||||||
|
auto const account = GetAccountIDWithString(ACCOUNT);
|
||||||
|
auto const accountKk = ripple::keylet::account(account).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, MAXSEQ, _)).WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
||||||
|
|
||||||
|
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
auto const ownerDirKk = ripple::keylet::ownerDir(account).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, 30, _))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
|
||||||
|
// nft null
|
||||||
|
auto const nftMaxKK = ripple::keylet::nftpage_max(account).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(nftMaxKK, 30, _)).WillByDefault(Return(std::nullopt));
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const line1 =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, 0);
|
||||||
|
bbs.push_back(line1.getSerializer().peekData());
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountObjectsHandler::LIMIT_MIN - 1));
|
||||||
|
|
||||||
|
auto const handler = AnyHandler{AccountObjectsHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](auto& yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(*output, json::parse(expectedOut));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountObjectsHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
static auto const expectedOut = fmt::format(
|
||||||
|
R"({{
|
||||||
|
"ledger_hash":"4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652",
|
||||||
|
"ledger_index":30,
|
||||||
|
"validated":true,
|
||||||
|
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"limit": {},
|
||||||
|
"account_objects":[
|
||||||
|
{{
|
||||||
|
"Balance":{{
|
||||||
|
"currency":"USD",
|
||||||
|
"issuer":"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
|
||||||
|
"value":"100"
|
||||||
|
}},
|
||||||
|
"Flags":0,
|
||||||
|
"HighLimit":{{
|
||||||
|
"currency":"USD",
|
||||||
|
"issuer":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||||
|
"value":"20"
|
||||||
|
}},
|
||||||
|
"LedgerEntryType":"RippleState",
|
||||||
|
"LowLimit":{{
|
||||||
|
"currency":"USD",
|
||||||
|
"issuer":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"value":"10"
|
||||||
|
}},
|
||||||
|
"PreviousTxnID":"E3FE6EA3D48F0C2B639448020EA4F03D4F4F8FFDB243A852A0F59177921B4879",
|
||||||
|
"PreviousTxnLgrSeq":123,
|
||||||
|
"index":"1B8590C01B0006EDFA9ED60296DD052DC5E90F99659B25014D08E1BC983515BC"
|
||||||
|
}}
|
||||||
|
]
|
||||||
|
}})",
|
||||||
|
AccountObjectsHandler::LIMIT_MAX);
|
||||||
|
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(MINSEQ); // min
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ); // max
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, MAXSEQ);
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
|
||||||
|
auto const account = GetAccountIDWithString(ACCOUNT);
|
||||||
|
auto const accountKk = ripple::keylet::account(account).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, MAXSEQ, _)).WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
||||||
|
|
||||||
|
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
auto const ownerDirKk = ripple::keylet::ownerDir(account).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, 30, _))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
|
||||||
|
// nft null
|
||||||
|
auto const nftMaxKK = ripple::keylet::nftpage_max(account).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(nftMaxKK, 30, _)).WillByDefault(Return(std::nullopt));
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const line1 =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, 0);
|
||||||
|
bbs.push_back(line1.getSerializer().peekData());
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountObjectsHandler::LIMIT_MAX + 1));
|
||||||
|
|
||||||
|
auto const handler = AnyHandler{AccountObjectsHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](auto& yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(*output, json::parse(expectedOut));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -325,108 +325,6 @@ TEST_F(RPCAccountOffersHandlerTest, DefaultParams)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RPCAccountOffersHandlerTest, DefaultParamsWithStrictTrue)
|
|
||||||
{
|
|
||||||
auto constexpr ledgerSeq = 30;
|
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
|
||||||
|
|
||||||
mockBackendPtr->updateRange(10); // min
|
|
||||||
mockBackendPtr->updateRange(ledgerSeq); // max
|
|
||||||
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, ledgerSeq);
|
|
||||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
|
||||||
|
|
||||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
|
||||||
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
|
||||||
|
|
||||||
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}}, INDEX1);
|
|
||||||
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
|
||||||
|
|
||||||
std::vector<Blob> bbs;
|
|
||||||
auto offer = CreateOfferLedgerObject(
|
|
||||||
ACCOUNT,
|
|
||||||
10,
|
|
||||||
20,
|
|
||||||
ripple::to_string(ripple::to_currency("USD")),
|
|
||||||
ripple::to_string(ripple::xrpCurrency()),
|
|
||||||
ACCOUNT2,
|
|
||||||
toBase58(ripple::xrpAccount()),
|
|
||||||
INDEX1);
|
|
||||||
offer.setFieldU32(ripple::sfExpiration, 123);
|
|
||||||
bbs.push_back(offer.getSerializer().peekData());
|
|
||||||
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
|
||||||
|
|
||||||
auto const static input = boost::json::parse(fmt::format(
|
|
||||||
R"({{
|
|
||||||
"account": "{}",
|
|
||||||
"strict": true
|
|
||||||
}})",
|
|
||||||
ACCOUNT));
|
|
||||||
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
|
|
||||||
runSpawn([&](auto& yield) {
|
|
||||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
|
||||||
ASSERT_TRUE(output);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCAccountOffersHandlerTest, DefaultParamsWithInvalidTypeStrict)
|
|
||||||
{
|
|
||||||
auto constexpr ledgerSeq = 30;
|
|
||||||
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
|
||||||
|
|
||||||
mockBackendPtr->updateRange(10); // min
|
|
||||||
mockBackendPtr->updateRange(ledgerSeq); // max
|
|
||||||
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, ledgerSeq);
|
|
||||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
|
||||||
|
|
||||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
|
||||||
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
|
||||||
|
|
||||||
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}}, INDEX1);
|
|
||||||
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, ledgerSeq, _))
|
|
||||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
|
||||||
|
|
||||||
std::vector<Blob> bbs;
|
|
||||||
auto offer = CreateOfferLedgerObject(
|
|
||||||
ACCOUNT,
|
|
||||||
10,
|
|
||||||
20,
|
|
||||||
ripple::to_string(ripple::to_currency("USD")),
|
|
||||||
ripple::to_string(ripple::xrpCurrency()),
|
|
||||||
ACCOUNT2,
|
|
||||||
toBase58(ripple::xrpAccount()),
|
|
||||||
INDEX1);
|
|
||||||
offer.setFieldU32(ripple::sfExpiration, 123);
|
|
||||||
bbs.push_back(offer.getSerializer().peekData());
|
|
||||||
|
|
||||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
|
||||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
|
||||||
|
|
||||||
auto const static input = boost::json::parse(fmt::format(
|
|
||||||
R"({{
|
|
||||||
"account": "{}",
|
|
||||||
"strict": "test"
|
|
||||||
}})",
|
|
||||||
ACCOUNT));
|
|
||||||
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
|
|
||||||
runSpawn([&](auto& yield) {
|
|
||||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
|
||||||
ASSERT_TRUE(output);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCAccountOffersHandlerTest, Limit)
|
TEST_F(RPCAccountOffersHandlerTest, Limit)
|
||||||
{
|
{
|
||||||
auto constexpr ledgerSeq = 30;
|
auto constexpr ledgerSeq = 30;
|
||||||
@@ -574,3 +472,111 @@ TEST_F(RPCAccountOffersHandlerTest, MarkerNotExists)
|
|||||||
EXPECT_EQ(err.at("error_message").as_string(), "Invalid marker.");
|
EXPECT_EQ(err.at("error_message").as_string(), "Invalid marker.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountOffersHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
auto constexpr ledgerSeq = 30;
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(ledgerSeq); // max
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, ledgerSeq);
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, ledgerSeq, _))
|
||||||
|
.WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
||||||
|
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{AccountOffersHandler::LIMIT_MIN + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, ledgerSeq, _))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto offer = CreateOfferLedgerObject(
|
||||||
|
ACCOUNT,
|
||||||
|
10,
|
||||||
|
20,
|
||||||
|
ripple::to_string(ripple::to_currency("USD")),
|
||||||
|
ripple::to_string(ripple::xrpCurrency()),
|
||||||
|
ACCOUNT2,
|
||||||
|
toBase58(ripple::xrpAccount()),
|
||||||
|
INDEX1);
|
||||||
|
offer.setFieldU32(ripple::sfExpiration, 123);
|
||||||
|
|
||||||
|
for (auto i = 0; i < AccountOffersHandler::LIMIT_MIN + 1; i++)
|
||||||
|
bbs.push_back(offer.getSerializer().peekData());
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"limit":{}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountOffersHandler::LIMIT_MIN - 1));
|
||||||
|
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](auto& yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("offers").as_array().size(), AccountOffersHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountOffersHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
auto constexpr ledgerSeq = 30;
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(ledgerSeq); // max
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, ledgerSeq);
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||||
|
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, ledgerSeq, _))
|
||||||
|
.WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
|
||||||
|
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{AccountOffersHandler::LIMIT_MAX + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
|
||||||
|
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, ledgerSeq, _))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto offer = CreateOfferLedgerObject(
|
||||||
|
ACCOUNT,
|
||||||
|
10,
|
||||||
|
20,
|
||||||
|
ripple::to_string(ripple::to_currency("USD")),
|
||||||
|
ripple::to_string(ripple::xrpCurrency()),
|
||||||
|
ACCOUNT2,
|
||||||
|
toBase58(ripple::xrpAccount()),
|
||||||
|
INDEX1);
|
||||||
|
offer.setFieldU32(ripple::sfExpiration, 123);
|
||||||
|
for (auto i = 0; i < AccountOffersHandler::LIMIT_MAX + 1; i++)
|
||||||
|
bbs.push_back(offer.getSerializer().peekData());
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"limit":{}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
AccountOffersHandler::LIMIT_MAX + 1));
|
||||||
|
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](auto& yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("offers").as_array().size(), AccountOffersHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -763,3 +763,43 @@ TEST_F(RPCAccountTxHandlerTest, TxLargerThanMaxSeq)
|
|||||||
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCAccountTxHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
mockBackendPtr->updateRange(MINSEQ); // min
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ); // max
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
auto const transactions = genTransactions(MINSEQ + 1, MAXSEQ - 1);
|
||||||
|
auto const transCursor = TransactionsAndCursor{transactions, TransactionsCursor{12, 34}};
|
||||||
|
ON_CALL(*rawBackendPtr, fetchAccountTransactions).WillByDefault(Return(transCursor));
|
||||||
|
EXPECT_CALL(
|
||||||
|
*rawBackendPtr,
|
||||||
|
fetchAccountTransactions(
|
||||||
|
testing::_, testing::_, false, testing::Optional(testing::Eq(TransactionsCursor{10, 11})), testing::_))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{AccountTxHandler{mockBackendPtr}};
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account":"{}",
|
||||||
|
"ledger_index_min": {},
|
||||||
|
"ledger_index_max": {},
|
||||||
|
"limit": {},
|
||||||
|
"forward": false,
|
||||||
|
"marker": {{"ledger":10,"seq":11}}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
AccountTxHandler::LIMIT_MIN - 1));
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("account").as_string(), ACCOUNT);
|
||||||
|
EXPECT_EQ(output->at("ledger_index_min").as_uint64(), MINSEQ);
|
||||||
|
EXPECT_EQ(output->at("ledger_index_max").as_uint64(), MAXSEQ);
|
||||||
|
EXPECT_EQ(output->at("limit").as_uint64(), AccountTxHandler::LIMIT_MIN);
|
||||||
|
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
||||||
|
EXPECT_EQ(output->at("transactions").as_array().size(), 2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1238,4 +1238,146 @@ TEST_F(RPCBookOffersHandlerTest, Limit)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// taker
|
TEST_F(RPCBookOffersHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
auto const seq = 300;
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(seq); // max
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
// return valid ledgerinfo
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, seq);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(seq, _)).WillByDefault(Return(ledgerinfo));
|
||||||
|
|
||||||
|
auto const issuer = GetAccountIDWithString(ACCOUNT);
|
||||||
|
// return valid book dir
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(1);
|
||||||
|
|
||||||
|
auto const getsXRPPaysUSDBook = getBookBase(std::get<ripple::Book>(
|
||||||
|
RPC::parseBook(ripple::to_currency("USD"), issuer, ripple::xrpCurrency(), ripple::xrpAccount())));
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(getsXRPPaysUSDBook, seq, _))
|
||||||
|
.WillByDefault(Return(ripple::uint256{PAYS20USDGETS10XRPBOOKDIR}));
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(5);
|
||||||
|
auto const indexes = std::vector<ripple::uint256>(10, ripple::uint256{INDEX2});
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::uint256{PAYS20USDGETS10XRPBOOKDIR}, seq, _))
|
||||||
|
.WillByDefault(Return(CreateOwnerDirLedgerObject(indexes, INDEX1).getSerializer().peekData()));
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(GetAccountIDWithString(ACCOUNT2)).key, seq, _))
|
||||||
|
.WillByDefault(Return(CreateAccountRootObject(ACCOUNT2, 0, 2, 200, 2, INDEX1, 2).getSerializer().peekData()));
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::fees().key, seq, _))
|
||||||
|
.WillByDefault(Return(CreateFeeSettingBlob(1, 2, 3, 4, 0)));
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(issuer).key, seq, _))
|
||||||
|
.WillByDefault(Return(
|
||||||
|
CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2, TRANSFERRATEX2).getSerializer().peekData()));
|
||||||
|
|
||||||
|
auto const gets10XRPPays20USDOffer = CreateOfferLedgerObject(
|
||||||
|
ACCOUNT2,
|
||||||
|
10,
|
||||||
|
20,
|
||||||
|
ripple::to_string(ripple::xrpCurrency()),
|
||||||
|
ripple::to_string(ripple::to_currency("USD")),
|
||||||
|
toBase58(ripple::xrpAccount()),
|
||||||
|
ACCOUNT,
|
||||||
|
PAYS20USDGETS10XRPBOOKDIR);
|
||||||
|
|
||||||
|
std::vector<Blob> bbs(10, gets10XRPPays20USDOffer.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"taker_gets":
|
||||||
|
{{
|
||||||
|
"currency": "XRP"
|
||||||
|
}},
|
||||||
|
"taker_pays":
|
||||||
|
{{
|
||||||
|
"currency": "USD",
|
||||||
|
"issuer": "{}"
|
||||||
|
}},
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
BookOffersHandler::LIMIT_MIN - 1));
|
||||||
|
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](boost::asio::yield_context yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output.value().as_object().at("offers").as_array().size(), BookOffersHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCBookOffersHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
auto const seq = 300;
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(seq); // max
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
// return valid ledgerinfo
|
||||||
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, seq);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(seq, _)).WillByDefault(Return(ledgerinfo));
|
||||||
|
|
||||||
|
auto const issuer = GetAccountIDWithString(ACCOUNT);
|
||||||
|
// return valid book dir
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(1);
|
||||||
|
|
||||||
|
auto const getsXRPPaysUSDBook = getBookBase(std::get<ripple::Book>(
|
||||||
|
RPC::parseBook(ripple::to_currency("USD"), issuer, ripple::xrpCurrency(), ripple::xrpAccount())));
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(getsXRPPaysUSDBook, seq, _))
|
||||||
|
.WillByDefault(Return(ripple::uint256{PAYS20USDGETS10XRPBOOKDIR}));
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(5);
|
||||||
|
auto const indexes = std::vector<ripple::uint256>(BookOffersHandler::LIMIT_MAX + 1, ripple::uint256{INDEX2});
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::uint256{PAYS20USDGETS10XRPBOOKDIR}, seq, _))
|
||||||
|
.WillByDefault(Return(CreateOwnerDirLedgerObject(indexes, INDEX1).getSerializer().peekData()));
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(GetAccountIDWithString(ACCOUNT2)).key, seq, _))
|
||||||
|
.WillByDefault(Return(CreateAccountRootObject(ACCOUNT2, 0, 2, 200, 2, INDEX1, 2).getSerializer().peekData()));
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::fees().key, seq, _))
|
||||||
|
.WillByDefault(Return(CreateFeeSettingBlob(1, 2, 3, 4, 0)));
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(issuer).key, seq, _))
|
||||||
|
.WillByDefault(Return(
|
||||||
|
CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2, TRANSFERRATEX2).getSerializer().peekData()));
|
||||||
|
|
||||||
|
auto const gets10XRPPays20USDOffer = CreateOfferLedgerObject(
|
||||||
|
ACCOUNT2,
|
||||||
|
10,
|
||||||
|
20,
|
||||||
|
ripple::to_string(ripple::xrpCurrency()),
|
||||||
|
ripple::to_string(ripple::to_currency("USD")),
|
||||||
|
toBase58(ripple::xrpAccount()),
|
||||||
|
ACCOUNT,
|
||||||
|
PAYS20USDGETS10XRPBOOKDIR);
|
||||||
|
|
||||||
|
std::vector<Blob> bbs(BookOffersHandler::LIMIT_MAX + 1, gets10XRPPays20USDOffer.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"taker_gets":
|
||||||
|
{{
|
||||||
|
"currency": "XRP"
|
||||||
|
}},
|
||||||
|
"taker_pays":
|
||||||
|
{{
|
||||||
|
"currency": "USD",
|
||||||
|
"issuer": "{}"
|
||||||
|
}},
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
BookOffersHandler::LIMIT_MAX + 1));
|
||||||
|
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
|
||||||
|
runSpawn([&](boost::asio::yield_context yield) {
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output.value().as_object().at("offers").as_array().size(), BookOffersHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -608,82 +608,6 @@ generateNormalPathTestBundles()
|
|||||||
ACCOUNT2,
|
ACCOUNT2,
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
fmt::format(R"("hotwallet": ["{}", "{}"])", ACCOUNT2, ACCOUNT3)},
|
fmt::format(R"("hotwallet": ["{}", "{}"])", ACCOUNT2, ACCOUNT3)},
|
||||||
NormalTestBundle{
|
|
||||||
"StrictTrue",
|
|
||||||
CreateOwnerDirLedgerObject(
|
|
||||||
{ripple::uint256{INDEX2}, ripple::uint256{INDEX2}, ripple::uint256{INDEX2}}, INDEX1),
|
|
||||||
std::vector{
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "USD", ISSUER, -10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123),
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "CNY", ISSUER, -20, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123),
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "EUR", ISSUER, -30, ACCOUNT, 100, ACCOUNT3, 200, TXNID, 123)
|
|
||||||
|
|
||||||
},
|
|
||||||
fmt::format(
|
|
||||||
R"({{
|
|
||||||
"balances": {{
|
|
||||||
"{}": [
|
|
||||||
{{
|
|
||||||
"currency": "EUR",
|
|
||||||
"value": "30"
|
|
||||||
}}
|
|
||||||
],
|
|
||||||
"{}": [
|
|
||||||
{{
|
|
||||||
"currency": "USD",
|
|
||||||
"value": "10"
|
|
||||||
}},
|
|
||||||
{{
|
|
||||||
"currency": "CNY",
|
|
||||||
"value": "20"
|
|
||||||
}}
|
|
||||||
]
|
|
||||||
}},
|
|
||||||
"account": "{}",
|
|
||||||
"ledger_index": 300,
|
|
||||||
"ledger_hash": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652"
|
|
||||||
}})",
|
|
||||||
ACCOUNT3,
|
|
||||||
ACCOUNT2,
|
|
||||||
ACCOUNT),
|
|
||||||
fmt::format(R"("hotwallet": ["{}", "{}"], "strict": true)", ACCOUNT2, ACCOUNT3)},
|
|
||||||
NormalTestBundle{
|
|
||||||
"StrictInvalidTypeHasNoEffect",
|
|
||||||
CreateOwnerDirLedgerObject(
|
|
||||||
{ripple::uint256{INDEX2}, ripple::uint256{INDEX2}, ripple::uint256{INDEX2}}, INDEX1),
|
|
||||||
std::vector{
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "USD", ISSUER, -10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123),
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "CNY", ISSUER, -20, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123),
|
|
||||||
CreateRippleStateLedgerObject(ACCOUNT, "EUR", ISSUER, -30, ACCOUNT, 100, ACCOUNT3, 200, TXNID, 123)
|
|
||||||
|
|
||||||
},
|
|
||||||
fmt::format(
|
|
||||||
R"({{
|
|
||||||
"balances": {{
|
|
||||||
"{}": [
|
|
||||||
{{
|
|
||||||
"currency": "EUR",
|
|
||||||
"value": "30"
|
|
||||||
}}
|
|
||||||
],
|
|
||||||
"{}": [
|
|
||||||
{{
|
|
||||||
"currency": "USD",
|
|
||||||
"value": "10"
|
|
||||||
}},
|
|
||||||
{{
|
|
||||||
"currency": "CNY",
|
|
||||||
"value": "20"
|
|
||||||
}}
|
|
||||||
]
|
|
||||||
}},
|
|
||||||
"account": "{}",
|
|
||||||
"ledger_index": 300,
|
|
||||||
"ledger_hash": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652"
|
|
||||||
}})",
|
|
||||||
ACCOUNT3,
|
|
||||||
ACCOUNT2,
|
|
||||||
ACCOUNT),
|
|
||||||
fmt::format(R"("hotwallet": ["{}", "{}"], "strict": "test")", ACCOUNT2, ACCOUNT3)},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -556,3 +556,92 @@ TEST_F(RPCLedgerDataHandlerTest, Binary)
|
|||||||
EXPECT_EQ(output->as_object().at("ledger_index").as_uint64(), RANGEMAX);
|
EXPECT_EQ(output->as_object().at("ledger_index").as_uint64(), RANGEMAX);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCLedgerDataHandlerTest, BinaryLimitMoreThanMax)
|
||||||
|
{
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(RANGEMIN); // min
|
||||||
|
mockBackendPtr->updateRange(RANGEMAX); // max
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(RANGEMAX, _))
|
||||||
|
.WillByDefault(Return(CreateLedgerInfo(LEDGERHASH, RANGEMAX)));
|
||||||
|
|
||||||
|
auto limit = LedgerDataHandler::LIMITBINARY + 1;
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(LedgerDataHandler::LIMITBINARY);
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(_, RANGEMAX, _)).WillByDefault(Return(ripple::uint256{INDEX2}));
|
||||||
|
|
||||||
|
while (limit--)
|
||||||
|
{
|
||||||
|
auto const line =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT, "USD", ACCOUNT2, 10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123);
|
||||||
|
bbs.push_back(line.getSerializer().peekData());
|
||||||
|
}
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{LedgerDataHandler{mockBackendPtr}};
|
||||||
|
auto const req = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"limit":{},
|
||||||
|
"binary": true
|
||||||
|
}})",
|
||||||
|
LedgerDataHandler::LIMITBINARY + 1));
|
||||||
|
auto const output = handler.process(req, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_TRUE(output->as_object().contains("ledger"));
|
||||||
|
EXPECT_TRUE(output->as_object().at("ledger").as_object().contains("ledger_data"));
|
||||||
|
EXPECT_TRUE(output->as_object().at("ledger").as_object().at("closed").as_bool());
|
||||||
|
EXPECT_EQ(output->as_object().at("state").as_array().size(), LedgerDataHandler::LIMITBINARY);
|
||||||
|
EXPECT_EQ(output->as_object().at("ledger_hash").as_string(), LEDGERHASH);
|
||||||
|
EXPECT_EQ(output->as_object().at("ledger_index").as_uint64(), RANGEMAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCLedgerDataHandlerTest, JsonLimitMoreThanMax)
|
||||||
|
{
|
||||||
|
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(RANGEMIN); // min
|
||||||
|
mockBackendPtr->updateRange(RANGEMAX); // max
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(RANGEMAX, _))
|
||||||
|
.WillByDefault(Return(CreateLedgerInfo(LEDGERHASH, RANGEMAX)));
|
||||||
|
|
||||||
|
auto limit = LedgerDataHandler::LIMITJSON + 1;
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(LedgerDataHandler::LIMITJSON);
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(_, RANGEMAX, _)).WillByDefault(Return(ripple::uint256{INDEX2}));
|
||||||
|
|
||||||
|
while (limit--)
|
||||||
|
{
|
||||||
|
auto const line =
|
||||||
|
CreateRippleStateLedgerObject(ACCOUNT, "USD", ACCOUNT2, 10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123);
|
||||||
|
bbs.push_back(line.getSerializer().peekData());
|
||||||
|
}
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{LedgerDataHandler{mockBackendPtr}};
|
||||||
|
auto const req = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"limit":{},
|
||||||
|
"binary": false
|
||||||
|
}})",
|
||||||
|
LedgerDataHandler::LIMITJSON + 1));
|
||||||
|
auto const output = handler.process(req, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_TRUE(output->as_object().contains("ledger"));
|
||||||
|
EXPECT_TRUE(output->as_object().at("ledger").as_object().at("closed").as_bool());
|
||||||
|
EXPECT_EQ(output->as_object().at("state").as_array().size(), LedgerDataHandler::LIMITJSON);
|
||||||
|
EXPECT_EQ(output->as_object().at("ledger_hash").as_string(), LEDGERHASH);
|
||||||
|
EXPECT_EQ(output->as_object().at("ledger_index").as_uint64(), RANGEMAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -567,3 +567,89 @@ TEST_F(RPCNFTBuyOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLimi
|
|||||||
ASSERT_TRUE(output); // todo: check limit somehow?
|
ASSERT_TRUE(output); // todo: check limit somehow?
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNFTBuyOffersHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerInfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerInfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
auto const directory = ripple::keylet::nft_buys(ripple::uint256{NFTID});
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{NFTBuyOffersHandler::LIMIT_MIN + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_)).Times(2);
|
||||||
|
|
||||||
|
// return two nft buy offers
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const offer = CreateNFTBuyOffer(NFTID, ACCOUNT);
|
||||||
|
for (auto i = 0; i < NFTBuyOffersHandler::LIMIT_MIN + 1; i++)
|
||||||
|
bbs.push_back(offer.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"nft_id": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
NFTID,
|
||||||
|
NFTBuyOffersHandler::LIMIT_MIN - 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto handler = AnyHandler{NFTBuyOffersHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("offers").as_array().size(), NFTBuyOffersHandler::LIMIT_MIN);
|
||||||
|
EXPECT_EQ(output->at("limit").as_uint64(), NFTBuyOffersHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNFTBuyOffersHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerInfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerInfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
auto const directory = ripple::keylet::nft_buys(ripple::uint256{NFTID});
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{NFTBuyOffersHandler::LIMIT_MAX + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_)).Times(2);
|
||||||
|
|
||||||
|
// return two nft buy offers
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const offer = CreateNFTBuyOffer(NFTID, ACCOUNT);
|
||||||
|
for (auto i = 0; i < NFTBuyOffersHandler::LIMIT_MAX + 1; i++)
|
||||||
|
bbs.push_back(offer.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"nft_id": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
NFTID,
|
||||||
|
NFTBuyOffersHandler::LIMIT_MAX + 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto handler = AnyHandler{NFTBuyOffersHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("offers").as_array().size(), NFTBuyOffersHandler::LIMIT_MAX);
|
||||||
|
EXPECT_EQ(output->at("limit").as_uint64(), NFTBuyOffersHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -709,3 +709,89 @@ TEST_F(RPCNFTHistoryHandlerTest, TxLargerThanMaxSeq)
|
|||||||
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNFTHistoryHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
mockBackendPtr->updateRange(MINSEQ); // min
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ); // max
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
auto const transactions = genTransactions(MINSEQ + 1, MAXSEQ - 1);
|
||||||
|
auto const transCursor = TransactionsAndCursor{transactions, TransactionsCursor{12, 34}};
|
||||||
|
ON_CALL(*rawBackendPtr, fetchNFTTransactions).WillByDefault(Return(transCursor));
|
||||||
|
EXPECT_CALL(
|
||||||
|
*rawBackendPtr,
|
||||||
|
fetchNFTTransactions(
|
||||||
|
testing::_,
|
||||||
|
testing::_,
|
||||||
|
false,
|
||||||
|
testing::Optional(testing::Eq(TransactionsCursor{MAXSEQ - 1, INT32_MAX})),
|
||||||
|
testing::_))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{NFTHistoryHandler{mockBackendPtr}};
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"nft_id":"{}",
|
||||||
|
"ledger_index_min": {},
|
||||||
|
"ledger_index_max": {},
|
||||||
|
"forward": false,
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
NFTID,
|
||||||
|
MINSEQ + 1,
|
||||||
|
MAXSEQ - 1,
|
||||||
|
NFTHistoryHandler::LIMIT_MIN - 1));
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("nft_id").as_string(), NFTID);
|
||||||
|
EXPECT_EQ(output->at("ledger_index_min").as_uint64(), MINSEQ + 1);
|
||||||
|
EXPECT_EQ(output->at("ledger_index_max").as_uint64(), MAXSEQ - 1);
|
||||||
|
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
||||||
|
EXPECT_EQ(output->at("transactions").as_array().size(), 2);
|
||||||
|
EXPECT_EQ(output->as_object().at("limit").as_uint64(), NFTHistoryHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNFTHistoryHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
mockBackendPtr->updateRange(MINSEQ); // min
|
||||||
|
mockBackendPtr->updateRange(MAXSEQ); // max
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
auto const transactions = genTransactions(MINSEQ + 1, MAXSEQ - 1);
|
||||||
|
auto const transCursor = TransactionsAndCursor{transactions, TransactionsCursor{12, 34}};
|
||||||
|
ON_CALL(*rawBackendPtr, fetchNFTTransactions).WillByDefault(Return(transCursor));
|
||||||
|
EXPECT_CALL(
|
||||||
|
*rawBackendPtr,
|
||||||
|
fetchNFTTransactions(
|
||||||
|
testing::_,
|
||||||
|
testing::_,
|
||||||
|
false,
|
||||||
|
testing::Optional(testing::Eq(TransactionsCursor{MAXSEQ - 1, INT32_MAX})),
|
||||||
|
testing::_))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{NFTHistoryHandler{mockBackendPtr}};
|
||||||
|
auto const static input = boost::json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"nft_id":"{}",
|
||||||
|
"ledger_index_min": {},
|
||||||
|
"ledger_index_max": {},
|
||||||
|
"forward": false,
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
NFTID,
|
||||||
|
MINSEQ + 1,
|
||||||
|
MAXSEQ - 1,
|
||||||
|
NFTHistoryHandler::LIMIT_MAX + 1));
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("nft_id").as_string(), NFTID);
|
||||||
|
EXPECT_EQ(output->at("ledger_index_min").as_uint64(), MINSEQ + 1);
|
||||||
|
EXPECT_EQ(output->at("ledger_index_max").as_uint64(), MAXSEQ - 1);
|
||||||
|
EXPECT_EQ(output->at("marker").as_object(), json::parse(R"({"ledger":12,"seq":34})"));
|
||||||
|
EXPECT_EQ(output->at("transactions").as_array().size(), 2);
|
||||||
|
EXPECT_EQ(output->as_object().at("limit").as_uint64(), NFTHistoryHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -567,3 +567,89 @@ TEST_F(RPCNFTSellOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLim
|
|||||||
ASSERT_TRUE(output); // todo: check limit?
|
ASSERT_TRUE(output); // todo: check limit?
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNFTSellOffersHandlerTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerInfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerInfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
auto const directory = ripple::keylet::nft_sells(ripple::uint256{NFTID});
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{NFTSellOffersHandler::LIMIT_MIN + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_)).Times(2);
|
||||||
|
|
||||||
|
// return two nft buy offers
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const offer = CreateNFTSellOffer(NFTID, ACCOUNT);
|
||||||
|
for (auto i = 0; i < NFTSellOffersHandler::LIMIT_MIN + 1; i++)
|
||||||
|
bbs.push_back(offer.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"nft_id": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
NFTID,
|
||||||
|
NFTSellOffersHandler::LIMIT_MIN - 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("offers").as_array().size(), NFTSellOffersHandler::LIMIT_MIN);
|
||||||
|
EXPECT_EQ(output->at("limit").as_uint64(), NFTSellOffersHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNFTSellOffersHandlerTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerInfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerInfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||||
|
|
||||||
|
// return owner index containing 2 indexes
|
||||||
|
auto const directory = ripple::keylet::nft_sells(ripple::uint256{NFTID});
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{NFTSellOffersHandler::LIMIT_MAX + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject(directory.key, testing::_, testing::_)).Times(2);
|
||||||
|
|
||||||
|
// return two nft buy offers
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
auto const offer = CreateNFTSellOffer(NFTID, ACCOUNT);
|
||||||
|
for (auto i = 0; i < NFTSellOffersHandler::LIMIT_MAX + 1; i++)
|
||||||
|
bbs.push_back(offer.getSerializer().peekData());
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"nft_id": "{}",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
NFTID,
|
||||||
|
NFTSellOffersHandler::LIMIT_MAX + 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->at("offers").as_array().size(), NFTSellOffersHandler::LIMIT_MAX);
|
||||||
|
EXPECT_EQ(output->at("limit").as_uint64(), NFTSellOffersHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -695,3 +695,107 @@ TEST_F(RPCNoRippleCheckTest, NormalPathTransactions)
|
|||||||
EXPECT_EQ(*output, json::parse(expectedOutput));
|
EXPECT_EQ(*output, json::parse(expectedOutput));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNoRippleCheckTest, LimitLessThanMin)
|
||||||
|
{
|
||||||
|
constexpr auto seq = 30;
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, seq);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _)).WillByDefault(Return(ledgerinfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerByHash).Times(1);
|
||||||
|
// fetch account object return valid account with DefaultRippleSet flag
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject)
|
||||||
|
.WillByDefault(Return(CreateAccountRootObject(ACCOUNT, ripple::lsfDefaultRipple, 2, 200, 2, INDEX1, 2)
|
||||||
|
.getSerializer()
|
||||||
|
.peekData()));
|
||||||
|
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||||
|
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, seq, _))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
auto const line1 = CreateRippleStateLedgerObject(
|
||||||
|
ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, ripple::lsfLowNoRipple);
|
||||||
|
|
||||||
|
auto const line2 = CreateRippleStateLedgerObject(
|
||||||
|
ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, ripple::lsfLowNoRipple);
|
||||||
|
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
bbs.push_back(line1.getSerializer().peekData());
|
||||||
|
bbs.push_back(line2.getSerializer().peekData());
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "{}",
|
||||||
|
"ledger_hash": "{}",
|
||||||
|
"role": "gateway",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
LEDGERHASH,
|
||||||
|
NoRippleCheckHandler::LIMIT_MIN - 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{NoRippleCheckHandler{mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->as_object().at("problems").as_array().size(), NoRippleCheckHandler::LIMIT_MIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCNoRippleCheckTest, LimitMoreThanMax)
|
||||||
|
{
|
||||||
|
constexpr auto seq = 30;
|
||||||
|
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||||
|
mockBackendPtr->updateRange(10); // min
|
||||||
|
mockBackendPtr->updateRange(30); // max
|
||||||
|
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, seq);
|
||||||
|
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _)).WillByDefault(Return(ledgerinfo));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, fetchLedgerByHash).Times(1);
|
||||||
|
// fetch account object return valid account with DefaultRippleSet flag
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject)
|
||||||
|
.WillByDefault(Return(CreateAccountRootObject(ACCOUNT, ripple::lsfDefaultRipple, 2, 200, 2, INDEX1, 2)
|
||||||
|
.getSerializer()
|
||||||
|
.peekData()));
|
||||||
|
auto const ownerDir =
|
||||||
|
CreateOwnerDirLedgerObject(std::vector{NoRippleCheckHandler::LIMIT_MAX + 1, ripple::uint256{INDEX1}}, INDEX1);
|
||||||
|
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, seq, _))
|
||||||
|
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||||
|
|
||||||
|
auto const line1 = CreateRippleStateLedgerObject(
|
||||||
|
ACCOUNT, "USD", ISSUER, 100, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123, ripple::lsfLowNoRipple);
|
||||||
|
|
||||||
|
std::vector<Blob> bbs;
|
||||||
|
for (auto i = 0; i < NoRippleCheckHandler::LIMIT_MAX + 1; i++)
|
||||||
|
{
|
||||||
|
bbs.push_back(line1.getSerializer().peekData());
|
||||||
|
}
|
||||||
|
|
||||||
|
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||||
|
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
|
||||||
|
|
||||||
|
auto const input = json::parse(fmt::format(
|
||||||
|
R"({{
|
||||||
|
"account": "{}",
|
||||||
|
"ledger_hash": "{}",
|
||||||
|
"role": "gateway",
|
||||||
|
"limit": {}
|
||||||
|
}})",
|
||||||
|
ACCOUNT,
|
||||||
|
LEDGERHASH,
|
||||||
|
NoRippleCheckHandler::LIMIT_MAX + 1));
|
||||||
|
runSpawn([&, this](auto& yield) {
|
||||||
|
auto const handler = AnyHandler{NoRippleCheckHandler{mockBackendPtr}};
|
||||||
|
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||||
|
ASSERT_TRUE(output);
|
||||||
|
EXPECT_EQ(output->as_object().at("problems").as_array().size(), NoRippleCheckHandler::LIMIT_MAX);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user