Skip to content

Commit

Permalink
fix: burn lfg ustc
Browse files Browse the repository at this point in the history
  • Loading branch information
fragwuerdig committed Jan 12, 2025
1 parent 79f2a5e commit 6d662cd
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
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())

Check warning

Code scanning / CodeQL

Calling the system time Warning test

Calling the system time may be a possible source of non-determinism
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)
}
}

0 comments on commit 6d662cd

Please sign in to comment.