File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from typing import Any
1+ from typing import Any , Tuple
22from urllib import parse
33
44from eth_utils import is_checksum_address
@@ -20,10 +20,10 @@ def is_etherscan_uri(value: Any) -> bool:
2020 if parsed .scheme != "etherscan" or not parsed .netloc :
2121 return False
2222
23- if ":" not in parsed .netloc :
23+ if parsed .path :
2424 return False
2525
26- address , chain_id = parsed . netloc . split ( ":" )
26+ address , chain_id = parse_etherscan_uri ( value )
2727 if not is_checksum_address (address ):
2828 return False
2929
@@ -33,5 +33,14 @@ def is_etherscan_uri(value: Any) -> bool:
3333 return True
3434
3535
36+ def parse_etherscan_uri (uri : str ) -> Tuple [str , str ]:
37+ parsed = parse .urlparse (uri )
38+ if ":" in parsed .netloc :
39+ address , _ , chain_id = parsed .netloc .partition (":" )
40+ else :
41+ address , chain_id = (parsed .netloc , "1" )
42+ return address , chain_id
43+
44+
3645def get_etherscan_network (chain_id : str ) -> str :
3746 return ETHERSCAN_SUPPORTED_CHAIN_IDS [chain_id ]
Original file line number Diff line number Diff line change 11import json
22import os
33from typing import Any , Dict , Iterable , Tuple
4- from urllib import parse
54
65from eth_typing import URI
76from eth_utils import to_dict , to_hex , to_int
109from ethpm .uri import create_latest_block_uri
1110import requests
1211
13- from ethpm_cli ._utils .etherscan import get_etherscan_network , is_etherscan_uri
12+ from ethpm_cli ._utils .etherscan import (
13+ get_etherscan_network ,
14+ is_etherscan_uri ,
15+ parse_etherscan_uri ,
16+ )
1417from ethpm_cli .config import get_ipfs_backend , setup_w3
1518from ethpm_cli .constants import ETHERSCAN_KEY_ENV_VAR
1619from ethpm_cli .exceptions import ContractNotVerified
@@ -41,7 +44,7 @@ def fetch_uri_contents(
4144def build_etherscan_manifest (
4245 uri : URI , package_name : str , version : str
4346) -> Iterable [Tuple [str , Any ]]:
44- address , chain_id = parse . urlparse (uri ). netloc . split ( ":" )
47+ address , chain_id = parse_etherscan_uri (uri )
4548 network = get_etherscan_network (chain_id )
4649 body = make_etherscan_request (address , network )
4750 contract_type = body ["ContractName" ]
Original file line number Diff line number Diff line change @@ -118,10 +118,6 @@ def test_activate_ipfs_uri_with_factories_and_deployments():
118118 # test contract factory is available
119119 child .sendline ("Address_factory" )
120120 child .expect ("web3._utils.datatypes.LinkableContract" )
121- # test deployment is available
122- child .sendline ("mainnet_BaseRegistrarImplementation" )
123- child .expect ("web3._utils.datatypes.LinkableContract at" )
124- child .close ()
125121
126122
127123def test_activate_github_uri_with_insufficient_contract_types_and_deployments ():
Original file line number Diff line number Diff line change 99
1010def test_ethpm_list (test_assets_dir ):
1111 ethpm_dir = test_assets_dir / "multiple" / ETHPM_PACKAGES_DIR
12- child = pexpect .spawn (f"ethpm list --ethpm-dir { ethpm_dir } " )
12+ child = pexpect .spawn (f"ethpm list --ethpm-dir { ethpm_dir } " , timeout = 30 )
1313 child .expect (ENTRY_DESCRIPTION )
1414 child .expect ("\r \n " )
1515 child .expect ("owned" )
Original file line number Diff line number Diff line change 66@pytest .mark .parametrize (
77 "uri,expected" ,
88 (
9+ ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729" , True ),
910 ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1" , True ),
1011 ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:3" , True ),
1112 ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:4" , True ),
1516 ("etherscan://invalid:1" , False ),
1617 # non-checksummed
1718 ("etherscan://0x6b5da3ca4286baa7fbaf64eeee1834c7d430b729:1" , False ),
18- # bad path
19+ # paths are not allowed
1920 ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/1" , False ),
21+ ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729/owned@1.0.0" , False ),
2022 # no chain_id
21- ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729" , False ),
2223 ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:" , False ),
2324 ("etherscan://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:10" , False ),
2425 ("://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1" , False ),
You can’t perform that action at this time.
0 commit comments