Skip to content

Commit

Permalink
test: add alliance test
Browse files Browse the repository at this point in the history
  • Loading branch information
duvbell committed Jan 2, 2024
1 parent ddc44e5 commit 91895ac
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ test-tokenfactory:
@echo "Testing tokenfactory..."
./scripts/tests/tokenfactory/tokenfactory.sh

test-alliance:
@echo "Testing alliance..."
./scripts/tests/alliance/delegate.sh


clean-testing-data:
@echo "Killing terrad and removing previous data"
@echo "Killing migallod and removing previous data"
-@pkill $(BINARY) 2>/dev/null
-@pkill rly 2>/dev/null
-@pkill migalood_new 2>/dev/null
Expand Down
108 changes: 108 additions & 0 deletions scripts/tests/alliance/delegate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

echo ""
echo "#################################################"
echo "# Alliance: bridge funds and create an alliance #"
echo "#################################################"
echo ""

BINARY=migalood
CHAIN_DIR=$(pwd)/data

AMOUNT_TO_DELEGATE=10000000000
UWHALE_DENOM=uwhale
VAL_WALLET_1=$($BINARY keys show val1 -a --keyring-backend test --home $CHAIN_DIR/test-1)
VAL_WALLET_2=$($BINARY keys show val2 -a --keyring-backend test --home $CHAIN_DIR/test-2)

