Skip to content
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
1 change: 1 addition & 0 deletions newsfragments/2542.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add black to ``tests/ethpm``
21 changes: 16 additions & 5 deletions tests/ethpm/_utils/test_backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
("erc1319://packages.zeppelinos.eth:1/erc20?version=1.0.0", ()),
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_get_resolvable_backends_for_supported_uris(dummy_ipfs_backend, uri, backends):
good_backends = get_resolvable_backends_for_uri(uri)
assert good_backends == backends
Expand All @@ -39,12 +41,19 @@ def test_get_resolvable_backends_for_supported_uris(dummy_ipfs_backend, uri, bac
@pytest.mark.parametrize(
"uri,backends",
(
("erc1319://packages.zeppelinos.eth:1/erc20?version=1.0.0", (RegistryURIBackend,)),
(
"erc1319://packages.zeppelinos.eth:1/erc20?version=1.0.0",
(RegistryURIBackend,),
),
("ipfs://QmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/", ()),
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_get_translatable_backends_for_supported_uris(dummy_ipfs_backend, uri, backends):
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_get_translatable_backends_for_supported_uris(
dummy_ipfs_backend, uri, backends
):
good_backends = get_translatable_backends_for_uri(uri)
assert good_backends == backends

Expand All @@ -66,7 +75,9 @@ def test_get_translatable_backends_for_supported_uris(dummy_ipfs_backend, uri, b
"https://github.com/ethpm/ethpm-spec/examples/owned/1.0.0.json#content_hash",
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_resolve_uri_contents_raises_exception_for_unsupported_schemes(uri):
with pytest.raises(CannotHandleURI):
resolve_uri_contents(uri)
2 changes: 1 addition & 1 deletion tests/ethpm/_utils/test_chain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_parse_BIP122_uri(value, expected_resource_type):
({}, False),
(None, False),
(False, False),
)
),
)
def test_is_supported_chain_id(chain_id, expected):
actual = is_supported_chain_id(chain_id)
Expand Down
4 changes: 3 additions & 1 deletion tests/ethpm/_utils/test_registry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601/[email protected]"),
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/[email protected]"),
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/[email protected]/"),
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/[email protected]/deployments/ERC139")
(
"erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/[email protected]/deployments/ERC139"
),
),
)
def test_is_registry_uri_validates(uri):
Expand Down
8 changes: 6 additions & 2 deletions tests/ethpm/backends/test_http_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"https://api.github.com/repos/ethpm/ethpm-spec/git/blobs/899042f95ad624d5ecf0b96b0926c96cd682522d", # noqa: E501
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3):
# these tests may occassionally fail CI as a result of their network requests
backend = GithubOverHTTPSBackend()
Expand All @@ -32,7 +34,9 @@ def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3):
assert owned_package.name == "owned"


@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3):
invalid_uri = "https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03123" # noqa: E501
with pytest.raises(HTTPError):
Expand Down
8 changes: 6 additions & 2 deletions tests/ethpm/backends/test_ipfs_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def test_get_uri_backend_with_env_variable(dummy_ipfs_backend, monkeypatch):
assert isinstance(backend, LocalIPFSBackend)


