From f710573199c7cc83acad77c78988b2804a224132 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 18 Feb 2022 16:35:34 +0400 Subject: [PATCH] [feature] #1902: Bare metal 4-peer setup script. Signed-off-by: Aleksandr --- .gitignore | 2 +- scripts/API/java.sh | 16 +++ scripts/cleanup_docker_test_env.sh | 3 - scripts/cleanup_iroha2_java_api.sh | 2 - scripts/setup_docker_test_env.sh | 7 -- scripts/setup_test_env.sh | 147 ++++++++++++++++++++++++ scripts/test_docker_compose.sh | 13 --- scripts/test_genesis_docker_compose.sh | 5 - scripts/test_iroha2_java_api.sh | 7 -- scripts/tests/genesis.sh | 6 + scripts/tests/register_mint_quantity.sh | 13 +++ test_js/config.json | 42 ------- test_js/genesis.json | 98 ---------------- 13 files changed, 183 insertions(+), 178 deletions(-) create mode 100644 scripts/API/java.sh delete mode 100755 scripts/cleanup_docker_test_env.sh delete mode 100755 scripts/cleanup_iroha2_java_api.sh delete mode 100755 scripts/setup_docker_test_env.sh create mode 100644 scripts/setup_test_env.sh delete mode 100755 scripts/test_docker_compose.sh delete mode 100755 scripts/test_genesis_docker_compose.sh delete mode 100755 scripts/test_iroha2_java_api.sh create mode 100644 scripts/tests/genesis.sh create mode 100644 scripts/tests/register_mint_quantity.sh delete mode 100644 test_js/config.json delete mode 100644 test_js/genesis.json diff --git a/.gitignore b/.gitignore index a96c5f63064..2c2aecf8c0a 100644 --- a/.gitignore +++ b/.gitignore @@ -43,5 +43,5 @@ cmake-build* *.deb \#* -/test_docker /cargo-timing*.html +/test/ diff --git a/scripts/API/java.sh b/scripts/API/java.sh new file mode 100644 index 00000000000..f6e03f9d321 --- /dev/null +++ b/scripts/API/java.sh @@ -0,0 +1,16 @@ +#!/bin/bash +case $1 in + setup) + mkdir iroha_api_test + cd iroha_api_test || exit + git clone https://github.com/hyperledger/iroha-java.git + cd iroha-java || exit + git checkout iroha2-java + ;; + run) + ./gradlew build + ;; + cleanup) + rm -rf iroha_api_test + ;; +esac diff --git a/scripts/cleanup_docker_test_env.sh b/scripts/cleanup_docker_test_env.sh deleted file mode 100755 index c7bab6c7205..00000000000 --- a/scripts/cleanup_docker_test_env.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -rm test_docker -r -f -docker-compose rm -s -f diff --git a/scripts/cleanup_iroha2_java_api.sh b/scripts/cleanup_iroha2_java_api.sh deleted file mode 100755 index bab7581bcce..00000000000 --- a/scripts/cleanup_iroha2_java_api.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -rm -rf iroha_api_test diff --git a/scripts/setup_docker_test_env.sh b/scripts/setup_docker_test_env.sh deleted file mode 100755 index 6a38cd8e4c1..00000000000 --- a/scripts/setup_docker_test_env.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -mkdir test_docker -cp ./target/debug/iroha_client_cli test_docker -echo '{"comment":{"String": "Hello Meta!"}}' >test_docker/metadata.json -cp ./configs/client_cli/config.json test_docker -docker-compose up -d --force-recreate -sleep 10 diff --git a/scripts/setup_test_env.sh b/scripts/setup_test_env.sh new file mode 100644 index 00000000000..63a067bb3df --- /dev/null +++ b/scripts/setup_test_env.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +# Un-comment for debugging +set -ex + +TEST=${TEST:-"./test"} +HOST=${HOST:-"127.0.0.1"} +IROHA2_CONFIG_PATH="$TEST/peers/config.json" +IROHA2_GENESIS_PATH="$TEST/peers/genesis.json" + +# TODO: don't hard-code these, instead, generate them. +declare -A public_keys +public_keys[iroha0]='ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0' +public_keys[iroha1]='ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1' +public_keys[iroha2]='ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020' +public_keys[iroha3]='ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f' + +declare -A private_keys +private_keys[iroha0]='9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0' +private_keys[iroha1]='3bac34cda9e3763fa069c1198312d1ec73b53023b8180c822ac355435edc4a24cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1' +private_keys[iroha2]='1261a436d36779223d7d6cf20e8b644510e488e6a50bafd77a7485264d27197dfaca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020' +private_keys[iroha3]='a70dab95c7482eb9f159111b65947e482108cfe67df877bd8d3b9441a781c7c98e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f' + +declare -A p2p_ports +p2p_ports[iroha0]='1337' +p2p_ports[iroha1]='1338' +p2p_ports[iroha2]='1339' +p2p_ports[iroha3]='1340' + +declare -A api_ports +api_ports[iroha0]='8080' +api_ports[iroha1]='8081' +api_ports[iroha2]='8082' +api_ports[iroha3]='8083' + +declare -A telemetry_ports +telemetry_ports[iroha0]='8180' +telemetry_ports[iroha1]='8181' +telemetry_ports[iroha2]='8182' +telemetry_ports[iroha3]='8183' + +function trusted_peer_entry { + # This way it's easier to read when debugging the script + echo "{" + echo "\"address\": \"$HOST:${p2p_ports[$1]}\"," + echo -n "\"public_key\": \"${public_keys[$1]}\"" + echo -n "}" +} + +function generate_trusted_peers { + echo -n "[" + for iter in {0..2} + do + trusted_peer_entry "iroha$iter" + echo -n "," + done + trusted_peer_entry iroha3 + echo "]" +} + +SUMERAGI_TRUSTED_PEERS="$(generate_trusted_peers)" + +function set_up_peers_common { + PEERS="$TEST/peers" + mkdir -p "$PEERS" + cp ./configs/peer/{config.json,genesis.json} "$PEERS" + cp ./target/debug/iroha "$PEERS" || { + # TODO this can fail for other reasons as well. + echo 'Please build the `iroha` binary, by running:' + echo '`cargo build --bin iroha`' + exit 1 + } +} + +function bulk_export { + export TORII_P2P_ADDR + export TORII_API_URL + export TORII_TELEMETRY_URL + export IROHA_PUBLIC_KEY + export IROHA_PRIVATE_KEY + export SUMERAGI_TRUSTED_PEERS + export IROHA2_CONFIG_PATH + export IROHA2_GENESIS_PATH +} + +function run_peer () { + TORII_P2P_ADDR="$HOST:${p2p_ports[$1]}" + TORII_API_URL="$HOST:${api_ports[$1]}" + TORII_TELEMETRY_URL="$HOST:${telemetry_ports[$1]}" + IROHA_PUBLIC_KEY=${public_keys[$1]} + IROHA_PRIVATE_KEY="{ \"digest_function\": \"ed25519\", \"payload\": \"${private_keys[$1]}\" }" + exec -a "$1" "$TEST/peers/iroha" > "$TEST/peers/$1.log" "$2" & disown +} + +function run_4_peers { + run_peer iroha1 + run_peer iroha2 + run_peer iroha3 + run_peer iroha0 --submit-genesis +} + +function clean_up_peers { + # Note: We want an exact match, hence '^' in the beginning and '$' + # at the end. If any of the peers has stopped working we want to + # signal a failure, but kill all the remaining peers. + pkill '^iroha0$' & + pkill '^iroha1$' & + pkill '^iroha2$' & + pkill '^iroha3$' & +} + +case $1 in + + setup) + ## Set client up to communicate with the first peer. + mkdir "$TEST" || echo "$TEST Already exists" + cp ./target/debug/iroha_client_cli "$TEST" || { + echo 'Please build `iroha_client_cli` by running' + echo '`cargo build --bin iroha_client_cli`' + exit + } + echo '{"comment":{"String": "Hello Meta!"}}' >"$TEST/metadata.json" + cp ./configs/client_cli/config.json "$TEST" + case $2 in + docker) + docker compose up --force-recreate;; + *) + set_up_peers_common + bulk_export + run_4_peers + esac + ;; + + cleanup) + case $2 in + docker) + docker-compose rm -s -f;; + *) + clean_up_peers + esac + rm "$TEST" -r -f + ;; + + *) + echo 'Specify either `setup` or `cleanup`' + exit 1 +esac diff --git a/scripts/test_docker_compose.sh b/scripts/test_docker_compose.sh deleted file mode 100755 index 080b595936c..00000000000 --- a/scripts/test_docker_compose.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -ex -cd test_docker -./iroha_client_cli domain register --id="Soramitsu" --metadata="metadata.json" -sleep 2 -./iroha_client_cli account register --id="Alice@Soramitsu" --key="ed0120a753146e75b910ae5e2994dc8adea9e7d87e5d53024cfa310ce992f17106f92c" -sleep 2 -./iroha_client_cli asset register --id="XOR#Soramitsu" --value-type=Quantity -sleep 2 -./iroha_client_cli asset mint --account="Alice@Soramitsu" --asset="XOR#Soramitsu" --quantity="100" -sleep 2 -./iroha_client_cli asset get --account="Alice@Soramitsu" --asset="XOR#Soramitsu" | grep -q 'Quantity(100)' - diff --git a/scripts/test_genesis_docker_compose.sh b/scripts/test_genesis_docker_compose.sh deleted file mode 100755 index f7fac79af8b..00000000000 --- a/scripts/test_genesis_docker_compose.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -ex -cd test_docker -sleep 10 -./iroha_client_cli asset get --account alice@wonderland --asset 'rose#wonderland' | grep -q 'Quantity(13)' diff --git a/scripts/test_iroha2_java_api.sh b/scripts/test_iroha2_java_api.sh deleted file mode 100755 index 09ddc406914..00000000000 --- a/scripts/test_iroha2_java_api.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -mkdir iroha_api_test -cd iroha_api_test || exit -git clone https://github.com/hyperledger/iroha-java.git -cd iroha-java || exit -git checkout iroha2-java -./gradlew build diff --git a/scripts/tests/genesis.sh b/scripts/tests/genesis.sh new file mode 100644 index 00000000000..ffadec4655b --- /dev/null +++ b/scripts/tests/genesis.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -ex +TEST=${TEST:-"./test"} +CMD="$TEST/iroha_client_cli --config $TEST/config.json" +$CMD asset get --account alice@wonderland --asset 'rose#wonderland' | grep -q 'Quantity(13)' +sleep ${SLEEP:-10} diff --git a/scripts/tests/register_mint_quantity.sh b/scripts/tests/register_mint_quantity.sh new file mode 100644 index 00000000000..9838fb8f50e --- /dev/null +++ b/scripts/tests/register_mint_quantity.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ex +TEST=${TEST:-"./test"} +CMD="$TEST/iroha_client_cli --config $TEST/config.json" +$CMD domain register --id="Soramitsu" --metadata="$TEST/metadata.json" +sleep 2 +$CMD account register --id="Alice@Soramitsu" --key="ed0120a753146e75b910ae5e2994dc8adea9e7d87e5d53024cfa310ce992f17106f92c" +sleep 2 +$CMD asset register --id="XOR#Soramitsu" --value-type=Quantity +sleep 2 +$CMD asset mint --account="Alice@Soramitsu" --asset="XOR#Soramitsu" --quantity="100" +sleep 2 +$CMD asset get --account="Alice@Soramitsu" --asset="XOR#Soramitsu" | grep -q 'Quantity(100)' diff --git a/test_js/config.json b/test_js/config.json deleted file mode 100644 index 2c670a9ec24..00000000000 --- a/test_js/config.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "TORII": { - "P2P_ADDR": "127.0.0.1:1337", - "API_URL": "127.0.0.1:8080", - "TELEMETRY_URL": "127.0.0.1:8081" - }, - "SUMERAGI": { - "TRUSTED_PEERS": [ - { - "address": "127.0.0.1:1337", - "public_key": "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" - } - ], - "BLOCK_TIME_MS": 100, - "COMMIT_TIME_MS": 100, - "TX_RECEIPT_TIME_MS": 100, - "MAX_FAULTY_PEERS": 0 - }, - "KURA": { - "INIT_MODE": "strict", - "BLOCK_STORE_PATH": "./blocks" - }, - "LOGGER": { - "MAX_LOG_LEVEL": "DEBUG" - }, - "BLOCK_SYNC": { - "GOSSIP_PERIOD_MS": 10000, - "BATCH_SIZE": 4 - }, - "PUBLIC_KEY": "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0", - "PRIVATE_KEY": { - "digest_function": "ed25519", - "payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" - }, - "GENESIS": { - "ACCOUNT_PUBLIC_KEY": "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0", - "ACCOUNT_PRIVATE_KEY": { - "digest_function": "ed25519", - "payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" - } - } -} diff --git a/test_js/genesis.json b/test_js/genesis.json deleted file mode 100644 index d9c3e8a8a23..00000000000 --- a/test_js/genesis.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "transactions": [ - { - "isi": [ - { - "Register": { - "object": { - "Raw": { - "Identifiable": { - "Domain": { - "id": { - "name": "wonderland" - }, - "accounts": {}, - "asset_definitions": {}, - "metadata": {} - } - } - } - } - } - }, - { - "Register": { - "object": { - "Raw": { - "Identifiable": { - "NewAccount": { - "id": { - "name": "alice", - "domain_id": { - "name": "wonderland" - } - }, - "signatories": [ - "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" - ], - "metadata": {} - } - } - } - } - } - }, - { - "Register": { - "object": { - "Raw": { - "Identifiable": { - "AssetDefinition": { - "id": { - "name": "rose", - "domain_id": { - "name": "wonderland" - } - }, - "value_type": "Quantity", - "metadata": {}, - "mintable": true - } - } - } - } - } - }, - { - "Mint": { - "object": { - "Raw": { - "U32": 13 - } - }, - "destination_id": { - "Raw": { - "Id": { - "AssetId": { - "definition_id": { - "name": "rose", - "domain_id": { - "name": "wonderland" - } - }, - "account_id": { - "name": "alice", - "domain_id": { - "name": "wonderland" - } - } - } - } - } - } - } - } - ] - } - ] -}