echo "Sending tokens from validator wallet on test-1 to validator wallet on test-2"
IBC_TRANSFER=$($BINARY tx ibc-transfer transfer transfer channel-0 $VAL_WALLET_2 $AMOUNT_TO_DELEGATE$UWHALE_DENOM --chain-id test-1 --from $VAL_WALLET_1 --home $CHAIN_DIR/test-1 --fees 60000$UWHALE_DENOM --node tcp://localhost:16657 --keyring-backend test -y -o json | jq -r '.raw_log' )

if [[ "$IBC_TRANSFER" == "failed to execute message"* ]]; then
echo "Error: IBC transfer failed, with error: $IBC_TRANSFER"
exit 1
fi

ACCOUNT_BALANCE=""
IBC_DENOM=""
while [ "$ACCOUNT_BALANCE" == "" ]; do
IBC_DENOM=$($BINARY q bank balances $VAL_WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.balances[0].denom')
IBC_QUERY=$($BINARY q bank balances $VAL_WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json)

echo $IBC_QUERY
if [ "$IBC_DENOM" != "$UWHALE_DENOM" ]; then
ACCOUNT_BALANCE=$($BINARY q bank balances $VAL_WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.balances[0].amount')
fi
sleep 2
done

GOV_ADDRESS=$($BINARY query auth module-account gov --output json | jq .account.base_account.address -r)
echo '{
"messages": [
{
"@type": "/alliance.alliance.MsgCreateAlliance",
"authority" : "'"$GOV_ADDRESS"'",
"denom": "'"$IBC_DENOM"'",
"reward_weight": "0.3",
"take_rate": "0.01",
"reward_change_rate": "0.01",
"reward_change_interval": "10s",
"reward_weight_range": {
"min":"0.0001",
"max":"0.3"
}
}
],
"metadata": "",
"deposit": "25000000000'$UWHALE_DENOM'",
"title": "Create an Alliance!",
"summary": "Source Code Version https://github.com/terra-money/core"
}' > $CHAIN_DIR/create-alliance.json


echo "Creating an alliance with the denom $IBC_DENOM"
PROPOSAL_HEIGHT=$($BINARY tx gov submit-proposal $CHAIN_DIR/create-alliance.json --from=$VAL_WALLET_2 --home $CHAIN_DIR/test-2 --node tcp://localhost:26657 -o json --keyring-backend test --fees 60000$UWHALE_DENOM -y | jq -r '.height')
sleep 3


PROPOSAL_ID=$($BINARY query gov proposals --home $CHAIN_DIR/test-2 --count-total --node tcp://localhost:26657 -o json --output json --chain-id=test-2 | jq .proposals[-1].id -r)


VOTE_RES=$($BINARY tx gov vote $PROPOSAL_ID yes --from=$VAL_WALLET_2 --home $CHAIN_DIR/test-2 --keyring-backend=test --fees 60000$UWHALE_DENOM --chain-id=test-2 --node tcp://localhost:26657 -o json -y)
echo "Vote res: $VOTE_RES"

ALLIANCE="null"
while [ "$ALLIANCE" == "null" ]; do
echo "Waiting for alliance with denom $IBC_DENOM to be created"
ALLIANCE=$($BINARY q alliance alliances --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.alliances[0]')
ALLIANCE_QUERY=$($BINARY q alliance alliances --chain-id test-2 --node tcp://localhost:26657 -o json)
echo $ALLIANCE_QUERY

sleep 2
done

echo "Delegating $AMOUNT_TO_DELEGATE to the alliance $IBC_DENOM"
VAL_ADDR=$($BINARY query staking validators --output json | jq .validators[0].operator_address --raw-output)
DELEGATE_RES=$($BINARY tx alliance delegate $VAL_ADDR $AMOUNT_TO_DELEGATE$IBC_DENOM --from=node0 --from=$VAL_WALLET_2 --home $CHAIN_DIR/test-2 --keyring-backend=test --fees 60000$UWHALE_DENOM --chain-id=test-2 -o json -y)
sleep 3
DELEGATIONS=$($BINARY query alliance delegation $VAL_WALLET_2 $VAL_ADDR $IBC_DENOM --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.delegation.balance.amount')
if [[ "$DELEGATIONS" == "0" ]]; then
echo "Error: Alliance delegations expected to be greater than 0"
exit 1
fi

echo "Query bank balance after alliance creation"
TOTAL_SUPPLY_BEFORE_ALLIANCE=$($BINARY query bank total --denom $UWHALE_DENOM --height $PROPOSAL_HEIGHT -o json | jq -r '.amount')
TOTAL_SUPPLY_AFTER_ALLIANCE=$($BINARY query bank total --denom $UWHALE_DENOM -o json | jq -r '.amount')
TOTAL_SUPPLY_INCREMENT=$(($TOTAL_SUPPLY_BEFORE_ALLIANCE - $TOTAL_SUPPLY_AFTER_ALLIANCE))


if [ "$TOTAL_SUPPLY_INCREMENT" -gt 100000 ] && [ "$TOTAL_SUPPLY_INCREMENT" -lt 1000000 ]; then
echo "Error: Something went wrong, total supply of $UWHALE_DENOM has increased out of range 100_000 between 1_000_000. current value $TOTAL_SUPPLY_INCREMENT"
exit 1
fi

echo ""
echo "#########################################################"
echo "# Success: Alliance bridge funds and create an alliance #"
echo "#########################################################"
echo ""
3 changes: 2 additions & 1 deletion scripts/tests/init-test-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ update_test_genesis () {
update_test_genesis ".app_state[\"staking\"][\"params\"][\"bond_denom\"]=\"$DENOM\""
update_test_genesis ".app_state[\"mint\"][\"params\"][\"mint_denom\"]=\"$DENOM\""
update_test_genesis ".app_state[\"crisis\"][\"constant_fee\"][\"denom\"]=\"$DENOM\""
update_test_genesis ".app_state[\"gov\"][\"deposit_params\"][\"min_deposit\"][0][\"denom\"]=\"$DENOM\""
update_test_genesis ".app_state[\"gov\"][\"params\"][\"min_deposit\"][0][\"denom\"]=\"$DENOM\""
update_test_genesis ".app_state[\"tokenfactory\"][\"params\"][\"denom_creation_fee\"][0][\"denom\"]=\"$DENOM\""
update_test_genesis


# Starting the chain
Expand Down
1 change: 1 addition & 0 deletions scripts/tests/tokenfactory/tokenfactory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ while [ "$IBC_RECEIVED_RES_AMOUNT" != "1" ] || [ "${IBC_RECEIVED_RES_DENOM:0:4}"
sleep 2
IBC_RECEIVED_RES_AMOUNT=$($BINARY query bank balances $WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.balances[0].amount')
IBC_RECEIVED_RES_DENOM=$($BINARY query bank balances $WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.balances[0].denom')

echo "Received:" $IBC_RECEIVED_RES_AMOUNT $IBC_RECEIVED_RES_DENOM
done

Expand Down

0 comments on commit 91895ac

Please sign in to comment.