diff --git a/scripts/test_env.py b/scripts/test_env.py index 65b2266c3ca..f6463040a1f 100755 --- a/scripts/test_env.py +++ b/scripts/test_env.py @@ -134,6 +134,35 @@ def run(self, is_genesis: bool = False): subprocess.Popen([self.name, genesis_arg], executable=f"{self.out_dir}/peers/iroha", stdout=log_file, stderr=subprocess.STDOUT) +def initialize_test_smart_contracts(root_dir: pathlib.Path, out_dir: pathlib.Path): + """ + Function to make directory called smartcontracts, build every integeration smartcontract, + the it moves the result WASM file to the smartcontracts directory. + """ + smartcontracts_dir = out_dir / "smartcontracts" + os.makedirs(smartcontracts_dir, exist_ok=True) + source_dir = pathlib.Path("./client/tests/integration/smartcontracts") + + #Iterate through every smartcontract in the inte + for folder in [f for f in source_dir.iterdir() if f.is_dir()]: + folder_name = folder.name + if folder_name == ".cargo": + continue + # Path of the output .wasm file + wasm_file_name = f"{folder_name}.wasm" + wasm_file_path = root_dir / wasm_file_name + + # Build the smart contracts in the root director + subprocess.run([ + "cargo", "run", "--bin", "iroha_wasm_builder_cli", "--", "build", + str(folder), "--optimize", "--outfile", str(wasm_file_path) + ]) + + # Move the .wasm file to the smarts contracts folder + if wasm_file_path.exists(): + shutil.move(str(wasm_file_path), str(smartcontracts_dir / wasm_file_name)) + + def pos_int(arg): if int(arg) > 0: return int(arg) @@ -181,6 +210,7 @@ def main(args: argparse.Namespace): def setup(args: argparse.Namespace): logging.info(f"Starting iroha network with {args.n_peers} peers...") os.makedirs(args.out_dir, exist_ok=True) + initialize_test_smart_contracts(args.root_dir, args.out_dir) copy_or_prompt_build_bin("iroha_client_cli", args.root_dir, args.out_dir) with open(os.path.join(args.out_dir, "metadata.json"), "w") as f: f.write('{"comment":{"String": "Hello Meta!"}}')