1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
13using simulation::Instruction;
17TEST(SerializationTest, Not8RoundTrip)
21 .operands = { Operand::from<uint8_t>(123), Operand::from<uint8_t>(45) } };
23 EXPECT_EQ(instr, decoded);
27TEST(SerializationTest, Add16RoundTrip)
32 .operands = { Operand::from<uint16_t>(1000), Operand::from<uint16_t>(1001), Operand::from<uint16_t>(1002) }
35 EXPECT_EQ(instr, decoded);
39TEST(SerializationTest, Jumpi32RoundTrip)
43 .operands = { Operand::from<uint16_t>(12345), Operand::from<uint32_t>(678901234) } };
45 EXPECT_EQ(instr, decoded);
49TEST(SerializationTest, Set64RoundTrip)
51 const uint64_t value_64 = 0xABCDEF0123456789LLU;
55 .operands = { Operand::from<uint16_t>(1002),
57 Operand::from<uint64_t>(value_64) } };
59 EXPECT_EQ(instr, decoded);
63TEST(SerializationTest, Set128RoundTrip)
69 .operands = { Operand::from<uint16_t>(1002),
71 Operand::from<uint128_t>(value_128) } };
73 EXPECT_EQ(instr, decoded);
77TEST(SerializationTest, SetFFRoundTrip)
83 .operands = { Operand::from<uint16_t>(1002),
85 Operand::from<FF>(large_ff) } };
87 EXPECT_EQ(instr, decoded);
93TEST(SerializationTest, DeserializeLargeFF)
100 .operands = { Operand::from<uint16_t>(1002),
103 auto serialized_instruction = instr.serialize();
106 serialized_instruction.insert(serialized_instruction.end() - 32,
buf.begin(),
buf.end());
109 ASSERT_EQ(3, decoded.operands.size());
110 EXPECT_EQ(decoded.operands[2].as<
FF>(), 145);
114TEST(SerializationTest, PCOutOfRange)
116 std::vector<uint8_t> bytecode;
117 bytecode.resize(35, 0);
122 EXPECT_EQ(error, InstrDeserializationError::PC_OUT_OF_RANGE);
127TEST(SerializationTest, OpcodeOutOfRange)
129 std::vector<uint8_t> bytecode;
135 EXPECT_EQ(error, InstrDeserializationError::OPCODE_OUT_OF_RANGE);
140TEST(SerializationTest, InstructionOutOfRange)
145 .operands = { Operand::from<uint16_t>(1002),
147 Operand::from<uint16_t>(12345) } };
149 auto bytecode = instr.serialize();
152 bytecode.resize(bytecode.size() - 1);
157 EXPECT_EQ(error, InstrDeserializationError::INSTRUCTION_OUT_OF_RANGE);
162TEST(SerializationTest, CheckTagValid)
166 .operands = { Operand::from<uint16_t>(1002),
168 Operand::from<uint128_t>(12345) } };
173TEST(SerializationTest, CheckTagInvalid)
177 .operands = { Operand::from<uint16_t>(1002),
179 Operand::from<uint128_t>(12345) } };
184TEST(SerializationTest, CheckTagInvalidNotEnoughOperands)
191TEST(SerializationTest, CheckTagInvalidTagNotByte)
195 .operands = { Operand::from<uint16_t>(1002),
197 Operand::from<uint128_t>(12345) } };
bool check_tag(const Instruction &instruction)
Check whether the instruction must have a tag operand and whether the operand value is in the value t...
TEST(EmitUnencryptedLogTest, Basic)
InstrDeserializationError
Instruction deserialize_instruction(std::span< const uint8_t > bytecode, size_t pos)
Parsing of an instruction in the supplied bytecode at byte position pos. This checks that the WireOpC...
Instruction
Enumeration of VM instructions that can be executed.
std::vector< uint8_t > to_buffer(T const &value)
unsigned __int128 uint128_t
static constexpr uint256_t modulus