diff --git a/src/rpc/common/Types.hpp b/src/rpc/common/Types.hpp index ccdea346..06bf68f1 100644 --- a/src/rpc/common/Types.hpp +++ b/src/rpc/common/Types.hpp @@ -94,7 +94,7 @@ struct ReturnType { * @param warnings The warnings generated by the RPC call */ ReturnType(std::expected result, boost::json::array warnings = {}) - : result{std::move(result)}, warnings{std::move(warnings)} + : result{std::move(result)}, warnings(std::move(warnings)) { } diff --git a/tests/unit/rpc/common/TypesTests.cpp b/tests/unit/rpc/common/TypesTests.cpp index e36ef670..5e886c6a 100644 --- a/tests/unit/rpc/common/TypesTests.cpp +++ b/tests/unit/rpc/common/TypesTests.cpp @@ -20,6 +20,8 @@ #include "rpc/Errors.hpp" #include "rpc/common/Types.hpp" +#include +#include #include #include @@ -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); + } +}