From 37a4ecf206ba6c57955a04fbe19dbcf432928d71 Mon Sep 17 00:00:00 2001 From: Patrick Collins <54278053+PatrickAlphaC@users.noreply.github.com> Date: Sun, 17 Nov 2024 15:29:24 -0500 Subject: [PATCH] Fix/inspect not compiling (#158) * fix: inspect works with imports now * fix: lint --- moccasin/commands/inspect.py | 15 ++++++++++++--- pyproject.toml | 2 +- tests/unit/test_unit_inspect.py | 17 ++++++++++++++--- uv.lock | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/moccasin/commands/inspect.py b/moccasin/commands/inspect.py index 4e315a6..ac669a0 100644 --- a/moccasin/commands/inspect.py +++ b/moccasin/commands/inspect.py @@ -2,6 +2,7 @@ from argparse import Namespace from typing import Any +from moccasin._sys_path_and_config_setup import _patch_sys_path, get_sys_paths_list from moccasin.commands.compile import compile_ from moccasin.config import Config, get_config, initialize_global_config @@ -31,9 +32,17 @@ def inspect_contract( config = get_config() contract_path = config.find_contract(contract) - vyper_deployer = compile_( - contract_path, config.get_root().joinpath(config.build_folder) - ) + + # We should probably refactor this so that `_patch_sys_path` is auto called on stuff like "compile" + # I keep forgetting to add it and it screws stuff up + with _patch_sys_path(get_sys_paths_list(config)): + contract_path = config.find_contract(contract) + vyper_deployer = compile_( + contract_path, + config.get_root().joinpath(config.out_folder), + is_zksync=False, + write_data=False, + ) if inspect_type in FUNCTION_SIGNATURES_ALTS: inspect_type = "function_signatures" diff --git a/pyproject.toml b/pyproject.toml index be1ef58..415f941 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "moccasin" -version = "0.3.4b3" +version = "0.3.4b4" description = "Pythonic smart contract development framework using Titanoboa" authors = [ { name = "PatrickAlphac", email = "54278053+PatrickAlphaC@users.noreply.github.com" }, diff --git a/tests/unit/test_unit_inspect.py b/tests/unit/test_unit_inspect.py index b947f9e..3657e9f 100644 --- a/tests/unit/test_unit_inspect.py +++ b/tests/unit/test_unit_inspect.py @@ -2,10 +2,9 @@ from pathlib import Path from moccasin.commands.inspect import inspect_contract -from tests.conftest import COMPLEX_PROJECT_PATH -def test_inspect_counter(complex_project_config): +def test_inspect_counter(complex_project_config, complex_temp_path): expected_dir = { "set_number(uint256)": "0xd6d1ee14 (3604082196)", "increment()": "0xd09de08a (3500007562)", @@ -14,8 +13,20 @@ def test_inspect_counter(complex_project_config): } current_dir = Path.cwd() try: - os.chdir(current_dir.joinpath(COMPLEX_PROJECT_PATH)) + os.chdir(current_dir.joinpath(complex_temp_path)) result = inspect_contract("Counter", "function_signatures", print_out=False) finally: os.chdir(current_dir) assert result == expected_dir + +def test_inspect_layout_imports(installation_project_config, installation_temp_path): + current_dir = Path.cwd() + try: + os.chdir(current_dir.joinpath(installation_temp_path)) + result = inspect_contract("MyToken", "storage_layout", print_out=False) + finally: + os.chdir(current_dir) + layout = result["storage_layout"] + # Spot check + assert layout["ow"]["owner"] == {'type': 'address', 'n_slots': 1, 'slot': 0} + assert layout["erc20"]["balanceOf"] == {'type': 'HashMap[address, uint256]', 'n_slots': 1, 'slot': 1} \ No newline at end of file diff --git a/uv.lock b/uv.lock index f83ddc6..13f6d15 100644 --- a/uv.lock +++ b/uv.lock @@ -682,7 +682,7 @@ wheels = [ [[package]] name = "moccasin" -version = "0.3.4b3" +version = "0.3.4b4" source = { editable = "." } dependencies = [ { name = "pytest-cov" },