-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test tokenfactory and alliance
- Loading branch information
Showing
2 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/bin/bash | ||
|
||
echo "" | ||
echo "##########################################" | ||
echo "# Testing tokenfactory and alliance #" | ||
echo "##########################################" | ||
echo "" | ||
|
||
BINARY=migalood | ||
CHAIN_DIR=$(pwd)/data | ||
TOKEN_DENOM=utoken$RANDOM | ||
MINT_AMOUNT=100000000000 | ||
AMOUNT_TO_DELEGATE=10000000 | ||
UWHALE_DENOM=uwhale | ||
|
||
GAS=2000000 | ||
FEES=1000000uwhale | ||
|
||
WALLET_1=$($BINARY keys show wallet1 -a --keyring-backend test --home $CHAIN_DIR/test-1) | ||
VAL_WALLET_1=$($BINARY keys show val1 -a --keyring-backend test --home $CHAIN_DIR/test-1) | ||
|
||
# Test setup: Create a token denom with tokenfactory | ||
echo "Creating token denom $TOKEN_DENOM with $WALLET_1 on chain test-1" | ||
TX_HASH=$($BINARY tx tokenfactory create-denom $TOKEN_DENOM --from $WALLET_1 --home $CHAIN_DIR/test-1 --chain-id test-1 --node tcp://localhost:16657 --gas "$GAS" --fees "$FEES" --keyring-backend test -o json -y | jq -r '.txhash') | ||
sleep 3 | ||
CREATED_RES_DENOM=$($BINARY query tx $TX_HASH -o json --chain-id test-1 --home $CHAIN_DIR/test-1 --node tcp://localhost:16657 | jq -r '.logs[0].events[5].attributes[1].value') | ||
|
||
# Test case: Check if the token denom was created successfully | ||
if [ "$CREATED_RES_DENOM" != "factory/$WALLET_1/$TOKEN_DENOM" ]; then | ||
echo "ERROR: Tokenfactory creating denom error. Expected result 'factory/$WALLET_1/$TOKEN_DENOM', got '$CREATED_RES_DENOM'" | ||
exit 1 | ||
fi | ||
|
||
# Test setup: Create an alliance | ||
GOV_ADDRESS=$($BINARY query auth module-account gov --output json | jq .account.base_account.address -r) | ||
|
||
echo $GOV_ADDRESS | ||
echo '{ | ||
"messages": [ | ||
{ | ||
"@type": "/alliance.alliance.MsgCreateAlliance", | ||
"authority" : "'"$GOV_ADDRESS"'", | ||
"denom": "'"$CREATED_RES_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 $CREATED_RES_DENOM" | ||
PROPOSAL_HEIGHT=$($BINARY tx gov submit-proposal $CHAIN_DIR/create-alliance.json --from=$VAL_WALLET_1 --home $CHAIN_DIR/test-1 --node tcp://localhost:16657 -o json --keyring-backend test --fees 60000$UWHALE_DENOM -y | jq -r '.height') | ||
sleep 3 | ||
|
||
# Test case: Check if the alliance was created successfully | ||
PROPOSAL_ID=$($BINARY query gov proposals --home $CHAIN_DIR/test-1 --count-total --node tcp://localhost:16657 -o json --output json --chain-id=test-1 | jq .proposals[-1].id -r) | ||
if [ -z "$PROPOSAL_ID" ]; then | ||
echo "ERROR: Alliance creation failed. No proposal ID found." | ||
exit 1 | ||
fi | ||
|
||
|
||
VOTE_RES=$($BINARY tx gov vote $PROPOSAL_ID yes --from=$VAL_WALLET_1 --home $CHAIN_DIR/test-1 --keyring-backend=test --fees 60000$UWHALE_DENOM --chain-id=test-1 --node tcp://localhost:16657 -o json -y) | ||
echo "Vote res: $VOTE_RES" | ||
|
||
ALLIANCE="null" | ||
while [ "$ALLIANCE" == "null" ]; do | ||
echo "Waiting for alliance with denom $CREATED_RES_DENOM to be created" | ||
ALLIANCE=$($BINARY q alliance alliances --chain-id test-1 --node tcp://localhost:16657 -o json | jq -r '.alliances[0]') | ||
ALLIANCE_QUERY=$($BINARY q alliance alliances --chain-id test-1 --node tcp://localhost:16657 -o json) | ||
echo $ALLIANCE_QUERY | ||
|
||
sleep 2 | ||
done | ||
|
||
echo "Minting $MINT_AMOUNT units of $TOKEN_DENOM with $WALLET_1 on chain test-1" | ||
TX_HASH=$($BINARY tx tokenfactory mint $MINT_AMOUNT$CREATED_RES_DENOM --from $WALLET_1 --home $CHAIN_DIR/test-1 --chain-id test-1 --node tcp://localhost:16657 --gas "$GAS" --fees "$FEES" --keyring-backend test -o json -y | jq -r '.txhash') | ||
sleep 3 | ||
MINT_RES=$($BINARY query tx $TX_HASH -o json --chain-id test-1 --home $CHAIN_DIR/test-1 --node tcp://localhost:16657 | jq -r '.logs[0].events[2].type') | ||
if [ "$MINT_RES" != "coinbase" ]; then | ||
echo "ERROR: Tokenfactory minting error. Expected result 'coinbase', got '$CREATED_RES_DENOM'" | ||
exit 1 | ||
fi | ||
|
||
echo "Querying $CREATED_RES_DENOM from $WALLET_1 on chain test-1 to validate the amount minted" | ||
BALANCE_RES_AMOUNT=$($BINARY query bank balances $WALLET_1 --denom $CREATED_RES_DENOM --chain-id test-1 --node tcp://localhost:16657 -o json | jq -r '.amount') | ||
if [ "$BALANCE_RES_AMOUNT" != $MINT_AMOUNT ]; then | ||
echo "ERROR: Tokenfactory minting error. Expected minted balance '$MINT_AMOUNT', got '$BALANCE_RES_AMOUNT'" | ||
exit 1 | ||
fi | ||
|
||
echo "Delegating $AMOUNT_TO_DELEGATE to the alliance $CREATED_RES_DENOM" | ||
VAL_ADDR=$($BINARY query staking validators --node tcp://localhost:16657 --output json | jq .validators[0].operator_address --raw-output) | ||
DELEGATE_RES=$($BINARY tx alliance delegate $VAL_ADDR $AMOUNT_TO_DELEGATE$CREATED_RES_DENOM --from=$WALLET_1 --home $CHAIN_DIR/test-1 --keyring-backend=test --node tcp://localhost:16657 --fees 60000$UWHALE_DENOM --chain-id test-1 -o json -y) | ||
sleep 3 | ||
TX_HASH=$(echo $DELEGATE_RES | jq -r '.txhash') | ||
echo $TX_HASH | ||
TX_RES=$($BINARY query tx $TX_HASH -o json --chain-id test-1 --home $CHAIN_DIR/test-1 --node tcp://localhost:16657) | ||
echo $TX_RES | ||
|
||
|
||
DELEGATIONS=$($BINARY query alliance delegation $WALLET_1 $VAL_ADDR $CREATED_RES_DENOM --chain-id test-1 --node tcp://localhost:16657 -o json | jq -r '.delegation.balance.amount') | ||
|
||
while [ "$DELEGATIONS" == "0" ]; do | ||
echo "Waiting for delegate '$DELEGATIONS'" | ||
DELEGATIONS=$($BINARY query alliance delegation $WALLET_1 $VAL_ADDR $CREATED_RES_DENOM --chain-id test-1 --node tcp://localhost:16657 -o json | jq -r '.delegation.balance.amount') | ||
sleep 2 | ||
done | ||
|
||
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: Testing tokenfactory and alliance #" | ||
echo "###################################################" | ||
echo "" |