diff --git a/newsfragments/2542.misc.rst b/newsfragments/2542.misc.rst new file mode 100644 index 0000000000..713a9990fb --- /dev/null +++ b/newsfragments/2542.misc.rst @@ -0,0 +1 @@ +Add black to ``tests/ethpm`` diff --git a/tests/ethpm/_utils/test_backend_utils.py b/tests/ethpm/_utils/test_backend_utils.py index 25f9e94c40..00d1b53547 100644 --- a/tests/ethpm/_utils/test_backend_utils.py +++ b/tests/ethpm/_utils/test_backend_utils.py @@ -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 @@ -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 @@ -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) diff --git a/tests/ethpm/_utils/test_chain_utils.py b/tests/ethpm/_utils/test_chain_utils.py index 97f8197ab7..51545b5857 100644 --- a/tests/ethpm/_utils/test_chain_utils.py +++ b/tests/ethpm/_utils/test_chain_utils.py @@ -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) diff --git a/tests/ethpm/_utils/test_registry_utils.py b/tests/ethpm/_utils/test_registry_utils.py index 93f30da5be..e355c1f4ea 100644 --- a/tests/ethpm/_utils/test_registry_utils.py +++ b/tests/ethpm/_utils/test_registry_utils.py @@ -39,7 +39,9 @@ ("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601/erc20@1.0.0"), ("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/erc20@1.0.0"), ("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/erc20@1.0.0/"), - ("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/erc20@1.0.0/deployments/ERC139") + ( + "erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/erc20@1.0.0/deployments/ERC139" + ), ), ) def test_is_registry_uri_validates(uri): diff --git a/tests/ethpm/backends/test_http_backends.py b/tests/ethpm/backends/test_http_backends.py index d40db579ac..ec7ef7196f 100644 --- a/tests/ethpm/backends/test_http_backends.py +++ b/tests/ethpm/backends/test_http_backends.py @@ -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() @@ -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): diff --git a/tests/ethpm/backends/test_ipfs_backends.py b/tests/ethpm/backends/test_ipfs_backends.py index fc7e45f32b..93a9d465b1 100644 --- a/tests/ethpm/backends/test_ipfs_backends.py +++ b/tests/ethpm/backends/test_ipfs_backends.py @@ -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) @@ -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] diff --git a/tests/ethpm/backends/test_registry_backend.py b/tests/ethpm/backends/test_registry_backend.py index feb46abc3f..d2fc7dedb4 100644 --- a/tests/ethpm/backends/test_registry_backend.py +++ b/tests/ethpm/backends/test_registry_backend.py @@ -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/owned@1.0.0" - 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/compound@1.0.0" 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/owned@1.0.0" with pytest.raises(CannotHandleURI, match="Currently only mainnet"): diff --git a/tests/ethpm/conftest.py b/tests/ethpm/conftest.py index fd5d43265b..92106e1b62 100644 --- a/tests/ethpm/conftest.py +++ b/tests/ethpm/conftest.py @@ -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) @@ -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 @@ -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 @@ -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] diff --git a/tests/ethpm/integration/test_ipfs_integration.py b/tests/ethpm/integration/test_ipfs_integration.py index 519aa4440d..719e93ca1a 100644 --- a/tests/ethpm/integration/test_ipfs_integration.py +++ b/tests/ethpm/integration/test_ipfs_integration.py @@ -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"}' ) diff --git a/tests/ethpm/test_contract.py b/tests/ethpm/test_contract.py index e1c013f7bb..9e4e8d5a28 100644 --- a/tests/ethpm/test_contract.py +++ b/tests/ethpm/test_contract.py @@ -25,16 +25,12 @@ ( "escrow", "Escrow", - { - "SafeSendLib": "0x4F5B11c860b37b68DE6D14Fb7e7b5f18A9A1bdC0" - }, + {"SafeSendLib": "0x4F5B11c860b37b68DE6D14Fb7e7b5f18A9A1bdC0"}, ), ( "wallet", "Wallet", - { - "safe-math-lib:SafeMathLib": "0xa66A05D6AB5c1c955F4D2c3FCC166AE6300b452B" - }, + {"safe-math-lib:SafeMathLib": "0xa66A05D6AB5c1c955F4D2c3FCC166AE6300b452B"}, ), ), ) @@ -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), ), ), ) diff --git a/tests/ethpm/test_deployments.py b/tests/ethpm/test_deployments.py index 495954bc95..a20f8ad994 100644 --- a/tests/ethpm/test_deployments.py +++ b/tests/ethpm/test_deployments.py @@ -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 diff --git a/tests/ethpm/test_get_build_dependencies.py b/tests/ethpm/test_get_build_dependencies.py index e5c577f8aa..48d0abffb4 100644 --- a/tests/ethpm/test_get_build_dependencies.py +++ b/tests/ethpm/test_get_build_dependencies.py @@ -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 @@ -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 diff --git a/tests/ethpm/test_get_deployments.py b/tests/ethpm/test_get_deployments.py index bcfae2a20b..f5fe3d417a 100644 --- a/tests/ethpm/test_get_deployments.py +++ b/tests/ethpm/test_get_deployments.py @@ -27,7 +27,9 @@ 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 @@ -35,7 +37,9 @@ 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 diff --git a/tests/ethpm/test_package.py b/tests/ethpm/test_package.py index df9851ed9e..4dea5277b7 100644 --- a/tests/ethpm/test_package.py +++ b/tests/ethpm/test_package.py @@ -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 @@ -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() diff --git a/tests/ethpm/test_package_init.py b/tests/ethpm/test_package_init.py index 5c0ff80cc5..875cbb0379 100644 --- a/tests/ethpm/test_package_init.py +++ b/tests/ethpm/test_package_init.py @@ -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)) @@ -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) @@ -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) diff --git a/tests/ethpm/test_uri.py b/tests/ethpm/test_uri.py index 99fc88a254..c2b5fd21a9 100644 --- a/tests/ethpm/test_uri.py +++ b/tests/ethpm/test_uri.py @@ -83,73 +83,185 @@ def test_create_github_uri(): ), ( "erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:5/owned", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "5", "owned", None, None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "5", + "owned", + None, + None, + None, + ], ), ( "erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/owned@1.0.0", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "owned", "1.0.0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "owned", + "1.0.0", + None, + None, + ], ), ( "erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/wallet@2.8.0/", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + None, + None, + ], ), # ethpm scheme ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/wallet@2.8.0", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + None, + None, + ], ), # w/o chain_id ( "erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/owned", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "owned", None, None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "owned", + None, + None, + None, + ], ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@2.8.0", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + None, + None, + ], ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@8%400", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "8@0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "8@0", + None, + None, + ], ), # escaped chars ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/wallet@8%400", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "8@0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "8@0", + None, + None, + ], ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/wallet@%250", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "%0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "%0", + None, + None, + ], ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/wallet@8%400/", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "8@0", None, None], + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "8@0", + None, + None, + ], ), # with namespaced manifest contents ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@2.8.0/deployments", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", "deployments", None], # noqa: E501 + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + "deployments", + None, + ], # noqa: E501 ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@2.8.0/deployments/", - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", "deployments", None], # noqa: E501 + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + "deployments", + None, + ], # noqa: E501 ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@2.8.0/deployments/WalletContract", # noqa: E501 - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", "deployments/WalletContract", None], # noqa: E501 + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + "deployments/WalletContract", + None, + ], # noqa: E501 ), ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@2.8.0/deployments/WalletContract/", # noqa: E501 - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0", "deployments/WalletContract", None], # noqa: E501 + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "2.8.0", + "deployments/WalletContract", + None, + ], # noqa: E501 ), # unescaped chars & namespaced assets ( "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@20%26/deployments/WalletContract/", # noqa: E501 - ["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "20&", "deployments/WalletContract", None], # noqa: E501 + [ + "0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", + "1", + "wallet", + "20&", + "deployments/WalletContract", + None, + ], # noqa: E501 ), ), ) def test_parse_registry_uri(uri, expected): - address, chain_id, pkg_name, pkg_version, namespaced_asset, ens = parse_registry_uri(uri) + ( + address, + chain_id, + pkg_name, + pkg_version, + namespaced_asset, + ens, + ) = parse_registry_uri(uri) assert address == expected[0] assert chain_id == expected[1] assert pkg_name == expected[2] @@ -174,7 +286,7 @@ def test_parse_registry_uri(uri, expected): # namespaced asset and missing version "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet/deployments/WalletContract", "ethpm://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/wallet@/deployments/WalletContract", - ) + ), ) def test_invalid_registry_uris(uri): with pytest.raises(EthPMValidationError): diff --git a/tests/ethpm/tools/test_builder.py b/tests/ethpm/tools/test_builder.py index a8edb65ff8..3ffa63e835 100644 --- a/tests/ethpm/tools/test_builder.py +++ b/tests/ethpm/tools/test_builder.py @@ -64,8 +64,8 @@ def owned_package(ethpm_spec_dir): manifest = get_ethpm_spec_manifest("owned", "v3.json") # source_id missing `./` prefix in ethpm-spec ("Owned.sol"/"./Owned.sol" though both are valid) - source_obj = manifest['sources'].pop('Owned.sol') - updated_manifest = assoc_in(manifest, ['sources', './Owned.sol'], source_obj) + source_obj = manifest["sources"].pop("Owned.sol") + updated_manifest = assoc_in(manifest, ["sources", "./Owned.sol"], source_obj) compiler = get_ethpm_local_manifest("owned", "output_v3.json")["contracts"] contracts_dir = ethpm_spec_dir / "examples" / "owned" / "contracts" @@ -117,9 +117,7 @@ def test_builder_simple_with_package(w3): "version": "1.0.0" }""" -MINIFIED_MANIFEST = ( - '{"manifest":"ethpm/3","name":"package","version":"1.0.0"}' -) +MINIFIED_MANIFEST = '{"manifest":"ethpm/3","name":"package","version":"1.0.0"}' OWNED_CONTRACT = "// SPDX-License-Identifier: MIT\npragma solidity ^0.6.8;\n\ncontract Owned {\n address owner;\n \n modifier onlyOwner { require(msg.sender == owner); _; }\n\n constructor() public {\n owner = msg.sender;\n }\n}" # noqa: E501 @@ -311,7 +309,7 @@ def test_builder_with_inline_source_with_package_root_dir_arg(owned_package): }, ) print(manifest) - print('-') + print("-") print(expected) assert manifest == expected @@ -387,8 +385,10 @@ def test_builder_with_default_contract_types(owned_package): manifest = build(BASE_MANIFEST, contract_type("Owned", compiler_output), validate()) - contract_type_data = normalize_contract_type(compiler_output["Owned.sol"]["Owned"], "Owned.sol") - compilers_data = contract_type_data.pop('compiler') + contract_type_data = normalize_contract_type( + compiler_output["Owned.sol"]["Owned"], "Owned.sol" + ) + compilers_data = contract_type_data.pop("compiler") compilers_data["contractTypes"] = ["Owned"] expected_with_contract_type = assoc( BASE_MANIFEST, "contractTypes", {"Owned": contract_type_data} @@ -406,8 +406,10 @@ def test_builder_with_single_alias_kwarg(owned_package): validate(), ) - contract_type_data = normalize_contract_type(compiler_output["Owned.sol"]["Owned"], "Owned.sol") - compilers_data = contract_type_data.pop('compiler') + contract_type_data = normalize_contract_type( + compiler_output["Owned.sol"]["Owned"], "Owned.sol" + ) + compilers_data = contract_type_data.pop("compiler") compilers_data["contractTypes"] = ["OwnedAlias"] expected_with_contract_type = assoc( BASE_MANIFEST, @@ -422,10 +424,14 @@ def test_builder_without_alias_and_with_select_contract_types(owned_package): _, _, compiler_output = owned_package manifest = build( - BASE_MANIFEST, contract_type("Owned", compiler_output, abi=True, source_id=True), validate() + BASE_MANIFEST, + contract_type("Owned", compiler_output, abi=True, source_id=True), + validate(), ) - contract_type_data = normalize_contract_type(compiler_output["Owned.sol"]["Owned"], "Owned.sol") + contract_type_data = normalize_contract_type( + compiler_output["Owned.sol"]["Owned"], "Owned.sol" + ) omitted_fields = ("deploymentBytecode", "userdoc", "devdoc", "compiler") selected_data = { k: v for k, v in contract_type_data.items() if k not in omitted_fields @@ -454,7 +460,9 @@ def test_builder_with_alias_and_select_contract_types(owned_package): validate(), ) - contract_type_data = normalize_contract_type(compiler_output["Owned.sol"]["Owned"], "Owned.sol") + contract_type_data = normalize_contract_type( + compiler_output["Owned.sol"]["Owned"], "Owned.sol" + ) contract_type_data.pop("compiler") expected = assoc( BASE_MANIFEST, @@ -486,13 +494,15 @@ def test_builder_manages_duplicate_compilers(owned_package): ), validate(), ) - contract_type_data = normalize_contract_type(compiler_output["Owned.sol"]["Owned"], "Owned.sol") + contract_type_data = normalize_contract_type( + compiler_output["Owned.sol"]["Owned"], "Owned.sol" + ) compiler_data = contract_type_data.pop("compiler") - contract_type_data.pop('deploymentBytecode') - contract_type_data.pop('devdoc') - contract_type_data.pop('userdoc') + contract_type_data.pop("deploymentBytecode") + contract_type_data.pop("devdoc") + contract_type_data.pop("userdoc") compiler_data_with_contract_types = assoc( - compiler_data, 'contractTypes', ['Owned', 'OwnedAlias'] + compiler_data, "contractTypes", ["Owned", "OwnedAlias"] ) expected_with_contract_types = assoc( BASE_MANIFEST, @@ -502,13 +512,15 @@ def test_builder_manages_duplicate_compilers(owned_package): "OwnedAlias": assoc(contract_type_data, "contractType", "Owned"), }, ) - expected_with_contract_types['contractTypes']['Owned'].pop("contractType") - expected = assoc(expected_with_contract_types, 'compilers', [compiler_data_with_contract_types]) + expected_with_contract_types["contractTypes"]["Owned"].pop("contractType") + expected = assoc( + expected_with_contract_types, "compilers", [compiler_data_with_contract_types] + ) assert manifest == expected def test_builder_raises_exception_if_selected_contract_type_missing_from_solc( - owned_package + owned_package, ): _, _, compiler_output = owned_package with pytest.raises(ManifestBuildingError, match="runtimeBytecode not available"): @@ -532,9 +544,16 @@ def test_builder_with_standard_token_manifest( version("1.0.0"), pin_source("StandardToken", compiler_output, ipfs_backend), pin_source("Token", compiler_output, ipfs_backend), - contract_type("StandardToken", compiler_output, abi=True, devdoc=True, source_id=True), contract_type( - "Token", compiler_output, abi=True, devdoc=True, userdoc=True, source_id=True + "StandardToken", compiler_output, abi=True, devdoc=True, source_id=True + ), + contract_type( + "Token", + compiler_output, + abi=True, + devdoc=True, + userdoc=True, + source_id=True, ), validate(), ) diff --git a/tests/ethpm/tools/test_checker.py b/tests/ethpm/tools/test_checker.py index a0bf20424f..b8a7d3ce05 100644 --- a/tests/ethpm/tools/test_checker.py +++ b/tests/ethpm/tools/test_checker.py @@ -89,9 +89,9 @@ def test_check_sources(manifest, expected): "deploymentBytecode": WARNINGS[ "deployment_bytecode_missing" ].format("x"), - "runtimeBytecode": WARNINGS[ - "bytecode_subfield_missing" - ].format("x", "runtime"), + "runtimeBytecode": WARNINGS["bytecode_subfield_missing"].format( + "x", "runtime" + ), "devdoc": WARNINGS["devdoc_missing"].format("x"), "userdoc": WARNINGS["userdoc_missing"].format("x"), } @@ -122,9 +122,9 @@ def test_check_sources(manifest, expected): "deploymentBytecode": WARNINGS[ "deployment_bytecode_missing" ].format("x"), - "runtimeBytecode": WARNINGS[ - "bytecode_subfield_missing" - ].format("x", "runtime"), + "runtimeBytecode": WARNINGS["bytecode_subfield_missing"].format( + "x", "runtime" + ), "devdoc": WARNINGS["devdoc_missing"].format("x"), "userdoc": WARNINGS["userdoc_missing"].format("x"), }, diff --git a/tests/ethpm/validation/test_manifest.py b/tests/ethpm/validation/test_manifest.py index 6633830f09..33b80e3a6d 100644 --- a/tests/ethpm/validation/test_manifest.py +++ b/tests/ethpm/validation/test_manifest.py @@ -17,13 +17,13 @@ def test_validate_raw_manifest_configuration_validates_strict_manifests( - all_strict_manifests + all_strict_manifests, ): assert validate_raw_manifest_format(all_strict_manifests) is None def test_validate_raw_manifest_format_invalidates_pretty_manifests( - all_pretty_manifests + all_pretty_manifests, ): with pytest.raises(EthPMValidationError): validate_raw_manifest_format(all_pretty_manifests) @@ -61,9 +61,11 @@ def test_validate_manifest_invalidates(invalid_manifest): def test_validate_manifest_deployments_catches_missing_contract_type_references( - manifest_with_conflicting_deployments + manifest_with_conflicting_deployments, ): - with pytest.raises(EthPMValidationError, match="Manifest missing references to contracts"): + with pytest.raises( + EthPMValidationError, match="Manifest missing references to contracts" + ): validate_manifest_deployments(manifest_with_conflicting_deployments) @@ -210,7 +212,7 @@ def test_validate_meta_object_invalidates(meta, extra_fields): "wallet_", "wallet-", "x" * 256, - ) + ), ) def test_validate_package_name_with_valid_package_names(package_name): assert validate_package_name(package_name) is None @@ -226,7 +228,7 @@ def test_validate_package_name_with_valid_package_names(package_name): ".invalid", "wallet.bad", "x" * 257, - ) + ), ) def test_validate_package_name_raises_exception_for_invalid_names(package_name): with pytest.raises(EthPMValidationError): diff --git a/tests/ethpm/validation/test_misc.py b/tests/ethpm/validation/test_misc.py index e1289744ea..a14b26c27d 100644 --- a/tests/ethpm/validation/test_misc.py +++ b/tests/ethpm/validation/test_misc.py @@ -42,7 +42,7 @@ def test_validate_empty_bytes_invalidates(offset, length, bytecode): "abcd", "abcd%40", "%20%24%26", - ) + ), ) def test_validate_escaped_strings(string): validate_escaped_string(string) @@ -55,7 +55,7 @@ def test_validate_escaped_strings(string): "@bcd%40", "!bcd%40", "&bcd%40", - ) + ), ) def test_validate_escaped_strings_invalidates(string): with pytest.raises(EthPMValidationError): diff --git a/tox.ini b/tox.ini index 5c10491ee2..8857d45f73 100644 --- a/tox.ini +++ b/tox.ini @@ -64,7 +64,7 @@ basepython=python extras=linter commands= flake8 {toxinidir}/web3 {toxinidir}/ens {toxinidir}/ethpm {toxinidir}/tests --exclude {toxinidir}/ethpm/ethpm-spec - black {toxinidir}/ethpm {toxinidir}/web3 {toxinidir}/tests/beacon/ {toxinidir}/tests/ens --exclude {toxinidir}/ethpm/ethpm-spec --check + black {toxinidir}/ethpm {toxinidir}/web3 {toxinidir}/tests/beacon/ {toxinidir}/tests/ens {toxinidir}/tests/ethpm --exclude {toxinidir}/ethpm/ethpm-spec --check isort --recursive --check-only --diff {toxinidir}/web3/ {toxinidir}/ens/ {toxinidir}/ethpm/ {toxinidir}/tests/ mypy -p web3 -p ethpm -p ens --config-file {toxinidir}/mypy.ini