Skip to content

Commit

Permalink
test: adjust tests to not double-download Safe contracts (#61)
Browse files Browse the repository at this point in the history
* test: integ

* test: adjust tests to not double dwnld

* test: copytree oops
  • Loading branch information
antazoey authored Jun 24, 2024
1 parent 7995f88 commit ac96203
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
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)

0 comments on commit ac96203

Please sign in to comment.