From 38fd1aee33ec3b8110dad78c73c73e122a175f04 Mon Sep 17 00:00:00 2001 From: Asem-Abdelhady Date: Wed, 17 Jan 2024 13:52:57 +0300 Subject: [PATCH 1/3] Revert scripts/test_env.py to the original state Signed-off-by: Asem-Abdelhady --- scripts/test_env.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test_env.py b/scripts/test_env.py index 65b2266c3ca..8cf64a5a8d2 100755 --- a/scripts/test_env.py +++ b/scripts/test_env.py @@ -131,8 +131,8 @@ def run(self, is_genesis: bool = False): # FD never gets closed log_file = open(peer_dir.joinpath(".log"), "w") # These processes are created detached from the parent process already - subprocess.Popen([self.name, genesis_arg], executable=f"{self.out_dir}/peers/iroha", - stdout=log_file, stderr=subprocess.STDOUT) + subprocess.Popen([self.name] + (["--submit-genesis"] if submit_genesis else []), + executable=f"{self.out_dir}/peers/iroha", env=peer_env, stdout=stdout_file, stderr=stderr_file) def pos_int(arg): if int(arg) > 0: From 6535ae1e3940eeb2afd9cf0d7a35cbf36599d1ac Mon Sep 17 00:00:00 2001 From: Asem-Abdelhady Date: Wed, 17 Jan 2024 18:11:44 +0300 Subject: [PATCH 2/3] [change] generation script to be a separate shell script Signed-off-by: Asem-Abdelhady --- .gitignore | 1 + scripts/generate_wasm.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 scripts/generate_wasm.sh diff --git a/.gitignore b/.gitignore index c17e43995f8..3aa0264ee2f 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ result /test/ /iroha-java/ /lcov.info +**/test-smartcontracts/ diff --git a/scripts/generate_wasm.sh b/scripts/generate_wasm.sh new file mode 100755 index 00000000000..74c20e4dc9d --- /dev/null +++ b/scripts/generate_wasm.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# First argument is the source directory +SOURCE_DIR="$1" + +TARGET_DIR="test-smartcontracts" + +mkdir -p "$TARGET_DIR" + +for folder in "$SOURCE_DIR"/**; do + if [ -d "$folder" ] && [ "$(basename "$folder")" != ".cargo" ]; then + + folder_name=$(basename "$folder") + target_wasm_file_path="${TARGET_DIR}/${folder_name}.wasm" + # Build the smart contracts + cargo run --bin iroha_wasm_builder_cli -- build "$folder" --optimize --outfile "$target_wasm_file_path" + + fi +done + +echo "Smart contracts build complete." + +# How to run: +# make sure you root from the root directrory if iroha or +# any iroha directory that is not a package in the working space +# run the following command: +# ./path/to/script/generate_wasm.sh /path/to/smart_contracts From 7d0fa0a92accd32ddf6a02234cf2874110617aa5 Mon Sep 17 00:00:00 2001 From: Asem-Abdelhady Date: Fri, 19 Jan 2024 12:28:27 +0300 Subject: [PATCH 3/3] [change] README to include steps of running generate_wasm.sh Signed-off-by: Asem-Abdelhady --- README.md | 7 +++++++ scripts/generate_wasm.sh | 24 ++++++++++-------------- scripts/test_env.py | 4 ++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 237481c5a48..906012f405f 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,13 @@ bash ./scripts/test_env.sh setup bash ./scripts/tests/register_mint_quantity.sh bash ./scripts/test_env.sh cleanup ``` +To generate WASM files for smart contracts, use the provided script `generate_wasm.sh`. If you are in the root directory of iroha run the following command: + +```bash +bash ./scripts/generate_wasm.sh [path/to/smartcontracts] +``` + +The generated WASM files will be saved in a generated directory `test-smartcontracts`, relative to your current working directory. The default path for smart contracts in this project is `client/tests/integration/smartcontracts`. diff --git a/scripts/generate_wasm.sh b/scripts/generate_wasm.sh index 74c20e4dc9d..e693108933f 100755 --- a/scripts/generate_wasm.sh +++ b/scripts/generate_wasm.sh @@ -1,18 +1,20 @@ -#!/bin/bash +#!/bin/sh -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi +# Default source directory +DEFAULT_SOURCE_DIR="client/tests/integration/smartcontracts" -# First argument is the source directory -SOURCE_DIR="$1" +# If no arguments are provided, use the default source directory +if [ "$#" -eq 0 ]; then + SOURCE_DIR="$DEFAULT_SOURCE_DIR" +else + SOURCE_DIR="$1" +fi TARGET_DIR="test-smartcontracts" mkdir -p "$TARGET_DIR" -for folder in "$SOURCE_DIR"/**; do +for folder in "$SOURCE_DIR"/*; do if [ -d "$folder" ] && [ "$(basename "$folder")" != ".cargo" ]; then folder_name=$(basename "$folder") @@ -24,9 +26,3 @@ for folder in "$SOURCE_DIR"/**; do done echo "Smart contracts build complete." - -# How to run: -# make sure you root from the root directrory if iroha or -# any iroha directory that is not a package in the working space -# run the following command: -# ./path/to/script/generate_wasm.sh /path/to/smart_contracts diff --git a/scripts/test_env.py b/scripts/test_env.py index 8cf64a5a8d2..65b2266c3ca 100755 --- a/scripts/test_env.py +++ b/scripts/test_env.py @@ -131,8 +131,8 @@ def run(self, is_genesis: bool = False): # FD never gets closed log_file = open(peer_dir.joinpath(".log"), "w") # These processes are created detached from the parent process already - subprocess.Popen([self.name] + (["--submit-genesis"] if submit_genesis else []), - executable=f"{self.out_dir}/peers/iroha", env=peer_env, stdout=stdout_file, stderr=stderr_file) + subprocess.Popen([self.name, genesis_arg], executable=f"{self.out_dir}/peers/iroha", + stdout=log_file, stderr=subprocess.STDOUT) def pos_int(arg): if int(arg) > 0: