-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bank migration in upgrade handler (#1892)
* fix bank migtation in upgrade handler * try atomated upgrade test * fix build * change so runs on yml change too * change so runs on yml change too * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * change again * passing upgrade test * Update app/upgrades/v8/upgrades.go Co-authored-by: Danilo Pantani <danpantani@gmail.com> * Update contrib/scripts/run-gaia-v7.sh Co-authored-by: Danilo Pantani <danpantani@gmail.com> * Update contrib/scripts/run-gaia-v7.sh Co-authored-by: Danilo Pantani <danpantani@gmail.com> * Update contrib/scripts/run-gaia-v7.sh Co-authored-by: Danilo Pantani <danpantani@gmail.com> * Update contrib/scripts/run-gaia-v7.sh Co-authored-by: Danilo Pantani <danpantani@gmail.com> * add unit test * Update app/upgrades/v8/upgrades_test.go Co-authored-by: Danilo Pantani <danpantani@gmail.com> * added check for deformed being removed Co-authored-by: Danilo Pantani <danpantani@gmail.com>
- Loading branch information
Showing
8 changed files
with
403 additions
and
11 deletions.
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
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,61 @@ | ||
package v8_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
gaiahelpers "github.com/cosmos/gaia/v8/app/helpers" | ||
v8 "github.com/cosmos/gaia/v8/app/upgrades/v8" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFixBankMetadata(t *testing.T) { | ||
app := gaiahelpers.Setup(t) | ||
ctx := app.BaseApp.NewContext(false, tmproto.Header{ | ||
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)), | ||
Height: 1, | ||
}) | ||
|
||
cdc := app.AppCodec() | ||
|
||
malformedDenom := "uatomu" | ||
denomMetaData := banktypes.Metadata{ | ||
Name: "Cosmos Hub Atom", | ||
Symbol: "ATOM", | ||
Description: "The native staking token of the Cosmos Hub.", | ||
DenomUnits: []*banktypes.DenomUnit{ | ||
{"uatom", uint32(0), []string{"microatom"}}, | ||
{"matom", uint32(3), []string{"milliatom"}}, | ||
{"atom", uint32(6), nil}, | ||
}, | ||
Base: "uatom", | ||
Display: "atom", | ||
} | ||
|
||
// add the old format | ||
key := app.AppKeepers.GetKey(banktypes.ModuleName) | ||
store := ctx.KVStore(key) | ||
oldDenomMetaDataStore := prefix.NewStore(store, banktypes.DenomMetadataPrefix) | ||
m := cdc.MustMarshal(&denomMetaData) | ||
oldDenomMetaDataStore.Set([]byte(malformedDenom), m) | ||
|
||
correctDenom := "uatom" | ||
|
||
_, foundCorrect := app.AppKeepers.BankKeeper.GetDenomMetaData(ctx, correctDenom) | ||
require.False(t, foundCorrect) | ||
|
||
err := v8.FixBankMetadata(ctx, &app.AppKeepers) | ||
require.NoError(t, err) | ||
|
||
_, foundCorrect = app.AppKeepers.BankKeeper.GetDenomMetaData(ctx, correctDenom) | ||
require.True(t, foundCorrect) | ||
|
||
_, foundMalformed := app.AppKeepers.BankKeeper.GetDenomMetaData(ctx, malformedDenom) | ||
require.False(t, foundMalformed) | ||
|
||
} |
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,30 @@ | ||
|
||
|
||
[{ | ||
"base": "uatom", | ||
"denom_units": [ | ||
{ | ||
"aliases": [ | ||
"microatom" | ||
], | ||
"denom": "uatom", | ||
"exponent": 0 | ||
}, | ||
{ | ||
"aliases": [ | ||
"milliatom" | ||
], | ||
"denom": "matom", | ||
"exponent": 3 | ||
}, | ||
{ | ||
"aliases": [], | ||
"denom": "atom", | ||
"exponent": 6 | ||
} | ||
], | ||
"description": "The native staking token of the Cosmos Hub.", | ||
"display": "atom", | ||
"name": "asdf", | ||
"symbol": "asdf" | ||
}] |
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,71 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit -o nounset | ||
|
||
NODE_HOME=$(realpath ./build/.gaia) | ||
echo "NODE_HOME = ${NODE_HOME}" | ||
BINARY=$NODE_HOME/cosmovisor/genesis/bin/gaiad | ||
echo "BINARY = ${BINARY}" | ||
CHAINID=cosmoshub-4 | ||
|
||
USER_MNEMONIC="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" | ||
|
||
if ! test -f "./build/gaiad7"; then | ||
echo "gaiad v7 does not exist" | ||
exit | ||
fi | ||
|
||
|
||
rm -rf ./build/.gaia | ||
|
||
mkdir -p "$NODE_HOME"/cosmovisor/genesis/bin | ||
cp ./build/gaiad7 "$NODE_HOME"/cosmovisor/genesis/bin/gaiad | ||
$BINARY init upgrader --chain-id $CHAINID --home "$NODE_HOME" | ||
|
||
|
||
if ! test -f "./build/gaiad8"; then | ||
echo "gaiad v8 does not exist" | ||
exit | ||
fi | ||
|
||
mkdir -p "$NODE_HOME"/cosmovisor/upgrades/v8-Rho/bin | ||
cp ./build/gaiad8 "$NODE_HOME"/cosmovisor/upgrades/v8-Rho/bin/gaiad | ||
|
||
GOPATH=$(go env GOPATH) | ||
|
||
export DAEMON_NAME=gaiad | ||
export DAEMON_HOME=$NODE_HOME | ||
COSMOVISOR=$GOPATH/bin/cosmovisor | ||
|
||
|
||
$BINARY config chain-id $CHAINID --home $NODE_HOME | ||
$BINARY config keyring-backend test --home $NODE_HOME | ||
tmp=$(mktemp) | ||
|
||
# add bank part of genesis | ||
jq --argjson foo "$(jq -c '.' contrib/denom.json)" '.app_state.bank.denom_metadata = $foo' $NODE_HOME/config/genesis.json > "$tmp" && mv "$tmp" $NODE_HOME/config/genesis.json | ||
|
||
# replace default stake token with uatom | ||
sed -i -e 's/stake/uatom/g' $NODE_HOME/config/genesis.json | ||
# min deposition amount (this one isn't working) | ||
sed -i -e 's%"amount": "10000000",%"amount": "1",%g' $NODE_HOME/config/genesis.json | ||
# min voting power that a proposal requires in order to be a valid proposal | ||
sed -i -e 's%"quorum": "0.334000000000000000",%"quorum": "0.000000000000000001",%g' $NODE_HOME/config/genesis.json | ||
# the minimum proportion of "yes" votes requires for the proposal to pass | ||
sed -i -e 's%"threshold": "0.500000000000000000",%"threshold": "0.000000000000000001",%g' $NODE_HOME/config/genesis.json | ||
# voting period to 30s | ||
sed -i -e 's%"voting_period": "172800s"%"voting_period": "30s"%g' $NODE_HOME/config/genesis.json | ||
|
||
echo $USER_MNEMONIC | $BINARY --home $NODE_HOME keys add val --recover --keyring-backend=test | ||
$BINARY add-genesis-account val 10000000000000000000000000uatom --home $NODE_HOME --keyring-backend test | ||
$BINARY gentx val 1000000000uatom --home $NODE_HOME --chain-id $CHAINID | ||
$BINARY collect-gentxs --home $NODE_HOME | ||
|
||
sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0uatom"/' $NODE_HOME/config/app.toml | ||
|
||
perl -i~ -0777 -pe 's/# Enable defines if the API server should be enabled. | ||
enable = false/# Enable defines if the API server should be enabled. | ||
enable = true/g' $NODE_HOME/config/app.toml | ||
|
||
$COSMOVISOR start --home $NODE_HOME --x-crisis-skip-assert-invariants | ||
|
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,75 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit -o nounset | ||
|
||
UPGRADE_HEIGHT=$1 | ||
|
||
if [ -z "$1" ]; then | ||
echo "Need to add an upgrade height" | ||
exit 1 | ||
fi | ||
|
||
# NODE_HOME=./build/.gaia | ||
NODE_HOME=$(realpath ./build/.gaia) | ||
echo "NODE_HOME = ${NODE_HOME}" | ||
|
||
BINARY=$NODE_HOME/cosmovisor/genesis/bin/gaiad | ||
echo "BINARY = ${BINARY}" | ||
|
||
USER_MNEMONIC="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" | ||
CHAINID=cosmoshub-4 | ||
|
||
if test -f "$BINARY"; then | ||
|
||
echo "wait 10 seconds for blockchain to start" | ||
sleep 10 | ||
|
||
$BINARY config chain-id $CHAINID --home $NODE_HOME | ||
$BINARY config output json --home $NODE_HOME | ||
$BINARY config keyring-backend test --home $NODE_HOME | ||
$BINARY config --home $NODE_HOME | ||
|
||
|
||
key=$($BINARY keys show val --home $NODE_HOME) | ||
if [ key == "" ]; then | ||
echo $USER_MNEMONIC | $BINARY --home $NODE_HOME keys add val --recover --keyring-backend=test | ||
fi | ||
|
||
# $BINARY keys list --home $NODE_HOME | ||
|
||
echo "\n" | ||
echo "Submitting proposal... \n" | ||
$BINARY tx gov submit-proposal software-upgrade v8-Rho \ | ||
--title v8-Rho \ | ||
--deposit 10000000uatom \ | ||
--upgrade-height $UPGRADE_HEIGHT \ | ||
--upgrade-info "upgrade to v8-Rho" \ | ||
--description "upgrade to v8-Rho" \ | ||
--gas auto \ | ||
--fees 400uatom \ | ||
--from val \ | ||
--keyring-backend test \ | ||
--chain-id $CHAINID \ | ||
--home $NODE_HOME \ | ||
--node tcp://localhost:26657 \ | ||
--yes | ||
echo "Done \n" | ||
|
||
sleep 6 | ||
echo "Casting vote... \n" | ||
|
||
$BINARY tx gov vote 1 yes \ | ||
--from val \ | ||
--keyring-backend test \ | ||
--chain-id $CHAINID \ | ||
--home $NODE_HOME \ | ||
--gas auto \ | ||
--fees 400uatom \ | ||
--node tcp://localhost:26657 \ | ||
--yes | ||
|
||
echo "Done \n" | ||
|
||
else | ||
echo "Please build gaia v7 and move to ./build/gaiad7" | ||
fi |
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
Oops, something went wrong.