def test_verification_overall_checksum(): """ Tamper with the overall checksum and see failures in verify_precompiled_checksums() """ manager = ContractManager(contracts_source_path()) manager.checksum_contracts() manager.verify_precompiled_checksums(contracts_precompiled_path()) original_checksum = manager.overall_checksum # We change the source code overall checksum manager.overall_checksum += '2' # Now the verification should fail with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(contracts_precompiled_path()) manager.overall_checksum = None with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(contracts_precompiled_path()) manager.overall_checksum = '' with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(contracts_precompiled_path()) checksum_fail = list(original_checksum) # Replace the first char with a different one checksum_fail[0] = list(filter(lambda x: x != checksum_fail[0], ['2', 'a']))[0] manager.overall_checksum = "".join(checksum_fail) with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(contracts_precompiled_path()) manager.overall_checksum = original_checksum manager.verify_precompiled_checksums(contracts_precompiled_path())
def test_verification_overall_checksum(): manager = ContractManager(CONTRACTS_SOURCE_DIRS) manager.checksum_contracts() manager.verify_precompiled_checksums(CONTRACTS_PRECOMPILED_PATH) original_checksum = manager.overall_checksum # We change the source code overall checksum manager.overall_checksum += '2' # Now the verification should fail with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(CONTRACTS_PRECOMPILED_PATH) manager.overall_checksum = None with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(CONTRACTS_PRECOMPILED_PATH) manager.overall_checksum = '' with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(CONTRACTS_PRECOMPILED_PATH) checksum_fail = list(original_checksum) # Replace the first char with a different one checksum_fail[0] = list(filter(lambda x: x != checksum_fail[0], ['2', 'a']))[0] manager.overall_checksum = "".join(checksum_fail) with pytest.raises(ContractManagerVerificationError): manager.verify_precompiled_checksums(CONTRACTS_PRECOMPILED_PATH) manager.overall_checksum = original_checksum manager.verify_precompiled_checksums(CONTRACTS_PRECOMPILED_PATH)