-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79f2a5e
commit 6d662cd
Showing
5 changed files
with
188 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}, | ||
} |
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,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()) | ||
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} | ||
} |
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,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()) | ||
} |
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,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) | ||
} | ||
} |