Create context in example host

This commit is contained in:
Paweł Bylica 2018-08-30 15:15:39 +02:00
parent 5aefc4faf3
commit 43dce45a5b
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
2 changed files with 26 additions and 4 deletions

View File

@ -128,7 +128,22 @@ static void emit_log(evmc_context* context,
(void)topics_count;
}
extern const evmc_context_fn_table mock_context_fn_table = {
static const evmc_context_fn_table methods = {
account_exists, get_storage, set_storage, get_balance, get_code_size, get_code_hash,
copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log,
};
struct example_host_context : evmc_context
{
example_host_context() : evmc_context{&methods} {}
};
evmc_context* example_host_create_context()
{
return new example_host_context;
}
void example_host_destroy_context(evmc_context* context)
{
delete context;
}

View File

@ -9,6 +9,12 @@
#include <array>
#include <cstring>
// Declarations of functions from example host:
evmc_context* example_host_create_context();
void example_host_destroy_context(evmc_context* context);
// Compile time checks:
static_assert(sizeof(evmc_uint256be) == 32, "evmc_uint256be is too big");
@ -27,7 +33,6 @@ static constexpr size_t optionalDataSize =
sizeof(evmc_result) - offsetof(evmc_result, create_address);
static_assert(optionalDataSize == sizeof(evmc_result_optional_storage), "");
extern const struct evmc_context_fn_table mock_context_fn_table;
TEST_F(evmc_vm_test, abi_version_match)
{
@ -36,12 +41,12 @@ TEST_F(evmc_vm_test, abi_version_match)
TEST_F(evmc_vm_test, execute)
{
evmc_context context = {&mock_context_fn_table};
evmc_context* context = example_host_create_context();
evmc_message msg{};
std::array<uint8_t, 2> code = {{0xfe, 0x00}};
evmc_result result =
vm->execute(vm, &context, EVMC_LATEST_REVISION, &msg, code.data(), code.size());
vm->execute(vm, context, EVMC_LATEST_REVISION, &msg, code.data(), code.size());
// Validate some constraints
if (result.status_code != EVMC_SUCCESS && result.status_code != EVMC_REVERT)
@ -56,6 +61,8 @@ TEST_F(evmc_vm_test, execute)
if (result.release)
result.release(&result);
example_host_destroy_context(context);
}
TEST_F(evmc_vm_test, set_option_unknown)