Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from oraichain/update/gomod-testscript
Browse files Browse the repository at this point in the history
Update/gomod testscript
  • Loading branch information
tubackkhoa authored Feb 10, 2023
2 parents 9ea01c3 + 5a08d81 commit 1b6ea25
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/oraid

build:
go build $(BUILD_FLAGS) -o build/oraid ./cmd/oraid && cp build/oraid /bin/oraid
go build $(BUILD_FLAGS) -o build/oraid ./cmd/oraid

# the oraid binary will be built to the root directory of the project (if in docker container then it's workspace/oraid)

Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ services:
soft: 65536
hard: 65536
ports:
- 1317:1317
- 26656:26656
- 26657:26657
- 9090:9090
- 3317:1317
- 36656:26656
- 36657:26657
- 3090:9090
cap_add:
- SYS_PTRACE
env_file:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/CosmWasm/wasmd v1.0.0
github.com/cosmos/cosmos-sdk v0.45.13-rc.1
github.com/cosmos/cosmos-sdk v0.45.12
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v4 v4.3.0
github.com/cosmos/interchain-accounts v0.2.6
Expand Down Expand Up @@ -42,7 +42,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect
github.com/cosmos/gogoproto v1.4.3 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.5 // indirect
github.com/cosmos/iavl v0.19.4 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -688,17 +688,17 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44=
github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU=
github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0=
github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE=
github.com/cosmos/cosmos-sdk v0.45.13-rc.1 h1:FJkb/gMnvvtFaLSF+bG/Os0ORfpfbIBjx+CtVz+HfGw=
github.com/cosmos/cosmos-sdk v0.45.13-rc.1/go.mod h1:4ze6AkyAUwLq4DghwovfgoSLrA3XdLNydrO0JOWVwZE=
github.com/cosmos/cosmos-sdk v0.45.12 h1:Z0kOOjOfHP+loO42KZZo3Y+PAZsoYycyiSckVXzwOm4=
github.com/cosmos/cosmos-sdk v0.45.12/go.mod h1:ZAdIs09zttoA3aSwQCTK9gecOThUVNnzBSVj3DiS6UY=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogoproto v1.4.3 h1:RP3yyVREh9snv/lsOvmsAPQt8f44LgL281X0IOIhhcI=
github.com/cosmos/gogoproto v1.4.3/go.mod h1:0hLIG5TR7IvV1fme1HCFKjfzW9X2x0Mo+RooWXCnOWU=
github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y=
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY=
github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok=
github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go/v4 v4.3.0 h1:yOzVsyZzsv4XPBux8gq+D0LhZn45yGWKjvT+6Vyo5no=
github.com/cosmos/ibc-go/v4 v4.3.0/go.mod h1:CcLvIoi9NNtIbNsxs4KjBGjYhlwqtsmXy1AKARKiMzQ=
github.com/cosmos/interchain-accounts v0.2.6 h1:TV2M2g1/Rb9MCNw1YePdBKE0rcEczNj1RGHT+2iRYas=
Expand Down
74 changes: 74 additions & 0 deletions scripts/e2e-412-upgrade-statesync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

# setup the network using the old binary

OLD_VERSION=${OLD_VERSION:-"v0.41.1"}
WASM_PATH=${WASM_PATH:-"../oraiwasm/package/plus/swapmap/artifacts/swapmap.wasm"}
ARGS="--chain-id testing -y --keyring-backend test --fees 200orai --gas auto --gas-adjustment 1.5 -b block"
NEW_VERSION=${NEW_VERSION:-"v0.41.2"}
VALIDATOR_HOME=${VALIDATOR_HOME:-"$HOME/.oraid/validator1"}
MIGRATE_MSG=${MIGRATE_MSG:-'{}'}
EXECUTE_MSG=${EXECUTE_MSG:-'{"ping":{}}'}
STATE_SYNC_HOME=${STATE_SYNC_HOME:-".oraid/state_sync"}

