mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -31,6 +31,7 @@
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <ripple/protocol/AccountID.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
@@ -604,3 +605,49 @@ TEST_F(RPCBaseTest, ToLowerModifier)
|
||||
ASSERT_TRUE(spec.process(passingInput4)); // empty str no problem
|
||||
ASSERT_EQ(passingInput4.at("str").as_string(), "");
|
||||
}
|
||||
|
||||
TEST_F(RPCBaseTest, ToNumberModifier)
|
||||
{
|
||||
auto const spec = RpcSpec{
|
||||
{"str", ToNumber{}},
|
||||
};
|
||||
|
||||
auto passingInput = json::parse(R"({ "str": [] })");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
|
||||
passingInput = json::parse(R"({ "str2": "TesT" })");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
|
||||
passingInput = json::parse(R"([])");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
|
||||
passingInput = json::parse(R"({ "str": "123" })");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
ASSERT_EQ(passingInput.at("str").as_int64(), 123);
|
||||
|
||||
auto failingInput = json::parse(R"({ "str": "ok" })");
|
||||
ASSERT_FALSE(spec.process(failingInput));
|
||||
|
||||
failingInput = json::parse(R"({ "str": "123.123" })");
|
||||
ASSERT_FALSE(spec.process(failingInput));
|
||||
}
|
||||
|
||||
TEST_F(RPCBaseTest, CustomModifier)
|
||||
{
|
||||
testing::StrictMock<testing::MockFunction<MaybeError(json::value & value, std::string_view)>> mockModifier;
|
||||
auto const customModifier = CustomModifier{mockModifier.AsStdFunction()};
|
||||
auto const spec = RpcSpec{
|
||||
{"str", customModifier},
|
||||
};
|
||||
|
||||
EXPECT_CALL(mockModifier, Call).WillOnce(testing::Return(MaybeError{}));
|
||||
auto passingInput = json::parse(R"({ "str": "sss" })");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
|
||||
passingInput = json::parse(R"({ "strNotExist": 123 })");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
|
||||
// not a json object
|
||||
passingInput = json::parse(R"([])");
|
||||
ASSERT_TRUE(spec.process(passingInput));
|
||||
}
|
||||
|
||||
@@ -427,6 +427,55 @@ TEST_F(RPCGetAggregatePriceHandlerTest, OracleLedgerEntrySinglePriceData)
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCGetAggregatePriceHandlerTest, OracleLedgerEntryStrOracleDocumentId)
|
||||
{
|
||||
EXPECT_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _))
|
||||
.WillOnce(Return(CreateLedgerHeader(LEDGERHASH, RANGEMAX)));
|
||||
|
||||
auto constexpr documentId = 1;
|
||||
mockLedgerObject(*backend, ACCOUNT, documentId, TX1, 1e3, 2); // 10
|
||||
|
||||
auto const handler = AnyHandler{GetAggregatePriceHandler{backend}};
|
||||
auto const req = json::parse(fmt::format(
|
||||
R"({{
|
||||
"base_asset": "USD",
|
||||
"quote_asset": "XRP",
|
||||
"oracles":
|
||||
[
|
||||
{{
|
||||
"account": "{}",
|
||||
"oracle_document_id": "{}"
|
||||
}}
|
||||
]
|
||||
}})",
|
||||
ACCOUNT,
|
||||
documentId
|
||||
));
|
||||
|
||||
auto const expected = json::parse(fmt::format(
|
||||
R"({{
|
||||
"entire_set":
|
||||
{{
|
||||
"mean": "10",
|
||||
"size": 1,
|
||||
"standard_deviation": "0"
|
||||
}},
|
||||
"median": "10",
|
||||
"time": 4321,
|
||||
"ledger_index": {},
|
||||
"ledger_hash": "{}",
|
||||
"validated": true
|
||||
}})",
|
||||
RANGEMAX,
|
||||
LEDGERHASH
|
||||
));
|
||||
runSpawn([&](auto yield) {
|
||||
auto const output = handler.process(req, Context{yield});
|
||||
ASSERT_TRUE(output);
|
||||
EXPECT_EQ(output.result.value(), expected);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCGetAggregatePriceHandlerTest, PreviousTxNotFound)
|
||||
{
|
||||
EXPECT_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _))
|
||||
|
||||
@@ -2315,7 +2315,7 @@ generateTestValuesForNormalPathTest()
|
||||
CreateChainOwnedClaimIDObject(ACCOUNT, ACCOUNT, ACCOUNT2, "JPY", ACCOUNT3, ACCOUNT)
|
||||
},
|
||||
NormalPathTestBundle{
|
||||
"OracleEntryFoundViaObject",
|
||||
"OracleEntryFoundViaIntOracleDocumentId",
|
||||
fmt::format(
|
||||
R"({{
|
||||
"binary": true,
|
||||
@@ -2341,6 +2341,33 @@ generateTestValuesForNormalPathTest()
|
||||
)
|
||||
)
|
||||
},
|
||||
NormalPathTestBundle{
|
||||
"OracleEntryFoundViaStrOracleDocumentId",
|
||||
fmt::format(
|
||||
R"({{
|
||||
"binary": true,
|
||||
"oracle": {{
|
||||
"account": "{}",
|
||||
"oracle_document_id": "1"
|
||||
}}
|
||||
}})",
|
||||
ACCOUNT
|
||||
),
|
||||
ripple::keylet::oracle(GetAccountIDWithString(ACCOUNT), 1).key,
|
||||
CreateOracleObject(
|
||||
ACCOUNT,
|
||||
"70726F7669646572",
|
||||
32u,
|
||||
1234u,
|
||||
ripple::Blob(8, 's'),
|
||||
ripple::Blob(8, 's'),
|
||||
RANGEMAX - 2,
|
||||
ripple::uint256{"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321"},
|
||||
CreatePriceDataSeries(
|
||||
{CreateOraclePriceData(2e4, ripple::to_currency("XRP"), ripple::to_currency("USD"), 3)}
|
||||
)
|
||||
)
|
||||
},
|
||||
NormalPathTestBundle{
|
||||
"OracleEntryFoundViaString",
|
||||
fmt::format(
|
||||
|
||||
Reference in New Issue
Block a user