Merge pull request #276 from ethereum/vmtester-create-address

docs: Clarify validity of result::create_address
This commit is contained in:
Paweł Bylica 2019-05-09 14:21:46 +02:00 committed by GitHub
commit 5946e115b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View File

@ -112,10 +112,7 @@ static struct evmc_result execute(struct evmc_instance* instance,
if (msg->kind == EVMC_CREATE)
{
evmc_address create_address = {
{1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
ret.status_code = EVMC_SUCCESS;
ret.create_address = create_address;
ret.gas_left = msg->gas / 10;
return ret;
}

View File

@ -385,10 +385,13 @@ struct evmc_result
evmc_release_result_fn release;
/**
* The address of the contract created by CREATE opcode.
* The address of the contract created by create instructions.
*
* This field has valid value only if the result describes successful
* CREATE (evmc_result::status_code is ::EVMC_SUCCESS).
* This field has valid value only if:
* - it is a result of the Host method evmc_host_interface::call
* - and the result describes successful contract creation
* (evmc_result::status_code is ::EVMC_SUCCESS).
* In all other cases the address MUST be null bytes.
*/
evmc_address create_address;

View File

@ -78,6 +78,8 @@ TEST_F(evmc_vm_test, execute_call)
read_buffer(result.output_data, result.output_size);
}
EXPECT_TRUE(is_zero(result.create_address));
if (result.release)
result.release(&result);
@ -88,7 +90,7 @@ 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_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, nullptr, 0, evmc_uint256be{},
evmc_bytes32{}};
std::array<uint8_t, 2> code = {{0xfe, 0x00}};
@ -101,7 +103,7 @@ TEST_F(evmc_vm_test, execute_create)
EXPECT_EQ(result.gas_left, 0);
}
if (result.output_data == NULL)
if (result.output_data == nullptr)
{
EXPECT_EQ(result.output_size, 0);
}
@ -111,11 +113,8 @@ TEST_F(evmc_vm_test, execute_create)
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));
}
// The VM will never provide the create address.
EXPECT_TRUE(is_zero(result.create_address));
if (result.release)
result.release(&result);