Fix discrepancies in ledger_entry (#739)

Fixes #738
This commit is contained in:
Alex Kremer
2023-07-07 12:04:59 +01:00
committed by GitHub
parent dcbc4577c2
commit 9f4f5d319e
2 changed files with 63 additions and 55 deletions

View File

@@ -96,11 +96,14 @@ generateTestValuesForParametersTest()
"account_rootNotString"},
ParamTestCaseBundle{
"UnknownOption",
"InvalidLedgerIndex",
R"({
"ledger_index": "wrong"
})",
"unknownOption",
"Unknown option."},
"invalidParams",
"ledgerIndexMalformed"},
ParamTestCaseBundle{"UnknownOption", R"({})", "unknownOption", "Unknown option."},
ParamTestCaseBundle{
"InvalidDepositPreauthType",
@@ -115,14 +118,13 @@ generateTestValuesForParametersTest()
R"({
"deposit_preauth": "invalid"
})",
"invalidParams",
"deposit_preauthMalformed"},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidDepositPreauthEmtpyJson",
R"({
"deposit_preauth": {
}
"deposit_preauth": {}
})",
"invalidParams",
"Required field 'owner' missing"},
@@ -175,8 +177,8 @@ generateTestValuesForParametersTest()
R"({
"ticket": "invalid"
})",
"invalidParams",
"ticketMalformed"},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidTicketEmptyJson",
@@ -218,8 +220,8 @@ generateTestValuesForParametersTest()
}}
}})",
ACCOUNT),
"invalidParams",
"Invalid parameters."},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidOfferType",
@@ -234,8 +236,8 @@ generateTestValuesForParametersTest()
R"({
"offer": "invalid"
})",
"invalidParams",
"offerMalformed"},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidOfferEmptyJson",
@@ -277,8 +279,8 @@ generateTestValuesForParametersTest()
}}
}})",
ACCOUNT),
"invalidParams",
"Invalid parameters."},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidEscrowType",
@@ -293,8 +295,8 @@ generateTestValuesForParametersTest()
R"({
"escrow": "invalid"
})",
"invalidParams",
"escrowMalformed"},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidEscrowEmptyJson",
@@ -336,8 +338,8 @@ generateTestValuesForParametersTest()
}}
}})",
ACCOUNT),
"invalidParams",
"Invalid parameters."},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidRippleStateType",
@@ -360,8 +362,7 @@ generateTestValuesForParametersTest()
ParamTestCaseBundle{
"InvalidRippleStateEmtpyJson",
R"({
"ripple_state": {
}
"ripple_state": {}
})",
"invalidParams",
"Required field 'accounts' missing"},
@@ -439,7 +440,7 @@ generateTestValuesForParametersTest()
"ripple_state": {{
"accounts" : ["{}","{}"],
"currency": 123
}}
}}
}})",
ACCOUNT,
ACCOUNT2),
@@ -459,8 +460,8 @@ generateTestValuesForParametersTest()
R"({
"directory": "123"
})",
"invalidParams",
"directoryMalformed"},
"malformedRequest",
"Malformed request."},
ParamTestCaseBundle{
"InvalidDirectoryEmtpyJson",
@@ -529,13 +530,14 @@ generateTestValuesForParametersTest()
fmt::format(
R"({{
"directory": {{
"dir_root": "{}",
"sub_index": "not int"
}}
"dir_root": "{}",
"sub_index": "not int"
}}
}})",
INDEX1),
"invalidParams",
"Invalid parameters."}};
"malformedRequest",
"Malformed request."},
};
}
INSTANTIATE_TEST_CASE_P(
@@ -573,11 +575,11 @@ struct IndexTest : public HandlerBaseTest, public WithParamInterface<std::string
};
};
// content of index, payment_channel, check, nft_page fields is ledger index
// content of index, payment_channel, nft_page and check fields is ledger index.
INSTANTIATE_TEST_CASE_P(
RPCLedgerEntryGroup3,
IndexTest,
Values("index", "payment_channel", "check", "nft_page"),
Values("index", "nft_page", "payment_channel", "check"),
IndexTest::NameGenerator{});
TEST_P(IndexTest, InvalidIndexUint256)
@@ -594,8 +596,8 @@ TEST_P(IndexTest, InvalidIndexUint256)
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
EXPECT_EQ(err.at("error_message").as_string(), index + "Malformed");
EXPECT_EQ(err.at("error").as_string(), "malformedRequest");
EXPECT_EQ(err.at("error_message").as_string(), "Malformed request.");
});
}
@@ -613,8 +615,8 @@ TEST_P(IndexTest, InvalidIndexNotString)
ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
EXPECT_EQ(err.at("error_message").as_string(), index + "NotString");
EXPECT_EQ(err.at("error").as_string(), "malformedRequest");
EXPECT_EQ(err.at("error_message").as_string(), "Malformed request.");
});
}
@@ -637,7 +639,7 @@ TEST_F(RPCLedgerEntryTest, LedgerEntryNotFound)
auto const handler = AnyHandler{LedgerEntryHandler{mockBackendPtr}};
auto const req = json::parse(fmt::format(
R"({{
"account_root": "{}"
"account_root": "{}"
}})",
ACCOUNT));
auto const output = handler.process(req, Context{std::ref(yield)});
@@ -813,7 +815,7 @@ generateTestValuesForNormalPathTest()
"binary": true,
"directory": {{
"owner": "{}"
}}
}}
}})",
ACCOUNT),
// default sub_index is 0
@@ -827,7 +829,7 @@ generateTestValuesForNormalPathTest()
"escrow": {{
"owner": "{}",
"seq": 1
}}
}}
}})",
ACCOUNT),
ripple::keylet::escrow(account1, 1).key,
@@ -840,7 +842,7 @@ generateTestValuesForNormalPathTest()
"deposit_preauth": {{
"owner": "{}",
"authorized": "{}"
}}
}}
}})",
ACCOUNT,
ACCOUNT2),
@@ -854,7 +856,7 @@ generateTestValuesForNormalPathTest()
"ripple_state": {{
"accounts": ["{}","{}"],
"currency": "USD"
}}
}}
}})",
ACCOUNT,
ACCOUNT2),
@@ -868,7 +870,7 @@ generateTestValuesForNormalPathTest()
"ticket": {{
"account": "{}",
"ticket_seq": 2
}}
}}
}})",
ACCOUNT),
ripple::getTicketIndex(account1, 2),
@@ -881,7 +883,7 @@ generateTestValuesForNormalPathTest()
"offer": {{
"account": "{}",
"seq": 2
}}
}}
}})",
ACCOUNT),
ripple::keylet::offer(account1, 2).key,