Skip to content

Commit 642ca9f

Browse files
authored
Merge pull request #260 from crytic/dev-fix-etherscan-anchoring
etherscan: make sure the file path is relative
2 parents 6bb6e72 + 1496257 commit 642ca9f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import re
99
import urllib.request
1010
from json.decoder import JSONDecodeError
11-
from pathlib import Path
11+
from pathlib import Path, PurePosixPath
1212
from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional
1313

1414
from crytic_compile.compilation_unit import CompilationUnit
@@ -147,16 +147,25 @@ def _handle_multiple_files(
147147

148148
filtered_paths: List[str] = []
149149
for filename, source_code in source_codes.items():
150-
path_filename = Path(filename)
150+
path_filename = PurePosixPath(filename)
151151
if "contracts" in path_filename.parts and not filename.startswith("@"):
152-
path_filename = Path(*path_filename.parts[path_filename.parts.index("contracts") :])
152+
path_filename = PurePosixPath(
153+
*path_filename.parts[path_filename.parts.index("contracts") :]
154+
)
155+
156+
# Convert "absolute" paths such as "/interfaces/IFoo.sol" into relative ones.
157+
# This is needed due to the following behavior from pathlib.Path:
158+
# > When several absolute paths are given, the last is taken as an anchor
159+
# We need to make sure this is relative, so that Path(directory, ...) remains anchored to directory
160+
if path_filename.is_absolute():
161+
path_filename = PurePosixPath(*path_filename.parts[1:])
153162

154-
filtered_paths.append(str(path_filename))
155-
path_filename = Path(directory, path_filename)
163+
filtered_paths.append(path_filename.as_posix())
164+
path_filename_disk = Path(directory, path_filename)
156165

157-
if not os.path.exists(path_filename.parent):
158-
os.makedirs(path_filename.parent)
159-
with open(path_filename, "w", encoding="utf8") as file_desc:
166+
if not os.path.exists(path_filename_disk.parent):
167+
os.makedirs(path_filename_disk.parent)
168+
with open(path_filename_disk, "w", encoding="utf8") as file_desc:
160169
file_desc.write(source_code["content"])
161170

162171
return list(filtered_paths), directory

scripts/ci_test_etherscan.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ then
2323
exit 255
2424
fi
2525

26+
# From crytic/slither#1154
27+
crytic-compile 0xcfc1E0968CA08aEe88CbF664D4A1f8B881d90f37 --compile-remove-metadata --etherscan-apikey "$GITHUB_ETHERSCAN"
28+
29+
if [ $? -ne 0 ]
30+
then
31+
echo "Etherscan test failed"
32+
exit 255
33+
fi

0 commit comments

Comments
 (0)