Add more tests for instruction tables

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

View File

@ -174,7 +174,7 @@ enum evmc_opcode
*/
struct evmc_instruction_metrics
{
/** The instruction gas cost. Value -1 indicates undefined instruction. */
/** The instruction gas cost. Value -1 indicates an undefined instruction. */
int16_t gas_cost;
/** The number of items the instruction pops from the EVM stack before execution. */

View File

@ -6,6 +6,15 @@
#include <gtest/gtest.h>
TEST(instructions, homestead_hard_fork)
{
const auto f = evmc_get_instruction_metrics_table(EVMC_FRONTIER);
const auto h = evmc_get_instruction_metrics_table(EVMC_HOMESTEAD);
EXPECT_EQ(f[OP_DELEGATECALL].gas_cost, -1);
EXPECT_EQ(h[OP_DELEGATECALL].gas_cost, 40);
}
TEST(instructions, tangerine_whistle_hard_fork)
{
const auto h = evmc_get_instruction_metrics_table(EVMC_HOMESTEAD);
@ -34,4 +43,33 @@ TEST(instructions, tangerine_whistle_hard_fork)
EXPECT_EQ(h[OP_SELFDESTRUCT].gas_cost, 0);
EXPECT_EQ(tw[OP_SELFDESTRUCT].gas_cost, 5000);
}
TEST(instructions, spurious_dragon_hard_fork)
{
const auto sd = evmc_get_instruction_metrics_table(EVMC_SPURIOUS_DRAGON);
const auto tw = evmc_get_instruction_metrics_table(EVMC_TANGERINE_WHISTLE);
EXPECT_EQ(sd[OP_EXP].gas_cost, 10);
EXPECT_EQ(tw[OP_EXP].gas_cost, 10);
}
TEST(instructions, byzantium_hard_fork)
{
const auto b = evmc_get_instruction_metrics_table(EVMC_BYZANTIUM);
const auto sd = evmc_get_instruction_metrics_table(EVMC_SPURIOUS_DRAGON);
EXPECT_EQ(b[OP_REVERT].gas_cost, 0);
EXPECT_EQ(b[OP_REVERT].num_stack_arguments, 2);
EXPECT_EQ(b[OP_REVERT].num_stack_returned_items, 0);
EXPECT_EQ(sd[OP_REVERT].gas_cost, -1);
EXPECT_EQ(b[OP_RETURNDATACOPY].gas_cost, 3);
EXPECT_EQ(sd[OP_RETURNDATACOPY].gas_cost, -1);
EXPECT_EQ(b[OP_RETURNDATASIZE].gas_cost, 2);
EXPECT_EQ(sd[OP_RETURNDATASIZE].gas_cost, -1);
EXPECT_EQ(b[OP_STATICCALL].gas_cost, 700);
EXPECT_EQ(sd[OP_STATICCALL].gas_cost, -1);
}