mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -97,16 +97,22 @@ public:
|
|||||||
return MaybeError{};
|
return MaybeError{};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
static auto const malformedRequestHexStringValidator =
|
||||||
|
validation::WithCustomError{validation::Uint256HexStringValidator, Status(ClioError::rpcMALFORMED_REQUEST)};
|
||||||
|
|
||||||
|
static auto const malformedRequestIntValidator =
|
||||||
|
validation::WithCustomError{validation::Type<uint32_t>{}, Status(ClioError::rpcMALFORMED_REQUEST)};
|
||||||
|
|
||||||
static auto const rpcSpec = RpcSpec{
|
static auto const rpcSpec = RpcSpec{
|
||||||
{JS(binary), validation::Type<bool>{}},
|
{JS(binary), validation::Type<bool>{}},
|
||||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||||
{JS(index), validation::Uint256HexStringValidator},
|
{JS(index), malformedRequestHexStringValidator},
|
||||||
{JS(account_root), validation::AccountBase58Validator},
|
{JS(account_root), validation::AccountBase58Validator},
|
||||||
{JS(check), validation::Uint256HexStringValidator},
|
{JS(check), malformedRequestHexStringValidator},
|
||||||
{JS(deposit_preauth),
|
{JS(deposit_preauth),
|
||||||
validation::Type<std::string, boost::json::object>{},
|
validation::Type<std::string, boost::json::object>{},
|
||||||
validation::IfType<std::string>{validation::Uint256HexStringValidator},
|
validation::IfType<std::string>{malformedRequestHexStringValidator},
|
||||||
validation::IfType<boost::json::object>{
|
validation::IfType<boost::json::object>{
|
||||||
validation::Section{
|
validation::Section{
|
||||||
{JS(owner),
|
{JS(owner),
|
||||||
@@ -118,33 +124,33 @@ public:
|
|||||||
}},
|
}},
|
||||||
{JS(directory),
|
{JS(directory),
|
||||||
validation::Type<std::string, boost::json::object>{},
|
validation::Type<std::string, boost::json::object>{},
|
||||||
validation::IfType<std::string>{validation::Uint256HexStringValidator},
|
validation::IfType<std::string>{malformedRequestHexStringValidator},
|
||||||
validation::IfType<boost::json::object>{validation::Section{
|
validation::IfType<boost::json::object>{validation::Section{
|
||||||
{JS(owner), validation::AccountBase58Validator},
|
{JS(owner), validation::AccountBase58Validator},
|
||||||
{JS(dir_root), validation::Uint256HexStringValidator},
|
{JS(dir_root), validation::Uint256HexStringValidator},
|
||||||
{JS(sub_index), validation::Type<uint32_t>{}}}}},
|
{JS(sub_index), malformedRequestIntValidator}}}},
|
||||||
{JS(escrow),
|
{JS(escrow),
|
||||||
validation::Type<std::string, boost::json::object>{},
|
validation::Type<std::string, boost::json::object>{},
|
||||||
validation::IfType<std::string>{validation::Uint256HexStringValidator},
|
validation::IfType<std::string>{malformedRequestHexStringValidator},
|
||||||
validation::IfType<boost::json::object>{
|
validation::IfType<boost::json::object>{
|
||||||
validation::Section{
|
validation::Section{
|
||||||
{JS(owner),
|
{JS(owner),
|
||||||
validation::Required{},
|
validation::Required{},
|
||||||
validation::WithCustomError{
|
validation::WithCustomError{
|
||||||
validation::AccountBase58Validator, Status(ClioError::rpcMALFORMED_OWNER)}},
|
validation::AccountBase58Validator, Status(ClioError::rpcMALFORMED_OWNER)}},
|
||||||
{JS(seq), validation::Required{}, validation::Type<uint32_t>{}},
|
{JS(seq), validation::Required{}, malformedRequestIntValidator},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
{JS(offer),
|
{JS(offer),
|
||||||
validation::Type<std::string, boost::json::object>{},
|
validation::Type<std::string, boost::json::object>{},
|
||||||
validation::IfType<std::string>{validation::Uint256HexStringValidator},
|
validation::IfType<std::string>{malformedRequestHexStringValidator},
|
||||||
validation::IfType<boost::json::object>{
|
validation::IfType<boost::json::object>{
|
||||||
validation::Section{
|
validation::Section{
|
||||||
{JS(account), validation::Required{}, validation::AccountBase58Validator},
|
{JS(account), validation::Required{}, validation::AccountBase58Validator},
|
||||||
{JS(seq), validation::Required{}, validation::Type<uint32_t>{}},
|
{JS(seq), validation::Required{}, malformedRequestIntValidator},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
{JS(payment_channel), validation::Uint256HexStringValidator},
|
{JS(payment_channel), malformedRequestHexStringValidator},
|
||||||
{JS(ripple_state),
|
{JS(ripple_state),
|
||||||
validation::Type<boost::json::object>{},
|
validation::Type<boost::json::object>{},
|
||||||
validation::Section{
|
validation::Section{
|
||||||
@@ -153,14 +159,14 @@ public:
|
|||||||
}},
|
}},
|
||||||
{JS(ticket),
|
{JS(ticket),
|
||||||
validation::Type<std::string, boost::json::object>{},
|
validation::Type<std::string, boost::json::object>{},
|
||||||
validation::IfType<std::string>{validation::Uint256HexStringValidator},
|
validation::IfType<std::string>{malformedRequestHexStringValidator},
|
||||||
validation::IfType<boost::json::object>{
|
validation::IfType<boost::json::object>{
|
||||||
validation::Section{
|
validation::Section{
|
||||||
{JS(account), validation::Required{}, validation::AccountBase58Validator},
|
{JS(account), validation::Required{}, validation::AccountBase58Validator},
|
||||||
{JS(ticket_seq), validation::Required{}, validation::Type<uint32_t>{}},
|
{JS(ticket_seq), validation::Required{}, malformedRequestIntValidator},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
{JS(nft_page), validation::Uint256HexStringValidator},
|
{JS(nft_page), malformedRequestHexStringValidator},
|
||||||
};
|
};
|
||||||
|
|
||||||
return rpcSpec;
|
return rpcSpec;
|
||||||
|
|||||||
@@ -96,11 +96,14 @@ generateTestValuesForParametersTest()
|
|||||||
"account_rootNotString"},
|
"account_rootNotString"},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"UnknownOption",
|
"InvalidLedgerIndex",
|
||||||
R"({
|
R"({
|
||||||
|
"ledger_index": "wrong"
|
||||||
})",
|
})",
|
||||||
"unknownOption",
|
"invalidParams",
|
||||||
"Unknown option."},
|
"ledgerIndexMalformed"},
|
||||||
|
|
||||||
|
ParamTestCaseBundle{"UnknownOption", R"({})", "unknownOption", "Unknown option."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidDepositPreauthType",
|
"InvalidDepositPreauthType",
|
||||||
@@ -115,14 +118,13 @@ generateTestValuesForParametersTest()
|
|||||||
R"({
|
R"({
|
||||||
"deposit_preauth": "invalid"
|
"deposit_preauth": "invalid"
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"deposit_preauthMalformed"},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidDepositPreauthEmtpyJson",
|
"InvalidDepositPreauthEmtpyJson",
|
||||||
R"({
|
R"({
|
||||||
"deposit_preauth": {
|
"deposit_preauth": {}
|
||||||
}
|
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"invalidParams",
|
||||||
"Required field 'owner' missing"},
|
"Required field 'owner' missing"},
|
||||||
@@ -175,8 +177,8 @@ generateTestValuesForParametersTest()
|
|||||||
R"({
|
R"({
|
||||||
"ticket": "invalid"
|
"ticket": "invalid"
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"ticketMalformed"},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidTicketEmptyJson",
|
"InvalidTicketEmptyJson",
|
||||||
@@ -218,8 +220,8 @@ generateTestValuesForParametersTest()
|
|||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"Invalid parameters."},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidOfferType",
|
"InvalidOfferType",
|
||||||
@@ -234,8 +236,8 @@ generateTestValuesForParametersTest()
|
|||||||
R"({
|
R"({
|
||||||
"offer": "invalid"
|
"offer": "invalid"
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"offerMalformed"},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidOfferEmptyJson",
|
"InvalidOfferEmptyJson",
|
||||||
@@ -277,8 +279,8 @@ generateTestValuesForParametersTest()
|
|||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"Invalid parameters."},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidEscrowType",
|
"InvalidEscrowType",
|
||||||
@@ -293,8 +295,8 @@ generateTestValuesForParametersTest()
|
|||||||
R"({
|
R"({
|
||||||
"escrow": "invalid"
|
"escrow": "invalid"
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"escrowMalformed"},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidEscrowEmptyJson",
|
"InvalidEscrowEmptyJson",
|
||||||
@@ -336,8 +338,8 @@ generateTestValuesForParametersTest()
|
|||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"Invalid parameters."},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidRippleStateType",
|
"InvalidRippleStateType",
|
||||||
@@ -360,8 +362,7 @@ generateTestValuesForParametersTest()
|
|||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidRippleStateEmtpyJson",
|
"InvalidRippleStateEmtpyJson",
|
||||||
R"({
|
R"({
|
||||||
"ripple_state": {
|
"ripple_state": {}
|
||||||
}
|
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"invalidParams",
|
||||||
"Required field 'accounts' missing"},
|
"Required field 'accounts' missing"},
|
||||||
@@ -439,7 +440,7 @@ generateTestValuesForParametersTest()
|
|||||||
"ripple_state": {{
|
"ripple_state": {{
|
||||||
"accounts" : ["{}","{}"],
|
"accounts" : ["{}","{}"],
|
||||||
"currency": 123
|
"currency": 123
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT,
|
ACCOUNT,
|
||||||
ACCOUNT2),
|
ACCOUNT2),
|
||||||
@@ -459,8 +460,8 @@ generateTestValuesForParametersTest()
|
|||||||
R"({
|
R"({
|
||||||
"directory": "123"
|
"directory": "123"
|
||||||
})",
|
})",
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"directoryMalformed"},
|
"Malformed request."},
|
||||||
|
|
||||||
ParamTestCaseBundle{
|
ParamTestCaseBundle{
|
||||||
"InvalidDirectoryEmtpyJson",
|
"InvalidDirectoryEmtpyJson",
|
||||||
@@ -529,13 +530,14 @@ generateTestValuesForParametersTest()
|
|||||||
fmt::format(
|
fmt::format(
|
||||||
R"({{
|
R"({{
|
||||||
"directory": {{
|
"directory": {{
|
||||||
"dir_root": "{}",
|
"dir_root": "{}",
|
||||||
"sub_index": "not int"
|
"sub_index": "not int"
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
INDEX1),
|
INDEX1),
|
||||||
"invalidParams",
|
"malformedRequest",
|
||||||
"Invalid parameters."}};
|
"Malformed request."},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(
|
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(
|
INSTANTIATE_TEST_CASE_P(
|
||||||
RPCLedgerEntryGroup3,
|
RPCLedgerEntryGroup3,
|
||||||
IndexTest,
|
IndexTest,
|
||||||
Values("index", "payment_channel", "check", "nft_page"),
|
Values("index", "nft_page", "payment_channel", "check"),
|
||||||
IndexTest::NameGenerator{});
|
IndexTest::NameGenerator{});
|
||||||
|
|
||||||
TEST_P(IndexTest, InvalidIndexUint256)
|
TEST_P(IndexTest, InvalidIndexUint256)
|
||||||
@@ -594,8 +596,8 @@ TEST_P(IndexTest, InvalidIndexUint256)
|
|||||||
ASSERT_FALSE(output);
|
ASSERT_FALSE(output);
|
||||||
|
|
||||||
auto const err = RPC::makeError(output.error());
|
auto const err = RPC::makeError(output.error());
|
||||||
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
|
EXPECT_EQ(err.at("error").as_string(), "malformedRequest");
|
||||||
EXPECT_EQ(err.at("error_message").as_string(), index + "Malformed");
|
EXPECT_EQ(err.at("error_message").as_string(), "Malformed request.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,8 +615,8 @@ TEST_P(IndexTest, InvalidIndexNotString)
|
|||||||
ASSERT_FALSE(output);
|
ASSERT_FALSE(output);
|
||||||
|
|
||||||
auto const err = RPC::makeError(output.error());
|
auto const err = RPC::makeError(output.error());
|
||||||
EXPECT_EQ(err.at("error").as_string(), "invalidParams");
|
EXPECT_EQ(err.at("error").as_string(), "malformedRequest");
|
||||||
EXPECT_EQ(err.at("error_message").as_string(), index + "NotString");
|
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 handler = AnyHandler{LedgerEntryHandler{mockBackendPtr}};
|
||||||
auto const req = json::parse(fmt::format(
|
auto const req = json::parse(fmt::format(
|
||||||
R"({{
|
R"({{
|
||||||
"account_root": "{}"
|
"account_root": "{}"
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT));
|
ACCOUNT));
|
||||||
auto const output = handler.process(req, Context{std::ref(yield)});
|
auto const output = handler.process(req, Context{std::ref(yield)});
|
||||||
@@ -813,7 +815,7 @@ generateTestValuesForNormalPathTest()
|
|||||||
"binary": true,
|
"binary": true,
|
||||||
"directory": {{
|
"directory": {{
|
||||||
"owner": "{}"
|
"owner": "{}"
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
// default sub_index is 0
|
// default sub_index is 0
|
||||||
@@ -827,7 +829,7 @@ generateTestValuesForNormalPathTest()
|
|||||||
"escrow": {{
|
"escrow": {{
|
||||||
"owner": "{}",
|
"owner": "{}",
|
||||||
"seq": 1
|
"seq": 1
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
ripple::keylet::escrow(account1, 1).key,
|
ripple::keylet::escrow(account1, 1).key,
|
||||||
@@ -840,7 +842,7 @@ generateTestValuesForNormalPathTest()
|
|||||||
"deposit_preauth": {{
|
"deposit_preauth": {{
|
||||||
"owner": "{}",
|
"owner": "{}",
|
||||||
"authorized": "{}"
|
"authorized": "{}"
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT,
|
ACCOUNT,
|
||||||
ACCOUNT2),
|
ACCOUNT2),
|
||||||
@@ -854,7 +856,7 @@ generateTestValuesForNormalPathTest()
|
|||||||
"ripple_state": {{
|
"ripple_state": {{
|
||||||
"accounts": ["{}","{}"],
|
"accounts": ["{}","{}"],
|
||||||
"currency": "USD"
|
"currency": "USD"
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT,
|
ACCOUNT,
|
||||||
ACCOUNT2),
|
ACCOUNT2),
|
||||||
@@ -868,7 +870,7 @@ generateTestValuesForNormalPathTest()
|
|||||||
"ticket": {{
|
"ticket": {{
|
||||||
"account": "{}",
|
"account": "{}",
|
||||||
"ticket_seq": 2
|
"ticket_seq": 2
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
ripple::getTicketIndex(account1, 2),
|
ripple::getTicketIndex(account1, 2),
|
||||||
@@ -881,7 +883,7 @@ generateTestValuesForNormalPathTest()
|
|||||||
"offer": {{
|
"offer": {{
|
||||||
"account": "{}",
|
"account": "{}",
|
||||||
"seq": 2
|
"seq": 2
|
||||||
}}
|
}}
|
||||||
}})",
|
}})",
|
||||||
ACCOUNT),
|
ACCOUNT),
|
||||||
ripple::keylet::offer(account1, 2).key,
|
ripple::keylet::offer(account1, 2).key,
|
||||||
|
|||||||
Reference in New Issue
Block a user