Skip to content

Commit

Permalink
chore: remove ethpm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Feb 2, 2024
1 parent 754662e commit 307464f
Show file tree
Hide file tree
Showing 14 changed files with 5 additions and 968 deletions.
103 changes: 0 additions & 103 deletions tests/cli/test_cli_ethpm.py

This file was deleted.

78 changes: 0 additions & 78 deletions tests/cli/test_cli_ethpm_release.py

This file was deleted.

39 changes: 3 additions & 36 deletions tests/cli/test_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,41 +122,6 @@ def test_cli_run_with_raise_flag(cli_tester):
assert cli_tester.mock_subroutines.call_count == 1


def test_cli_ethpm(cli_tester, testproject):
cli_tester.monkeypatch.setattr("brownie._cli.ethpm._list", cli_tester.mock_subroutines)

args = (testproject._path,)
kwargs = {}
parameters = (args, kwargs)
cli_tester.run_and_test_parameters("ethpm list", parameters)
cli_tester.run_and_test_parameters("ethpm foo", parameters)

assert cli_tester.mock_subroutines.called is True
assert cli_tester.mock_subroutines.call_count == 1


def test_cli_ethpm_with_projectnotfound_exception(cli_tester):
cli_tester.monkeypatch.setattr("brownie._cli.ethpm._list", cli_tester.mock_subroutines)

with pytest.raises(SystemExit):
cli_tester.run_and_test_parameters("ethpm list", parameters=None)

assert cli_tester.mock_subroutines.called is False
assert cli_tester.mock_subroutines.call_count == 0


def test_cli_ethpm_with_type_error_exception(cli_tester, testproject):
cli_tester.monkeypatch.setattr(
"brownie._cli.ethpm._list",
lambda project_path: cli_tester.raise_type_error_exception("foobar"),
)

cli_tester.run_and_test_parameters("ethpm list", parameters=None)

assert cli_tester.mock_subroutines.called is False
assert cli_tester.mock_subroutines.call_count == 0


def test_test_no_args(cli_tester, testproject):
cli_tester.monkeypatch.setattr("pytest.main", cli_tester.mock_subroutines)
params = ([testproject._path.joinpath("tests").as_posix()], ["pytest-brownie"])
Expand Down Expand Up @@ -194,9 +159,11 @@ def test_no_args_shows_help(cli_tester, capfd):
def test_cli_pm(cli_tester):
cli_tester.run_and_test_parameters("pm list", None)


def test_cli_console_doesnt_accept_compile(cli_tester):
with pytest.raises(SystemExit):
cli_tester.run_and_test_parameters('console --compile')
cli_tester.run_and_test_parameters("console --compile")


def test_cli_console_accepts_no_compile(cli_tester):
cli_tester.monkeypatch.setattr("brownie._cli.console.main", cli_tester.mock_subroutines)
Expand Down
48 changes: 2 additions & 46 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import pytest
import solcx
from _pytest.monkeypatch import MonkeyPatch
from ethpm._utils.ipfs import dummy_ipfs_pin
from ethpm.backends.ipfs import BaseIPFSBackend
from prompt_toolkit.input.defaults import create_pipe_input

import brownie
Expand Down Expand Up @@ -147,6 +145,7 @@ def _copy_all(src_folder, dest_folder):

# project fixtures


# creates a temporary folder and sets it as the working directory
@pytest.fixture
def project(tmp_path):
Expand Down Expand Up @@ -180,6 +179,7 @@ def testproject(_project_factory, project, tmp_path):
os.chdir(path)
return project.load(path, "TestProject")


# same as function above but doesn't compile
@pytest.fixture
def testproject_nocompile(_project_factory, project, tmp_path):
Expand Down Expand Up @@ -376,50 +376,6 @@ def vypertester(testproject, devnetwork, accounts):
# ipfs fixtures


class DummyIPFSBackend(BaseIPFSBackend):

_assets: Dict = {}
_path = Path("./tests/data/ipfs-cache-mock").resolve()

def fetch_uri_contents(self, ipfs_uri: str) -> bytes:
ipfs_uri = ipfs_uri.replace("ipfs://", "")
if ipfs_uri not in self._assets:
with self._path.joinpath(ipfs_uri).open() as fp:
self._assets[ipfs_uri] = fp.read()
return self._assets[ipfs_uri].encode()

def pin_assets(self, file_or_dir_path: Path) -> List:
"""
Return a dict containing the IPFS hash, file name, and size of a file.
"""
if file_or_dir_path.is_dir():
for path in file_or_dir_path.glob("*"):
with path.open() as fp:
self._assets[path.name] = fp.read()
asset_data = [dummy_ipfs_pin(path) for path in file_or_dir_path.glob("*")]
elif file_or_dir_path.is_file():
asset_data = [dummy_ipfs_pin(file_or_dir_path)]
with file_or_dir_path.open() as fp:
self._assets[file_or_dir_path.name] = fp.read()
self._assets[asset_data[0]["Hash"]] = self._assets[file_or_dir_path.name]
else:
raise FileNotFoundError(f"{file_or_dir_path} is not a valid file or directory path.")
return asset_data


@pytest.fixture
def ipfs_mock(monkeypatch):
monkeypatch.setattr("brownie.project.ethpm.InfuraIPFSBackend", DummyIPFSBackend)
ipfs_path = brownie._config._get_data_folder().joinpath("ipfs_cache")
temp_path = ipfs_path.parent.joinpath("_ipfs_cache")
ipfs_path.mkdir(exist_ok=True)
ipfs_path.rename(temp_path)
yield DummyIPFSBackend()
if ipfs_path.exists():
shutil.rmtree(ipfs_path)
temp_path.rename(ipfs_path)


@pytest.fixture
def package_test():
pass
Expand Down
26 changes: 0 additions & 26 deletions tests/network/contract/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,13 @@ def test_contractabi_replace_contract(testproject, tester):
Contract.from_abi("BrownieTester", tester.address, tester.abi)


def test_contract_from_ethpm(ipfs_mock, network):
network.connect("ropsten")
Contract.from_ethpm("ComplexNothing", manifest_uri="ipfs://testipfs-complex")


def test_contract_from_ethpm_multiple_deployments(ipfs_mock, network):
network.connect("mainnet")
with pytest.raises(ValueError):
Contract.from_ethpm("ComplexNothing", manifest_uri="ipfs://testipfs-complex")


def test_contract_from_ethpm_no_deployments(ipfs_mock, network):
network.connect("kovan")
with pytest.raises(ContractNotFound):
Contract.from_ethpm("ComplexNothing", manifest_uri="ipfs://testipfs-complex")


def test_deprecated_init_abi(tester):
with pytest.warns(DeprecationWarning):
old = Contract("BrownieTester", tester.address, tester.abi)

assert old == Contract.from_abi("BrownieTester", tester.address, tester.abi)


def test_deprecated_init_ethpm(ipfs_mock, network):
network.connect("ropsten")

with pytest.warns(DeprecationWarning):
old = Contract("ComplexNothing", manifest_uri="ipfs://testipfs-complex")

assert old == Contract.from_ethpm("ComplexNothing", manifest_uri="ipfs://testipfs-complex")


def test_from_explorer(network):
network.connect("mainnet")
contract = Contract.from_explorer("0x973e52691176d36453868d9d86572788d27041a9")
Expand Down
Loading

0 comments on commit 307464f

Please sign in to comment.