# kill all running binaries
pkill oraid && sleep 2s

# download current production binary
git clone https://github.com/oraichain/orai.git && cd orai/ && git checkout $OLD_VERSION && go get ./... && make install && cd ../ && rm -rf orai/

# setup local network
sh $PWD/scripts/multinode-local-testnet.sh

# deploy new contract
store_ret=$(oraid tx wasm store $WASM_PATH --from validator1 --home $VALIDATOR_HOME $ARGS --output json)
code_id=$(echo $store_ret | jq -r '.logs[0].events[1].attributes[] | select(.key | contains("code_id")).value')
oraid tx wasm instantiate $code_id '{}' --label 'testing' --from validator1 --home $VALIDATOR_HOME -b block --admin $(oraid keys show validator1 --keyring-backend test --home $VALIDATOR_HOME -a) $ARGS
contract_address=$(oraid query wasm list-contract-by-code $code_id --output json | jq -r '.contracts[0]')

echo "contract address: $contract_address"

# # create new upgrade proposal
UPGRADE_HEIGHT=${UPGRADE_HEIGHT:-30}
oraid tx gov submit-proposal software-upgrade $NEW_VERSION --title "foobar" --description "foobar" --from validator1 --upgrade-height $UPGRADE_HEIGHT --upgrade-info "x" --deposit 10000000orai $ARGS --home $VALIDATOR_HOME
oraid tx gov vote 1 yes --from validator1 --home "$HOME/.oraid/validator1" $ARGS && oraid tx gov vote 1 yes --from validator2 --home "$HOME/.oraid/validator2" $ARGS

# sleep to wait til the proposal passes
echo "Sleep til the proposal passes..."
sleep 3m

# kill all processes when lastest height = UPGRADE_HEIGHT - 1 = 29
pkill oraid && sleep 3s

# install new binary for the upgrade
echo "install new binary"
make install

# re-run all validators. All should run
screen -S validator1 -d -m oraid start --home=$HOME/.oraid/validator1 --minimum-gas-prices=0.00001orai
screen -S validator2 -d -m oraid start --home=$HOME/.oraid/validator2 --minimum-gas-prices=0.00001orai
screen -S validator3 -d -m oraid start --home=$HOME/.oraid/validator3 --minimum-gas-prices=0.00001orai

# sleep a bit for the network to start
echo "Sleep to wait for the network to start and wait for new snapshot intervals are after the upgrade to take place..."
sleep 1m

# now we setup statesync node
sh $PWD/scripts/state_sync.sh

echo "Sleep 1 min to get statesync done..."
sleep 1m

# add new key so we test sending wasm transaction afters statesync
# create new key
oraid keys add alice --keyring-backend=test --home=$STATE_SYNC_HOME

echo "## Send fund to state sync account"
oraid tx send $(oraid keys show validator1 -a --keyring-backend=test --home=$VALIDATOR_HOME) $(oraid keys show alice -a --keyring-backend=test --home=$STATE_SYNC_HOME) 500000orai --home=$VALIDATOR_HOME --node http://localhost:26657 $ARGS

echo "Sleep 6s to prevent account sequence error"
sleep 6s

# test wasm transaction using statesync node (port 26647)
echo "## Test execute wasm transaction"
oraid tx wasm execute $contract_address $EXECUTE_MSG --from=validator1 --home=$VALIDATOR_HOME --node tcp://localhost:26647 $ARGS
16 changes: 15 additions & 1 deletion scripts/e2e-412-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ echo "Migrate the contract"
store_ret=$(oraid tx wasm store $WASM_PATH --from validator1 --home $VALIDATOR_HOME $ARGS --output json)
new_code_id=$(echo $store_ret | jq -r '.logs[0].events[1].attributes[] | select(.key | contains("code_id")).value')

oraid tx wasm migrate $contract_address $new_code_id $MIGRATE_MSG --from validator1 $ARGS --home $VALIDATOR_HOME
oraid tx wasm migrate $contract_address $new_code_id $MIGRATE_MSG --from validator1 $ARGS --home $VALIDATOR_HOME

