From 13cdfd7b401c08b0b87eb9f20e535d56ca7a61bc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 24 Apr 2019 11:33:55 +0100 Subject: [PATCH] vmtester: add test case for CREATE --- test/vmtester/tests.cpp | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/vmtester/tests.cpp b/test/vmtester/tests.cpp index 6ab0ec7..6c4a424 100644 --- a/test/vmtester/tests.cpp +++ b/test/vmtester/tests.cpp @@ -6,6 +6,7 @@ #include "vmtester.hpp" #include +#include #include #include @@ -45,7 +46,7 @@ TEST_F(evmc_vm_test, version) EXPECT_GT(std::strlen(vm->version), 0) << "VM name cannot be empty"; } -TEST_F(evmc_vm_test, execute) +TEST_F(evmc_vm_test, execute_call) { evmc_context* context = example_host_create_context(); evmc_message msg{}; @@ -76,6 +77,45 @@ TEST_F(evmc_vm_test, execute) example_host_destroy_context(context); } +TEST_F(evmc_vm_test, execute_create) +{ + evmc_context* context = example_host_create_context(); + evmc_message msg{ + EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, NULL, 0, evmc_uint256be{}, + evmc_bytes32{}}; + std::array code = {{0xfe, 0x00}}; + + evmc_result result = + vm->execute(vm, context, EVMC_MAX_REVISION, &msg, code.data(), code.size()); + + // Validate some constraints + if (result.status_code != EVMC_SUCCESS && result.status_code != EVMC_REVERT) + { + EXPECT_EQ(result.gas_left, 0); + } + + if (result.output_data == NULL) + { + EXPECT_EQ(result.output_size, 0); + } + else + { + EXPECT_NE(result.output_size, 0); + read_buffer(result.output_data, result.output_size); + } + + if (result.status_code == EVMC_SUCCESS) + { + // This assumes that CREATE returns a non-zero address on success. + EXPECT_FALSE(is_zero(result.create_address)); + } + + if (result.release) + result.release(&result); + + example_host_destroy_context(context); +} + TEST_F(evmc_vm_test, set_option_unknown_name) { if (vm->set_option)