From e11537fd9d97a65855af0b64771e2401cfd1b1ef Mon Sep 17 00:00:00 2001 From: p0p3yee Date: Tue, 8 Aug 2023 09:20:52 -0400 Subject: [PATCH] Add test block tx limit script --- Makefile | 9 +++ scripts/tests/blockTxLimit.sh | 104 ++++++++++++++++++++++++++++++++++ scripts/tests/start.sh | 8 ++- 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100755 scripts/tests/blockTxLimit.sh diff --git a/Makefile b/Makefile index 1401df37..2d674a7a 100644 --- a/Makefile +++ b/Makefile @@ -170,6 +170,11 @@ sync-docs: ### Integration Tests ### ############################################################################### +test-block-tx-limit: init-test-framework \ + test-tx-limit + -@rm -rf ./data + -@killall fairyringd 2>/dev/null + integration-test-all: init-test-framework \ init-relayer \ test-keyshare-module \ @@ -177,6 +182,10 @@ integration-test-all: init-test-framework \ -@rm -rf ./data -@killall fairyringd 2>/dev/null +test-tx-limit: + @echo "Testing Block tx limit..." + ./scripts/tests/blockTxLimit.sh + test-keyshare-module: @echo "Testing KeyShare module..." ./scripts/tests/keyshare.sh diff --git a/scripts/tests/blockTxLimit.sh b/scripts/tests/blockTxLimit.sh new file mode 100755 index 00000000..df2132c7 --- /dev/null +++ b/scripts/tests/blockTxLimit.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +GENERATOR=ShareGenerator +BINARY=fairyringd +CHAIN_DIR=$(pwd)/data +CHAINID_1=fairyring_test_1 +CHAINID_2=fairyring_test_2 +CHAIN1_NODE=tcp://localhost:16657 +BLOCK_TIME=5 + +WALLET_1=$($BINARY keys show wallet1 -a --keyring-backend test --home $CHAIN_DIR/$CHAINID_1) +VALIDATOR_1=$($BINARY keys show val1 -a --keyring-backend test --home $CHAIN_DIR/$CHAINID_1) + +check_tx_code () { + local TX_CODE=$(echo "$1" | jq -r '.code') + if [ "$TX_CODE" != 0 ]; then + echo "ERROR: Tx failed with code: $TX_CODE" + exit 1 + fi +} + +wait_for_tx () { + sleep $BLOCK_TIME + local TXHASH=$(echo "$1" | jq -r '.txhash') + RESULT=$($BINARY q tx --type=hash $TXHASH --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node $CHAIN1_NODE -o json) + echo "$RESULT" +} + + +GENERATED_RESULT=$($GENERATOR generate 1 1) +GENERATED_SHARE=$(echo "$GENERATED_RESULT" | jq -r '.Shares[0].Value') +PUB_KEY=$(echo "$GENERATED_RESULT" | jq -r '.MasterPublicKey') + + +echo "Staked account registering as a validator on chain fairyring_test_1" +RESULT=$($BINARY tx keyshare register-validator --from $VALIDATOR_1 --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node tcp://localhost:16657 --broadcast-mode sync --keyring-backend test -o json -y) +check_tx_code $RESULT +RESULT=$(wait_for_tx $RESULT) +VALIDATOR_ADDR=$(echo "$RESULT" | jq -r '.logs[0].events[1].attributes[0].value') +if [ "$VALIDATOR_ADDR" != "$VALIDATOR_1" ]; then + echo "ERROR: KeyShare module register validator error. Expected registered validator address '$VALIDATOR_1', got '$VALIDATOR_ADDR'" + echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')" + exit 1 +fi + + +echo "Trusted address submit pub key on chain fairyring_test_1" +RESULT=$($BINARY tx keyshare create-latest-pub-key $PUB_KEY --from $VALIDATOR_1 --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node $CHAIN1_NODE --broadcast-mode sync --keyring-backend test -o json -y) +check_tx_code $RESULT +RESULT=$(wait_for_tx $RESULT) +VALIDATOR_ADDR=$(echo "$RESULT" | jq -r '.logs[0].events[1].attributes[2].value') +if [ "$VALIDATOR_ADDR" != "$VALIDATOR_1" ]; then + echo "ERROR: KeyShare module submit pub key from trusted address error. Expected creator address '$VALIDATOR_1', got '$VALIDATOR_ADDR'" + echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')" + exit 1 +fi + + +ACCOUNT_INFO=$($BINARY query account $VALIDATOR_1 --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node $CHAIN1_NODE -o json) +ACCOUNT_NUMBER=$(echo $ACCOUNT_INFO | jq -r '.account_number') +ACCOUNT_SEQ=$(echo $ACCOUNT_INFO | jq -r '.sequence') + +echo "Testing Submit keyshare tx limit" +CURRENT_BLOCK=$($BINARY query block --home $CHAIN_DIR/$CHAINID_1 --node $CHAIN1_NODE | jq -r '.block.header.height') +echo "Current Block: $CURRENT_BLOCK" + +SUBMITTED_TX_HASH=() + +SUBMITTED=0 +while true +do + LATEST_BLOCK=$($BINARY query block --home $CHAIN_DIR/$CHAINID_1 --node $CHAIN1_NODE | jq -r '.block.header.height') + if [ "$LATEST_BLOCK" != "$CURRENT_BLOCK" ]; then + echo "1 Block passed, current block: $LATEST_BLOCK, submitted: $SUBMITTED" + + TX_HASH_LENGTH=${#SUBMITTED_TX_HASH[*]} + + echo "Total Tx Hash: $TX_HASH_LENGTH" + + sleep $BLOCK_TIME + + for EACH_TX_HASH in "${SUBMITTED_TX_HASH[@]}" + do + RESP=$($BINARY q tx --type=hash $EACH_TX_HASH --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node $CHAIN1_NODE -o json) + echo "Tx Hash: $EACH_TX_HASH confirmed at block $(echo $RESP | jq -r '.height') with code: $(echo $RESP | jq -r '.code')" + done + + break + fi + TARGET_HEIGHT=$(($CURRENT_BLOCK + $SUBMITTED)) + + EXTRACTED_RESULT=$($GENERATOR derive $GENERATED_SHARE 0 $TARGET_HEIGHT) + EXTRACTED_SHARE=$(echo "$EXTRACTED_RESULT" | jq -r '.KeyShare') + EXTRACTED_COMMITMENT=$(echo "$EXTRACTED_RESULT" | jq -r '.Commitment') + RESULT=$($BINARY tx keyshare send-keyshare $EXTRACTED_SHARE $EXTRACTED_COMMITMENT 0 $TARGET_HEIGHT --from $VALIDATOR_1 --offline --account-number $ACCOUNT_NUMBER --sequence $ACCOUNT_SEQ --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node $CHAIN1_NODE --broadcast-mode async --keyring-backend test -o json -y) + + TX_CODE=$(echo "$RESULT" | jq -r '.code') + TX_HASH=$(echo "$RESULT" | jq -r '.txhash') + echo "Tx Code: $TX_CODE, Tx Hash: $TX_HASH" + SUBMITTED_TX_HASH+=("$TX_HASH") + + SUBMITTED=$(($SUBMITTED+1)) + ACCOUNT_SEQ=$(($ACCOUNT_SEQ+1)) +done diff --git a/scripts/tests/start.sh b/scripts/tests/start.sh index db6ec3f8..44fcb179 100755 --- a/scripts/tests/start.sh +++ b/scripts/tests/start.sh @@ -29,6 +29,8 @@ GRPCPORT_2=9092 GRPCWEB_1=9091 GRPCWEB_2=9093 +BLOCK_TIME=5 + # Stop if it is already running if pgrep -x "$BINARY" >/dev/null; then echo "Terminating $BINARY..." @@ -98,8 +100,8 @@ $BINARY collect-gentxs --home $CHAIN_DIR/$CHAINID_2 &> /dev/null echo "Changing defaults and ports in app.toml and config.toml files..." sed -i -e 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT_1"'"#g' $CHAIN_DIR/$CHAINID_1/config/config.toml sed -i -e 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT_1"'"#g' $CHAIN_DIR/$CHAINID_1/config/config.toml -sed -i -e 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAINID_1/config/config.toml -sed -i -e 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAINID_1/config/config.toml +sed -i -e 's/timeout_commit = "5s"/timeout_commit = "5s"/g' $CHAIN_DIR/$CHAINID_1/config/config.toml +sed -i -e 's/timeout_propose = "3s"/timeout_propose = "5s"/g' $CHAIN_DIR/$CHAINID_1/config/config.toml sed -i -e 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAINID_1/config/config.toml sed -i -e 's/enable = false/enable = true/g' $CHAIN_DIR/$CHAINID_1/config/app.toml sed -i -e 's/swagger = false/swagger = true/g' $CHAIN_DIR/$CHAINID_1/config/app.toml @@ -152,7 +154,7 @@ rm rly1.json &> /dev/null rm rly2.json &> /dev/null echo "Waiting both chain to run..." -sleep 5 +sleep $BLOCK_TIME echo "Starting Hermes Relayer..." echo "Creating log file at $CHAIN_DIR/relayer.log"