Do not allow set_tracer function to be null

This commit is contained in:
Paweł Bylica 2018-06-18 14:18:39 +02:00
parent 2c7ad06072
commit d2ac75f6a8
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
2 changed files with 22 additions and 1 deletions

View File

@ -9,6 +9,8 @@ struct examplevm
{
struct evmc_instance instance;
int verbose;
evmc_trace_callback trace_callback;
struct evmc_tracer_context* tracer_context;
};
static void destroy(struct evmc_instance* evm)
@ -113,6 +115,15 @@ static struct evmc_result execute(struct evmc_instance* instance,
return ret;
}
static void set_tracer(struct evmc_instance* instance,
evmc_trace_callback callback,
struct evmc_tracer_context* context)
{
struct examplevm* vm = (struct examplevm*)instance;
vm->trace_callback = callback;
vm->tracer_context = context;
}
struct evmc_instance* evmc_create_examplevm()
{
struct evmc_instance init = {
@ -122,6 +133,7 @@ struct evmc_instance* evmc_create_examplevm()
.destroy = destroy,
.execute = execute,
.set_option = set_option,
.set_tracer = set_tracer,
};
struct examplevm* vm = calloc(1, sizeof(struct examplevm));
struct evmc_instance* interface = &vm->instance;

View File

@ -59,4 +59,13 @@ TEST_F(evmc_vm_test, version)
{
ASSERT_NE(vm->version, nullptr);
EXPECT_GT(std::strlen(vm->version), 0) << "VM name cannot be empty";
}
}
TEST_F(evmc_vm_test, set_tracer)
{
static constexpr auto tracer_callback = [](evmc_tracer_context*, int, size_t, evmc_status_code,
int64_t, size_t, const evmc_uint256be*, size_t,
size_t, size_t, const uint8_t*) noexcept {};
ASSERT_NE(vm->set_tracer, nullptr);
vm->set_tracer(vm, tracer_callback, nullptr);
}