Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test cases #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions scripts/tests/keyshare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ GENERATOR=ShareGenerator
BINARY=fairyringd
CHAIN_DIR=$(pwd)/data
CHAINID_1=fairyring_test_1
CHAINID_2=fairyring_test_2
BLOCK_TIME=5

WALLET_1=$($BINARY keys show wallet1 -a --keyring-backend test --home $CHAIN_DIR/$CHAINID_1)
WALLET_3=$($BINARY keys show wallet3 -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 () {
Expand Down Expand Up @@ -148,6 +148,16 @@ if [ "$KEYSHARE_HEIGHT" != "$TARGET_HEIGHT" ]; then
exit 1
fi

echo "Registered validator remove authorized address that does not exists on chain fairyring_test_1"
RESULT=$($BINARY tx keyshare delete-authorized-address $WALLET_3 --from $VALIDATOR_1 --gas-prices 1ufairy --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)
ERROR_MSG=$(echo "$RESULT" | jq -r '.raw_log')
if [[ "$ERROR_MSG" != *"target authorized address not found"* ]]; then
echo "ERROR: KeyShare module registered validator remove authorized address error. Expected target authorized address not found, got '$ERROR_MSG'"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')"
exit 1
fi

echo "Registered validator remove authorized address to submit key share on chain fairyring_test_1"
RESULT=$($BINARY tx keyshare delete-authorized-address $WALLET_1 --from $VALIDATOR_1 --gas-prices 1ufairy --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAINID_1 --node tcp://localhost:16657 --broadcast-mode sync --keyring-backend test -o json -y)
Expand Down Expand Up @@ -185,7 +195,7 @@ EXTRACTED_RESULT=$($GENERATOR derive $GENERATED_SHARE 1 $TARGET_HEIGHT)
EXTRACTED_SHARE=$(echo "$EXTRACTED_RESULT" | jq -r '.KeyShare')


echo "Registered validator submit valid key share on chain fairyring_test_1"
echo "Registered validator submit VALID key share on chain fairyring_test_1"
RESULT=$($BINARY tx keyshare send-keyshare $EXTRACTED_SHARE 1 $TARGET_HEIGHT --from $VALIDATOR_1 --gas-prices 1ufairy --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)
Expand All @@ -196,7 +206,34 @@ if [ "$RESULT_EVENT" != "keyshare-aggregated" ]; then
exit 1
fi

./scripts/tests/keyshareSender.sh $BINARY $CHAIN_DIR/$CHAINID_1 tcp://localhost:16657 $VALIDATOR_1 $CHAINID_1 $GENERATOR $GENERATED_SHARE > $CHAIN_DIR/keyshareSender.log 2>&1 &
CURRENT_BLOCK=$($BINARY query block --home $CHAIN_DIR/$CHAINID_1 --node tcp://localhost:16657 | jq -r '.block.header.height')

echo "Registered validator submit valid key share but with current block height on chain fairyring_test_1"
RESULT=$($BINARY tx keyshare send-keyshare $EXTRACTED_SHARE 1 $CURRENT_BLOCK --from $VALIDATOR_1 --gas-prices 1ufairy --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)
ERROR_MSG=$(echo "$RESULT" | jq -r '.raw_log')
if [[ "$ERROR_MSG" != *"key share height is lower than the current block height"* ]]; then
echo "ERROR: KeyShare module submit valid key share but with current block height from registered validator error. Expected to get a key share height is lower than the current block height error, got '$ERROR_MSG'"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')"
echo "$RESULT"
exit 1
fi

CURRENT_BLOCK=$($BINARY query block --home $CHAIN_DIR/$CHAINID_1 --node tcp://localhost:16657 | jq -r '.block.header.height')
NEW_TARGET_HEIGHT=$((CURRENT_BLOCK+3))

echo "Registered validator submit valid key share with target block + 2 on chain fairyring_test_1"
RESULT=$($BINARY tx keyshare send-keyshare $EXTRACTED_SHARE 1 $NEW_TARGET_HEIGHT --from $VALIDATOR_1 --gas-prices 1ufairy --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)
ERROR_MSG=$(echo "$RESULT" | jq -r '.raw_log')
if [[ "$ERROR_MSG" != *"key share height is higher than the current block height"* ]]; then
echo "ERROR: KeyShare module submit valid key share with target block height + 2 from registered validator error. Expected to get a key share height is higher than the current block height error, got '$ERROR_MSG'"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')"
echo "$RESULT"
exit 1
fi

echo "Query submitted key share on chain fairyring_test_1"
RESULT=$($BINARY query keyshare list-key-share --node tcp://localhost:16657 -o json)
Expand All @@ -220,6 +257,20 @@ if [ "$RESULT_HEIGHT" != "$TARGET_HEIGHT" ]; then
fi
echo "Key Share Successfully aggregated: '$RESULT_DATA'"

echo "Testing idle validator slashing logic"
STAKED=$(fairyringd q staking validators -o json --home $CHAIN_DIR/$CHAINID_1 --node tcp://localhost:16657 | jq -r '.validators[0].tokens')
echo "Validator staked amount before testing slash idle validator: $STAKED"

sleep 60

NEW_STAKED=$(fairyringd q staking validators -o json --home $CHAIN_DIR/$CHAINID_1 --node tcp://localhost:16657 | jq -r '.validators[0].tokens')
echo "Validator staked amount after being slashed because of idling: $NEW_STAKED"
if [ "$NEW_STAKED" -ge "$STAKED" ]; then
echo "ERROR: KeyShare module didn't slash idle validator"
exit 1
fi

./scripts/tests/keyshareSender.sh $BINARY $CHAIN_DIR/$CHAINID_1 tcp://localhost:16657 $VALIDATOR_1 $CHAINID_1 $GENERATOR $GENERATED_SHARE > $CHAIN_DIR/keyshareSender.log 2>&1 &

echo ""
echo "######################################################"
Expand Down
59 changes: 55 additions & 4 deletions scripts/tests/pep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ CHAINID_2=fairyring_test_2
CHAIN2_NODE=tcp://localhost:26657
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)
WALLET_2=$($BINARY keys show wallet2 -a --keyring-backend test --home $CHAIN_DIR/$CHAINID_2)
VALIDATOR_2=$($BINARY keys show val2 -a --keyring-backend test --home $CHAIN_DIR/$CHAINID_2)

Expand Down Expand Up @@ -102,6 +100,11 @@ echo "Sending 1 $TARGET_BAL_DENOM to target address"
$BINARY tx bank send $VALIDATOR_2 $WALLET_2 1$TARGET_BAL_DENOM --from $VALIDATOR_2 --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE --keyring-backend test --generate-only -o json -y > unsigned2.json
SIGNED_DATA_2=$($BINARY tx sign unsigned2.json --from $VALIDATOR_2 --offline --account-number 0 --sequence $PEP_NONCE_2ND --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE --keyring-backend test -y)

echo "Signing third bank send tx with pep nonce: 18446744073709551615 without gas fee"
echo "Sending 1 $TARGET_BAL_DENOM to target address"
$BINARY tx bank send $VALIDATOR_2 $WALLET_2 1$TARGET_BAL_DENOM --from $VALIDATOR_2 --gas-prices 1ufairy --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE --keyring-backend test --generate-only -o json -y > unsigned3.json
SIGNED_DATA_3=$($BINARY tx sign unsigned3.json --from $VALIDATOR_2 --offline --account-number 0 --sequence 18446744073709551615 --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE --keyring-backend test -y)


echo "Query aggregated key share from key share module for submitting to pep module on chain fairyring_test_1"
CURRENT_BLOCK=$($BINARY query block --home $CHAIN_DIR/$CHAINID_1 --node $CHAIN1_NODE | jq -r '.block.header.height')
Expand Down Expand Up @@ -141,12 +144,20 @@ fi
echo "Encrypting signed tx with Pub key: '$PUB_KEY'"
CIPHER=$($ENCRYPTER $AGG_KEY_HEIGHT $PUB_KEY $SIGNED_DATA)

ANOTHER_PUB_KEY=$($GENERATOR generate 1 1 | jq -r ".MasterPublicKey")

echo "Encrypting signed tx with another Pub key: '$ANOTHER_PUB_KEY'"
CIPHER_ANOTHER_PUB_KEY=$($ENCRYPTER $AGG_KEY_HEIGHT $ANOTHER_PUB_KEY $SIGNED_DATA_2)

echo "Encrypting 2nd signed tx with Pub key: '$PUB_KEY'"
CIPHER_2=$($ENCRYPTER $AGG_KEY_HEIGHT $PUB_KEY $SIGNED_DATA_2)

echo "Encrypting 3rd signed tx with Pub key: '$PUB_KEY'"
CIPHER_3=$($ENCRYPTER $AGG_KEY_HEIGHT $PUB_KEY $SIGNED_DATA_3)

rm -r unsigned.json &> /dev/null
rm -r unsigned2.json &> /dev/null
rm -r unsigned3.json &> /dev/null


RESULT=$($BINARY query bank balances $VALIDATOR_2 --node $CHAIN2_NODE -o json)
Expand Down Expand Up @@ -195,6 +206,46 @@ BAL_AMT=$(echo "$RESULT" | jq -r '.balances[0].amount')
echo "Balance after submitting second encrypted tx: $BAL_AMT$BAL_DENOM"


echo "Submit tx encrypted with another public key to pep module on chain fairyring_test_2"
RESULT=$($BINARY tx pep submit-encrypted-tx $CIPHER_ANOTHER_PUB_KEY $AGG_KEY_HEIGHT --from $VALIDATOR_2 --gas-prices 1ufairy --gas 300000 --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE --broadcast-mode sync --keyring-backend test -o json -y)
check_tx_code $RESULT
RESULT=$(wait_for_tx $RESULT)
EVENT_TYPE=$(echo "$RESULT" | jq -r '.logs[0].events[5].type')
TARGET_HEIGHT=$(echo "$RESULT" | jq -r '.logs[0].events[5].attributes[1].value')
if [ "$EVENT_TYPE" != "new-encrypted-tx-submitted" ] && [ "$TARGET_HEIGHT" != "$AGG_KEY_HEIGHT" ]; then
echo "ERROR: Pep module submit encrypted tx error. Expected tx to submitted without error with target height '$AGG_KEY_HEIGHT', got '$TARGET_HEIGHT' and '$EVENT_TYPE' | '$CURRENT_BLOCK'"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq '.')"
exit 1
fi


RESULT=$($BINARY query bank balances $VALIDATOR_2 --node $CHAIN2_NODE -o json)
BAL_DENOM=$(echo "$RESULT" | jq -r '.balances[0].denom')
BAL_AMT=$(echo "$RESULT" | jq -r '.balances[0].amount')
echo "Balance after submitting 3rd encrypted tx: $BAL_AMT$BAL_DENOM"


echo "Submit encrypted tx signed with max uint64 pep nonce to pep module on chain fairyring_test_2"
RESULT=$($BINARY tx pep submit-encrypted-tx $CIPHER_3 $AGG_KEY_HEIGHT --from $VALIDATOR_2 --gas-prices 1ufairy --gas 500000 --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE --broadcast-mode sync --keyring-backend test -o json -y)
check_tx_code $RESULT
RESULT=$(wait_for_tx $RESULT)
EVENT_TYPE=$(echo "$RESULT" | jq -r '.logs[0].events[5].type')
TARGET_HEIGHT=$(echo "$RESULT" | jq -r '.logs[0].events[5].attributes[1].value')
if [ "$EVENT_TYPE" != "new-encrypted-tx-submitted" ] && [ "$TARGET_HEIGHT" != "$AGG_KEY_HEIGHT" ]; then
echo "ERROR: Pep module submit encrypted tx error. Expected tx to submitted without error with target height '$AGG_KEY_HEIGHT', got '$TARGET_HEIGHT' and '$EVENT_TYPE' | '$CURRENT_BLOCK'"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq '.')"
exit 1
fi


RESULT=$($BINARY query bank balances $VALIDATOR_2 --node $CHAIN2_NODE -o json)
BAL_DENOM=$(echo "$RESULT" | jq -r '.balances[0].denom')
BAL_AMT=$(echo "$RESULT" | jq -r '.balances[0].amount')
echo "Balance after submitting 4th encrypted tx: $BAL_AMT$BAL_DENOM"


echo "Query account pep nonce after submitting encrypted tx from pep module on chain fairyring_test_2"
RESULT=$($BINARY query pep show-pep-nonce $VALIDATOR_2 --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE -o json)
VALIDATOR_PEP_NONCE=$(echo "$RESULT" | jq -r '.pepNonce.nonce')
Expand Down Expand Up @@ -233,8 +284,8 @@ fi
echo "Query account pep nonce after encrypted tx being processed from pep module on chain fairyring_test_2"
RESULT=$($BINARY query pep show-pep-nonce $VALIDATOR_2 --home $CHAIN_DIR/$CHAINID_2 --chain-id $CHAINID_2 --node $CHAIN2_NODE -o json)
VALIDATOR_PEP_NONCE=$(echo "$RESULT" | jq -r '.pepNonce.nonce')
if [ "$VALIDATOR_PEP_NONCE" != "3" ]; then
echo "ERROR: Pep module query Pep Nonce error. Expected Pep Nonce to be 3, got '$VALIDATOR_PEP_NONCE'"
if [ "$VALIDATOR_PEP_NONCE" != "18446744073709551615" ]; then
echo "ERROR: Pep module query Pep Nonce error. Expected Pep Nonce to be 18446744073709551615, got '$VALIDATOR_PEP_NONCE'"
echo "ERROR MESSAGE: $(echo "$RESULT" | jq -r '.raw_log')"
exit 1
fi
Expand Down
Loading