mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-22 12:45:52 +00:00
@@ -121,7 +121,7 @@ public:
|
|||||||
verify(boost::json::value const& value, std::string_view key)
|
verify(boost::json::value const& value, std::string_view key)
|
||||||
{
|
{
|
||||||
if (value.is_object() and value.as_object().contains(key.data()))
|
if (value.is_object() and value.as_object().contains(key.data()))
|
||||||
return Error{Status{RippledError::rpcNOT_SUPPORTED, "Not supported field '" + std::string{key}}};
|
return Error{Status{RippledError::rpcNOT_SUPPORTED, "Not supported field '" + std::string{key} + '\''}};
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto const checkLedgerForward = [&]() {
|
auto const checkLedgerForward = [&]() {
|
||||||
return ctx.method == "ledger" and
|
return ctx.method == "ledger" and request.contains("queue") and request.at("queue").is_bool() and
|
||||||
((request.contains("queue") and request.at("queue").is_bool() and request.at("queue").as_bool()) or
|
request.at("queue").as_bool();
|
||||||
(request.contains("full") and request.at("full").is_bool() and request.at("full").as_bool()) or
|
|
||||||
(request.contains("accounts") and request.at("accounts").is_bool() and request.at("accounts").as_bool()
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return static_cast<bool>(checkAccountInfoForward() or checkLedgerForward());
|
return static_cast<bool>(checkAccountInfoForward() or checkLedgerForward());
|
||||||
|
|||||||
@@ -62,13 +62,16 @@ public:
|
|||||||
* @brief A struct to hold the input data for the command
|
* @brief A struct to hold the input data for the command
|
||||||
*
|
*
|
||||||
* Clio does not support:
|
* Clio does not support:
|
||||||
* - accounts
|
|
||||||
* - full
|
|
||||||
* - owner_finds
|
|
||||||
* - queue
|
* - queue
|
||||||
|
*
|
||||||
|
* And the following are deprecated altogether:
|
||||||
|
* - full
|
||||||
|
* - accounts
|
||||||
|
* - ledger
|
||||||
* - type
|
* - type
|
||||||
*
|
*
|
||||||
* Clio will throw an error when any of `accounts`/`full`/`owner_funds`/`queue` are set to `true`
|
* Clio will throw an error when `queue` is set to `true`
|
||||||
|
* or if `full` or `accounts` are used.
|
||||||
* @see https://github.com/XRPLF/clio/issues/603
|
* @see https://github.com/XRPLF/clio/issues/603
|
||||||
*/
|
*/
|
||||||
struct Input {
|
struct Input {
|
||||||
@@ -102,9 +105,9 @@ public:
|
|||||||
spec([[maybe_unused]] uint32_t apiVersion)
|
spec([[maybe_unused]] uint32_t apiVersion)
|
||||||
{
|
{
|
||||||
static auto const rpcSpec = RpcSpec{
|
static auto const rpcSpec = RpcSpec{
|
||||||
{JS(full), validation::Type<bool>{}, validation::NotSupported{true}},
|
{JS(full), validation::NotSupported{}},
|
||||||
{JS(full), check::Deprecated{}},
|
{JS(full), check::Deprecated{}},
|
||||||
{JS(accounts), validation::Type<bool>{}, validation::NotSupported{true}},
|
{JS(accounts), validation::NotSupported{}},
|
||||||
{JS(accounts), check::Deprecated{}},
|
{JS(accounts), check::Deprecated{}},
|
||||||
{JS(owner_funds), validation::Type<bool>{}},
|
{JS(owner_funds), validation::Type<bool>{}},
|
||||||
{JS(queue), validation::Type<bool>{}, validation::NotSupported{true}},
|
{JS(queue), validation::Type<bool>{}, validation::NotSupported{true}},
|
||||||
|
|||||||
@@ -160,66 +160,6 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfAccountInfoWithQueueSpe
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithQueueSpecified)
|
|
||||||
{
|
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
|
||||||
auto const apiVersion = 2u;
|
|
||||||
auto const method = "ledger";
|
|
||||||
auto const params = json::parse(R"({"queue": true})");
|
|
||||||
|
|
||||||
ON_CALL(*rawHandlerProviderPtr, isClioOnly(_)).WillByDefault(Return(false));
|
|
||||||
EXPECT_CALL(*rawHandlerProviderPtr, isClioOnly(method)).Times(1);
|
|
||||||
|
|
||||||
runSpawn([&](auto yield) {
|
|
||||||
auto const range = backend->fetchLedgerRange();
|
|
||||||
auto const ctx =
|
|
||||||
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
|
|
||||||
|
|
||||||
auto const res = proxy.shouldForward(ctx);
|
|
||||||
ASSERT_TRUE(res);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithFullSpecified)
|
|
||||||
{
|
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
|
||||||
auto const apiVersion = 2u;
|
|
||||||
auto const method = "ledger";
|
|
||||||
auto const params = json::parse(R"({"full": true})");
|
|
||||||
|
|
||||||
ON_CALL(*rawHandlerProviderPtr, isClioOnly(_)).WillByDefault(Return(false));
|
|
||||||
EXPECT_CALL(*rawHandlerProviderPtr, isClioOnly(method)).Times(1);
|
|
||||||
|
|
||||||
runSpawn([&](auto yield) {
|
|
||||||
auto const range = backend->fetchLedgerRange();
|
|
||||||
auto const ctx =
|
|
||||||
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
|
|
||||||
|
|
||||||
auto const res = proxy.shouldForward(ctx);
|
|
||||||
ASSERT_TRUE(res);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithAccountsSpecified)
|
|
||||||
{
|
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
|
||||||
auto const apiVersion = 2u;
|
|
||||||
auto const method = "ledger";
|
|
||||||
auto const params = json::parse(R"({"accounts": true})");
|
|
||||||
|
|
||||||
ON_CALL(*rawHandlerProviderPtr, isClioOnly(_)).WillByDefault(Return(false));
|
|
||||||
EXPECT_CALL(*rawHandlerProviderPtr, isClioOnly(method)).Times(1);
|
|
||||||
|
|
||||||
runSpawn([&](auto yield) {
|
|
||||||
auto const range = backend->fetchLedgerRange();
|
|
||||||
auto const ctx =
|
|
||||||
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
|
|
||||||
|
|
||||||
auto const res = proxy.shouldForward(ctx);
|
|
||||||
ASSERT_TRUE(res);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAccountInfoQueueIsFalse)
|
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAccountInfoQueueIsFalse)
|
||||||
{
|
{
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
auto const rawHandlerProviderPtr = handlerProvider.get();
|
||||||
@@ -240,6 +180,26 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfAccountInfoQueueIsFals
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsTrueIfLedgerWithQueueSpecified)
|
||||||
|
{
|
||||||
|
auto const rawHandlerProviderPtr = handlerProvider.get();
|
||||||
|
auto const apiVersion = 2u;
|
||||||
|
auto const method = "ledger";
|
||||||
|
auto const params = json::parse(R"({"queue": true})");
|
||||||
|
|
||||||
|
ON_CALL(*rawHandlerProviderPtr, isClioOnly(_)).WillByDefault(Return(false));
|
||||||
|
EXPECT_CALL(*rawHandlerProviderPtr, isClioOnly(method)).Times(1);
|
||||||
|
|
||||||
|
runSpawn([&](auto yield) {
|
||||||
|
auto const range = backend->fetchLedgerRange();
|
||||||
|
auto const ctx =
|
||||||
|
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
|
||||||
|
|
||||||
|
auto const res = proxy.shouldForward(ctx);
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerQueueIsFalse)
|
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerQueueIsFalse)
|
||||||
{
|
{
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
auto const rawHandlerProviderPtr = handlerProvider.get();
|
||||||
@@ -260,46 +220,6 @@ TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerQueueIsFalse)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerFullIsFalse)
|
|
||||||
{
|
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
|
||||||
auto const apiVersion = 2u;
|
|
||||||
auto const method = "ledger";
|
|
||||||
auto const params = json::parse(R"({"full": false})");
|
|
||||||
|
|
||||||
ON_CALL(*rawHandlerProviderPtr, isClioOnly(_)).WillByDefault(Return(false));
|
|
||||||
EXPECT_CALL(*rawHandlerProviderPtr, isClioOnly(method)).Times(1);
|
|
||||||
|
|
||||||
runSpawn([&](auto yield) {
|
|
||||||
auto const range = backend->fetchLedgerRange();
|
|
||||||
auto const ctx =
|
|
||||||
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
|
|
||||||
|
|
||||||
auto const res = proxy.shouldForward(ctx);
|
|
||||||
ASSERT_FALSE(res);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldForwardReturnsFalseIfLedgerAccountsIsFalse)
|
|
||||||
{
|
|
||||||
auto const rawHandlerProviderPtr = handlerProvider.get();
|
|
||||||
auto const apiVersion = 2u;
|
|
||||||
auto const method = "ledger";
|
|
||||||
auto const params = json::parse(R"({"accounts": false})");
|
|
||||||
|
|
||||||
ON_CALL(*rawHandlerProviderPtr, isClioOnly(_)).WillByDefault(Return(false));
|
|
||||||
EXPECT_CALL(*rawHandlerProviderPtr, isClioOnly(method)).Times(1);
|
|
||||||
|
|
||||||
runSpawn([&](auto yield) {
|
|
||||||
auto const range = backend->fetchLedgerRange();
|
|
||||||
auto const ctx =
|
|
||||||
web::Context(yield, method, apiVersion, params.as_object(), nullptr, tagFactory, *range, CLIENT_IP, true);
|
|
||||||
|
|
||||||
auto const res = proxy.shouldForward(ctx);
|
|
||||||
ASSERT_FALSE(res);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RPCForwardingProxyTest, ShouldNotForwardReturnsTrueIfAPIVersionIsV1)
|
TEST_F(RPCForwardingProxyTest, ShouldNotForwardReturnsTrueIfAPIVersionIsV1)
|
||||||
{
|
{
|
||||||
auto const apiVersion = 1u;
|
auto const apiVersion = 1u;
|
||||||
|
|||||||
@@ -85,28 +85,28 @@ generateTestValuesForParametersTest()
|
|||||||
{
|
{
|
||||||
return std::vector<LedgerParamTestCaseBundle>{
|
return std::vector<LedgerParamTestCaseBundle>{
|
||||||
{
|
{
|
||||||
"AccountsNotBool",
|
"AccountsInvalidBool",
|
||||||
R"({"accounts": 123})",
|
|
||||||
"invalidParams",
|
|
||||||
"Invalid parameters.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AccountsInvalid",
|
|
||||||
R"({"accounts": true})",
|
R"({"accounts": true})",
|
||||||
"notSupported",
|
"notSupported",
|
||||||
"Not supported field 'accounts's value 'true'",
|
"Not supported field 'accounts'",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"FullExist",
|
"AccountsInvalidInt",
|
||||||
|
R"({"accounts": 123})",
|
||||||
|
"notSupported",
|
||||||
|
"Not supported field 'accounts'",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FullInvalidBool",
|
||||||
R"({"full": true})",
|
R"({"full": true})",
|
||||||
"notSupported",
|
"notSupported",
|
||||||
"Not supported field 'full's value 'true'",
|
"Not supported field 'full'",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"FullNotBool",
|
"FullInvalidInt",
|
||||||
R"({"full": 123})",
|
R"({"full": 123})",
|
||||||
"invalidParams",
|
"notSupported",
|
||||||
"Invalid parameters.",
|
"Not supported field 'full'",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"QueueExist",
|
"QueueExist",
|
||||||
@@ -301,21 +301,18 @@ TEST_F(RPCLedgerHandlerTest, Default)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// not supported fields can be set to its default value
|
// fields not supported for specific value can be set to its default value
|
||||||
TEST_F(RPCLedgerHandlerTest, NotSupportedFieldsDefaultValue)
|
TEST_F(RPCLedgerHandlerTest, ConditionallyNotSupportedFieldsDefaultValue)
|
||||||
{
|
{
|
||||||
backend->setRange(RANGEMIN, RANGEMAX);
|
backend->setRange(RANGEMIN, RANGEMAX);
|
||||||
|
|
||||||
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, RANGEMAX);
|
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, RANGEMAX);
|
||||||
EXPECT_CALL(*backend, fetchLedgerBySequence).Times(1);
|
EXPECT_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _)).WillRepeatedly(Return(ledgerinfo));
|
||||||
ON_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _)).WillByDefault(Return(ledgerinfo));
|
|
||||||
|
|
||||||
runSpawn([&, this](auto yield) {
|
runSpawn([&, this](auto yield) {
|
||||||
auto const handler = AnyHandler{LedgerHandler{backend}};
|
auto const handler = AnyHandler{LedgerHandler{backend}};
|
||||||
auto const req = json::parse(
|
auto const req = json::parse(
|
||||||
R"({
|
R"({
|
||||||
"full": false,
|
|
||||||
"accounts": false,
|
|
||||||
"queue": false
|
"queue": false
|
||||||
})"
|
})"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user