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

@@ -48,7 +48,7 @@ TEST_F(RPCNFTBuyOffersHandlerTest, 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());
@@ -57,6 +57,60 @@ TEST_F(RPCNFTBuyOffersHandlerTest, NonHexLedgerHash)
});
}
TEST_F(RPCNFTBuyOffersHandlerTest, LimitNotInt)
{
runSpawn([this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, LimitNegative)
{
runSpawn([this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, LimitZero)
{
runSpawn([this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, NonStringLedgerHash)
{
runSpawn([this](boost::asio::yield_context yield) {
@@ -67,7 +121,7 @@ TEST_F(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, NonExistLedgerViaLedgerHash)
LEDGERHASH));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, NonExistLedgerViaLedgerIndex)
NFTID));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, NonExistLedgerViaLedgerHash2)
LEDGERHASH));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, NonExistLedgerViaLedgerIndex2)
NFTID));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, NoNFT)
LEDGERHASH));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, 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(RPCNFTBuyOffersHandlerTest, DefaultParameters)
NFTID));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, MultipleResultsWithMarkerAndLimitOutput)
NFTID));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, ResultsForInputWithMarkerAndLimit)
NFTID));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTBuyOffersHandler{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(RPCNFTBuyOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLimi
"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(RPCNFTBuyOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLimi
"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 somehow?
});
@@ -563,7 +617,7 @@ TEST_F(RPCNFTBuyOffersHandlerTest, ResultsWithoutMarkerForInputWithMarkerAndLimi
"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 somehow?
});
}
@@ -603,7 +657,7 @@ TEST_F(RPCNFTBuyOffersHandlerTest, LimitLessThanMin)
NFTBuyOffersHandler::LIMIT_MIN - 1));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTBuyOffersHandler{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(), NFTBuyOffersHandler::LIMIT_MIN);
@@ -646,7 +700,7 @@ TEST_F(RPCNFTBuyOffersHandlerTest, LimitMoreThanMax)
NFTBuyOffersHandler::LIMIT_MAX + 1));
runSpawn([&, this](auto yield) {
auto handler = AnyHandler{NFTBuyOffersHandler{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(), NFTBuyOffersHandler::LIMIT_MAX);