|
8 | 8 |
|
9 | 9 |
|
10 | 10 | def main(cli_args: List[str]): |
11 | | - # TODO: when possible, also add multiversx/mx-exchange-sc (as of May 2023, it references mx-sdk-rs < v0.41.0, thus cannot be used for testing reproducible builds v5). |
12 | | - project_path = download_project_repository("https://github.com/multiversx/mx-reproducible-contract-build-example-sc/archive/refs/tags/v0.4.0.zip", "mx-exchange-sc-main") |
13 | | - parent_output_using_project = PARENT_OUTPUT_FOLDER / "using-project" |
14 | | - parent_output_using_packaged_src = PARENT_OUTPUT_FOLDER / "using-packaged-src" |
15 | | - |
16 | | - shutil.rmtree(parent_output_using_project, ignore_errors=True) |
17 | | - shutil.rmtree(parent_output_using_packaged_src, ignore_errors=True) |
18 | | - |
19 | | - check_project_folder_and_packaged_src_are_equivalent(project_path, parent_output_using_project, parent_output_using_packaged_src, ["adder", "multisig"]) |
| 11 | + repository_url = "https://github.com/multiversx/mx-reproducible-contract-build-example-sc" |
| 12 | + tag = "0.4.7-beta.1" |
| 13 | + archve_subfolder = f"mx-reproducible-contract-build-example-sc-{tag}" |
| 14 | + project_path = download_project_repository(f"{repository_url}/archive/refs/tags/v{tag}.zip", archve_subfolder) |
| 15 | + project_path = project_path / archve_subfolder |
| 16 | + |
| 17 | + # Only package_whole_project_src = True works. |
| 18 | + # package_whole_project_src = False does not work, since a missing Cargo.lock at the workspace level leads to build errors. |
| 19 | + check_project_folder_and_packaged_src_are_equivalent( |
| 20 | + project_path=project_path, |
| 21 | + package_whole_project_src=True, |
| 22 | + parent_output_folder=PARENT_OUTPUT_FOLDER, |
| 23 | + contracts=["adder", "multisig"], |
| 24 | + ) |
20 | 25 |
|
21 | 26 |
|
22 | 27 | def check_project_folder_and_packaged_src_are_equivalent( |
23 | 28 | project_path: Path, |
24 | | - parent_output_using_project: Path, |
25 | | - parent_output_using_packaged_src: Path, |
| 29 | + package_whole_project_src: bool, |
| 30 | + parent_output_folder: Path, |
26 | 31 | contracts: List[str]): |
27 | 32 | for contract in contracts: |
28 | | - for package_whole_project_src in [True, False]: |
29 | | - output_using_project = parent_output_using_project / contract / ("whole" if package_whole_project_src else "truncated") |
30 | | - output_using_packaged_src = parent_output_using_packaged_src / contract / ("whole" if package_whole_project_src else "truncated") |
31 | | - |
32 | | - output_using_packaged_src.mkdir(parents=True, exist_ok=True) |
33 | | - output_using_project.mkdir(parents=True, exist_ok=True) |
34 | | - |
35 | | - run_docker( |
36 | | - project_path=project_path, |
37 | | - package_whole_project_src=package_whole_project_src, |
38 | | - packaged_src_path=None, |
39 | | - contract_name=contract, |
40 | | - image="sdk-rust-contract-builder:next", |
41 | | - output_folder=output_using_project |
42 | | - ) |
43 | | - |
44 | | - packaged_src_path = output_using_project / f"{contract}/{contract}-0.0.0.source.json" |
45 | | - |
46 | | - run_docker( |
47 | | - project_path=None, |
48 | | - package_whole_project_src=package_whole_project_src, |
49 | | - packaged_src_path=packaged_src_path, |
50 | | - contract_name=contract, |
51 | | - image="sdk-rust-contract-builder:next", |
52 | | - output_folder=output_using_packaged_src |
53 | | - ) |
54 | | - |
55 | | - # Check that output folders are identical |
56 | | - using_project_output_files = sorted((output_using_project / contract).rglob("*")) |
57 | | - using_packaged_src_output_files = sorted((output_using_packaged_src / contract).rglob("*")) |
58 | | - |
59 | | - assert len(using_project_output_files) == len(using_packaged_src_output_files) |
60 | | - |
61 | | - for index, file in enumerate(using_project_output_files): |
62 | | - if not file.is_file() or file.suffix == ".zip": |
63 | | - continue |
64 | | - using_project_file_content = file.read_bytes() |
65 | | - using_packaged_src_file_content = using_packaged_src_output_files[index].read_bytes() |
66 | | - |
67 | | - if using_project_file_content != using_packaged_src_file_content: |
68 | | - raise Exception(f"Files differ ({contract}): {file.name}") |
| 33 | + output_using_project = parent_output_folder / "using-project" / contract / ("whole" if package_whole_project_src else "truncated") |
| 34 | + output_using_packaged_src = parent_output_folder / "using-packaged-src" / contract / ("whole" if package_whole_project_src else "truncated") |
| 35 | + |
| 36 | + shutil.rmtree(output_using_project, ignore_errors=True) |
| 37 | + shutil.rmtree(output_using_packaged_src, ignore_errors=True) |
| 38 | + |
| 39 | + output_using_project.mkdir(parents=True, exist_ok=True) |
| 40 | + output_using_packaged_src.mkdir(parents=True, exist_ok=True) |
| 41 | + |
| 42 | + run_docker( |
| 43 | + project_path=project_path, |
| 44 | + package_whole_project_src=package_whole_project_src, |
| 45 | + packaged_src_path=None, |
| 46 | + contract_name=contract, |
| 47 | + image="sdk-rust-contract-builder:next", |
| 48 | + output_folder=output_using_project |
| 49 | + ) |
| 50 | + |
| 51 | + packaged_src_path = output_using_project / f"{contract}/{contract}-0.0.0.source.json" |
| 52 | + |
| 53 | + run_docker( |
| 54 | + project_path=None, |
| 55 | + package_whole_project_src=package_whole_project_src, |
| 56 | + packaged_src_path=packaged_src_path, |
| 57 | + contract_name=contract, |
| 58 | + image="sdk-rust-contract-builder:next", |
| 59 | + output_folder=output_using_packaged_src |
| 60 | + ) |
| 61 | + |
| 62 | + # Check that output folders are identical |
| 63 | + using_project_output_files = sorted((output_using_project / contract).rglob("*")) |
| 64 | + using_packaged_src_output_files = sorted((output_using_packaged_src / contract).rglob("*")) |
| 65 | + |
| 66 | + assert len(using_project_output_files) == len(using_packaged_src_output_files) |
| 67 | + |
| 68 | + for index, file_using_project in enumerate(using_project_output_files): |
| 69 | + file_using_packaged_src = using_packaged_src_output_files[index] |
| 70 | + |
| 71 | + if not file_using_project.is_file() or file_using_project.suffix == ".zip": |
| 72 | + continue |
| 73 | + file_content_using_project = file_using_project.read_bytes() |
| 74 | + file_content_using_packaged_src = file_using_packaged_src.read_bytes() |
| 75 | + |
| 76 | + if file_content_using_project == file_content_using_packaged_src: |
| 77 | + print(f"Files are identical ({contract}): {file_using_project.name}") |
| 78 | + else: |
| 79 | + print(f"Files differ ({contract}):") |
| 80 | + print(f" {file_using_project}") |
| 81 | + print(f" {file_using_packaged_src}") |
| 82 | + raise Exception(f"Files differ ({contract}): {file_using_project.name}") |
69 | 83 |
|
70 | 84 |
|
71 | 85 | if __name__ == "__main__": |
|
0 commit comments