def get_source_file_hash(self): source_file_paths = find_project_contracts(self.project_dir) return hashlib.md5(b''.join( open(source_file_path, 'rb').read() for source_file_path in source_file_paths )).hexdigest()
def get_source_modification_time(self): source_file_paths = find_project_contracts(self.project_dir) return max( os.path.getmtime(source_file_path) for source_file_path in source_file_paths ) if len(source_file_paths) > 0 else None
def test_gets_correct_files_custom_dir(project_dir, write_project_file): custom_dir = "my_custom_dir" mkdir(os.path.join(project_dir, custom_dir)) file_names = find_project_contracts(project_dir, custom_dir) should_match = { '{}/SolidityContract.sol'.format(custom_dir), '{}/AnotherFile.sol'.format(custom_dir), } should_not_match = { '{}/BackedUpContract.sol.bak'.format(custom_dir), '{}/Swapfile.sol.swp'.format(custom_dir), '{}/not-contract.txt'.format(custom_dir), } for filename in should_match: write_project_file(filename) for filename in should_not_match: write_project_file(filename) for file_name in file_names: assert os.path.exists(file_name) assert os.path.basename(file_name) in should_match assert os.path.basename(file_name) not in should_not_match
def test_contract_factories(project): from solc import compile_files from populus.utils.filesystem import ( recursive_find_files, ) from populus.compilation import ( find_project_contracts, ) base_tests_dir = os.path.dirname(__file__) test_source_files = [ os.path.relpath(source_path, project.project_dir) for source_path in recursive_find_files(base_tests_dir, 'Test*.sol') ] all_source_files = test_source_files + list(find_project_contracts( project.project_dir, project.contracts_dir, )) compiled_contracts = compile_files(all_source_files) for contract_name, contract_data in compiled_contracts.items(): project.compiled_contracts.setdefault(contract_name, contract_data)
def test_gets_correct_files(): project_dir = "tests/utility/projects/test-01/" file_names = find_project_contracts(project_dir) should_match = { 'MutanContract.mu', 'SerpentContract.se', 'LLLContract.lll', 'SolidityContract.sol', } should_not_match = { 'BackedUpContract.sol.bak', 'Swapfile.sol.swp', 'not-contract.txt', } for file_name in file_names: assert os.path.exists(file_name) assert os.path.basename(file_name) in should_match assert os.path.basename(file_name) not in should_not_match
def test_gets_correct_files(project_dir, write_project_file): file_names = find_project_contracts(project_dir) should_match = { 'contracts/SolidityContract.sol', 'contracts/AnotherFile.sol', } should_not_match = { 'contracts/BackedUpContract.sol.bak', 'contracts/Swapfile.sol.swp', 'contracts/not-contract.txt', } for filename in should_match: write_project_file(filename) for filename in should_not_match: write_project_file(filename) for file_name in file_names: assert os.path.exists(file_name) assert os.path.basename(file_name) in should_match assert os.path.basename(file_name) not in should_not_match
def test_gets_correct_files_default_dir(project_dir, write_project_file): file_names = find_project_contracts(project_dir) should_match = { 'contracts/SolidityContract.sol', 'contracts/AnotherFile.sol', } should_not_match = { 'contracts/BackedUpContract.sol.bak', 'contracts/Swapfile.sol.swp', 'contracts/not-contract.txt', } for filename in should_match: write_project_file(filename) for filename in should_not_match: write_project_file(filename) for file_name in file_names: assert os.path.exists(file_name) assert os.path.basename(file_name) in should_match assert os.path.basename(file_name) not in should_not_match