Skip to content

Commit 69ed5cd

Browse files
authored
Make Result accessible via evmc_result reference (#686)
Add Result::raw() method for accessing the result object via reference to evmc_result.
1 parent 44fc118 commit 69ed5cd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/evmc/evmc.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ class Result : private evmc_result
414414
return *this;
415415
}
416416

417+
/// Access the result object as a referenced to ::evmc_result.
418+
evmc_result& raw() noexcept { return *this; }
419+
420+
/// Access the result object as a const referenced to ::evmc_result.
421+
const evmc_result& raw() const noexcept { return *this; }
422+
417423
/// Releases the ownership and returns the raw copy of evmc_result.
418424
///
419425
/// This method drops the ownership of the result

test/unittests/cpp_test.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -973,3 +973,25 @@ TEST(cpp, revision_to_string_invalid)
973973
EXPECT_EQ(os.str(), "<unknown>");
974974
}
975975
}
976+
977+
TEST(cpp, result_c_const_access)
978+
{
979+
static constexpr auto get_status = [](const evmc_result& c_result) noexcept {
980+
return c_result.status_code;
981+
};
982+
983+
const evmc::Result r{EVMC_REVERT};
984+
EXPECT_EQ(get_status(r.raw()), EVMC_REVERT);
985+
}
986+
987+
TEST(cpp, result_c_nonconst_access)
988+
{
989+
static constexpr auto set_status = [](evmc_result& c_result) noexcept {
990+
c_result.status_code = EVMC_SUCCESS;
991+
};
992+
993+
evmc::Result r;
994+
EXPECT_EQ(r.status_code, EVMC_INTERNAL_ERROR);
995+
set_status(r.raw());
996+
EXPECT_EQ(r.status_code, EVMC_SUCCESS);
997+
}

0 commit comments

Comments
 (0)