Skip to content

Commit

Permalink
[ci] #4151: Enhance the test environment by automatically generating …
Browse files Browse the repository at this point in the history
…WASM files for the smartcontracts to be tested (#4187)

[add] generate_wasm.sh to generate WASM files of the smart contracts

Signed-off-by: Asem-Abdelhady <[email protected]>

---------

Signed-off-by: Asem-Abdelhady <[email protected]>
  • Loading branch information
Asem-Abdelhady authored Jan 22, 2024
1 parent ba7577e commit 57f87af
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ result
/test/
/iroha-java/
/lcov.info
**/test-smartcontracts/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

</details>

Expand Down
28 changes: 28 additions & 0 deletions scripts/generate_wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

# Default source directory
DEFAULT_SOURCE_DIR="client/tests/integration/smartcontracts"

# 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
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."

0 comments on commit 57f87af

Please sign in to comment.