Skip to content
Open
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
148 changes: 148 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Claude Code settings
.claude/*

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
381 changes: 381 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[tool.poetry]
name = "objkt-swap"
version = "0.1.0"
description = "FA2 token swap smart contracts for Tezos blockchain"
authors = ["objkt-swap contributors"]
readme = "README.md"
packages = [{include = "smart-py"}]

[tool.poetry.dependencies]
python = "^3.8"
smartpy = "*"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.0"

[tool.poetry.scripts]

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"--strict-markers",
"--strict-config",
"--cov=smart-py",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-report=term-missing",
"--cov-fail-under=0",
"-v"
]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow running tests"
]

[tool.coverage.run]
source = ["smart-py"]
omit = [
"*/tests/*",
"*/test_*",
"*/__pycache__/*",
"*/venv/*",
"*/.venv/*"
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]

[tool.coverage.html]
directory = "htmlcov"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tests package
109 changes: 109 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""Shared pytest fixtures for the test suite."""

import os
import tempfile
import pytest
from unittest.mock import Mock, MagicMock
from pathlib import Path


@pytest.fixture
def temp_dir():
"""Provide a temporary directory for tests."""
with tempfile.TemporaryDirectory() as temp_dir:
yield Path(temp_dir)


@pytest.fixture
def temp_file(temp_dir):
"""Provide a temporary file for tests."""
temp_file = temp_dir / "test_file.txt"
temp_file.write_text("test content")
return temp_file


@pytest.fixture
def mock_config():
"""Provide a mock configuration object."""
config = Mock()
config.debug_mode = False
config.single_asset = False
config.non_fungible = True
config.readable = True
config.force_layouts = True
config.support_operator = True
config.assume_consecutive_token_ids = True
config.add_permissions_descriptor = False
config.lazy_entry_points = False
config.lazy_entry_points_multiple = False
return config


@pytest.fixture
def mock_smartpy():
"""Provide a mock SmartPy context."""
smartpy_mock = MagicMock()
smartpy_mock.map = MagicMock()
smartpy_mock.big_map = MagicMock()
smartpy_mock.contract = MagicMock()
smartpy_mock.record = MagicMock()
smartpy_mock.variant = MagicMock()
smartpy_mock.nat = MagicMock()
smartpy_mock.mutez = MagicMock()
smartpy_mock.address = MagicMock()
return smartpy_mock


@pytest.fixture
def sample_token_data():
"""Provide sample token data for tests."""
return {
"token_id": 0,
"name": "Test Token",
"symbol": "TEST",
"decimals": 0,
"total_supply": 1,
"metadata": {
"name": "Test Token",
"description": "A test token for unit tests",
"image": "ipfs://test-image-hash"
}
}


@pytest.fixture
def sample_address():
"""Provide a sample Tezos address for tests."""
return "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb"


@pytest.fixture
def sample_contract_address():
"""Provide a sample contract address for tests."""
return "KT1Hkg5qeNhfwpKW4fXvq7HGZB9z2EnmCCA9"


@pytest.fixture(autouse=True)
def clean_environment():
"""Clean environment variables before and after each test."""
# Store original environment
original_env = dict(os.environ)

yield

# Restore original environment
os.environ.clear()
os.environ.update(original_env)


@pytest.fixture
def mock_blockchain_context():
"""Provide a mock blockchain context for testing smart contracts."""
context = MagicMock()
context.sender = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb"
context.amount = 0
context.balance = 1000000
context.now = 1640995200 # 2022-01-01 00:00:00 UTC
context.level = 100000
context.chain_id = "NetXdQprcVkpaWU"
return context
1 change: 1 addition & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Integration tests package
Loading