From 307464f2f8b6d886e615a38f66e0f26fbcb90542 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Fri, 2 Feb 2024 04:38:26 +0400 Subject: [PATCH] chore: remove ethpm tests --- tests/cli/test_cli_ethpm.py | 103 ------- tests/cli/test_cli_ethpm_release.py | 78 ----- tests/cli/test_cli_main.py | 39 +-- tests/conftest.py | 48 +-- tests/network/contract/test_contract.py | 26 -- tests/project/ethpm/conftest.py | 62 ---- tests/project/ethpm/test_create_manifest.py | 293 ------------------- tests/project/ethpm/test_get_manifest.py | 81 ----- tests/project/ethpm/test_install_remove.py | 86 ------ tests/project/ethpm/test_process_manifest.py | 49 ---- tests/project/ethpm/test_release_package.py | 20 -- tests/project/ethpm/test_verify_manifest.py | 59 ---- tests/project/main/test_main_project.py | 14 - tests/project/packages/test_install.py | 15 - 14 files changed, 5 insertions(+), 968 deletions(-) delete mode 100644 tests/cli/test_cli_ethpm.py delete mode 100644 tests/cli/test_cli_ethpm_release.py delete mode 100644 tests/project/ethpm/conftest.py delete mode 100644 tests/project/ethpm/test_create_manifest.py delete mode 100644 tests/project/ethpm/test_get_manifest.py delete mode 100644 tests/project/ethpm/test_install_remove.py delete mode 100644 tests/project/ethpm/test_process_manifest.py delete mode 100644 tests/project/ethpm/test_release_package.py delete mode 100644 tests/project/ethpm/test_verify_manifest.py diff --git a/tests/cli/test_cli_ethpm.py b/tests/cli/test_cli_ethpm.py deleted file mode 100644 index f903ebd81..000000000 --- a/tests/cli/test_cli_ethpm.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/python3 - -import json - -import pytest - -from brownie._cli import ethpm as cli_ethpm -from brownie.project import ethpm - -pytestmark = pytest.mark.skip(reason="deprecated, must be updated for ethpmv3") - -ETHPM_CONFIG = { - "package_name": "testpackage", - "version": "1.0.0", - "settings": {"deployment_networks": False, "include_dependencies": False}, -} - -ERC1319_URI = "ethpm://zeppelin.snakecharmers.eth:1/access@1.0.0" - - -def test_all(np_path): - cli_ethpm._all(np_path) - ethpm.install_package(np_path, ERC1319_URI) - cli_ethpm._all(np_path) - - -def test_list(ipfs_mock, np_path, mocker): - mocker.spy(ethpm, "get_installed_packages") - cli_ethpm._list(np_path) - assert ethpm.get_installed_packages.call_count == 1 - ethpm.install_package(np_path, "ipfs://testipfs-math") - cli_ethpm._list(np_path) - assert ethpm.get_installed_packages.call_count == 2 - - -def test_list_with_modified_packages(ipfs_mock, np_path, mocker, monkeypatch): - monkeypatch.setattr( - "brownie.project.ethpm.get_installed_packages", lambda project_path: [[], ["P1"]] - ) - cli_ethpm._list(np_path) - assert True - - -def test_install(ipfs_mock, np_path, mocker): - mocker.spy(ethpm, "install_package") - cli_ethpm._install(np_path, ERC1319_URI, "false") - assert ethpm.install_package.call_count == 1 - assert np_path.joinpath("contracts/access").exists() - - -def test_install_value_error(ipfs_mock, np_path, mocker): - mocker.spy(ethpm, "install_package") - - with pytest.raises(ValueError): - cli_ethpm._install(np_path, ERC1319_URI, "foobar") - - -def test_unlink(ipfs_mock, np_path, mocker): - ethpm.install_package(np_path, "ipfs://testipfs-math") - mocker.spy(ethpm, "remove_package") - cli_ethpm._unlink(np_path, "math") - assert ethpm.remove_package.call_count == 1 - assert np_path.joinpath("contracts/math").exists() - cli_ethpm._unlink(np_path, "math") - assert ethpm.remove_package.call_count == 2 - assert np_path.joinpath("contracts/math").exists() - - -def test_remove(ipfs_mock, np_path, mocker): - ethpm.install_package(np_path, "ipfs://testipfs-math") - mocker.spy(ethpm, "remove_package") - cli_ethpm._remove(np_path, "math") - assert ethpm.remove_package.call_count == 1 - assert not np_path.joinpath("contracts/math").exists() - cli_ethpm._remove(np_path, "math") - assert ethpm.remove_package.call_count == 2 - assert not np_path.joinpath("contracts/math").exists() - - -def test_create(np_path, mocker): - mocker.spy(ethpm, "create_manifest") - with np_path.joinpath("ethpm-config.yaml").open("w") as fp: - json.dump(ETHPM_CONFIG, fp) - cli_ethpm._create(np_path) - assert ethpm.create_manifest.call_count == 1 - assert np_path.joinpath("manifest.json").exists() - - -def raise_exception(e): - raise e - - -def test_exceptions(np_path, monkeypatch): - monkeypatch.setattr( - "brownie.project.ethpm.create_manifest", - lambda project_path, package_config: raise_exception(Exception("foobar")), - ) - - with np_path.joinpath("ethpm-config.yaml").open("w") as fp: - json.dump(ETHPM_CONFIG, fp) - cli_ethpm._create(np_path) - - assert not np_path.joinpath("manifest.json").exists() diff --git a/tests/cli/test_cli_ethpm_release.py b/tests/cli/test_cli_ethpm_release.py deleted file mode 100644 index 4c39da7d5..000000000 --- a/tests/cli/test_cli_ethpm_release.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/python3 - -import json - -import pytest - -from brownie._cli import ethpm as cli_ethpm -from brownie.exceptions import UnknownAccount -from brownie.project import ethpm - -ETHPM_CONFIG = { - "package_name": "testpackage", - "version": "1.0.0", - "settings": {"deployment_networks": False, "include_dependencies": False}, -} - - -@pytest.fixture -def registry(ipfs_mock, testproject, accounts, monkeypatch): - monkeypatch.setattr("brownie._cli.ethpm.network.connect", lambda k: True) - with testproject._path.joinpath("ethpm-config.yaml").open("w") as fp: - json.dump(ETHPM_CONFIG, fp) - yield testproject.PackageRegistry.deploy({"from": accounts[0]}) - - -@pytest.fixture(autouse=True) -def mocker_spy(mocker): - mocker.spy(ethpm, "create_manifest") - mocker.spy(ethpm, "verify_manifest") - mocker.spy(ethpm, "release_package") - - -def test_release_localaccount(registry, accounts, tp_path, monkeypatch, tmpdir): - - monkeypatch.setattr("brownie.network.account.getpass", lambda x: "") - a = accounts.add() - a.save(tmpdir + "/release_tester.json") - accounts[0].transfer(a, "1 ether") - accounts._reset() - - cli_ethpm._release(tp_path, registry.address, tmpdir + "/release_tester.json") - assert ethpm.create_manifest.call_count == 1 - assert ethpm.verify_manifest.call_count == 1 - assert ethpm.release_package.call_count == 1 - id_ = registry.getReleaseId("testpackage", "1.0.0") - assert registry.getReleaseData(id_)[-1] == ethpm.create_manifest.spy_return[1] - - -def test_release_account(registry, accounts, tp_path): - - cli_ethpm._release(tp_path, registry.address, accounts[0].address) - assert ethpm.create_manifest.call_count == 1 - assert ethpm.verify_manifest.call_count == 1 - assert ethpm.release_package.call_count == 1 - id_ = registry.getReleaseId("testpackage", "1.0.0") - assert registry.getReleaseData(id_)[-1] == ethpm.create_manifest.spy_return[1] - - -def test_release_unknown_account(registry, accounts, tp_path): - with pytest.raises(UnknownAccount): - cli_ethpm._release(tp_path, registry.address, "0x2a8638962741B4fA728983A6C0F57080522aa73a") - - -def raise_exception(e): - raise e - - -def test_exceptions(registry, accounts, tp_path, monkeypatch): - monkeypatch.setattr( - "brownie.project.ethpm.release_package", - lambda registry_address, account, package_name, version, uri: raise_exception( - Exception("foobar") - ), - ) - - cli_ethpm._release(tp_path, registry.address, accounts[0].address) - assert ethpm.create_manifest.call_count == 1 - assert ethpm.verify_manifest.call_count == 0 diff --git a/tests/cli/test_cli_main.py b/tests/cli/test_cli_main.py index f4caea325..1deadb8ee 100644 --- a/tests/cli/test_cli_main.py +++ b/tests/cli/test_cli_main.py @@ -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"]) @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index 93a2f4423..15f528f8f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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): @@ -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): @@ -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 diff --git a/tests/network/contract/test_contract.py b/tests/network/contract/test_contract.py index 967fe3671..87c803095 100644 --- a/tests/network/contract/test_contract.py +++ b/tests/network/contract/test_contract.py @@ -93,23 +93,6 @@ 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) @@ -117,15 +100,6 @@ def test_deprecated_init_abi(tester): 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") diff --git a/tests/project/ethpm/conftest.py b/tests/project/ethpm/conftest.py deleted file mode 100644 index dc90d693e..000000000 --- a/tests/project/ethpm/conftest.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python3 - -import json - -import pytest - -from brownie import network, project, web3 -from brownie.project import ethpm - - -@pytest.fixture(autouse=True) -def ipfs_setup(ipfs_mock): - pass - - -@pytest.fixture -def dep_project(testproject): - # this bit of hackiness is needed to trigger a recompile of the project - ethpm.install_package(testproject._path, "ipfs://testipfs-utils") - testproject.close() - yield project.load(testproject._path) - - -@pytest.fixture -def deployments(testproject): - path = testproject._path.joinpath("build/deployments/ropsten") - path.mkdir(exist_ok=True) - with path.joinpath("0xBcd0a9167015Ee213Ba01dAff79d60CD221B0cAC.json").open("w") as fp: - json.dump(testproject.BrownieTester._build, fp) - - path = testproject._path.joinpath("build/deployments/mainnet") - path.mkdir(exist_ok=True) - with path.joinpath("0xdAC17F958D2ee523a2206206994597C13D831ec7.json").open("w") as fp: - json.dump(testproject.BrownieTester._build, fp) - with path.joinpath("0xB8c77482e45F1F44dE1745F52C74426C631bDD52.json").open("w") as fp: - json.dump(testproject.BrownieTester._build, fp) - - -@pytest.fixture(scope="session") -def ropsten_uri(): - prev = network.show_active() - if prev: - network.disconnect(False) - network.connect("ropsten") - uri = web3.chain_uri - network.disconnect(False) - if prev: - network.connect(prev) - yield uri - - -@pytest.fixture(scope="session") -def mainnet_uri(): - prev = network.show_active() - if prev: - network.disconnect(False) - network.connect("mainnet") - uri = web3.chain_uri - network.disconnect(False) - if prev: - network.connect(prev) - yield uri diff --git a/tests/project/ethpm/test_create_manifest.py b/tests/project/ethpm/test_create_manifest.py deleted file mode 100644 index de68a6ca0..000000000 --- a/tests/project/ethpm/test_create_manifest.py +++ /dev/null @@ -1,293 +0,0 @@ -#!/usr/bin/python3 - -import json - -import pytest - -from brownie.exceptions import InvalidManifest -from brownie.project import ethpm - -ETHPM_CONFIG = { - "package_name": "testpackage", - "version": "1.0.0", - "settings": {"deployment_networks": False, "include_dependencies": False}, -} - -DEPLOYMENTS_ROPSTEN = { - "BrownieTester": { - "address": "0xBcd0a9167015Ee213Ba01dAff79d60CD221B0cAC", - "contract_type": "BrownieTester", - } -} -DEPLOYMENTS_MAINNET = { - "BrownieTester": { - "address": "0xB8c77482e45F1F44dE1745F52C74426C631bDD52", - "contract_type": "BrownieTester", - }, - "BrownieTester-1": { - "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7", - "contract_type": "BrownieTester", - }, -} - - -def test_standard_fields(tp_path): - manifest, _ = ethpm.create_manifest(tp_path, ETHPM_CONFIG) - assert manifest["manifest_version"] == "2" - assert manifest["package_name"] == "testpackage" - assert manifest["version"] == "1.0.0" - assert manifest["sources"] - assert manifest["contract_types"] - assert "build_dependencies" not in manifest - - -def test_meta(np_path): - package_config = ETHPM_CONFIG.copy() - package_config["meta"] = { - "description": "blahblahblah", - "authors": ["foo", None], - "keywords": [None, None], - "license": None, - "links": {"website": "www.potato.com", "documentation": None}, - "foo": "bar", - } - manifest, _ = ethpm.create_manifest(np_path, package_config) - assert manifest["meta"] == { - "description": "blahblahblah", - "authors": ["foo"], - "links": {"website": "www.potato.com"}, - "foo": "bar", - } - - -def test_invalid_package_name(np_path): - package_config = ETHPM_CONFIG.copy() - package_config["package_name"] = "A Very Invalid Name!" - with pytest.raises(ValueError): - ethpm.create_manifest(np_path, package_config) - - -def test_missing_fields(np_path): - for key in ETHPM_CONFIG: - package_config = ETHPM_CONFIG.copy() - del package_config[key] - with pytest.raises(KeyError): - ethpm.create_manifest(np_path, package_config) - - -def test_field_as_none(np_path): - for key in ETHPM_CONFIG: - package_config = ETHPM_CONFIG.copy() - package_config[key] = None - with pytest.raises(KeyError): - ethpm.create_manifest(np_path, package_config) - - -def test_base_path(newproject, solc5source): - with newproject._path.joinpath("contracts/Foo.sol").open("w") as fp: - fp.write(solc5source) - newproject.load() - manifest, _ = ethpm.create_manifest(newproject._path, ETHPM_CONFIG) - assert sorted(manifest["sources"]) == ["./Foo.sol"] - newproject.close() - - # adding an interface should change the base path - with newproject._path.joinpath("interfaces/Baz.sol").open("w") as fp: - fp.write("pragma solidity ^0.5.0; interface Baz {}") - newproject.load() - manifest, _ = ethpm.create_manifest(newproject._path, ETHPM_CONFIG) - assert sorted(manifest["sources"]) == ["./contracts/Foo.sol", "./interfaces/Baz.sol"] - - -def test_sources(tp_path): - manifest, _ = ethpm.create_manifest(tp_path, ETHPM_CONFIG) - assert sorted(manifest["sources"]) == [ - "./BrownieTester.sol", - "./EVMTester.sol", - "./PackageRegistry.sol", - "./SafeMath.sol", - "./VyperTester.vy", - ] - - -def test_contract_types(tp_path): - manifest, _ = ethpm.create_manifest(tp_path, ETHPM_CONFIG) - with tp_path.joinpath("build/contracts/EVMTester.json").open() as fp: - build = json.load(fp) - assert "EVMTester" in manifest["contract_types"] - assert manifest["contract_types"]["EVMTester"] == { - "contract_name": "EVMTester", - "source_path": "./EVMTester.sol", - "deployment_bytecode": {"bytecode": f"0x{build['bytecode']}"}, - "runtime_bytecode": {"bytecode": f"0x{build['deployedBytecode']}"}, - "abi": build["abi"], - "compiler": { - "name": "solc", - "version": build["compiler"]["version"], - "settings": { - "optimizer": build["compiler"]["optimizer"], - "evmVersion": build["compiler"]["evm_version"], - }, - }, - } - - -def test_contract_types_unimplemented(newproject): - code = """ -pragma solidity ^0.5.0; -contract A { function bar() external returns (bool); } -interface B { function bar() external returns (bool); } -contract C { function bar() external returns (bool) { return true; } } -""" - - with newproject._path.joinpath("contracts/Foo.sol").open("w") as fp: - fp.write(code) - newproject.load() - manifest, _ = ethpm.create_manifest(newproject._path, ETHPM_CONFIG) - - # base contracts are not included - assert "A" not in manifest["contract_types"] - # interfaces are included - assert "B" in manifest["contract_types"] - # compilable contracts are included - assert "C" in manifest["contract_types"] - - -def test_contract_types_json_interface(np_path): - with np_path.joinpath("interfaces/Bar.json").open("w") as fp: - json.dump([{"inputs": [], "name": "baz", "outputs": []}], fp) - manifest, _ = ethpm.create_manifest(np_path, ETHPM_CONFIG) - assert "Bar" in manifest["contract_types"] - - -def test_dependencies_include(dep_project): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["include_dependencies"] = True - manifest, _ = ethpm.create_manifest(dep_project._path, package_config) - assert "build_dependencies" not in manifest - assert "./math/Math.sol" in manifest["sources"] - assert "Math" in manifest["contract_types"] - assert "./utils/Arrays.sol" in manifest["sources"] - assert "Arrays" in manifest["contract_types"] - assert "deployments" not in manifest - - -def test_dependencies_not_include(dep_project): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["include_dependencies"] = False - manifest, _ = ethpm.create_manifest(dep_project._path, package_config) - assert manifest["build_dependencies"] == {"utils": "ipfs://testipfs-utils"} - assert "./math/Math.sol" not in manifest["sources"] - assert "Math" not in manifest["contract_types"] - assert "./utils/Arrays.sol" not in manifest["sources"] - assert "Arrays" not in manifest["contract_types"] - assert "deployments" not in manifest - - -def test_dependencies_modified_source(dep_project): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["include_dependencies"] = False - with dep_project._path.joinpath("contracts/math/Math.sol").open("a") as fp: - fp.write("\n") - with pytest.raises(InvalidManifest): - ethpm.create_manifest(dep_project._path, package_config) - - -@pytest.mark.skip -def test_deployments_ropsten(tp_path, deployments, ropsten_uri): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["deployment_networks"] = "ropsten" - - manifest, _ = ethpm.create_manifest(tp_path, package_config) - assert manifest["deployments"] == {ropsten_uri: DEPLOYMENTS_ROPSTEN} - - -@pytest.mark.skip -def test_deployments_mainnet(tp_path, deployments, mainnet_uri): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["deployment_networks"] = ["mainnet"] - - manifest, _ = ethpm.create_manifest(tp_path, package_config) - assert manifest["deployments"] == {mainnet_uri: DEPLOYMENTS_MAINNET} - - -@pytest.mark.skip -def test_deployments_all(tp_path, deployments, mainnet_uri, ropsten_uri): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["deployment_networks"] = "*" - - manifest, uri = ethpm.create_manifest(tp_path, package_config) - assert manifest["deployments"] == { - mainnet_uri: DEPLOYMENTS_MAINNET, - ropsten_uri: DEPLOYMENTS_ROPSTEN, - } - - package_config["settings"]["deployment_networks"] = ["mainnet", "ropsten"] - assert manifest["deployments"], uri == ethpm.create_manifest(tp_path, package_config) - - -@pytest.mark.skip -def test_deployments_unknown_network(tp_path, deployments): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["deployment_networks"] = ["potatonet"] - - manifest, _ = ethpm.create_manifest(tp_path, package_config) - assert "deployments" not in manifest - - -@pytest.mark.skip -def test_deployments_changed_source(tp_path, deployments, mainnet_uri): - address = "0xdAC17F958D2ee523a2206206994597C13D831ec7" - path = tp_path.joinpath(f"build/deployments/mainnet/{address}.json") - with path.open() as fp: - build_json = json.load(fp) - build_json["bytecode"] += "ff" - with path.open("w") as fp: - json.dump(build_json, fp) - - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["deployment_networks"] = ["mainnet"] - - manifest, _ = ethpm.create_manifest(tp_path, package_config) - assert manifest["deployments"][mainnet_uri] - assert address not in [i["address"] for i in manifest["deployments"][mainnet_uri].values()] - - -# failing from config changes, but also redundant from PM -@pytest.mark.skip -def test_deployments_of_dependencies(dep_project, config, accounts): - config.active_network["persist"] = True - address = dep_project.Math.deploy({"from": accounts[0]}).address - - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["include_dependencies"] = False - package_config["settings"]["deployment_networks"] = ["development"] - - manifest, uri = ethpm.create_manifest(dep_project._path, package_config) - - assert "./math/Math.sol" not in manifest["sources"] - assert "Math" not in manifest["contract_types"] - - assert "utils:Math" in list(manifest["contract_types"]) - assert len(manifest["deployments"]) == 1 - assert list(manifest["deployments"].values())[0] == { - "Math": {"address": address, "contract_type": "utils:Math"} - } - assert manifest["build_dependencies"] == {"utils": "ipfs://testipfs-utils"} - - -@pytest.mark.skip -def test_pin_and_get(dep_project): - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["include_dependencies"] = False - manifest, uri = ethpm.create_manifest(dep_project._path, package_config, True) - - process = ethpm.process_manifest(manifest, uri) - get = ethpm.get_manifest(uri) - - for key in list(process) + list(get): - if isinstance(process[key], str): - assert process[key] == get[key] - continue - for k in list(process[key]) + list(get[key]): - assert process[key][k] == get[key][k] diff --git a/tests/project/ethpm/test_get_manifest.py b/tests/project/ethpm/test_get_manifest.py deleted file mode 100644 index 6105bede4..000000000 --- a/tests/project/ethpm/test_get_manifest.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/python3 - -import shutil - -import pytest - -from brownie._config import _get_data_folder -from brownie.project import ethpm - -ROPSTEN_GENESIS_HASH = "41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d" -MAINNET_GENESIS_HASH = "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" - -pytestmark = pytest.mark.skip(reason="deprecated, must be updated for ethpmv3") - - -def test_get_manifest_from_ipfs(): - path = _get_data_folder().joinpath("ethpm/zeppelin.snakecharmers.eth") - if path.exists(): - shutil.rmtree(path) - ethpm.get_manifest("ethpm://zeppelin.snakecharmers.eth:1/access@1.0.0") - assert _get_data_folder().joinpath("ethpm/zeppelin.snakecharmers.eth").exists() - ethpm.get_manifest("ethpm://zeppelin.snakecharmers.eth:1/access@1.0.0") - assert _get_data_folder().joinpath("ethpm/zeppelin.snakecharmers.eth").exists() - - -def test_meta_brownie(): - manifest = ethpm.get_manifest("ethpm://zeppelin.snakecharmers.eth:1/access@1.0.0") - assert manifest["meta_brownie"] == { - "registry_address": "zeppelin.snakecharmers.eth", - "manifest_uri": "ipfs://QmWqn5uYx9LvV4aqj2qZ5FiFZykmS3LGdLpod7XLjxPVYr", - } - - -def test_get_mock_manifests(): - ethpm.get_manifest("ipfs://testipfs-math") - ethpm.get_manifest("ipfs://testipfs-utils") - ethpm.get_manifest("ipfs://testipfs-complex") - - -def test_dependency_paths(): - sources = ethpm.get_manifest("ipfs://testipfs-complex")["sources"] - assert "contracts/Complex.sol" in sources - assert "contracts/math/Math.sol" in sources - assert "contracts/utils/Arrays.sol" in sources - - -def test_contract_types(): - contract_types = ethpm.get_manifest("ipfs://testipfs-complex")["contract_types"] - assert "ComplexNothing" in contract_types - assert "abi" in contract_types["ComplexNothing"] - assert contract_types["ComplexNothing"]["source_path"] == "contracts/Complex.sol" - - -def test_get_deployment_addresses_active_network(): - manifest = ethpm.get_manifest("ipfs://testipfs-complex") - mainnet_addresses = ethpm.get_deployment_addresses( - manifest, "ComplexNothing", MAINNET_GENESIS_HASH - ) - assert len(mainnet_addresses) == 2 - ropsten_addresses = ethpm.get_deployment_addresses( - manifest, "ComplexNothing", ROPSTEN_GENESIS_HASH - ) - assert len(ropsten_addresses) == 1 - assert ropsten_addresses[0] not in mainnet_addresses - - -def test_deployment_addresses_from_dependencies(): - math_manifest = ethpm.get_manifest("ipfs://testipfs-math") - assert ethpm.get_deployment_addresses(math_manifest, "Math", MAINNET_GENESIS_HASH) - - # math is a dependency of complex, the deployment should not be inherited - complex_manifest = ethpm.get_manifest("ipfs://testipfs-complex") - assert not ethpm.get_deployment_addresses(complex_manifest, "Math", MAINNET_GENESIS_HASH) - - -def test_deployment_addresses_genesis_hash(network): - manifest = ethpm.get_manifest("ipfs://testipfs-complex") - ropsten = ethpm.get_deployment_addresses(manifest, "ComplexNothing", ROPSTEN_GENESIS_HASH) - assert len(ropsten) == 1 - network.connect("ropsten") - assert ropsten == ethpm.get_deployment_addresses(manifest, "ComplexNothing") diff --git a/tests/project/ethpm/test_install_remove.py b/tests/project/ethpm/test_install_remove.py deleted file mode 100644 index 51d7f22a5..000000000 --- a/tests/project/ethpm/test_install_remove.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/python3 - -import pytest - -from brownie.project import ethpm - - -def test_install_package(np_path): - assert ethpm.get_installed_packages(np_path) == ([], []) - ethpm.install_package(np_path, "ipfs://testipfs-math") - assert np_path.joinpath("contracts/math/Math.sol").exists() - assert ethpm.get_installed_packages(np_path) == ([("math", "1.0.0")], []) - - -def test_remove_package(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-math") - ethpm.remove_package(np_path, "math", True) - assert ethpm.get_installed_packages(np_path) == ([], []) - assert not np_path.joinpath("contracts/math/Math.sol").exists() - - -def test_remove_no_delete(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-math") - ethpm.remove_package(np_path, "math", False) - assert ethpm.get_installed_packages(np_path) == ([], []) - assert np_path.joinpath("contracts/math/Math.sol").exists() - - -def test_remove_no_delete_re_add(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-math") - ethpm.remove_package(np_path, "math", False) - ethpm.install_package(np_path, "ipfs://testipfs-math") - assert np_path.joinpath("contracts/math/Math.sol").exists() - assert ethpm.get_installed_packages(np_path) == ([("math", "1.0.0")], []) - - -def test_install_and_remove_with_deps(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-complex") - assert np_path.joinpath("contracts/math/Math.sol").exists() - assert ethpm.get_installed_packages(np_path) == ([("complex", "1.0.0")], []) - ethpm.install_package(np_path, "ipfs://testipfs-math") - assert ethpm.get_installed_packages(np_path) == ([("complex", "1.0.0"), ("math", "1.0.0")], []) - ethpm.remove_package(np_path, "complex", True) - assert np_path.joinpath("contracts/math/Math.sol").exists() - assert not np_path.joinpath("contracts/complex/Complex.sol").exists() - assert ethpm.get_installed_packages(np_path) == ([("math", "1.0.0")], []) - - -def test_modified(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-math") - with np_path.joinpath("contracts/math/Math.sol").open("a") as fp: - fp.write(" ") - assert ethpm.get_installed_packages(np_path) == ([], [("math", "1.0.0")]) - - -def test_modified_overwrite(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-math") - with np_path.joinpath("contracts/math/Math.sol").open("a") as fp: - fp.write(" ") - with pytest.raises(FileExistsError): - ethpm.install_package(np_path, "ipfs://testipfs-complex") - assert ethpm.get_installed_packages(np_path) == ([], [("math", "1.0.0")]) - - ethpm.install_package(np_path, "ipfs://testipfs-complex", replace_existing=True) - assert ethpm.get_installed_packages(np_path) == ([("complex", "1.0.0"), ("math", "1.0.0")], []) - - -def test_delete_files(np_path): - ethpm.install_package(np_path, "ipfs://testipfs-utils") - - np_path.joinpath("contracts/utils/ReentrancyGuard.sol").unlink() - assert ethpm.get_installed_packages(np_path) == ([], [("utils", "1.0.0")]) - - np_path.joinpath("contracts/utils/Arrays.sol").unlink() - np_path.joinpath("contracts/utils/Address.sol").unlink() - np_path.joinpath("contracts/math/Math.sol").unlink() - - assert ethpm.get_installed_packages(np_path) == ([], []) - assert not np_path.joinpath("contracts/utils").exists() - assert not np_path.joinpath("contracts/math").exists() - - -def test_vyper_package_json_interface(newproject): - ethpm.install_package(newproject._path, "ipfs://testipfs-vyper") - newproject.load() - assert newproject._path.joinpath("interfaces/Bar.json").exists() diff --git a/tests/project/ethpm/test_process_manifest.py b/tests/project/ethpm/test_process_manifest.py deleted file mode 100644 index 0d4a00817..000000000 --- a/tests/project/ethpm/test_process_manifest.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/python3 - -import pytest - -from brownie.exceptions import InvalidManifest -from brownie.project import ethpm - -TEST_MANIFEST = {"manifest_version": "2", "version": "1.0.0", "package_name": "simple"} - - -def test_invalid_manifest(): - with pytest.raises(InvalidManifest): - ethpm.process_manifest({}) - with pytest.raises(InvalidManifest): - ethpm.process_manifest({"manifest_version": "1"}) - - -def test_source_paths(): - original = TEST_MANIFEST.copy() - original["sources"] = {"./simple.sol": "ipfs://testipfs-simple-source"} - - processed = ethpm.process_manifest(original) - assert list(processed["sources"]) == ["contracts/simple.sol"] - - original["sources"] = {"./contracts/simple.sol": "ipfs://testipfs-simple-source"} - assert processed == ethpm.process_manifest(original) - - original["sources"] = {"simple.sol": "ipfs://testipfs-simple-source"} - assert processed == ethpm.process_manifest(original) - - original["sources"] = {"contracts/simple.sol": "ipfs://testipfs-simple-source"} - assert processed == ethpm.process_manifest(original) - - -def test_source_paths_with_interface(): - original = TEST_MANIFEST.copy() - original["sources"] = { - "./contracts/foo.sol": "ipfs://testipfs-simple-source", - "./interfaces/bar.sol": "ipfs://testipfs-simple-source", - } - - processed = ethpm.process_manifest(original) - assert sorted(processed["sources"]) == ["contracts/foo.sol", "interfaces/bar.sol"] - - original["sources"] = { - "contracts/foo.sol": "ipfs://testipfs-simple-source", - "interfaces/bar.sol": "ipfs://testipfs-simple-source", - } - assert processed == ethpm.process_manifest(original) diff --git a/tests/project/ethpm/test_release_package.py b/tests/project/ethpm/test_release_package.py deleted file mode 100644 index 1c323dd5c..000000000 --- a/tests/project/ethpm/test_release_package.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/python3 - -from brownie.project import ethpm - -ETHPM_CONFIG = { - "package_name": "testpackage", - "version": "1.0.0", - "settings": {"deployment_networks": False, "include_dependencies": False}, -} - - -def test_release_package(dep_project, accounts): - registry = dep_project.PackageRegistry.deploy({"from": accounts[0]}) - - package_config = ETHPM_CONFIG.copy() - package_config["settings"]["include_dependencies"] = False - manifest, uri = ethpm.create_manifest(dep_project._path, package_config, True) - ethpm.release_package(registry.address, accounts[0], "testpackage", "1.0.0", uri) - id_ = registry.getReleaseId("testpackage", "1.0.0") - assert registry.getReleaseData(id_)[-1] == uri diff --git a/tests/project/ethpm/test_verify_manifest.py b/tests/project/ethpm/test_verify_manifest.py deleted file mode 100644 index 2c9ed5ce9..000000000 --- a/tests/project/ethpm/test_verify_manifest.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/python3 - -import json - -import pytest - -from brownie.exceptions import InvalidManifest -from brownie.project.ethpm import verify_manifest - - -def pin(ipfs, manifest): - ipfs._assets["invalid"] = json.dumps(manifest, sort_keys=True, separators=(",", ":")) - - -def test_not_json(ipfs_mock): - ipfs_mock._assets["invalid"] = "foo" - with pytest.raises(InvalidManifest, match="URI did not return valid JSON encoded data"): - verify_manifest("invalid", "1.0.0", "invalid") - - -def test_packing(ipfs_mock): - ipfs_mock._assets["invalid"] = '{"version": "1.0.0"}' - with pytest.raises(InvalidManifest, match="JSON data is not tightly packed with sorted keys"): - verify_manifest("invalid", "1.0.0", "invalid") - - -def test_invalid_package_name(ipfs_mock): - manifest = {"manifest_version": "2", "package_name": "Not a good name!", "version": "1.0.0"} - pin(ipfs_mock, manifest) - with pytest.raises(ValueError): - verify_manifest("Not a good name!", "1.0.0", "invalid") - - -def test_fields(ipfs_mock): - manifest = {"manifest_version": "2", "package_name": "invalid", "version": "1.0.0"} - for key, value in manifest.items(): - manifest[key] += "xx" - pin(ipfs_mock, manifest) - with pytest.raises(InvalidManifest, match=f"Missing or invalid field: {key}"): - verify_manifest("invalid", "1.0.0", "invalid") - del manifest[key] - pin(ipfs_mock, manifest) - with pytest.raises(InvalidManifest, match=f"Missing or invalid field: {key}"): - verify_manifest("invalid", "1.0.0", "invalid") - manifest[key] = value - pin(ipfs_mock, manifest) - verify_manifest("invalid", "1.0.0", "invalid") - - -def test_cannot_process(ipfs_mock): - manifest = { - "manifest_version": "2", - "package_name": "invalid", - "version": "1.0.0", - "sources": "foo", - } - pin(ipfs_mock, manifest) - with pytest.raises(InvalidManifest, match="Cannot process manifest"): - verify_manifest("invalid", "1.0.0", "invalid") diff --git a/tests/project/main/test_main_project.py b/tests/project/main/test_main_project.py index 56efa8b51..a3eb57afe 100644 --- a/tests/project/main/test_main_project.py +++ b/tests/project/main/test_main_project.py @@ -132,20 +132,6 @@ def test_create_folders(project, tmp_path): assert Path(tmp_path).joinpath(path).exists() -def test_from_ethpm(ipfs_mock, project): - p = project.from_ethpm("ipfs://testipfs-math") - assert type(p) is TempProject - assert "Math" in p - assert not len(p.Math) - - -def test_from_ethpm_with_deployments(ipfs_mock, project, network): - network.connect("mainnet") - p = project.from_ethpm("ipfs://testipfs-math") - assert len(p.Math) == 1 - assert p.Math[0].address == "0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2" - - def test_compile_source_solc_without_pragma(project): project.compile_source("""contract X {}""") diff --git a/tests/project/packages/test_install.py b/tests/project/packages/test_install.py index d228c5974..c99903a5d 100644 --- a/tests/project/packages/test_install.py +++ b/tests/project/packages/test_install.py @@ -29,11 +29,6 @@ def test_install_from_github(): install_package("brownie-mix/token-mix@1.0.0") -@pytest.mark.skip(reason="Need to update to ethpm v3") -def test_install_from_ethpm(ipfs_mock): - install_package("ethpm://zeppelin.snakecharmers.eth:1/access@1.0.0") - - def test_github_already_installed(): path = _get_data_folder().joinpath("packages/brownie-mix") path.mkdir() @@ -43,16 +38,6 @@ def test_github_already_installed(): install_package("brownie-mix/token-mix@1.0.0") -@pytest.mark.skip(reason="Need to update to ethpm v3") -def test_ethpm_already_installed(): - path = _get_data_folder().joinpath("packages/zeppelin.snakecharmers.eth") - path.mkdir() - path.joinpath("access@1.0.0").mkdir() - - with pytest.raises(FileExistsError): - install_package("ethpm://zeppelin.snakecharmers.eth:1/access@1.0.0") - - def test_unknown_version(): with pytest.raises(ValueError): install_package("brownie-mix/token-mix@1.0.1")