Skip to content

Commit 84aaac0

Browse files
Yoichi Hiraipirapira
authored andcommitted
Separate _verify_single_precompiled_checksum()
This commit separates a function that checks one entry of contracts.json. This eases the implementation of raiden-network#1257.
1 parent cf7bcb9 commit 84aaac0

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

raiden_contracts/contract_source_manager.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,21 @@ def compile_contracts(self, target_path: Path) -> ContractManager:
102102
return ContractManager(target_path)
103103

104104
def verify_precompiled_checksums(self, precompiled_path: Path) -> None:
105-
""" Compare source code checksums with those from a precompiled file """
105+
""" Compare source code checksums with those from a precompiled file
106+
107+
If `contract_name` is None, all contracts checksums and the overall checksum are checked.
108+
"""
106109

107110
# We get the precompiled file data
108111
contracts_precompiled = ContractManager(precompiled_path)
109112

110113
# Compare each contract source code checksum with the one from the precompiled file
111114
for contract, checksum in self.contracts_checksums.items():
112-
try:
113-
# Silence mypy
114-
assert contracts_precompiled.contracts_checksums is not None
115-
precompiled_checksum = contracts_precompiled.contracts_checksums[contract]
116-
except KeyError:
117-
raise ContractSourceManagerVerificationError(f"No checksum for {contract}")
118-
if precompiled_checksum != checksum:
119-
raise ContractSourceManagerVerificationError(
120-
f"checksum of {contract} does not match {precompiled_checksum} != {checksum}"
121-
)
115+
_verify_single_precompiled_checksum(
116+
checked_checksums=contracts_precompiled.contracts_checksums,
117+
contract_name=contract,
118+
expected_checksum=checksum,
119+
)
122120

123121
# Compare the overall source code checksum with the one from the precompiled file
124122
if self.overall_checksum != contracts_precompiled.overall_checksum:
@@ -184,3 +182,18 @@ def check_runtime_codesize(d: Dict) -> None:
184182
runtime_code_len = len(compilation["bin-runtime"]) // 2
185183
if runtime_code_len > 0x6000:
186184
raise RuntimeError(f"{name}'s runtime code is too big ({runtime_code_len} bytes).")
185+
186+
187+
def _verify_single_precompiled_checksum(
188+
checked_checksums: Dict[str, str], contract_name: str, expected_checksum: str
189+
) -> None:
190+
""" Get `checked_checksums[contract_name]` and compare it against `expected_checksum` """
191+
try:
192+
precompiled_checksum = checked_checksums[contract_name]
193+
except KeyError:
194+
raise ContractSourceManagerVerificationError(f"No checksum for {contract_name}")
195+
if precompiled_checksum != expected_checksum:
196+
raise ContractSourceManagerVerificationError(
197+
f"checksum of {contract_name} does not match. got {precompiled_checksum} != "
198+
"expected {expected_checksum}"
199+
)

0 commit comments

Comments
 (0)