Skip to content

Commit

Permalink
[enhance]: Automate the smartcontracts generation in test environment
Browse files Browse the repository at this point in the history
Signed-off-by: Asem-Abdelhady <[email protected]>
  • Loading branch information
Asem-Abdelhady committed Jan 9, 2024
1 parent 6f2c04c commit 395591a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions scripts/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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!"}}')
Expand Down

0 comments on commit 395591a

Please sign in to comment.