From 0fa27b8e213000e47072e63413d1c3522217d216 Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Tue, 23 Oct 2018 00:24:31 +0200 Subject: [PATCH] Remove generator type and add asm get opcode tests --- mythril/disassembler/asm.py | 2 +- tests/disassembler/__init__.py | 0 tests/disassembler/asm.py | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/disassembler/__init__.py create mode 100644 tests/disassembler/asm.py diff --git a/mythril/disassembler/asm.py b/mythril/disassembler/asm.py index 8eca0c8e..6308b5d8 100644 --- a/mythril/disassembler/asm.py +++ b/mythril/disassembler/asm.py @@ -42,7 +42,7 @@ def get_opcode_from_name(operation_name): raise RuntimeError("Unknown opcode") -def find_op_code_sequence(pattern, instruction_list) -> Generator[int, None, None]: +def find_op_code_sequence(pattern, instruction_list): """ Returns all indices in instruction_list that point to instruction sequences following a pattern :param pattern: The pattern to look for. diff --git a/tests/disassembler/__init__.py b/tests/disassembler/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/disassembler/asm.py b/tests/disassembler/asm.py new file mode 100644 index 00000000..4eaada3f --- /dev/null +++ b/tests/disassembler/asm.py @@ -0,0 +1,20 @@ +from mythril.disassembler.asm import * +import pytest + +valid_names = [("PUSH1", 0x60), ("STOP", 0x0), ("RETURN", 0xf3)] + + +@pytest.mark.parametrize("operation_name, hex_value", valid_names) +def test_get_opcode(operation_name: str, hex_value: int): + # Act + return_value = get_opcode_from_name(operation_name) + # Assert + assert return_value == hex_value + + +def test_get_unknown_opcode(): + operation_name = "definitely unknown" + + # Act + with pytest.raises(RuntimeError): + get_opcode_from_name(operation_name)