mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-03 10:05:51 +00:00
@@ -22,6 +22,7 @@
|
||||
#include <data/BackendInterface.h>
|
||||
#include <etl/ETLService.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/JsonBool.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
#include <util/JsonUtils.h>
|
||||
@@ -67,17 +68,18 @@ public:
|
||||
}
|
||||
|
||||
static RpcSpecConstRef
|
||||
spec([[maybe_unused]] uint32_t apiVersion)
|
||||
spec(uint32_t apiVersion)
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
static const RpcSpec rpcSpecForV1 = {
|
||||
{JS(transaction), validation::Uint256HexStringValidator},
|
||||
{JS(binary), validation::Type<bool>{}},
|
||||
{JS(min_ledger), validation::Type<uint32_t>{}},
|
||||
{JS(max_ledger), validation::Type<uint32_t>{}},
|
||||
{JS(ctid), validation::Type<std::string>{}},
|
||||
};
|
||||
|
||||
return rpcSpec;
|
||||
static auto const rpcSpec = RpcSpec{rpcSpecForV1, {{JS(binary), validation::Type<bool>{}}}};
|
||||
|
||||
return apiVersion == 1 ? rpcSpecForV1 : rpcSpec;
|
||||
}
|
||||
|
||||
Result
|
||||
@@ -273,7 +275,7 @@ private:
|
||||
}
|
||||
|
||||
if (jsonObject.contains(JS(binary)))
|
||||
input.binary = jv.at(JS(binary)).as_bool();
|
||||
input.binary = boost::json::value_to<JsonBool>(jsonObject.at(JS(binary)));
|
||||
|
||||
if (jsonObject.contains(JS(min_ledger)))
|
||||
input.minLedger = jv.at(JS(min_ledger)).as_int64();
|
||||
|
||||
@@ -143,6 +143,58 @@ TEST_F(RPCTxTest, ExcessiveLgrRange)
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, InvalidBinaryV1)
|
||||
{
|
||||
auto const rawBackendPtr = dynamic_cast<MockBackend*>(mockBackendPtr.get());
|
||||
ASSERT_NE(rawBackendPtr, nullptr);
|
||||
TransactionAndMetadata tx;
|
||||
tx.metadata = CreateMetaDataForCreateOffer(CURRENCY, ACCOUNT, 100, 200, 300).getSerializer().peekData();
|
||||
tx.transaction =
|
||||
CreateCreateOfferTransactionObject(ACCOUNT, 2, 100, CURRENCY, ACCOUNT2, 200, 300).getSerializer().peekData();
|
||||
tx.date = 123456;
|
||||
tx.ledgerSequence = 100;
|
||||
EXPECT_CALL(*rawBackendPtr, fetchTransaction(ripple::uint256{TXNID}, _)).WillOnce(Return(tx));
|
||||
|
||||
auto const rawETLPtr = dynamic_cast<MockETLService*>(mockETLServicePtr.get());
|
||||
ASSERT_NE(rawETLPtr, nullptr);
|
||||
EXPECT_CALL(*rawETLPtr, getETLState).WillOnce(Return(etl::ETLState{}));
|
||||
|
||||
runSpawn([this](auto yield) {
|
||||
auto const handler = AnyHandler{TestTxHandler{mockBackendPtr, mockETLServicePtr}};
|
||||
auto const req = json::parse(fmt::format(
|
||||
R"({{
|
||||
"command": "tx",
|
||||
"transaction": "{}",
|
||||
"binary": 12
|
||||
}})",
|
||||
TXNID
|
||||
));
|
||||
auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 1u});
|
||||
ASSERT_TRUE(output);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, InvalidBinaryV2)
|
||||
{
|
||||
runSpawn([this](auto yield) {
|
||||
auto const handler = AnyHandler{TestTxHandler{mockBackendPtr, mockETLServicePtr}};
|
||||
auto const req = json::parse(fmt::format(
|
||||
R"({{
|
||||
"command": "tx",
|
||||
"transaction": "{}",
|
||||
"binary": 12
|
||||
}})",
|
||||
TXNID
|
||||
));
|
||||
auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2u});
|
||||
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(), "Invalid parameters.");
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, InvalidLgrRange)
|
||||
{
|
||||
runSpawn([this](auto yield) {
|
||||
|
||||
Reference in New Issue
Block a user