Skip to content

Commit

Permalink
feat: run preupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
duvbell committed Apr 2, 2024
1 parent eae022e commit 0898bf1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 68 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,14 @@ ictest-push-wasm:

include contrib/make/release.mk


test-upgrade: clean-testing-data
@echo "Starting upgrade test"
./scripts/tweak-test-upgrade.sh


clean-testing-data:
@echo "Killing binary and removing previous data"
-@pkill centaurid 2>/dev/null
-@rm -rf ./mytestnet

8 changes: 5 additions & 3 deletions scripts/localnode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ $BINARY gentx $KEY 1000000000000000000000$DENOM --keyring-backend $KEYRING --ch

update_test_genesis '.app_state["gov"]["params"]["voting_period"]="50s"'
update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"'
update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "0"}]'
update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1000000"}]'
update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}'
update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"'

# sed -i 's/timeout_commit = "5s"/timeout_commit = "500ms"/' $HOME_DIR/config/config.toml

echo "updating.."
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "500ms"/' $HOME_DIR/config/config.toml


# Collect genesis tx
$BINARY collect-gentxs --home $HOME_DIR
Expand All @@ -66,6 +69,5 @@ fi
# update request max size so that we can upload the light client
# '' -e is a must have params on mac, if use linux please delete before run
sed -i'' -e 's/max_body_bytes = /max_body_bytes = 1/g' $HOME_DIR/config/config.toml

# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
$BINARY start --pruning=nothing --minimum-gas-prices=0.0001ppica --rpc.laddr tcp://0.0.0.0:26657 --home $HOME_DIR --log_level debug
$BINARY start --pruning=nothing --minimum-gas-prices=0$DENOM --rpc.laddr tcp://0.0.0.0:26657 --home $HOME_DIR --log_level debug
25 changes: 13 additions & 12 deletions scripts/tweak-test-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ROOT=$(pwd)
DENOM=upica
CHAIN_ID=localpica
SOFTWARE_UPGRADE_NAME="v7_0_1"
ADDITIONAL_PRE_SCRIPTS=""
ADDITIONAL_AFTER_SCRIPTS=""
ADDITIONAL_PRE_SCRIPTS="./scripts/upgrade/v6_to_7/pre_08_wasm.sh"
ADDITIONAL_AFTER_SCRIPTS="./scripts/upgrade/v6_to_7/post_08_wasm.sh"

SLEEP_TIME=1

