Return error when limit<=0 (#804)

Fix #806
This commit is contained in:
cyan317
2023-08-02 15:34:42 +01:00
committed by GitHub
parent 1804e3e9c0
commit c90bc15959
45 changed files with 832 additions and 562 deletions

View File

@@ -38,6 +38,60 @@ class RPCNFTSellOffersHandlerTest : public HandlerBaseTest
{
};
TEST_F(RPCNFTSellOffersHandlerTest, LimitNotInt)
{
runSpawn([this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const input = json::parse(fmt::format(
R"({{
"nft_id": "{}",
"limit": "xxx"
}})",
NFTID));
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
});
}
TEST_F(RPCNFTSellOffersHandlerTest, LimitNegative)
{
runSpawn([this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const input = json::parse(fmt::format(
R"({{
"nft_id": "{}",
"limit": -1
}})",
NFTID));
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
});
}
TEST_F(RPCNFTSellOffersHandlerTest, LimitZero)
{
runSpawn([this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const input = json::parse(fmt::format(
R"({{
"nft_id": "{}",
"limit": 0
}})",
NFTID));
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
});
}
TEST_F(RPCNFTSellOffersHandlerTest, NonHexLedgerHash)
{
runSpawn([this](boost::asio::yield_context yield) {
@@ -48,7 +102,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NonHexLedgerHash)
"ledger_hash": "xxx"
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -67,7 +121,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NonStringLedgerHash)
"ledger_hash": 123
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -86,7 +140,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, InvalidLedgerIndexString)
"ledger_index": "notvalidated"
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -103,7 +157,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NFTIDInvalidFormat)
auto const input = json::parse(R"({
"nft_id": "00080000B4F4AFC5FBCBD76873F18006173D2193467D3EE7"
})");
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
@@ -119,7 +173,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NFTIDNotString)
auto const input = json::parse(R"({
"nft_id": 12
})");
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -146,7 +200,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NonExistLedgerViaLedgerHash)
LEDGERHASH));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -172,7 +226,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NonExistLedgerViaLedgerIndex)
NFTID));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
@@ -200,7 +254,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NonExistLedgerViaLedgerHash2)
LEDGERHASH));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
@@ -225,7 +279,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NonExistLedgerViaLedgerIndex2)
NFTID));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
@@ -253,7 +307,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, NoNFT)
LEDGERHASH));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTSellOffersHandler{mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "objectNotFound");
@@ -271,7 +325,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, MarkerNotString)
"marker": 9
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -292,7 +346,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, InvalidMarker)
"marker": "123invalid"
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -307,7 +361,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, InvalidMarker)
"marker": 250
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
@@ -366,7 +420,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, DefaultParameters)
NFTID));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(json::parse(correctOutput), *output);
@@ -410,7 +464,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, MultipleResultsWithMarkerAndLimitOutput)
NFTID));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(output->at("offers").as_array().size(), 50);
@@ -471,7 +525,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, ResultsForInputWithMarkerAndLimit)
NFTID));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(output->at("offers").as_array().size(), 50);
@@ -534,7 +588,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLim
"limit": 50
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(output->at("offers").as_array().size(), 50);
@@ -551,7 +605,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLim
"limit": 49
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output); // todo: check limit?
});
@@ -563,7 +617,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLim
"limit": 501
}})",
NFTID));
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output); // todo: check limit?
});
}
@@ -603,7 +657,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, LimitLessThanMin)
NFTSellOffersHandler::LIMIT_MIN - 1));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(output->at("offers").as_array().size(), NFTSellOffersHandler::LIMIT_MIN);
@@ -646,7 +700,7 @@ TEST_F(RPCNFTSellOffersHandlerTest, LimitMoreThanMax)
NFTSellOffersHandler::LIMIT_MAX + 1));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTSellOffersHandler{this->mockBackendPtr}};
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(output->at("offers").as_array().size(), NFTSellOffersHandler::LIMIT_MAX);