@@ -102,23 +102,21 @@ def compile_contracts(self, target_path: Path) -> ContractManager:
102
102
return ContractManager (target_path )
103
103
104
104
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
+ """
106
109
107
110
# We get the precompiled file data
108
111
contracts_precompiled = ContractManager (precompiled_path )
109
112
110
113
# Compare each contract source code checksum with the one from the precompiled file
111
114
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
+ )
122
120
123
121
# Compare the overall source code checksum with the one from the precompiled file
124
122
if self .overall_checksum != contracts_precompiled .overall_checksum :
@@ -184,3 +182,18 @@ def check_runtime_codesize(d: Dict) -> None:
184
182
runtime_code_len = len (compilation ["bin-runtime" ]) // 2
185
183
if runtime_code_len > 0x6000 :
186
184
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