1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
12using simulation::InstrDeserializationError;
14using simulation::Instruction;
18TEST(SerializationTest, Not8RoundTrip)
22 .operands = { Operand::from<uint8_t>(123), Operand::from<uint8_t>(45) } };
24 EXPECT_EQ(instr, decoded);
28TEST(SerializationTest, Add16RoundTrip)
33 .operands = { Operand::from<uint16_t>(1000), Operand::from<uint16_t>(1001), Operand::from<uint16_t>(1002) }
36 EXPECT_EQ(instr, decoded);
40TEST(SerializationTest, Jumpi32RoundTrip)
44 .operands = { Operand::from<uint16_t>(12345), Operand::from<uint32_t>(678901234) } };
46 EXPECT_EQ(instr, decoded);
50TEST(SerializationTest, Set64RoundTrip)
52 const uint64_t value_64 = 0xABCDEF0123456789LLU;
56 .operands = { Operand::from<uint16_t>(1002),
58 Operand::from<uint64_t>(value_64) } };
60 EXPECT_EQ(instr, decoded);
64TEST(SerializationTest, Set128RoundTrip)
70 .operands = { Operand::from<uint16_t>(1002),
72 Operand::from<uint128_t>(value_128) } };
74 EXPECT_EQ(instr, decoded);
78TEST(SerializationTest, SetFFRoundTrip)
84 .operands = { Operand::from<uint16_t>(1002),
86 Operand::from<FF>(large_ff) } };
88 EXPECT_EQ(instr, decoded);
94TEST(SerializationTest, DeserializeLargeFF)
101 .operands = { Operand::from<uint16_t>(1002),
104 auto serialized_instruction = instr.serialize();
107 serialized_instruction.insert(serialized_instruction.end() - 32,
buf.begin(),
buf.end());
110 ASSERT_EQ(3, decoded.operands.size());
111 EXPECT_EQ(decoded.operands[2].as<
FF>(), 145);
115TEST(SerializationTest, PCOutOfRange)
122 }
catch (
const InstrDeserializationError& error) {
123 EXPECT_EQ(error.type, InstrDeserializationEventError::PC_OUT_OF_RANGE);
124 EXPECT_TRUE(error.message.has_value());
129TEST(SerializationTest, OpcodeOutOfRange)
136 }
catch (
const InstrDeserializationError& error) {
137 EXPECT_EQ(error.type, InstrDeserializationEventError::OPCODE_OUT_OF_RANGE);
138 EXPECT_TRUE(error.message.has_value());
143TEST(SerializationTest, InstructionOutOfRange)
148 .operands = { Operand::from<uint16_t>(1002),
150 Operand::from<uint16_t>(12345) } };
159 }
catch (
const InstrDeserializationError& error) {
160 EXPECT_EQ(error.type, InstrDeserializationEventError::INSTRUCTION_OUT_OF_RANGE);
161 EXPECT_TRUE(error.message.has_value());
166TEST(SerializationTest, CheckTagValid)
170 .operands = { Operand::from<uint16_t>(1002),
172 Operand::from<uint128_t>(12345) } };
177TEST(SerializationTest, CheckTagInvalid)
181 .operands = { Operand::from<uint16_t>(1002),
183 Operand::from<uint128_t>(12345) } };
188TEST(SerializationTest, CheckTagInvalidNotEnoughOperands)
195TEST(SerializationTest, CheckTagInvalidTagNotByte)
199 .operands = { Operand::from<uint16_t>(1002),
201 Operand::from<uint128_t>(12345) } };
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
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...
InstrDeserializationEventError
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.
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
std::vector< uint8_t > to_buffer(T const &value)
unsigned __int128 uint128_t
static constexpr uint256_t modulus