Skip to content

Commit

Permalink
feat: rearrange and export modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-AA committed Jun 14, 2024
1 parent 41d9d6f commit e210157
Show file tree
Hide file tree
Showing 42 changed files with 81 additions and 64 deletions.
2 changes: 1 addition & 1 deletion tests/parser/environment/test_call_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
StorageAccesses,
StorageWrites,
)
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def get_add(call_context: CallContext) -> Instruction:
Expand Down
4 changes: 2 additions & 2 deletions tests/parser/information_flow/test_information_flow_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
FlowNodeWithResult,
FlowWithResult,
)
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.parser.storage.storage_writes import (
ReturnDataAccess,
StorageAccesses,
StorageWrites,
)
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


class _TestFlowNode(FlowNodeWithResult):
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/instructions/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
)
from traces_parser.parser.instructions_parser import InstructionMetadata
from traces_parser.parser.trace_evm.trace_evm import parse_instruction
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


_opcodes_to_instruction = [
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/storage/test_address_key_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
_test_group32,
_test_address_key_storage,
)
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def test_address_key_storage_get():
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/storage/test_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPECIAL_STEP_INDEXES,
)
from traces_parser.parser.storage.balances import InvalidAddressException
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def test_balances_last_modified_at_step_index():
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/storage/test_stack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from tests.test_utils.test_utils import _test_group, _test_group32, _test_stack
from traces_parser.parser.storage.stack import Stack
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def test_stack_empty():
Expand Down
4 changes: 2 additions & 2 deletions tests/parser/storage/test_storage_value.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.datatypes.hexstring import HexString


def test_storage_byte_group_empty():
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/test_events_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from traces_parser.parser.events_parser import parse_events
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def test_events_parser():
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/test_instructions_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
parse_transaction,
)
from traces_parser.parser.trace_evm.trace_evm import parse_instruction
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def get_parsing_info(verify_storages=True) -> TransactionParsingInfo:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from traces_parser.parser.storage.balances import Balances
from traces_parser.parser.storage.memory import Memory
from traces_parser.parser.storage.stack import Stack
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.parser.storage.storage_writes import (
MemoryAccess,
PersistentStorageAccess,
Expand All @@ -36,7 +36,7 @@
StorageWrites,
)
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString
from traces_parser.utils.mnemonics import opcode_to_name

TestVal = str | HexString | StorageByteGroup
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_hexstring.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def test_hexstring_equals_str():
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_precompiled_contracts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString
from traces_parser.utils.precompiled_contracts import (
addr_to_precompiled_contract_name,
is_precompiled_contract,
Expand Down
1 change: 1 addition & 0 deletions traces_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
4 changes: 1 addition & 3 deletions traces_parser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from pathlib import Path

from traces_parser.parser.events_parser import parse_events
from traces_parser.parser.instructions_parser import (
parse_transaction,
)
from traces_parser.parser.instructions_parser import parse_transaction
from traces_parser.utils.metadata_file_loader import load_metadata_file


Expand Down
4 changes: 4 additions & 0 deletions traces_parser/datatypes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from traces_parser.datatypes.hexstring import HexString as HexString
from traces_parser.datatypes.storage_byte_group import (
StorageByteGroup as StorageByteGroup,
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


class StorageByte:
Expand Down
1 change: 1 addition & 0 deletions traces_parser/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
1 change: 1 addition & 0 deletions traces_parser/parser/environment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
4 changes: 2 additions & 2 deletions traces_parser/parser/environment/call_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from typing_extensions import Self

from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.datatypes.hexstring import HexString

if TYPE_CHECKING:
from traces_parser.parser.instructions.instructions import (
Expand Down
2 changes: 1 addition & 1 deletion traces_parser/parser/environment/parsing_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
RevertableStorage,
Storage,
)
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


class ParsingEnvironment:
Expand Down
2 changes: 1 addition & 1 deletion traces_parser/parser/events_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Iterable
from dataclasses import dataclass

from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions traces_parser/parser/information_flow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SPECIAL_STEP_INDEXES,
)
from traces_parser.parser.information_flow.information_flow_spec import Flow, FlowSpec
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.parser.storage.storage_writes import (
BalanceAccess,
BalanceTransferWrite,
Expand All @@ -34,7 +34,7 @@
TransientStorageAccess,
TransientStorageWrite,
)
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions traces_parser/parser/instructions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
4 changes: 2 additions & 2 deletions traces_parser/parser/instructions/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
)
from traces_parser.parser.information_flow.information_flow_spec import FlowSpec
from traces_parser.parser.instructions.instruction import Instruction
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.parser.storage.storage_writes import (
MemoryWrite,
StackPush,
StorageWrites,
)
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString

