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

test: fix the tests #48

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from enum import Enum
from pathlib import Path
from typing import Annotated
from ape.managers.compilers import CompilerError

from ape import Project
from ape.managers.compilers import CompilerError
from ethpm_types import PackageManifest
from fastapi import BackgroundTasks, Body, FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -113,7 +113,7 @@ async def updated_compilation_task(
background_tasks: BackgroundTasks,
task_id: str,
project: Annotated[PackageManifest, Body()],
)-> str:
) -> str:
"""
Re-triggers a compilation task using the updated project encoded as an EthPM v3 manifest.
"""
Expand Down Expand Up @@ -178,7 +178,7 @@ async def compile_project(project_root: Path, manifest: PackageManifest):
# Create a contracts directory
contracts_dir = project_root / "contracts"
contracts_dir.mkdir()

# add request contracts in temp directory
if manifest.sources:
for filename, source in manifest.sources.items():
Expand All @@ -198,5 +198,5 @@ async def compile_project(project_root: Path, manifest: PackageManifest):
]
tasks[project_root.name] = TaskStatus.FAILED
except Exception as e:
results[project_root.name] = {e.__class__.__name__:str(e)}
results[project_root.name] = {e.__class__.__name__: str(e)}
tasks[project_root.name] = TaskStatus.FAILED
45 changes: 29 additions & 16 deletions test_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from fastapi.testclient import TestClient
import re
from pathlib import Path

from fastapi.testclient import TestClient
from main import app

client = TestClient(app)
Expand All @@ -15,43 +17,54 @@ def test_create_compilation_task():
# empty sources should work
response = client.post("/compile", json={"manifest": "ethpm/3"})
assert response.status_code == 200
data = response.json()
assert "task_id" in data
task_id = response.json()
assert isinstance(task_id, str)


def test_get_task_status():
# Test get task status
response = client.get("/status/some_invalid_task_id")
assert response.status_code == 400 # Invalid task_id should return 400 Bad Request
assert response.status_code == 404 # Not found

response = client.get("/status/some_valid_task_id")
task_id = client.post("/compile", json={"manifest": "ethpm/3"}).json()
response = client.get(f"/status/{task_id}")
assert response.status_code == 200
data = response.json()
assert data in ["In Progress", "Success", "Error"]
assert data.lower() in ["in progress", "success", "error"]


def test_get_task_exceptions():
# Test get task exceptions
response = client.get("/exceptions/some_invalid_task_id")
assert response.status_code == 400 # Invalid task_id should return 400 Bad Request
assert response.status_code == 404 # Not found

# Assuming the task_id has an Error status
response = client.get("/exceptions/some_valid_task_id")
assert response.status_code == 200
task_id = client.post("/compile", json={"manifest": "ethpm/3"}).json()
response = client.get(f"/exceptions/{task_id}")
assert response.status_code == 400
data = response.json()
assert "task_id" in data
assert "compilation_errors" in data
actual = data["detail"]
assert re.match(r"Task '\w*' is not completed with Error status", actual)


def test_get_compiled_artifact():
# Test get compiled artifact
response = client.get("/artifacts/some_invalid_task_id")
assert response.status_code == 400 # Invalid task_id should return 400 Bad Request
assert response.status_code == 404 # Not found

# Assuming the task_id has a Success status
response = client.get("/artifacts/some_valid_task_id")
source_id = "contracts/ERC20.vy"
source_text = (Path(__file__).parent / source_id).read_text()
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()
assert "contract_name" in data
assert "abi" in data
assert "compiler" in data
assert "name" in data
assert "contractTypes" in data
assert "compilers" in data

# Show we get the ERC20 contract-type.
assert "ERC20" in data["contractTypes"]
assert "abi" in data["contractTypes"]["ERC20"]
assert len(data["contractTypes"]["ERC20"]["abi"]) > 1
4 changes: 1 addition & 3 deletions vvm_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
installable_versions = vvm.get_installable_vyper_versions()

for version in installable_versions:
version_str = (
str(version.major) + "." + str(version.minor) + "." + str(version.micro)
)
version_str = str(version.major) + "." + str(version.minor) + "." + str(version.micro)
if version not in installed_versions:
if version_str == "0.3.8":
print("Skipping Broken version: " + version_str)
Expand Down
Loading