def test_pin_assets_to_dummy_backend(dummy_ipfs_backend, ethpm_spec_dir, owned_manifest_path):
def test_pin_assets_to_dummy_backend(
dummy_ipfs_backend, ethpm_spec_dir, owned_manifest_path
):
# Test pinning a file
backend = get_ipfs_backend()
hashes = backend.pin_assets(owned_manifest_path)
Expand All @@ -119,7 +121,9 @@ def test_pin_assets_to_dummy_backend(dummy_ipfs_backend, ethpm_spec_dir, owned_m
assert asset_data["Hash"] == "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR"
assert asset_data["Size"] == "478"
# Test pinning a directory
dir_data = backend.pin_assets(ethpm_spec_dir / "examples" / "standard-token" / "contracts")
dir_data = backend.pin_assets(
ethpm_spec_dir / "examples" / "standard-token" / "contracts"
)
dir_names = [result["Name"] for result in dir_data]
dir_hashes = [result["Hash"] for result in dir_data]
dir_sizes = [result["Size"] for result in dir_data]
Expand Down
18 changes: 12 additions & 6 deletions tests/ethpm/backends/test_registry_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,37 @@ def backend():
return RegistryURIBackend()


@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_registry_uri_backend(backend):
valid_uri = "erc1319://0x1457890158DECD360e6d4d979edBcDD59c35feeB:1/[email protected]"
expected_uri = 'ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW'
expected_uri = "ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW"
assert backend.can_translate_uri(valid_uri) is True
assert backend.can_resolve_uri(valid_uri) is False
assert backend.fetch_uri_contents(valid_uri) == expected_uri


@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_registry_uri_supports_ens_domains(backend):
valid_uri = "erc1319://defi.snakecharmers.eth:1/[email protected]"
parsed = parse_registry_uri(valid_uri)
expected_uri = 'ipfs://QmYvsyuxjj9mKmCvn3jrdfnaHYwFsyHXUu7kETrN4dBhE6'
expected_uri = "ipfs://QmYvsyuxjj9mKmCvn3jrdfnaHYwFsyHXUu7kETrN4dBhE6"
assert backend.can_translate_uri(valid_uri) is True
assert backend.can_resolve_uri(valid_uri) is False
assert backend.fetch_uri_contents(valid_uri) == expected_uri
assert parsed.address == "0xA635F17288187daE5b424D343E21FF44a79ce922"
assert parsed.ens == "defi.snakecharmers.eth"
assert parsed.chain_id == '1'
assert parsed.chain_id == "1"
assert parsed.name == "compound"
assert parsed.version == "1.0.0"


@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_registry_uri_backend_raises_exception_for_non_mainnet_chains(backend):
ropsten_uri = "erc1319://snakecharmers.eth:3/[email protected]"
with pytest.raises(CannotHandleURI, match="Currently only mainnet"):
Expand Down
20 changes: 11 additions & 9 deletions tests/ethpm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ def ethpm_spec_dir():

@pytest.fixture(params=V3_PACKAGE_NAMES)
def all_strict_manifests(request):
return (
(fetch_manifest_path(request.param[0], "v3.json"))
.read_text()
.rstrip("\n")
)
return (fetch_manifest_path(request.param[0], "v3.json")).read_text().rstrip("\n")


@pytest.fixture(params=V3_PACKAGE_NAMES)
Expand All @@ -69,10 +65,12 @@ def fetch_manifest(name, version):

def fetch_manifest_path(name, version):
ethpm_spec_dir = get_ethpm_spec_dir()
return ethpm_spec_dir / 'examples' / name / version
return ethpm_spec_dir / "examples" / name / version


MANIFESTS_V3 = {name: fetch_manifest(name, version) for name, version in V3_PACKAGE_NAMES}
MANIFESTS_V3 = {
name: fetch_manifest(name, version) for name, version in V3_PACKAGE_NAMES
}


@pytest.fixture
Expand Down Expand Up @@ -145,7 +143,9 @@ def _get_factory(package, factory_name):

@pytest.fixture
def owned_contract(ethpm_spec_dir):
return (ethpm_spec_dir / "examples" / "owned" / "contracts" / "Owned.sol").read_text()
return (
ethpm_spec_dir / "examples" / "owned" / "contracts" / "Owned.sol"
).read_text()


@pytest.fixture
Expand Down Expand Up @@ -190,7 +190,9 @@ def safe_math_lib_package(deployer, w3):

@pytest.fixture
def safe_math_lib_package_with_alias(deployer, w3):
safe_math_lib_manifest = ASSETS_DIR / "safe-math-lib" / "v3-strict-no-deployments.json"
safe_math_lib_manifest = (
ASSETS_DIR / "safe-math-lib" / "v3-strict-no-deployments.json"
)
safe_math_deployer = deployer(safe_math_lib_manifest)
pkg = safe_math_deployer.deploy("SafeMathLib")
blockchain_uri = list(pkg.manifest["deployments"].keys())[0]
Expand Down
3 changes: 2 additions & 1 deletion tests/ethpm/integration/test_ipfs_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ def test_builder_pins_manifest_to_provided_ipfs_backend(backend, request):
assert manifest["Hash"] == minified_manifest_hash
pinned_manifest = backend.fetch_uri_contents(manifest["Hash"])
assert (
pinned_manifest == b'{"manifest_version":"2","package_name":"package","version":"1.0.0"}'
pinned_manifest
== b'{"manifest_version":"2","package_name":"package","version":"1.0.0"}'
)
17 changes: 9 additions & 8 deletions tests/ethpm/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@
(
"escrow",
"Escrow",
{
"SafeSendLib": "0x4F5B11c860b37b68DE6D14Fb7e7b5f18A9A1bdC0"
},
{"SafeSendLib": "0x4F5B11c860b37b68DE6D14Fb7e7b5f18A9A1bdC0"},
),
(
"wallet",
"Wallet",
{
"safe-math-lib:SafeMathLib": "0xa66A05D6AB5c1c955F4D2c3FCC166AE6300b452B"
},
{"safe-math-lib:SafeMathLib": "0xa66A05D6AB5c1c955F4D2c3FCC166AE6300b452B"},
),
),
)
Expand Down Expand Up @@ -98,8 +94,13 @@ def test_linkable_contract_class_handles_missing_link_refs(get_manifest, w3):
{"length": 20, "name": "SafeMathLib", "offsets": [25]},
],
{"SafeSendLib": SAFE_SEND_CANON, "SafeMathLib": SAFE_MATH_CANON},
b"\00" + SAFE_SEND_CANON + bytearray(4) + SAFE_MATH_CANON
+ bytearray(5) + SAFE_SEND_CANON + bytearray(10),
b"\00"
+ SAFE_SEND_CANON
+ bytearray(4)
+ SAFE_MATH_CANON
+ bytearray(5)
+ SAFE_SEND_CANON
+ bytearray(10),
),
),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/ethpm/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_deployment_implements_key_lookup(deployment):


