diff --git a/raiden_contracts/contract_source_manager.py b/raiden_contracts/contract_source_manager.py index e4c5d0b69..3affc61c9 100644 --- a/raiden_contracts/contract_source_manager.py +++ b/raiden_contracts/contract_source_manager.py @@ -102,23 +102,21 @@ def compile_contracts(self, target_path: Path) -> ContractManager: return ContractManager(target_path) def verify_precompiled_checksums(self, precompiled_path: Path) -> None: - """ Compare source code checksums with those from a precompiled file """ + """ Compare source code checksums with those from a precompiled file + + If `contract_name` is None, all contracts checksums and the overall checksum are checked. + """ # We get the precompiled file data contracts_precompiled = ContractManager(precompiled_path) # Compare each contract source code checksum with the one from the precompiled file for contract, checksum in self.contracts_checksums.items(): - try: - # Silence mypy - assert contracts_precompiled.contracts_checksums is not None - precompiled_checksum = contracts_precompiled.contracts_checksums[contract] - except KeyError: - raise ContractSourceManagerVerificationError(f"No checksum for {contract}") - if precompiled_checksum != checksum: - raise ContractSourceManagerVerificationError( - f"checksum of {contract} does not match {precompiled_checksum} != {checksum}" - ) + self._verify_single_precompiled_checksum( + checked_checksums=contracts_precompiled.contracts_checksums, + contract_name=contract, + expected_checksum=checksum, + ) # Compare the overall source code checksum with the one from the precompiled file if self.overall_checksum != contracts_precompiled.overall_checksum: @@ -127,6 +125,20 @@ def verify_precompiled_checksums(self, precompiled_path: Path) -> None: f"{self.overall_checksum} != {contracts_precompiled.overall_checksum}" ) + def _verify_single_precompiled_checksum( + self, checked_checksums: Dict[str, str], contract_name: str, expected_checksum: str + ): + """ Get `checked_checksums[contract_name]` and compare it against `expected_checksum` """ + try: + precompiled_checksum = checked_checksums[contract_name] + except KeyError: + raise ContractSourceManagerVerificationError(f"No checksum for {contract_name}") + if precompiled_checksum != expected_checksum: + raise ContractSourceManagerVerificationError( + f"checksum of {contract_name} does not match. got {precompiled_checksum} != " + "expected {expected_checksum}" + ) + def _checksum_contracts(self) -> Tuple[Dict[str, str], str]: """ Compute the checksum of each source, and the overall checksum