Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: burn lfg ustc #545

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (

// v9 had been used by tax2gas and has to be skipped
v10_1 "github.com/classic-terra/core/v3/app/upgrades/v10_1"
v11 "github.com/classic-terra/core/v3/app/upgrades/v11"

customante "github.com/classic-terra/core/v3/custom/auth/ante"
custompost "github.com/classic-terra/core/v3/custom/auth/post"
Expand Down Expand Up @@ -95,6 +96,7 @@ var (
v8_2.Upgrade,
v8_3.Upgrade,
v10_1.Upgrade,
v11.Upgrade,
}

// Forks defines forks to be applied to the network
Expand Down
17 changes: 17 additions & 0 deletions app/upgrades/v11/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//nolint:revive

Check failure on line 1 in app/upgrades/v11/constants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

directive `//nolint:revive` is unused for linter "revive" (nolintlint)
package v11

import (
"github.com/classic-terra/core/v3/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
)

const UpgradeName = "v11"

Check failure on line 9 in app/upgrades/v11/constants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
const LFGWallet = "terra1gr0xesnseevzt3h4nxr64sh5gk4dwrwgszx3nw"
const LFGWalletTestnet = "terra1gr0xesnseevzt3h4nxr64sh5gk4dwrwgszx3nw"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV11UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
100 changes: 100 additions & 0 deletions app/upgrades/v11/test_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package v11

//nolint
//DONTCOVER

import (
"testing"
"time"

"github.com/stretchr/testify/require"

customauth "github.com/classic-terra/core/v3/custom/auth"
custombank "github.com/classic-terra/core/v3/custom/bank"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

simparams "cosmossdk.io/simapp/params"
types "github.com/classic-terra/core/v3/x/dyncomm/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

var ModuleBasics = module.NewBasicManager(
customauth.AppModuleBasic{},
custombank.AppModuleBasic{},
)

// MakeTestCodec
func MakeTestCodec(t *testing.T) codec.Codec {
return MakeEncodingConfig(t).Codec
}

// MakeEncodingConfig
func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(codec, tx.DefaultSignModes)

std.RegisterInterfaces(interfaceRegistry)
std.RegisterLegacyAminoCodec(amino)

ModuleBasics.RegisterLegacyAminoCodec(amino)
ModuleBasics.RegisterInterfaces(interfaceRegistry)
types.RegisterLegacyAminoCodec(amino)
types.RegisterInterfaces(interfaceRegistry)

return simparams.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: txCfg,
Amino: amino,
}
}

var maccPerms = map[string][]string{banktypes.ModuleName: {authtypes.Burner, authtypes.Minter}}

type TestInput struct {
Ctx sdk.Context
Cdc *codec.LegacyAmino
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
}

func CreateTestInput(t *testing.T) TestInput {

Check failure on line 79 in app/upgrades/v11/test_utils.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
keyAcc := sdk.NewKVStoreKey(authtypes.StoreKey)
keyBank := sdk.NewKVStoreKey(banktypes.StoreKey)

db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ctx := sdk.NewContext(ms, tmproto.Header{Time: time.Now().UTC()}, false, log.NewNopLogger())
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
encodingConfig := MakeEncodingConfig(t)
appCodec, legacyAmino := encodingConfig.Codec, encodingConfig.Amino

ms.MountStoreWithDB(keyAcc, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyBank, storetypes.StoreTypeIAVL, db)

require.NoError(t, ms.LoadLatestVersion())

accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, authtypes.ProtoBaseAccount, maccPerms, sdk.GetConfig().GetBech32AccountAddrPrefix(), authtypes.NewModuleAddress(govtypes.ModuleName).String())
bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, map[string]bool{}, authtypes.NewModuleAddress(govtypes.ModuleName).String())

bankModuleAcc := authtypes.NewEmptyModuleAccount(banktypes.ModuleName, authtypes.Burner, authtypes.Minter)
accountKeeper.SetModuleAccount(ctx, bankModuleAcc)
return TestInput{ctx, legacyAmino, accountKeeper, bankKeeper}
}
28 changes: 28 additions & 0 deletions app/upgrades/v11/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//nolint:revive

Check failure on line 1 in app/upgrades/v11/upgrade_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

directive `//nolint:revive` is unused for linter "revive" (nolintlint)
package v11

import (
"testing"

"github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
)

func TestJustBurnItAlready(t *testing.T) {
input := CreateTestInput(t)
address := types.AccAddress("cosmos1gr0xesnseevzt3h4nxr64sh5gk4dwrwgszx3nw")
acc := authtypes.NewBaseAccount(address, nil, 0, 0)
input.AccountKeeper.NewAccount(input.Ctx, acc)
uusdCoins := types.NewCoins(types.NewCoin("uusd", types.NewInt(1000000)))

err := input.BankKeeper.MintCoins(input.Ctx, banktypes.ModuleName, uusdCoins)
require.NoError(t, err)
err = input.BankKeeper.SendCoinsFromModuleToAccount(input.Ctx, banktypes.ModuleName, address, uusdCoins)
require.NoError(t, err)
justBurnItAlready(input.Ctx, input.BankKeeper, address)

afterBalance := input.BankKeeper.GetBalance(input.Ctx, address, "uusd")
require.True(t, afterBalance.IsZero())
}
41 changes: 41 additions & 0 deletions app/upgrades/v11/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//nolint:revive

Check failure on line 1 in app/upgrades/v11/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

directive `//nolint:revive` is unused for linter "revive" (nolintlint)
package v11

import (
"github.com/classic-terra/core/v3/app/keepers"
"github.com/classic-terra/core/v3/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func justBurnItAlready(ctx sdk.Context, bank bankeeper.Keeper, targetAddr sdk.AccAddress) {
ustc := bank.GetBalance(ctx, targetAddr, "uusd")
if ustc.IsZero() {
return
}
bank.SendCoinsFromAccountToModule(ctx, targetAddr, banktypes.ModuleName, sdk.NewCoins(ustc))
bank.BurnCoins(ctx, banktypes.ModuleName, sdk.NewCoins(ustc))
}

func CreateV11UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
var targetAddr sdk.AccAddress
if ctx.ChainID() == "rebel-2" {

Check failure on line 31 in app/upgrades/v11/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ifElseChain: rewrite if-else to switch statement (gocritic)
targetAddr = sdk.MustAccAddressFromBech32(LFGWalletTestnet)
} else if ctx.ChainID() == "columbus-5" {
targetAddr = sdk.MustAccAddressFromBech32(LFGWallet)
} else {
return mm.RunMigrations(ctx, cfg, fromVM)
}
justBurnItAlready(ctx, keepers.BankKeeper, targetAddr)
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
Loading