CallDataNew = TypedDict(
"CallDataNew",
Expand Down
29 changes: 7 additions & 22 deletions traces_parser/parser/instructions_parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from collections.abc import Iterable
from dataclasses import dataclass
from typing import Sequence

from traces_parser.parser.environment.call_context import CallContext
from traces_parser.parser.environment.call_context_manager import (
CallTree,
build_call_tree,
)
from traces_parser.parser.environment.call_context_manager import build_call_tree
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
Expand All @@ -16,24 +12,13 @@
SPECIAL_STEP_INDEXES,
)
from traces_parser.parser.instructions.instruction import Instruction
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.utils.hexstring import HexString


@dataclass
class TransactionParsingInfo:
sender: HexString
to: HexString
calldata: HexString
value: HexString
verify_storages: bool = True


@dataclass
class ParsedTransaction:
instructions: Sequence[Instruction]
call_tree: CallTree
from traces_parser.parser.transaction_parsing_info import (
ParsedTransaction,
TransactionParsingInfo,
)
from traces_parser.datatypes.hexstring import HexString


def parse_transaction(
Expand Down
1 change: 1 addition & 0 deletions traces_parser/parser/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
4 changes: 2 additions & 2 deletions traces_parser/parser/storage/address_key_storage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing_extensions import Self

from traces_parser.parser.storage.storage import CloneableStorage
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.datatypes.hexstring import HexString


class AddressKeyStorage(CloneableStorage):
Expand Down
2 changes: 1 addition & 1 deletion traces_parser/parser/storage/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPECIAL_STEP_INDEXES,
)
from traces_parser.parser.storage.storage import CloneableStorage
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


class InvalidAddressException(Exception):
Expand Down
4 changes: 2 additions & 2 deletions traces_parser/parser/storage/memory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.datatypes.hexstring import HexString


class Memory:
Expand Down
4 changes: 2 additions & 2 deletions traces_parser/parser/storage/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from traces_parser.parser.information_flow.constant_step_indexes import (
SPECIAL_STEP_INDEXES,
)
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.datatypes.hexstring import HexString


class Stack:
Expand Down
4 changes: 2 additions & 2 deletions traces_parser/parser/storage/storage_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from dataclasses import dataclass
from typing import Iterable, Sequence

from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.datatypes.hexstring import HexString


@dataclass
Expand Down
1 change: 1 addition & 0 deletions traces_parser/parser/trace_evm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
4 changes: 2 additions & 2 deletions traces_parser/parser/trace_evm/trace_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
CallInstruction,
get_instruction_class,
)
from traces_parser.parser.storage.storage_value import StorageByteGroup
from traces_parser.datatypes.storage_byte_group import StorageByteGroup
from traces_parser.parser.storage.storage_writes import StorageAccesses, StorageWrites
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString
from traces_parser.utils.mnemonics import opcode_to_name


Expand Down
21 changes: 21 additions & 0 deletions traces_parser/parser/transaction_parsing_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from dataclasses import dataclass
from typing import Sequence

from traces_parser.parser.environment.call_context_manager import CallTree
from traces_parser.parser.instructions.instruction import Instruction
from traces_parser.datatypes.hexstring import HexString


@dataclass
class TransactionParsingInfo:
sender: HexString
to: HexString
calldata: HexString
value: HexString
verify_storages: bool = True


@dataclass
class ParsedTransaction:
instructions: Sequence[Instruction]
call_tree: CallTree
1 change: 1 addition & 0 deletions traces_parser/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
2 changes: 1 addition & 1 deletion traces_parser/utils/metadata_file_loader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from pathlib import Path
from traces_parser.parser.instructions_parser import TransactionParsingInfo
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


def load_metadata_file(path: Path) -> TransactionParsingInfo:
Expand Down
2 changes: 1 addition & 1 deletion traces_parser/utils/precompiled_contracts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString

_ADDR_TO_NAME = {
1: "ecRecover",
Expand Down
1 change: 1 addition & 0 deletions traces_parser/utils/signatures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from . import *
2 changes: 1 addition & 1 deletion traces_parser/utils/signatures/signature_lookup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod

from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString


class SignatureLookup(ABC):
Expand Down
2 changes: 1 addition & 1 deletion traces_parser/utils/signatures/signature_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import requests

from traces_parser.utils.hexstring import HexString
from traces_parser.datatypes.hexstring import HexString
from traces_parser.utils.signatures.signature_lookup import SignatureLookup


Expand Down

0 comments on commit e210157

Please sign in to comment.