Expand Down Expand Up @@ -51,14 +51,15 @@ if ! command -v _build/new/centaurid &> /dev/null || [[ "$FORCE_BUILD" == "true"
fi

# run old node
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "running old node"
bash scripts/localnode.sh _build/old/centaurid $DENOM
else
node1 bash scripts/localnode.sh _build/old/centaurid $DENOM
fi
# if [[ "$OSTYPE" == "darwin"* ]]; then

# else
# screen node1 bash scripts/localnode.sh _build/old/centaurid $DENOM
# fi
echo "running old node"
screen -dms old-node bash scripts/localnode.sh _build/old/centaurid $DENOM

sleep 5 # wait for note to start
sleep 2 # wait for note to start

# execute additional pre scripts
if [ ! -z "$ADDITIONAL_PRE_SCRIPTS" ]; then
Expand All @@ -68,8 +69,8 @@ if [ ! -z "$ADDITIONAL_PRE_SCRIPTS" ]; then
# check if SCRIPT is a file
if [ -f "$SCRIPT" ]; then
echo "executing additional pre scripts from $SCRIPT"
source $SCRIPT _build/old/centaurid
sleep 5
source $SCRIPT
sleep 2
else
echo "$SCRIPT is not a file"
fi
Expand Down Expand Up @@ -157,7 +158,7 @@ sleep 1
# run new node
echo -e "\n\n=> =>continue running nodes after upgrade"
if [[ "$OSTYPE" == "darwin"* ]]; then
CONTINUE="true" bash scripts/localnode.sh _build/new/centaurid $DENOM
screen -L -dmS new-node CONTINUE="true" bash scripts/localnode.sh _build/new/centaurid $DENOM
else
CONTINUE="true" bash scripts/localnode.sh _build/new/centaurid $DENOM
fi
Expand Down
65 changes: 12 additions & 53 deletions scripts/upgrade/v6_to_7/pre_08_wasm.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,19 @@
echo -e "\n ********** Running Pre 08_wasm scripts **********"
echo "---> running pre_08_wasm.sh"
#!/bin/bash
KEY="mykey"
KEYALGO="secp256k1"
KEYRING="test"
HOME_DIR="mytestnet"

BINARY=$1
DENOM=${2:-upica}
CHAIN_DIR=$(pwd)/mytestnet

KEY="test0"
KEY1="test1"
KEY2="test2"

# validate dependencies are installed
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; }

DEFAULT_GAS_FLAG="--gas 3000000 --gas-prices 0.025$DENOM --gas-adjustment 1.5"
DEFAULT_ENV_FLAG="--keyring-backend test --chain-id localpica --home $CHAIN_DIR"

stat $(pwd)/contracts/ics10_grandpa_cw.wasm
./_build/old/centaurid tx 08-wasm push-wasm $(pwd)/contracts/ics10_grandpa_cw.wasm --from=mykey --gas 10002152622 --fees 10020166upica --keyring-backend test --chain-id=localpica -y --home $HOME_DIR

sleep 3

echo "binary value: $BINARY"
COUNTER_CONTRACT_DIR=$(pwd)/scripts/upgrade/contracts/counter.wasm

WALLET_1=$($BINARY keys show $KEY1 -a --keyring-backend test --home $CHAIN_DIR)
BALANCE_1=$($BINARY query bank balances $WALLET_1 --home $CHAIN_DIR -o json | jq -r '.balances[0].amount')
echo "wallet 1: $WALLET_1 - balance: $BALANCE_1"


############ Settingup WASM environment ############
### Create a counter contract, then increment the counter to 1 ####
## Deploy the counter contract
TX_HASH=$($BINARY tx wasm store $COUNTER_CONTRACT_DIR --from $KEY1 $DEFAULT_ENV_FLAG $DEFAULT_GAS_FLAG -y -o json | jq -r '.txhash')

## Get CODE ID
sleep 1
CODE_ID=$($BINARY query tx $TX_HASH -o json | jq -r '.logs[0].events[1].attributes[1].value')
echo "code id: $CODE_ID"

## Get contract address
# NOTE: CAN USE https://github.com/CosmWasm/wasmd/blob/9e44af168570391b0b69822952f206d35320d473/contrib/local/02-contracts.sh#L38 instantiate2 to predict address
RANDOM_HASH=$(hexdump -vn16 -e'4/4 "%08X" 1 "\n"' /dev/urandom)
TX_HASH=$($BINARY tx wasm instantiate2 $CODE_ID '{"count": 0}' $RANDOM_HASH --no-admin --label="Label with $RANDOM_HASH" --from $KEY1 $DEFAULT_ENV_FLAG $DEFAULT_GAS_FLAG -y -o json | jq -r '.txhash')

sleep 1
CONTRACT_ADDRESS=$($BINARY query tx $TX_HASH -o json | jq -r '.logs[0].events[1].attributes[0].value')
echo "Contract address deployed at: $CONTRACT_ADDRESS"

## Execute the contract, increment counter to 1
echo "wallet1: call the increment() function"
$BINARY tx wasm execute $CONTRACT_ADDRESS '{"increment":{}}' --from $KEY1 $DEFAULT_ENV_FLAG $DEFAULT_GAS_FLAG -y -o json > /dev/null

## assert counter value to be 1
sleep 1
echo "wallet1: call the get_count() function"
$BINARY query wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{"addr": "'"$WALLET_1"'"}}' -o json
COUNTER_VALUE=$($BINARY query wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{"addr": "'"$WALLET_1"'"}}' -o json | jq -r '.data.count')
if [ "$COUNTER_VALUE" -ne 1 ]; then
echo "Assertion failed: Expected counter value to be 1, got $COUNTER_VALUE"
exit 1
fi
echo "Assertion passed: Counter value is 1 as expected"

export CONTRACT_ADDRESS=$CONTRACT_ADDRESS

./_build/old/centaurid query 08-wasm all-wasm-code --home $HOME_DIR

0 comments on commit 0898bf1

Please sign in to comment.