height_before=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')

# sleep for 2 mins to make sure the network is still running
sleep 1m

height_after=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')

if [ $height_after -gt $height_before ]
then
echo "Test done"
else
echo "Test failed"
fi
33 changes: 28 additions & 5 deletions scripts/multinode-local-testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ sed -i -e "s%^snapshot-keep-recent *=.*%snapshot-keep-recent = \"$snapshot_keep_
sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR1_CONFIG

# validator2
sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26655|g' $VALIDATOR2_CONFIG
sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26654|g' $VALIDATOR2_CONFIG
sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26655|g' $VALIDATOR2_CONFIG
sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26654|g' $VALIDATOR2_CONFIG
sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26653|g' $VALIDATOR2_CONFIG
sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' $VALIDATOR2_CONFIG
sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG

# validator3
sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26652|g' $VALIDATOR3_CONFIG
sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26651|g' $VALIDATOR3_CONFIG
sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26652|g' $VALIDATOR3_CONFIG
sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26651|g' $VALIDATOR3_CONFIG
sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' $VALIDATOR3_CONFIG
sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' $VALIDATOR3_CONFIG
sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR3_CONFIG
Expand Down Expand Up @@ -149,4 +149,27 @@ oraid tx send $(oraid keys show validator1 -a --keyring-backend=test --home=$HOM
oraid tx staking create-validator --amount=500000000orai --from=validator2 --pubkey=$(oraid tendermint show-validator --home=$HOME/.oraid/validator2) --moniker="validator2" --chain-id="testing" --commission-rate="0.1" --commission-max-rate="0.2" --commission-max-change-rate="0.05" --min-self-delegation="500000000" --keyring-backend=test --home=$HOME/.oraid/validator2 --broadcast-mode block --gas 200000 --fees 2orai --node http://localhost:26657 --yes
oraid tx staking create-validator --amount=400000000orai --from=validator3 --pubkey=$(oraid tendermint show-validator --home=$HOME/.oraid/validator3) --moniker="validator3" --chain-id="testing" --commission-rate="0.1" --commission-max-rate="0.2" --commission-max-change-rate="0.05" --min-self-delegation="400000000" --keyring-backend=test --home=$HOME/.oraid/validator3 --broadcast-mode block --gas 200000 --fees 2orai --node http://localhost:26657 --yes

echo "All 3 Validators are up and running!"
echo "All 3 Validators are up and running!"

echo "-----------------------"
echo "## Add new CosmWasm contract"
RESP=$(oraid tx wasm store scripts/wasm_file/cw_nameservice-aarch64.wasm \
--from=validator1 --keyring-backend=test --home=$HOME/.oraid/validator1 --gas 1500000 --fees 150orai --chain-id="testing" -y --node=http://localhost:26657 -b block -o json)

# first contract with code id = 1
CODE_ID=$(echo "$RESP" | jq -r '.logs[0].events[1].attributes[-1].value')
CODE_HASH=$(echo "$RESP" | jq -r '.logs[0].events[1].attributes[-2].value')
echo "* Code id: $CODE_ID"
echo "* Code checksum: $CODE_HASH"

echo "-----------------------"
echo "## Migrate contract"
echo "### Upload new code"
RESP=$(oraid tx wasm store scripts/wasm_file/burner.wasm \
--from=validator1 --keyring-backend=test --home=$HOME/.oraid/validator1 --node=http://localhost:26657 --gas 1500000 --fees 150orai --chain-id="testing" -y -b block -o json)

# second contract with code id = 2
CODE_ID=$(echo "$RESP" | jq -r '.logs[0].events[1].attributes[-1].value')
CODE_HASH=$(echo "$RESP" | jq -r '.logs[0].events[1].attributes[-2].value')
echo "* Code id: $CODE_ID"
echo "* Code checksum: $CODE_HASH"
44 changes: 17 additions & 27 deletions scripts/state_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ moniker="NODE_SYNC"
mkdir .oraid
mkdir .oraid/state_sync

SNAP_RPC2="http://127.0.0.1:26651"
SNAP_RPC1="http://127.0.0.1:26657"
SNAP_RPC="http://127.0.0.1:26654"
SNAP_RPC2="http://0.0.0.0:26651"
SNAP_RPC1="http://0.0.0.0:26657"
SNAP_RPC="http://0.0.0.0:26654"
CHAIN_ID="testing"
TRUST_HEIGHT_RANGE=${TRUST_HEIGHT_RANGE:-10}

PEER_RPC_PORT=26657
PEER_P2P_PORT=26656
PEER_ID=$(curl --no-progress-meter http://0.0.0.0:$PEER_RPC_PORT/status | jq -r '.result.node_info.id')

echo "peer id: $PEER_ID"

# persistent_peers
PEER="0a89582c5138a51a23f46175e42bb4a7312f2e7e@127.0.0.1:26653"
PEER="$PEER_ID@0.0.0.0:$PEER_P2P_PORT"

# MAKE HOME FOLDER AND GET GENESIS
oraid init $moniker --chain-id $CHAIN_ID --home=.oraid/state_sync
Expand All @@ -37,8 +44,8 @@ sed -i -E 's|0.0.0.0:9091|0.0.0.0:9081|g' $STATESYNC_APP_TOML
STATESYNC_CONFIG=.oraid/state_sync/config/config.toml

# state sync node
sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26648|g' $STATESYNC_CONFIG
sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26647|g' $STATESYNC_CONFIG
sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26648|g' $STATESYNC_CONFIG
sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26647|g' $STATESYNC_CONFIG
sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26643|g' $STATESYNC_CONFIG
sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26640|g' $STATESYNC_CONFIG

Expand All @@ -50,38 +57,21 @@ sed -i -e "s%^indexer *=.*%indexer = \"null\"%; " $STATESYNC_CONFIG

# GET TRUST HASH AND TRUST HEIGHT
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 2000)); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - $TRUST_HEIGHT_RANGE)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

# pruning
pruning="custom"
pruning_keep_recent="5"
pruning_keep_every="10"
pruning_interval="10"

sed -i -e "s%^pruning *=.*%pruning = \"$pruning\"%; " $STATESYNC_APP_TOML
sed -i -e "s%^pruning-keep-recent *=.*%pruning-keep-recent = \"$pruning_keep_recent\"%; " $STATESYNC_APP_TOML
sed -i -e "s%^pruning-keep-every *=.*%pruning-keep-every = \"$pruning_keep_every\"%; " $STATESYNC_APP_TOML
sed -i -e "s%^pruning-interval *=.*%pruning-interval = \"$pruning_interval\"%; " $STATESYNC_APP_TOML

# state sync
snapshot_interval="10"
snapshot_keep_recent="2"

sed -i -e "s%^snapshot-interval *=.*%snapshot-interval = \"$snapshot_interval\"%; " $STATESYNC_APP_TOML
sed -i -e "s%^snapshot-keep-recent *=.*%snapshot-keep-recent = \"$snapshot_keep_recent\"%; " $STATESYNC_APP_TOML


# TELL USER WHAT WE ARE DOING
echo "LATEST HEIGHT: $LATEST_HEIGHT"
echo "TRUST HEIGHT: $BLOCK_HEIGHT"
echo "TRUST HASH: $TRUST_HASH"

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(allow_duplicate_ip[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(addr_book_strict[[:space:]]+=[[:space:]]+).*$|\1false| ; \
s|^(persistent_peers[[:space:]]+=[[:space:]]+).*$|\1\"$PEER,$PEER\"| ; \
s|^(persistent_peers[[:space:]]+=[[:space:]]+).*$|\1\"$PEER\"| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC1,$SNAP_RPC2\"| ; \
Expand Down
Loading

0 comments on commit 1b6ea25

Please sign in to comment.