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

@@ -107,6 +107,18 @@ generateTestValuesForParametersTest()
"invalidParams",
"Invalid parameters.",
},
{
"LimitNegative",
R"({"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "limit": -1})",
"invalidParams",
"Invalid parameters.",
},
{
"LimitZero",
R"({"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "limit": 0})",
"invalidParams",
"Invalid parameters.",
},
{
"MarkerNotString",
R"({"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "marker": 123})",
@@ -134,7 +146,7 @@ TEST_P(AccountOfferParameterTest, InvalidParams)
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
auto const req = json::parse(testBundle.testJson);
auto const output = handler.process(req, Context{std::ref(yield)});
auto const output = handler.process(req, Context{yield});
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), testBundle.expectedError);
@@ -161,7 +173,7 @@ TEST_F(RPCAccountOffersHandlerTest, LedgerNotFoundViaHash)
LEDGERHASH));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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");
@@ -188,7 +200,7 @@ TEST_F(RPCAccountOffersHandlerTest, LedgerNotFoundViaStringIndex)
seq));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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");
@@ -215,7 +227,7 @@ TEST_F(RPCAccountOffersHandlerTest, LedgerNotFoundViaIntIndex)
seq));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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");
@@ -242,7 +254,7 @@ TEST_F(RPCAccountOffersHandlerTest, AccountNotFound)
ACCOUNT));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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(), "actNotFound");
@@ -319,7 +331,7 @@ TEST_F(RPCAccountOffersHandlerTest, DefaultParams)
ACCOUNT));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
auto const output = handler.process(input, Context{std::ref(yield)});
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(*output, json::parse(expectedOutput));
});
@@ -370,7 +382,7 @@ TEST_F(RPCAccountOffersHandlerTest, Limit)
ACCOUNT));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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(), 10);
EXPECT_EQ(output->at("marker").as_string(), fmt::format("{},0", INDEX1));
@@ -427,7 +439,7 @@ TEST_F(RPCAccountOffersHandlerTest, Marker)
startPage));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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(), 19);
EXPECT_FALSE(output->as_object().contains("marker"));
@@ -465,7 +477,7 @@ TEST_F(RPCAccountOffersHandlerTest, MarkerNotExists)
startPage));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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");
@@ -521,7 +533,7 @@ TEST_F(RPCAccountOffersHandlerTest, LimitLessThanMin)
AccountOffersHandler::LIMIT_MIN - 1));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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(), AccountOffersHandler::LIMIT_MIN);
});
@@ -575,7 +587,7 @@ TEST_F(RPCAccountOffersHandlerTest, LimitMoreThanMax)
AccountOffersHandler::LIMIT_MAX + 1));
auto const handler = AnyHandler{AccountOffersHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
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(), AccountOffersHandler::LIMIT_MAX);
});