Skip to content

Commit

Permalink
Fix/inspect not compiling (#158)
Browse files Browse the repository at this point in the history
* fix: inspect works with imports now

* fix: lint
  • Loading branch information
PatrickAlphaC authored Nov 17, 2024
1 parent 12433e0 commit 37a4ecf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
15 changes: 12 additions & 3 deletions moccasin/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" },
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/test_unit_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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}
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37a4ecf

Please sign in to comment.