mirror of
				https://github.com/XRPLF/clio.git
				synced 2025-11-04 11:55:51 +00:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			104ef6a9dc
			...
			release/2.
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					7b18e28c47 | ||
| 
						 | 
					4940d463dc | 
@@ -94,7 +94,7 @@ struct ReturnType {
 | 
			
		||||
     * @param warnings The warnings generated by the RPC call
 | 
			
		||||
     */
 | 
			
		||||
    ReturnType(std::expected<boost::json::value, Status> result, boost::json::array warnings = {})
 | 
			
		||||
        : result{std::move(result)}, warnings{std::move(warnings)}
 | 
			
		||||
        : result{std::move(result)}, warnings(std::move(warnings))
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@
 | 
			
		||||
#include <fmt/core.h>
 | 
			
		||||
#include <ripple/basics/base_uint.h>
 | 
			
		||||
#include <ripple/protocol/AccountID.h>
 | 
			
		||||
#include <ripple/protocol/ErrorCodes.h>
 | 
			
		||||
#include <ripple/protocol/UintTypes.h>
 | 
			
		||||
#include <ripple/protocol/tokens.h>
 | 
			
		||||
 | 
			
		||||
@@ -140,8 +141,12 @@ CustomValidator CurrencyValidator =
 | 
			
		||||
        if (!value.is_string())
 | 
			
		||||
            return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + "NotString"}};
 | 
			
		||||
 | 
			
		||||
        auto const currencyStr = boost::json::value_to<std::string>(value);
 | 
			
		||||
        if (currencyStr.empty())
 | 
			
		||||
            return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + "IsEmpty"}};
 | 
			
		||||
 | 
			
		||||
        ripple::Currency currency;
 | 
			
		||||
        if (!ripple::to_currency(currency, boost::json::value_to<std::string>(value)))
 | 
			
		||||
        if (!ripple::to_currency(currency, currencyStr))
 | 
			
		||||
            return Error{Status{ClioError::rpcMALFORMED_CURRENCY, "malformedCurrency"}};
 | 
			
		||||
 | 
			
		||||
        return MaybeError{};
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,8 @@
 | 
			
		||||
#include "rpc/Errors.hpp"
 | 
			
		||||
#include "rpc/common/Types.hpp"
 | 
			
		||||
 | 
			
		||||
#include <boost/json/array.hpp>
 | 
			
		||||
#include <boost/json/value.hpp>
 | 
			
		||||
#include <gtest/gtest.h>
 | 
			
		||||
 | 
			
		||||
#include <expected>
 | 
			
		||||
@@ -34,3 +36,46 @@ TEST(MaybeErrorTest, OperatorEquals)
 | 
			
		||||
    EXPECT_EQ(MaybeError{std::unexpected{Status{"Error"}}}, MaybeError{std::unexpected{Status{"Error"}}});
 | 
			
		||||
    EXPECT_NE(MaybeError{std::unexpected{Status{"Error"}}}, MaybeError{std::unexpected{Status{"Another_error"}}});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(ReturnTypeTests, Constructor)
 | 
			
		||||
{
 | 
			
		||||
    boost::json::value const value{42};
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
        ReturnType const r{value};
 | 
			
		||||
        ASSERT_TRUE(r.result);
 | 
			
		||||
        EXPECT_EQ(r.result.value(), value);
 | 
			
		||||
        EXPECT_EQ(r.warnings, boost::json::array{});
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
        boost::json::array const warnings{1, 2, 3};
 | 
			
		||||
        ReturnType const r{value, warnings};
 | 
			
		||||
        ASSERT_TRUE(r.result);
 | 
			
		||||
        EXPECT_EQ(r.result.value(), value);
 | 
			
		||||
        EXPECT_EQ(r.warnings, warnings);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
        Status const status{"Error"};
 | 
			
		||||
 | 
			
		||||
        ReturnType const r{std::unexpected{status}};
 | 
			
		||||
        ASSERT_FALSE(r.result);
 | 
			
		||||
        EXPECT_EQ(r.result.error(), status);
 | 
			
		||||
        EXPECT_EQ(r.warnings, boost::json::array{});
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(ReturnTypeTests, operatorBool)
 | 
			
		||||
{
 | 
			
		||||
    {
 | 
			
		||||
        boost::json::value const value{42};
 | 
			
		||||
        ReturnType const r{value};
 | 
			
		||||
        EXPECT_TRUE(r);
 | 
			
		||||
    }
 | 
			
		||||
    {
 | 
			
		||||
        Status const status{"Error"};
 | 
			
		||||
        ReturnType const r{std::unexpected{status}};
 | 
			
		||||
        EXPECT_FALSE(r);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -160,6 +160,22 @@ generateTestValuesForParametersTest()
 | 
			
		||||
            "invalidParams",
 | 
			
		||||
            "Invalid parameters."
 | 
			
		||||
        },
 | 
			
		||||
        GetAggregatePriceParamTestCaseBundle{
 | 
			
		||||
            "emtpy_base_asset",
 | 
			
		||||
            R"({
 | 
			
		||||
                    "quote_asset" : "USD",
 | 
			
		||||
                    "base_asset": "",
 | 
			
		||||
                    "oracles": 
 | 
			
		||||
                    [
 | 
			
		||||
                        {
 | 
			
		||||
                            "account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
 | 
			
		||||
                            "oracle_document_id": 2
 | 
			
		||||
                        }
 | 
			
		||||
                    ]
 | 
			
		||||
                })",
 | 
			
		||||
            "invalidParams",
 | 
			
		||||
            "Invalid parameters."
 | 
			
		||||
        },
 | 
			
		||||
        GetAggregatePriceParamTestCaseBundle{
 | 
			
		||||
            "invalid_base_asset2",
 | 
			
		||||
            R"({
 | 
			
		||||
@@ -207,6 +223,22 @@ generateTestValuesForParametersTest()
 | 
			
		||||
            "invalidParams",
 | 
			
		||||
            "Invalid parameters."
 | 
			
		||||
        },
 | 
			
		||||
        GetAggregatePriceParamTestCaseBundle{
 | 
			
		||||
            "empty_quote_asset",
 | 
			
		||||
            R"({
 | 
			
		||||
                    "quote_asset" : "",
 | 
			
		||||
                    "base_asset": "USD",
 | 
			
		||||
                    "oracles": 
 | 
			
		||||
                    [
 | 
			
		||||
                        {
 | 
			
		||||
                            "account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
 | 
			
		||||
                            "oracle_document_id": 2
 | 
			
		||||
                        }
 | 
			
		||||
                    ]
 | 
			
		||||
                })",
 | 
			
		||||
            "invalidParams",
 | 
			
		||||
            "Invalid parameters."
 | 
			
		||||
        },
 | 
			
		||||
        GetAggregatePriceParamTestCaseBundle{
 | 
			
		||||
            "invalid_quote_asset2",
 | 
			
		||||
            R"({
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user