cpp: Require the host interface for HostContext be passed by reference

This commit is contained in:
Paweł Bylica 2019-11-10 10:13:16 +01:00
parent 1bb7ccd7a4
commit 0522110797
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
2 changed files with 10 additions and 6 deletions

View File

@ -402,8 +402,10 @@ public:
HostContext() = default;
/// Constructor from the EVMC Host primitives.
HostContext(const evmc_host_interface* interface, evmc_host_context* ctx) noexcept
: host{interface}, context{ctx}
/// @param interface The reference to the Host interface.
/// @param ctx The pointer to the Host context object. This parameter MAY be null.
HostContext(const evmc_host_interface& interface, evmc_host_context* ctx) noexcept
: host{&interface}, context{ctx}
{}
bool account_exists(const address& address) noexcept final

View File

@ -440,9 +440,10 @@ TEST(cpp, host)
{
// Use example host to execute all methods from the C++ host wrapper.
auto* host_interface = example_host_get_interface();
const auto* host_interface = example_host_get_interface();
ASSERT_NE(host_interface, nullptr);
auto* host_context = example_host_create_context(evmc_tx_context{});
auto host = evmc::HostContext{host_interface, host_context};
auto host = evmc::HostContext{*host_interface, host_context};
const auto a = evmc::address{{{1}}};
const auto v = evmc::bytes32{{{7, 7, 7}}};
@ -476,9 +477,10 @@ TEST(cpp, host_call)
// Use example host to test Host::call() method.
auto host = evmc::HostContext{}; // Use default constructor.
auto* host_interface = example_host_get_interface();
const auto* host_interface = example_host_get_interface();
ASSERT_NE(host_interface, nullptr);
auto* host_context = example_host_create_context(evmc_tx_context{});
host = evmc::HostContext{host_interface, host_context};
host = evmc::HostContext{*host_interface, host_context};
EXPECT_EQ(host.call({}).gas_left, 0);