From 6d662cd10c891c45daace0a3cca28ca37149bc3c Mon Sep 17 00:00:00 2001 From: Till Ziegler Date: Sun, 12 Jan 2025 22:29:06 +0100 Subject: [PATCH] fix: burn lfg ustc --- app/app.go | 2 + app/upgrades/v11/constants.go | 17 ++++++ app/upgrades/v11/test_utils.go | 100 +++++++++++++++++++++++++++++++ app/upgrades/v11/upgrade_test.go | 28 +++++++++ app/upgrades/v11/upgrades.go | 41 +++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 app/upgrades/v11/constants.go create mode 100644 app/upgrades/v11/test_utils.go create mode 100644 app/upgrades/v11/upgrade_test.go create mode 100644 app/upgrades/v11/upgrades.go diff --git a/app/app.go b/app/app.go index cf5250ca..7f689e5f 100644 --- a/app/app.go +++ b/app/app.go @@ -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" @@ -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 diff --git a/app/upgrades/v11/constants.go b/app/upgrades/v11/constants.go new file mode 100644 index 00000000..bf19ff7f --- /dev/null +++ b/app/upgrades/v11/constants.go @@ -0,0 +1,17 @@ +//nolint:revive +package v11 + +import ( + "github.com/classic-terra/core/v3/app/upgrades" + store "github.com/cosmos/cosmos-sdk/store/types" +) + +const UpgradeName = "v11" +const LFGWallet = "terra1gr0xesnseevzt3h4nxr64sh5gk4dwrwgszx3nw" +const LFGWalletTestnet = "terra1gr0xesnseevzt3h4nxr64sh5gk4dwrwgszx3nw" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateV11UpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/app/upgrades/v11/test_utils.go b/app/upgrades/v11/test_utils.go new file mode 100644 index 00000000..5df63930 --- /dev/null +++ b/app/upgrades/v11/test_utils.go @@ -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 { + + 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()) + 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} +} diff --git a/app/upgrades/v11/upgrade_test.go b/app/upgrades/v11/upgrade_test.go new file mode 100644 index 00000000..46d1ac2f --- /dev/null +++ b/app/upgrades/v11/upgrade_test.go @@ -0,0 +1,28 @@ +//nolint:revive +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()) +} diff --git a/app/upgrades/v11/upgrades.go b/app/upgrades/v11/upgrades.go new file mode 100644 index 00000000..1b3ed712 --- /dev/null +++ b/app/upgrades/v11/upgrades.go @@ -0,0 +1,41 @@ +//nolint:revive +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" { + 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) + } +}