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

@@ -114,6 +114,24 @@ generateTestValuesForParametersTest()
})",
"invalidParams",
"Invalid parameters."},
NoRippleParamTestCaseBundle{
"LimitNegative",
R"({
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"role": "gateway",
"limit": -1
})",
"invalidParams",
"Invalid parameters."},
NoRippleParamTestCaseBundle{
"LimitZero",
R"({
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"role": "gateway",
"limit": 0
})",
"invalidParams",
"Invalid parameters."},
NoRippleParamTestCaseBundle{
"TransactionsNotBool",
R"({
@@ -138,7 +156,7 @@ TEST_P(NoRippleCheckParameterTest, InvalidParams)
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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());
@@ -166,7 +184,7 @@ TEST_F(RPCNoRippleCheckTest, LedgerNotExistViaHash)
LEDGERHASH));
auto const handler = AnyHandler{NoRippleCheckHandler{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");
@@ -194,7 +212,7 @@ TEST_F(RPCNoRippleCheckTest, LedgerNotExistViaIntIndex)
seq));
auto const handler = AnyHandler{NoRippleCheckHandler{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");
@@ -222,7 +240,7 @@ TEST_F(RPCNoRippleCheckTest, LedgerNotExistViaStringIndex)
seq));
auto const handler = AnyHandler{NoRippleCheckHandler{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");
@@ -251,7 +269,7 @@ TEST_F(RPCNoRippleCheckTest, AccountNotExist)
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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(), "actNotFound");
@@ -313,7 +331,7 @@ TEST_F(RPCNoRippleCheckTest, NormalPathRoleUserDefaultRippleSetTrustLineNoRipple
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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, json::parse(expectedOutput));
});
@@ -371,7 +389,7 @@ TEST_F(RPCNoRippleCheckTest, NormalPathRoleUserDefaultRippleUnsetTrustLineNoRipp
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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, json::parse(expectedOutput));
});
@@ -432,7 +450,7 @@ TEST_F(RPCNoRippleCheckTest, NormalPathRoleGatewayDefaultRippleSetTrustLineNoRip
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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, json::parse(expectedOutput));
});
@@ -490,7 +508,7 @@ TEST_F(RPCNoRippleCheckTest, NormalPathRoleGatewayDefaultRippleUnsetTrustLineNoR
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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, json::parse(expectedOutput));
});
@@ -541,7 +559,7 @@ TEST_F(RPCNoRippleCheckTest, NormalPathRoleGatewayDefaultRippleUnsetTrustLineNoR
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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->as_object().at("transactions").as_array().size(), 1);
EXPECT_EQ(output->as_object().at("problems").as_array().size(), 1);
@@ -593,7 +611,7 @@ TEST_F(RPCNoRippleCheckTest, NormalPathLimit)
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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->as_object().at("problems").as_array().size(), 1);
});
@@ -695,64 +713,12 @@ TEST_F(RPCNoRippleCheckTest, NormalPathTransactions)
LEDGERHASH));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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, 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;
@@ -799,7 +765,7 @@ TEST_F(RPCNoRippleCheckTest, LimitMoreThanMax)
NoRippleCheckHandler::LIMIT_MAX + 1));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{NoRippleCheckHandler{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->as_object().at("problems").as_array().size(), NoRippleCheckHandler::LIMIT_MAX);
});