def test_insert_check_end(self): instructions = self.evmcode.disassemble() instructions.insert(0, registry.create_instruction(name="JUMPDEST")) for idx in range(len(instructions)): instructions.insert(-idx, registry.create_instruction(name="JUMPDEST")) self._check_address_linear(instructions) for _ in range(len(instructions)): idx = random.randint(0, len(instructions) - 1) instructions.insert(idx, registry.create_instruction(name="JUMPDEST")) self._check_address_linear(instructions)
def test_instruction_set_operand_bytes(self): value = b'\xc0\xfe\xfe' push = registry.create_instruction("PUSH%d" % len(value)) push.operand_bytes = value self.assertEqual(push.operand, utils.bytes_to_str(value, prefix="")) self.assertEqual(push.operand_bytes, value) self.assertEqual(push.operand_length, len(value))
def test_instruction_set_operand(self): value = "c0fefe" push = registry.create_instruction("PUSH%d" % len(value)) push.operand = value self.assertEqual(push.operand, value) self.assertEqual(push.operand_bytes, utils.str_to_bytes(value)) self.assertEqual(push.operand_length, len(value))
def test_append_check_end_no_fix_address(self): instructions = self.evmcode.disassemble() instructions._fix_addresses = False for _ in range(4000): instructions.append(registry.create_instruction(name="JUMPDEST")) error = False pc = instructions[0].address for instr in instructions: if not instr.address == pc: error = True break pc += len(instr) self.assertTrue(error)
def test_append_check_end_getitem(self): instructions = self.evmcode.disassemble() for _ in range(4000): instructions.append(registry.create_instruction(name="JUMPDEST")) self._check_address_linear_getitem(instructions) self._check_address_linear_getitem(instructions)
def test_create_instruction(self): self.assertEqual(registry.instruction.JUMP, registry.INSTRUCTIONS_BY_NAME["JUMP"]) self.assertNotEqual(registry.instruction.JUMP, registry.create_instruction(name="JUMP"))