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: adjust tests to not double-download Safe contracts #61

Merged
merged 3 commits into from
Jun 24, 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
23 changes: 17 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import shutil
import tempfile
from pathlib import Path

import ape
import pytest
from ape.contracts import ContractContainer
from ape.utils import ZERO_ADDRESS
from ape.utils import ZERO_ADDRESS, create_tempdir
from ethpm_types import ContractType

from ape_safe import MultiSend
Expand All @@ -14,14 +15,24 @@
contracts_directory = Path(__file__).parent / "contracts"
TESTS_DIR = Path(__file__).parent.absolute()

# TODO: Test more versions.
VERSIONS = ("1.3.0",)


@pytest.fixture(scope="session", autouse=True)
def config():
def config(project):
cfg = ape.config

# Ensure we have the safe-contracts dependencies.
for version in VERSIONS:
_ = project.dependencies.get_dependency("safe-contracts", version)

# Ensure we don't persist any .ape data.
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir).resolve()
cfg.DATA_FOLDER = path
with create_tempdir() as path:
# First, copy in Safe contracts so we don't download each time.
dest = path / "dest"
shutil.copytree(cfg.DATA_FOLDER, dest)
cfg.DATA_FOLDER = dest
yield cfg


Expand All @@ -40,7 +51,7 @@ def receiver(accounts):
return accounts[9]


@pytest.fixture(scope="session", params=["1.3.0"]) # TODO: Test more versions later?
@pytest.fixture(scope="session", params=VERSIONS)
def VERSION(request):
return request.param

Expand Down
20 changes: 16 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import shutil
from contextlib import contextmanager

import pytest
from ape.utils import create_tempdir
from click.testing import CliRunner

from ape_safe._cli import cli as CLI
Expand All @@ -18,11 +20,21 @@ def cli():

@pytest.fixture
def no_safes(data_folder):
shutil.rmtree(data_folder, ignore_errors=True)
with _remove_safes(data_folder):
yield


@pytest.fixture
def one_safe(data_folder, safes, safe):
shutil.rmtree(data_folder, ignore_errors=True)
safes.save_account(safe.alias, safe.address)
return safes.load_account(safe.alias)
with _remove_safes(data_folder):
safes.save_account(safe.alias, safe.address)
yield safes.load_account(safe.alias)


@contextmanager
def _remove_safes(data_folder):
with create_tempdir() as temp_dir:
dest = temp_dir / "dest"
shutil.move(data_folder, dest)
yield
shutil.move(dest, data_folder)
Loading