Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show snekmate working #51

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ape-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
- pypi: snekmate
config_override:
contracts_folder: src/snekmate
1 change: 1 addition & 0 deletions contracts/ERC20.vy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed
from snekmate.tokens import erc20

implements: IERC20
implements: IERC20Detailed
Expand Down
14 changes: 13 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,19 @@ async def compile_project(project_root: Path, manifest: PackageManifest):
# Create a contracts directory
contracts_dir = project_root / "contracts"
contracts_dir.mkdir()
project = Project.from_manifest(manifest)

# Hacked in for testing..
project = Project.from_manifest(
manifest,
config_override={
"dependencies": [
{
"pypi": "snekmate",
"config_override": {"base_path": "src", "contracts_folder": "snekmate"},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So one goal of mine is to get Ape able to detect this config from projects like snekmate.
I am not 100% sure on how to do that yet. For now, may have to hardcode it in the hosted-compiler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great goal for us, but keep in mind that likely remix may have a set of whitelisted dependencies here w.r.t. snekmate (maybe not whitelist the version, but how the object is formed otherwise)

}
],
},
)

try:
# NOTE: Updates itself because manifest projects are their own cache.
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ src_paths = ["main.py", "test_app.py"]
check_untyped_defs = true
plugins = ["pydantic.mypy"]

[tool.pytest.ini_options]
# Ape's Pytest plugin is not needed and interferes a bit.
addopts = """
-p no:ape_test
"""

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
15 changes: 14 additions & 1 deletion test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from fastapi.testclient import TestClient
from main import app
import pytest

client = TestClient(app)

Expand Down Expand Up @@ -58,8 +59,20 @@ def test_get_compiled_artifact():
manifest = {"manifest": "ethpm/3", "sources": {source_id: source_text}}
task_id = client.post("/compile", json=manifest).json()
response = client.get(f"/artifacts/{task_id}")
assert response.status_code == 200
data = response.json()

if response.status_code == 404:
# Bad request. Let's check for the exception.
response = client.get(f"/exceptions/{task_id}")
if response.status_code == 200:
# This will show actual compiler errors in the tests.
error_data = response.json()
errors = "\n".join(error_data) if isinstance(error_data, list) else f"{error_data}"
pytest.fail(errors)

else:
assert response.status_code == 200, data

assert "name" in data
assert "contractTypes" in data
assert "compilers" in data
Expand Down
Loading