Skip to content
Open
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
15 changes: 12 additions & 3 deletions ethpm_cli/_utils/etherscan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Tuple
from urllib import parse

from eth_utils import is_checksum_address
Expand All @@ -20,10 +20,10 @@ def is_etherscan_uri(value: Any) -> bool:
if parsed.scheme != "etherscan" or not parsed.netloc:
return False

if ":" not in parsed.netloc:
if parsed.path:
return False

address, chain_id = parsed.netloc.split(":")
address, chain_id = parse_etherscan_uri(value)
if not is_checksum_address(address):
return False

Expand All @@ -33,5 +33,14 @@ def is_etherscan_uri(value: Any) -> bool:
return True


def parse_etherscan_uri(uri: str) -> Tuple[str, str]:
parsed = parse.urlparse(uri)
if ":" in parsed.netloc:
address, _, chain_id = parsed.netloc.partition(":")
else:
address, chain_id = (parsed.netloc, "1")
return address, chain_id


def get_etherscan_network(chain_id: str) -> str:
return ETHERSCAN_SUPPORTED_CHAIN_IDS[chain_id]
9 changes: 6 additions & 3 deletions ethpm_cli/commands/etherscan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import os
from typing import Any, Dict, Iterable, Tuple
from urllib import parse

from eth_typing import URI
from eth_utils import to_dict, to_hex, to_int
Expand All @@ -10,7 +9,11 @@
from ethpm.uri import create_latest_block_uri
import requests

from ethpm_cli._utils.etherscan import get_etherscan_network, is_etherscan_uri
from ethpm_cli._utils.etherscan import (
get_etherscan_network,
is_etherscan_uri,
parse_etherscan_uri,
)
from ethpm_cli.config import get_ipfs_backend, setup_w3
from ethpm_cli.constants import ETHERSCAN_KEY_ENV_VAR
from ethpm_cli.exceptions import ContractNotVerified
Expand Down Expand Up @@ -41,7 +44,7 @@ def fetch_uri_contents(
def build_etherscan_manifest(
uri: URI, package_name: str, version: str
) -> Iterable[Tuple[str, Any]]:
address, chain_id = parse.urlparse(uri).netloc.split(":")
address, chain_id = parse_etherscan_uri(uri)
network = get_etherscan_network(chain_id)
body = make_etherscan_request(address, network)
contract_type = body["ContractName"]
Expand Down
4 changes: 0 additions & 4 deletions tests/cli/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ def test_activate_ipfs_uri_with_factories_and_deployments():
# test contract factory is available
child.sendline("Address_factory")
child.expect("web3._utils.datatypes.LinkableContract")
# test deployment is available
child.sendline("mainnet_BaseRegistrarImplementation")
child.expect("web3._utils.datatypes.LinkableContract at")
child.close()


def test_activate_github_uri_with_insufficient_contract_types_and_deployments():
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_ethpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def test_ethpm_list(test_assets_dir):
ethpm_dir = test_assets_dir / "multiple" / ETHPM_PACKAGES_DIR
child = pexpect.spawn(f"ethpm list --ethpm-dir {ethpm_dir}")
child = pexpect.spawn(f"ethpm list --ethpm-dir {ethpm_dir}", timeout=30)
child.expect(ENTRY_DESCRIPTION)
child.expect("\r\n")
child.expect("owned")
Expand Down
5 changes: 3 additions & 2 deletions tests/core/_utils/test_etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@pytest.mark.parametrize(
"uri,expected",
(
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", True),
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1", True),
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:3", True),
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:4", True),
Expand All @@ -15,10 +16,10 @@
("etherscan://invalid:1", False),
# non-checksummed
("etherscan://0x6b5da3ca4286baa7fbaf64eeee1834c7d430b729:1", False),
# bad path
# paths are not allowed
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/1", False),
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/owned@1.0.0", False),
# no chain_id
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", False),
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:", False),
("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:10", False),
("://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1", False),
Expand Down