1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
13using simulation::InstrDeserializationError;
15using simulation::Instruction;
19TEST(SerializationTest, Not8RoundTrip)
23 .operands = { Operand::from<uint8_t>(123), Operand::from<uint8_t>(45) } };
25 EXPECT_EQ(instr, decoded);
29TEST(SerializationTest, Add16RoundTrip)
34 .operands = { Operand::from<uint16_t>(1000), Operand::from<uint16_t>(1001), Operand::from<uint16_t>(1002) }
37 EXPECT_EQ(instr, decoded);
41TEST(SerializationTest, Jumpi32RoundTrip)
45 .operands = { Operand::from<uint16_t>(12345), Operand::from<uint32_t>(678901234) } };
47 EXPECT_EQ(instr, decoded);
51TEST(SerializationTest, Set64RoundTrip)
53 const uint64_t value_64 = 0xABCDEF0123456789LLU;
57 .operands = { Operand::from<uint16_t>(1002),
59 Operand::from<uint64_t>(value_64) } };
61 EXPECT_EQ(instr, decoded);
65TEST(SerializationTest, Set128RoundTrip)
71 .operands = { Operand::from<uint16_t>(1002),
73 Operand::from<uint128_t>(value_128) } };
75 EXPECT_EQ(instr, decoded);
79TEST(SerializationTest, SetFFRoundTrip)
85 .operands = { Operand::from<uint16_t>(1002),
87 Operand::from<FF>(large_ff) } };
89 EXPECT_EQ(instr, decoded);
95TEST(SerializationTest, DeserializeLargeFF)
101 .addressing_mode = 0,
102 .operands = { Operand::from<uint16_t>(1002),
105 auto serialized_instruction = instr.serialize();
108 serialized_instruction.insert(serialized_instruction.end() - 32, buf.begin(), buf.end());
111 ASSERT_EQ(3, decoded.operands.size());
112 EXPECT_EQ(decoded.operands[2].as<
FF>(), 145);
116TEST(SerializationTest, PCOutOfRange)
123 }
catch (
const InstrDeserializationError& error) {
124 EXPECT_EQ(error.type, InstrDeserializationEventError::PC_OUT_OF_RANGE);
125 EXPECT_TRUE(error.message.has_value());
130TEST(SerializationTest, OpcodeOutOfRange)
137 }
catch (
const InstrDeserializationError& error) {
138 EXPECT_EQ(error.type, InstrDeserializationEventError::OPCODE_OUT_OF_RANGE);
139 EXPECT_TRUE(error.message.has_value());
144TEST(SerializationTest, InstructionOutOfRange)
148 .addressing_mode = 2,
149 .operands = { Operand::from<uint16_t>(1002),
151 Operand::from<uint16_t>(12345) } };
160 }
catch (
const InstrDeserializationError& error) {
161 EXPECT_EQ(error.type, InstrDeserializationEventError::INSTRUCTION_OUT_OF_RANGE);
162 EXPECT_TRUE(error.message.has_value());
167TEST(SerializationTest, CheckTagValid)
170 .addressing_mode = 2,
171 .operands = { Operand::from<uint16_t>(1002),
173 Operand::from<uint128_t>(12345) } };
178TEST(SerializationTest, CheckTagInvalid)
181 .addressing_mode = 2,
182 .operands = { Operand::from<uint16_t>(1002),
184 Operand::from<uint128_t>(12345) } };
189TEST(SerializationTest, CheckTagInvalidNotEnoughOperands)
192 .addressing_mode = 2,
193 .operands = { Operand::from<uint16_t>(1002) } };
196 EXPECT_THROW(
check_tag(instr), std::runtime_error);
200TEST(SerializationTest, CheckTagInvalidTagNotByte)
203 .addressing_mode = 2,
204 .operands = { Operand::from<uint16_t>(1002),
206 Operand::from<uint128_t>(12345) } };
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
bool check_tag(const Instruction &instruction)
Checks whether the tag operand of an instruction is a valid MemoryTag. Called by bytecode managers du...
InstrDeserializationEventError
Instruction deserialize_instruction(std::span< const uint8_t > bytecode, size_t pos)
Attempts to deserialize the instruction at position pos in bytecode. Called by bytecode managers duri...
Instruction
Enumeration of VM instructions that can be executed.
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
std::vector< uint8_t > to_buffer(T const &value)
unsigned __int128 uint128_t
static constexpr uint256_t modulus