def test_deployment_implements_key_lookup_with_nonexistent_key_raises_exception(
deployment
deployment,
):
key = "invalid" in deployment
assert key is False
Expand Down
8 changes: 6 additions & 2 deletions tests/ethpm/test_get_build_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def test_get_build_dependencies_without_dependencies_raises_exception(
):
piper_coin_manifest.pop("buildDependencies", None)
pkg = Package(piper_coin_manifest, w3)
with pytest.raises(EthPMValidationError, match="Manifest doesn't have any build dependencies"):
with pytest.raises(
EthPMValidationError, match="Manifest doesn't have any build dependencies"
):
pkg.build_dependencies


Expand All @@ -44,5 +46,7 @@ def test_get_build_dependencies_with_empty_dependencies_raises_exception(
):
piper_coin_manifest["buildDependencies"] = {}
pkg = Package(piper_coin_manifest, w3)
with pytest.raises(EthPMValidationError, match="Manifest's build dependencies key is empty"):
with pytest.raises(
EthPMValidationError, match="Manifest's build dependencies key is empty"
):
pkg.build_dependencies
8 changes: 6 additions & 2 deletions tests/ethpm/test_get_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ def test_get_deployments_with_no_match_raises_exception(
manifest_with_no_matching_deployments, w3
):
package = Package(manifest_with_no_matching_deployments, w3)
with pytest.raises(EthPMValidationError, match="Package has no matching URIs on chain."):
with pytest.raises(
EthPMValidationError, match="Package has no matching URIs on chain."
):
package.deployments


def test_get_deployments_with_multiple_matches_raises_exception(
manifest_with_multiple_matches, w3
):
package = Package(manifest_with_multiple_matches, w3)
with pytest.raises(EthPMValidationError, match="Package has too many \\(2\\) matching URIs"):
with pytest.raises(
EthPMValidationError, match="Package has too many \\(2\\) matching URIs"
):
package.deployments


Expand Down
9 changes: 6 additions & 3 deletions tests/ethpm/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def test_update_web3(deployed_safe_math, w3):
assert new_package.w3 is new_w3
assert original_package is not new_package
assert original_package.manifest == new_package.manifest
with pytest.raises(EthPMValidationError, match="Package has no matching URIs on chain."):
with pytest.raises(
EthPMValidationError, match="Package has no matching URIs on chain."
):
new_package.deployments


Expand Down Expand Up @@ -89,8 +91,9 @@ def test_package_object_properties(safe_math_package):
assert safe_math_package.contract_types == ["SafeMathLib"]


def test_cached_properties(piper_coin_manifest, safe_math_lib_package,
safe_math_lib_package_with_alias, w3):
def test_cached_properties(
piper_coin_manifest, safe_math_lib_package, safe_math_lib_package_with_alias, w3
):
package1 = Package(piper_coin_manifest, w3)
package2 = Package(piper_coin_manifest, w3)
first_build_dependencies_package1 = package1.build_dependencies.items()
Expand Down
12 changes: 5 additions & 7 deletions tests/ethpm/test_package_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def valid_manifest_from_path(tmpdir):

@pytest.fixture
def invalid_manifest_from_path(tmpdir):
invalid_manifest = (
'{"manifest":"xx","name":"foo","version":"1.0.0"}'
)
invalid_manifest = '{"manifest":"xx","name":"foo","version":"1.0.0"}'
temp_manifest = tmpdir.mkdir("invalid").join("manifest.json")
temp_manifest.write(invalid_manifest)
yield Path(str(temp_manifest))
Expand Down Expand Up @@ -64,9 +62,7 @@ def test_package_init_for_all_manifest_use_cases(all_manifests, w3):
assert isinstance(package, Package)


def test_package_init_for_manifest_with_build_dependency(
piper_coin_manifest, w3
):
def test_package_init_for_manifest_with_build_dependency(piper_coin_manifest, w3):
pkg = Package(piper_coin_manifest, w3)
assert isinstance(pkg, Package)

Expand Down Expand Up @@ -134,7 +130,9 @@ def test_package_from_uri_with_valid_uri(w3):
"bzz://da6adeeb4589d8652bbe5679aae6b6409ec85a20e92a8823c7c99e25dba9493d",
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
@pytest.mark.skipif(
"WEB3_INFURA_PROJECT_ID" not in os.environ, reason="Infura API key unavailable"
)
def test_package_from_uri_rejects_invalid_ipfs_uri(uri, w3):
with pytest.raises(CannotHandleURI):
Package.from_uri(uri, w3)
Loading