From 582f2cb1606d52cf403267b2c135f5093597ba89 Mon Sep 17 00:00:00 2001 From: Anh Minh <1phamminh0811@gmail.com> Date: Mon, 13 May 2024 17:34:55 +0700 Subject: [PATCH] lint and change all deprecated types --- app/app.go | 10 +-- app/legacy/migrate.go | 3 +- app/testing/test_suite.go | 16 ++--- app/upgrades/v8/upgrades.go | 17 +++-- cmd/terrad/root.go | 2 +- cmd/terrad/testnet.go | 5 +- custom/auth/ante/ante.go | 30 +++++---- custom/auth/ante/fee.go | 15 +++-- custom/auth/ante/fee_burntax.go | 3 +- custom/auth/ante/fee_tax.go | 8 +-- custom/auth/ante/min_initial_deposit.go | 6 +- custom/auth/ante/spamming_prevention_test.go | 3 +- custom/bank/simulation/operations.go | 4 +- custom/wasm/module.go | 4 +- custom/wasm/types/legacy/msgs.go | 69 ++++++++++---------- tests/e2e/configurer/chain/chain.go | 37 ----------- tests/e2e/containers/containers.go | 4 +- tests/e2e/initialization/chain.go | 11 ++-- tests/e2e/initialization/init.go | 4 +- tests/interchaintest/helpers/cosmwams.go | 6 +- wasmbinding/helper.go | 13 ---- wasmbinding/message_plugin.go | 29 ++++---- wasmbinding/query_plugin.go | 17 +++-- wasmbinding/wasm.go | 5 +- x/dyncomm/ante/ante.go | 7 +- x/market/handler.go | 3 +- x/market/keeper/swap.go | 18 ++--- x/market/types/errors.go | 8 +-- x/market/types/msgs.go | 15 +++-- x/oracle/handler.go | 3 +- x/oracle/keeper/keeper.go | 14 ++-- x/oracle/keeper/msg_server.go | 13 ++-- x/oracle/types/errors.go | 28 ++++---- x/oracle/types/msgs.go | 25 +++---- x/treasury/proposal_handler.go | 8 ++- x/treasury/types/errors.go | 4 +- x/treasury/types/gov.go | 7 +- 37 files changed, 222 insertions(+), 252 deletions(-) diff --git a/app/app.go b/app/app.go index b8e7ac504..3e5a4bf61 100644 --- a/app/app.go +++ b/app/app.go @@ -61,6 +61,7 @@ import ( customauthtx "github.com/classic-terra/core/v3/custom/auth/tx" "github.com/CosmWasm/wasmd/x/wasm" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" // unnamed import of statik for swagger UI support @@ -224,7 +225,7 @@ func NewTerraApp( DistributionKeeper: app.DistrKeeper, GovKeeper: app.GovKeeper, WasmConfig: &wasmConfig, - TXCounterStoreKey: app.GetKey(wasm.StoreKey), + TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey), DyncommKeeper: app.DyncommKeeper, StakingKeeper: app.StakingKeeper, Cdc: app.appCodec, @@ -278,8 +279,8 @@ func NewTerraApp( func (app *TerraApp) Name() string { return app.BaseApp.Name() } // DefaultGenesis returns a default genesis from the registered AppModuleBasic's. -func (a *TerraApp) DefaultGenesis() map[string]json.RawMessage { - return ModuleBasics.DefaultGenesis(a.appCodec) +func (app *TerraApp) DefaultGenesis() map[string]json.RawMessage { + return ModuleBasics.DefaultGenesis(app.appCodec) } // BeginBlocker application updates every begin block @@ -434,7 +435,8 @@ func (app *TerraApp) setupUpgradeStoreLoaders() { for _, upgrade := range Upgrades { if upgradeInfo.Name == upgrade.UpgradeName { - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) + storeUpgrades := upgrade.StoreUpgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } } } diff --git a/app/legacy/migrate.go b/app/legacy/migrate.go index 9bbe4357b..078cc2f9b 100644 --- a/app/legacy/migrate.go +++ b/app/legacy/migrate.go @@ -13,7 +13,6 @@ import ( "github.com/spf13/cobra" ibcxfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - "github.com/cosmos/ibc-go/v7/modules/core/exported" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibccoretypes "github.com/cosmos/ibc-go/v7/modules/core/types" @@ -133,7 +132,7 @@ $ terrad migrate /path/to/genesis.json --chain-id=cosmoshub-4 --genesis-time=201 ibcTransferGenesis.Params.ReceiveEnabled = false ibcTransferGenesis.Params.SendEnabled = false - ibcCoreGenesis.ClientGenesis.Params.AllowedClients = []string{exported.Tendermint} + ibcCoreGenesis.ClientGenesis.Params.AllowedClients = []string{ibcexported.Tendermint} stakingGenesis.Params.HistoricalEntries = 10000 newGenState[ibcxfertypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(ibcTransferGenesis) diff --git a/app/testing/test_suite.go b/app/testing/test_suite.go index 8809a70ba..02b1d88f1 100644 --- a/app/testing/test_suite.go +++ b/app/testing/test_suite.go @@ -98,7 +98,7 @@ type EmptyAppOptions struct{} func (EmptyAppOptions) Get(_ string) interface{} { return nil } -func SetupApp(t *testing.T, chainId string) *app.TerraApp { +func SetupApp(t *testing.T, chainID string) *app.TerraApp { t.Helper() privVal := NewPV() @@ -116,7 +116,7 @@ func SetupApp(t *testing.T, chainId string) *app.TerraApp { Coins: sdk.NewCoins(sdk.NewCoin(appparams.BondDenom, sdk.NewInt(100000000000000))), } genesisAccounts := []authtypes.GenesisAccount{acc} - app := SetupWithGenesisValSet(t, chainId, valSet, genesisAccounts, balance) + app := SetupWithGenesisValSet(t, chainID, valSet, genesisAccounts, balance) return app } @@ -125,10 +125,10 @@ func SetupApp(t *testing.T, chainId string) *app.TerraApp { // that also act as delegators. For simplicity, each validator is bonded with a delegation // of one consensus engine unit in the default token of the app from first genesis // account. A Nop logger is set in app. -func SetupWithGenesisValSet(t *testing.T, chainId string, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.TerraApp { +func SetupWithGenesisValSet(t *testing.T, chainID string, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.TerraApp { t.Helper() - terraApp, genesisState := setup(chainId) + terraApp, genesisState := setup(chainID) genesisState = genesisStateWithValSet(t, terraApp, genesisState, valSet, genAccs, balances...) stateBytes, err := json.MarshalIndent(genesisState, "", "") @@ -137,7 +137,7 @@ func SetupWithGenesisValSet(t *testing.T, chainId string, valSet *tmtypes.Valida // init chain will set the validator set and initialize the genesis accounts terraApp.InitChain( abci.RequestInitChain{ - ChainId: chainId, + ChainId: chainID, Validators: []abci.ValidatorUpdate{}, ConsensusParams: DefaultConsensusParams, AppStateBytes: stateBytes, @@ -147,7 +147,7 @@ func SetupWithGenesisValSet(t *testing.T, chainId string, valSet *tmtypes.Valida // commit genesis changes terraApp.Commit() terraApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - ChainID: chainId, + ChainID: chainID, Height: terraApp.LastBlockHeight() + 1, AppHash: terraApp.LastCommitID().Hash, ValidatorsHash: valSet.Hash(), @@ -157,7 +157,7 @@ func SetupWithGenesisValSet(t *testing.T, chainId string, valSet *tmtypes.Valida return terraApp } -func setup(chainId string) (*app.TerraApp, app.GenesisState) { +func setup(chainID string) (*app.TerraApp, app.GenesisState) { db := dbm.NewMemDB() encCdc := app.MakeEncodingConfig() appOptions := make(simtestutil.AppOptionsMap, 0) @@ -174,7 +174,7 @@ func setup(chainId string) (*app.TerraApp, app.GenesisState) { encCdc, simtestutil.EmptyAppOptions{}, emptyWasmOpts, - baseapp.SetChainID(chainId), + baseapp.SetChainID(chainID), ) return terraapp, app.GenesisState{} diff --git a/app/upgrades/v8/upgrades.go b/app/upgrades/v8/upgrades.go index 9bb79a995..81c28b7a0 100644 --- a/app/upgrades/v8/upgrades.go +++ b/app/upgrades/v8/upgrades.go @@ -28,7 +28,6 @@ func CreateV8UpgradeHandler( keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Set param key table for params module migration for _, subspace := range keepers.ParamsKeeper.GetSubspaces() { subspace := subspace @@ -36,23 +35,23 @@ func CreateV8UpgradeHandler( var keyTable paramstypes.KeyTable switch subspace.Name() { case authtypes.ModuleName: - keyTable = authtypes.ParamKeyTable() //nolint:staticcheck + keyTable = authtypes.ParamKeyTable() case banktypes.ModuleName: - keyTable = banktypes.ParamKeyTable() //nolint:staticcheck + keyTable = banktypes.ParamKeyTable() case stakingtypes.ModuleName: - keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + keyTable = stakingtypes.ParamKeyTable() case minttypes.ModuleName: - keyTable = minttypes.ParamKeyTable() //nolint:staticcheck + keyTable = minttypes.ParamKeyTable() case distrtypes.ModuleName: - keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck + keyTable = distrtypes.ParamKeyTable() case slashingtypes.ModuleName: - keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck + keyTable = slashingtypes.ParamKeyTable() case govtypes.ModuleName: - keyTable = govv1.ParamKeyTable() //nolint:staticcheck + keyTable = govv1.ParamKeyTable() case wasmtypes.ModuleName: keyTable = wasmtypes.ParamKeyTable() case crisistypes.ModuleName: - keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck + keyTable = crisistypes.ParamKeyTable() } if !subspace.HasKeyTable() { diff --git a/cmd/terrad/root.go b/cmd/terrad/root.go index 93c31a9ca..79c477bad 100644 --- a/cmd/terrad/root.go +++ b/cmd/terrad/root.go @@ -129,7 +129,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { genutilcli.ValidateGenesisCmd(terraapp.ModuleBasics), AddGenesisAccountCmd(terraapp.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), - testnetCmd(terraapp.ModuleBasics, banktypes.GenesisBalancesIterator{}, gentxModule.GenTxValidator), + testnetCmd(terraapp.ModuleBasics, banktypes.GenesisBalancesIterator{}), debug.Cmd(), pruning.Cmd(a.newApp, terraapp.DefaultNodeHome), snapshot.Cmd(a.newApp), diff --git a/cmd/terrad/testnet.go b/cmd/terrad/testnet.go index 382e8547d..7fb7c41a4 100644 --- a/cmd/terrad/testnet.go +++ b/cmd/terrad/testnet.go @@ -49,7 +49,7 @@ var ( ) // get cmd to initialize all files for tendermint testnet and application -func testnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator, validator genutiltypes.MessageValidator) *cobra.Command { +func testnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command { cmd := &cobra.Command{ Use: "testnet", Short: "Initialize files for a terrad testnet", @@ -81,7 +81,7 @@ Example: return InitTestnet( clientCtx, cmd, config, mbm, genBalIterator, outputDir, chainID, minGasPrices, - nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo, numValidators, validator, + nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo, numValidators, ) }, } @@ -117,7 +117,6 @@ func InitTestnet( keyringBackend, algoStr string, numValidators int, - validator genutiltypes.MessageValidator, ) error { if chainID == "" { chainID = "chain-" + tmrand.NewRand().Str(6) diff --git a/custom/auth/ante/ante.go b/custom/auth/ante/ante.go index 41833685d..8ff628612 100644 --- a/custom/auth/ante/ante.go +++ b/custom/auth/ante/ante.go @@ -1,6 +1,15 @@ package ante import ( + errorsmod "cosmossdk.io/errors" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/auth/signing" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + dyncommante "github.com/classic-terra/core/v3/x/dyncomm/ante" dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper" "github.com/cosmos/cosmos-sdk/codec" @@ -10,13 +19,6 @@ import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/ante" - "github.com/cosmos/cosmos-sdk/x/auth/signing" - distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" ) // HandlerOptions are the options required for constructing a default SDK AnteHandler. @@ -46,31 +48,31 @@ type HandlerOptions struct { // signer. func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") } if options.OracleKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder") } if options.TreasuryKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "treasury keeper is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "treasury keeper is required for ante builder") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } if options.WasmConfig == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") } if options.TXCounterStoreKey == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") } return sdk.ChainAnteDecorators( diff --git a/custom/auth/ante/fee.go b/custom/auth/ante/fee.go index a6ef2a16a..44acc1f4b 100644 --- a/custom/auth/ante/fee.go +++ b/custom/auth/ante/fee.go @@ -4,6 +4,7 @@ import ( "fmt" "math" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -33,11 +34,11 @@ func NewFeeDecorator(ak ante.AccountKeeper, bk BankKeeper, fk ante.FeegrantKeepe func (fd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { - return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } if !simulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") + return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") } var ( @@ -83,7 +84,7 @@ func (fd FeeDecorator) checkDeductFee(ctx sdk.Context, feeTx sdk.FeeTx, taxes sd } else if !feeGranter.Equals(feePayer) { err := fd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, feeTx.GetMsgs()) if err != nil { - return sdkerrors.Wrapf(err, "%s does not not allow to pay fees for %s", feeGranter, feePayer) + return errorsmod.Wrapf(err, "%s does not not allow to pay fees for %s", feeGranter, feePayer) } } @@ -128,12 +129,12 @@ func (fd FeeDecorator) checkDeductFee(ctx sdk.Context, feeTx sdk.FeeTx, taxes sd // DeductFees deducts fees from the given account. func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins) error { if !fees.IsValid() { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) + return errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) } err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) } return nil @@ -146,7 +147,7 @@ func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI func (fd FeeDecorator) checkTxFee(ctx sdk.Context, tx sdk.Tx, taxes sdk.Coins) (int64, error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { - return 0, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return 0, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } feeCoins := feeTx.GetFee() @@ -176,7 +177,7 @@ func (fd FeeDecorator) checkTxFee(ctx sdk.Context, tx sdk.Tx, taxes sdk.Coins) ( // Check required fees if !requiredFees.IsZero() && !feeCoins.IsAnyGTE(requiredFees) { - return 0, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %q, required: %q = %q(gas) + %q(stability)", feeCoins, requiredFees, requiredGasFees, taxes) + return 0, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %q, required: %q = %q(gas) + %q(stability)", feeCoins, requiredFees, requiredGasFees, taxes) } } diff --git a/custom/auth/ante/fee_burntax.go b/custom/auth/ante/fee_burntax.go index c02ea3e20..fd76cd3ea 100644 --- a/custom/auth/ante/fee_burntax.go +++ b/custom/auth/ante/fee_burntax.go @@ -1,6 +1,7 @@ package ante import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -30,7 +31,7 @@ func (fd FeeDecorator) BurnTaxSplit(ctx sdk.Context, taxes sdk.Coins) (err error treasury.BurnModuleName, taxes, ); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) } } diff --git a/custom/auth/ante/fee_tax.go b/custom/auth/ante/fee_tax.go index b10f5e750..96a0e48d6 100644 --- a/custom/auth/ante/fee_tax.go +++ b/custom/auth/ante/fee_tax.go @@ -4,7 +4,7 @@ import ( "regexp" "strings" - "github.com/CosmWasm/wasmd/x/wasm" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" authz "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -54,13 +54,13 @@ func FilterMsgAndComputeTax(ctx sdk.Context, tk TreasuryKeeper, msgs ...sdk.Msg) case *marketexported.MsgSwapSend: taxes = taxes.Add(computeTax(ctx, tk, sdk.NewCoins(msg.OfferCoin))...) - case *wasm.MsgInstantiateContract: + case *wasmtypes.MsgInstantiateContract: taxes = taxes.Add(computeTax(ctx, tk, msg.Funds)...) - case *wasm.MsgInstantiateContract2: + case *wasmtypes.MsgInstantiateContract2: taxes = taxes.Add(computeTax(ctx, tk, msg.Funds)...) - case *wasm.MsgExecuteContract: + case *wasmtypes.MsgExecuteContract: if !tk.HasBurnTaxExemptionContract(ctx, msg.Contract) { taxes = taxes.Add(computeTax(ctx, tk, msg.Funds)...) } diff --git a/custom/auth/ante/min_initial_deposit.go b/custom/auth/ante/min_initial_deposit.go index 236310c5d..aba117587 100644 --- a/custom/auth/ante/min_initial_deposit.go +++ b/custom/auth/ante/min_initial_deposit.go @@ -3,12 +3,14 @@ package ante import ( "fmt" - core "github.com/classic-terra/core/v3/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + core "github.com/classic-terra/core/v3/types" ) // MinInitialDeposit Decorator will check Initial Deposits for MsgSubmitProposal @@ -75,7 +77,7 @@ func (midd MinInitialDepositDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, si err := HandleCheckMinInitialDeposit(ctx, msg, midd.govKeeper, midd.treasuryKeeper) if err != nil { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, err.Error()) + return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, err.Error()) } } diff --git a/custom/auth/ante/spamming_prevention_test.go b/custom/auth/ante/spamming_prevention_test.go index 3e301899c..63ad02235 100644 --- a/custom/auth/ante/spamming_prevention_test.go +++ b/custom/auth/ante/spamming_prevention_test.go @@ -1,6 +1,7 @@ package ante_test import ( + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -84,5 +85,5 @@ func (ok dummyOracleKeeper) ValidateFeeder(_ sdk.Context, feederAddr sdk.AccAddr return nil } - return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "cannot ensure feeder right") + return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "cannot ensure feeder right") } diff --git a/custom/bank/simulation/operations.go b/custom/bank/simulation/operations.go index 5474880d5..28e1561d4 100644 --- a/custom/bank/simulation/operations.go +++ b/custom/bank/simulation/operations.go @@ -8,12 +8,12 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/types" banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation" + "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) diff --git a/custom/wasm/module.go b/custom/wasm/module.go index a55448df5..6c4bbe7cd 100644 --- a/custom/wasm/module.go +++ b/custom/wasm/module.go @@ -38,7 +38,7 @@ type AppModule struct { wasm.AppModule appModuleBasic AppModuleBasic cdc codec.Codec - keeper *wasm.Keeper + keeper *keeper.Keeper validatorSetSource keeper.ValidatorSetSource accountKeeper types.AccountKeeper // for simulation bankKeeper simulation.BankKeeper @@ -47,7 +47,7 @@ type AppModule struct { // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, - keeper *wasm.Keeper, + keeper *keeper.Keeper, validatorSetSource keeper.ValidatorSetSource, ak types.AccountKeeper, bk simulation.BankKeeper, diff --git a/custom/wasm/types/legacy/msgs.go b/custom/wasm/types/legacy/msgs.go index e6b5879d9..d95786c3d 100644 --- a/custom/wasm/types/legacy/msgs.go +++ b/custom/wasm/types/legacy/msgs.go @@ -3,10 +3,11 @@ package legacy import ( "encoding/json" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - wasm "github.com/CosmWasm/wasmd/x/wasm" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) // ensure Msg interface compliance at compile time @@ -47,7 +48,7 @@ func NewMsgStoreCode(sender sdk.AccAddress, wasmByteCode []byte) *MsgStoreCode { } // Route implements sdk.Msg -func (msg MsgStoreCode) Route() string { return wasm.RouterKey } +func (msg MsgStoreCode) Route() string { return wasmtypes.RouterKey } // Type implements sdk.Msg func (msg MsgStoreCode) Type() string { return TypeMsgStoreCode } @@ -71,15 +72,15 @@ func (msg MsgStoreCode) GetSigners() []sdk.AccAddress { func (msg MsgStoreCode) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) } if len(msg.WASMByteCode) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty wasm code") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty wasm code") } if uint64(len(msg.WASMByteCode)) > EnforcedMaxContractSize { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm code too large") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm code too large") } return nil @@ -96,7 +97,7 @@ func NewMsgMigrateCode(codeID uint64, sender sdk.AccAddress, wasmByteCode []byte } // Route implements sdk.Msg -func (msg MsgMigrateCode) Route() string { return wasm.RouterKey } +func (msg MsgMigrateCode) Route() string { return wasmtypes.RouterKey } // Type implements sdk.Msg func (msg MsgMigrateCode) Type() string { return TypeMsgMigrateCode } @@ -120,15 +121,15 @@ func (msg MsgMigrateCode) GetSigners() []sdk.AccAddress { func (msg MsgMigrateCode) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) } if len(msg.WASMByteCode) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty wasm code") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty wasm code") } if uint64(len(msg.WASMByteCode)) > EnforcedMaxContractSize { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm code too large") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm code too large") } return nil @@ -152,7 +153,7 @@ func NewMsgInstantiateContract(sender, admin sdk.AccAddress, codeID uint64, init // Route implements sdk.Msg func (msg MsgInstantiateContract) Route() string { - return wasm.RouterKey + return wasmtypes.RouterKey } // Type implements sdk.Msg @@ -164,26 +165,26 @@ func (msg MsgInstantiateContract) Type() string { func (msg MsgInstantiateContract) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) } if len(msg.Admin) != 0 { _, err := sdk.AccAddressFromBech32(msg.Admin) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid admin address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid admin address (%s)", err) } } if !msg.InitCoins.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.InitCoins.String()) + return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.InitCoins.String()) } if uint64(len(msg.InitMsg)) > EnforcedMaxContractMsgSize { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte size is too huge") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte size is too huge") } if !json.Valid(msg.InitMsg) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte format is invalid json") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte format is invalid json") } return nil @@ -216,7 +217,7 @@ func NewMsgExecuteContract(sender sdk.AccAddress, contract sdk.AccAddress, execM // Route implements sdk.Msg func (msg MsgExecuteContract) Route() string { - return wasm.RouterKey + return wasmtypes.RouterKey } // Type implements sdk.Msg @@ -228,24 +229,24 @@ func (msg MsgExecuteContract) Type() string { func (msg MsgExecuteContract) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) } if !msg.Coins.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Coins.String()) + return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.Coins.String()) } if uint64(len(msg.ExecuteMsg)) > EnforcedMaxContractMsgSize { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte size is too huge") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte size is too huge") } if !json.Valid(msg.ExecuteMsg) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte format is invalid json") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte format is invalid json") } return nil @@ -278,7 +279,7 @@ func NewMsgMigrateContract(admin, contract sdk.AccAddress, newCodeID uint64, mig // Route implements sdk.Msg func (msg MsgMigrateContract) Route() string { - return wasm.RouterKey + return wasmtypes.RouterKey } // Type implements sdk.Msg @@ -289,25 +290,25 @@ func (msg MsgMigrateContract) Type() string { // ValidateBasic implements sdk.Msg func (msg MsgMigrateContract) ValidateBasic() error { if msg.NewCodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "missing new_code_id") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "missing new_code_id") } _, err := sdk.AccAddressFromBech32(msg.Admin) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid admin address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid admin address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) } if uint64(len(msg.MigrateMsg)) > EnforcedMaxContractMsgSize { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte size is too huge") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte size is too huge") } if !json.Valid(msg.MigrateMsg) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte format is invalid json") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "wasm msg byte format is invalid json") } return nil @@ -339,7 +340,7 @@ func NewMsgUpdateContractAdmin(admin, newAdmin, contract sdk.AccAddress) *MsgUpd // Route implements sdk.Msg func (msg MsgUpdateContractAdmin) Route() string { - return wasm.RouterKey + return wasmtypes.RouterKey } // Type implements sdk.Msg @@ -351,17 +352,17 @@ func (msg MsgUpdateContractAdmin) Type() string { func (msg MsgUpdateContractAdmin) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Admin) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid admin address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid admin address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.NewAdmin) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid new admin address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid new admin address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) } return nil @@ -391,7 +392,7 @@ func NewMsgClearContractAdmin(admin, contract sdk.AccAddress) *MsgClearContractA // Route implements sdk.Msg func (msg MsgClearContractAdmin) Route() string { - return wasm.RouterKey + return wasmtypes.RouterKey } // Type implements sdk.Msg @@ -403,12 +404,12 @@ func (msg MsgClearContractAdmin) Type() string { func (msg MsgClearContractAdmin) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Admin) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid contract address (%s)", err) } return nil diff --git a/tests/e2e/configurer/chain/chain.go b/tests/e2e/configurer/chain/chain.go index 2e4ef0ae1..dd5f72e55 100644 --- a/tests/e2e/configurer/chain/chain.go +++ b/tests/e2e/configurer/chain/chain.go @@ -9,7 +9,6 @@ import ( "time" coretypes "github.com/cometbft/cometbft/rpc/core/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" "github.com/classic-terra/core/v3/tests/e2e/configurer/config" @@ -114,42 +113,6 @@ func (c *Config) WaitForNumHeights(heightsToWait int64) { c.WaitUntilHeight(currentHeight + heightsToWait) } -func (c *Config) SendIBC(dstChain *Config, recipient string, token sdk.Coin, hermesContainerName string) { - c.t.Logf("IBC sending %s from %s to %s (%s)", token, c.ID, dstChain.ID, recipient) - - dstNode, err := dstChain.GetDefaultNode() - require.NoError(c.t, err) - - balancesDstPre, err := dstNode.QueryBalances(recipient) - require.NoError(c.t, err) - - cmd := []string{"hermes", "tx", "raw", "ft-transfer", dstChain.ID, c.ID, "transfer", "channel-0", token.Amount.String(), fmt.Sprintf("--denom=%s", token.Denom), fmt.Sprintf("--receiver=%s", recipient), "--timeout-height-offset=1000"} - _, _, err = c.containerManager.ExecHermesCmd(c.t, cmd, "SUCCESS") - require.NoError(c.t, err) - - require.Eventually( - c.t, - func() bool { - balancesDstPost, err := dstNode.QueryBalances(recipient) - require.NoError(c.t, err) - ibcCoin := balancesDstPost.Sub(balancesDstPre...) - if ibcCoin.Len() == 1 { - tokenPre := balancesDstPre.AmountOfNoDenomValidation(ibcCoin[0].Denom) - tokenPost := balancesDstPost.AmountOfNoDenomValidation(ibcCoin[0].Denom) - resPre := token.Amount - resPost := tokenPost.Sub(tokenPre) - return resPost.Uint64() == resPre.Uint64() - } - return false - }, - initialization.FiveMin, - time.Second, - "tx not received on destination chain", - ) - - c.t.Log("successfully sent IBC tokens") -} - func (c *Config) GetDefaultNode() (*NodeConfig, error) { return c.getNodeAtIndex(defaultNodeIndex) } diff --git a/tests/e2e/containers/containers.go b/tests/e2e/containers/containers.go index d3864320c..8ffbbbd80 100644 --- a/tests/e2e/containers/containers.go +++ b/tests/e2e/containers/containers.go @@ -216,7 +216,7 @@ func (m *Manager) ExecQueryTxHash(t *testing.T, containerName, txHash string) (b if _, ok := m.resources[containerName]; !ok { return bytes.Buffer{}, bytes.Buffer{}, fmt.Errorf("no resource %s found", containerName) } - containerId := m.resources[containerName].Container.ID + containerID := m.resources[containerName].Container.ID var ( exec *docker.Exec @@ -245,7 +245,7 @@ func (m *Manager) ExecQueryTxHash(t *testing.T, containerName, txHash string) (b Context: ctx, AttachStdout: true, AttachStderr: true, - Container: containerId, + Container: containerID, User: "root", Cmd: command, }) diff --git a/tests/e2e/initialization/chain.go b/tests/e2e/initialization/chain.go index 48657683e..a32da6faf 100644 --- a/tests/e2e/initialization/chain.go +++ b/tests/e2e/initialization/chain.go @@ -12,13 +12,12 @@ type internalChain struct { nodes []*internalNode } -func new(id, dataDir string) (*internalChain, error) { - chainMeta := ChainMeta{ - ID: id, - DataDir: dataDir, - } +func newChain(id, dataDir string) (*internalChain, error) { return &internalChain{ - chainMeta: chainMeta, + chainMeta: ChainMeta{ + ID: id, + DataDir: dataDir, + }, }, nil } diff --git a/tests/e2e/initialization/init.go b/tests/e2e/initialization/init.go index 39c39032c..c3bfbcb33 100644 --- a/tests/e2e/initialization/init.go +++ b/tests/e2e/initialization/init.go @@ -45,7 +45,7 @@ func SetAddressPrefixes() { } func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, forkHeight int) (*Chain, error) { - chain, err := new(id, dataDir) + chain, err := newChain(id, dataDir) if err != nil { return nil, err } @@ -84,7 +84,7 @@ func InitSingleNode(chainID, dataDir string, existingGenesisDir string, nodeConf return nil, errors.New("creating individual validator nodes after starting up chain is not currently supported") } - chain, err := new(chainID, dataDir) + chain, err := newChain(chainID, dataDir) if err != nil { return nil, err } diff --git a/tests/interchaintest/helpers/cosmwams.go b/tests/interchaintest/helpers/cosmwams.go index 278a7cf0a..8d0e5df59 100644 --- a/tests/interchaintest/helpers/cosmwams.go +++ b/tests/interchaintest/helpers/cosmwams.go @@ -27,7 +27,8 @@ func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, func ExecuteMsgWithAmount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, message string) { chainNode := chain.FullNodes[0] - cmd := []string{"terrad", "tx", "wasm", "execute", contractAddr, message, + cmd := []string{ + "terrad", "tx", "wasm", "execute", contractAddr, message, "--amount", amount, } _, err := chainNode.ExecTx(ctx, user.KeyName(), cmd...) @@ -40,7 +41,8 @@ func ExecuteMsgWithAmount(t *testing.T, ctx context.Context, chain *cosmos.Cosmo func ExecuteMsgWithFee(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) { chainNode := chain.FullNodes[0] - cmd := []string{"terrad", "tx", "wasm", "execute", contractAddr, message, + cmd := []string{ + "terrad", "tx", "wasm", "execute", contractAddr, message, "--fees", feeCoin, } diff --git a/wasmbinding/helper.go b/wasmbinding/helper.go index ef5f80a7a..12465981e 100644 --- a/wasmbinding/helper.go +++ b/wasmbinding/helper.go @@ -44,16 +44,3 @@ func ConvertSdkCoinToWasmCoin(coin sdk.Coin) wasmvmtypes.Coin { Amount: coin.Amount.String(), } } - -// parseAddress parses address from bech32 string and verifies its format. -// func parseAddress(addr string) (sdk.AccAddress, error) { -// parsed, err := sdk.AccAddressFromBech32(addr) -// if err != nil { -// return nil, sdkerrors.Wrap(err, "address from bech32") -// } -// err = sdk.VerifyAddressFormat(parsed) -// if err != nil { -// return nil, sdkerrors.Wrap(err, "verify address format") -// } -// return parsed, nil -// } diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 6c58b1b81..7f0520bdd 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -3,12 +3,11 @@ package wasmbinding import ( "encoding/json" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - // bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/classic-terra/core/v3/wasmbinding/bindings" marketkeeper "github.com/classic-terra/core/v3/x/market/keeper" @@ -37,21 +36,21 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre if msg.Custom != nil { var contractMsg bindings.TerraMsg if err := json.Unmarshal(msg.Custom, &contractMsg); err != nil { - return nil, nil, sdkerrors.Wrap(err, "terra msg") + return nil, nil, errorsmod.Wrap(err, "terra msg") } switch { case contractMsg.Swap != nil: _, bz, err := m.swap(ctx, contractAddr, contractMsg.Swap) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "swap msg failed") + return nil, nil, errorsmod.Wrap(err, "swap msg failed") } return nil, bz, nil case contractMsg.SwapSend != nil: _, bz, err := m.swapSend(ctx, contractAddr, contractMsg.SwapSend) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "swap msg failed") + return nil, nil, errorsmod.Wrap(err, "swap msg failed") } return nil, bz, nil @@ -66,12 +65,12 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre func (m *CustomMessenger) swap(ctx sdk.Context, contractAddr sdk.AccAddress, contractMsg *bindings.Swap) ([]sdk.Event, [][]byte, error) { res, err := PerformSwap(m.marketKeeper, ctx, contractAddr, contractMsg) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "perform swap") + return nil, nil, errorsmod.Wrap(err, "perform swap") } bz, err := json.Marshal(res) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "error marshal swap response") + return nil, nil, errorsmod.Wrap(err, "error marshal swap response") } return nil, [][]byte{bz}, nil @@ -88,7 +87,7 @@ func PerformSwap(f *marketkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAd msgSwap := markettypes.NewMsgSwap(contractAddr, contractMsg.OfferCoin, contractMsg.AskDenom) if err := msgSwap.ValidateBasic(); err != nil { - return nil, sdkerrors.Wrap(err, "failed validating MsgSwap") + return nil, errorsmod.Wrap(err, "failed validating MsgSwap") } // swap @@ -97,7 +96,7 @@ func PerformSwap(f *marketkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAd msgSwap, ) if err != nil { - return nil, sdkerrors.Wrap(err, "swapping") + return nil, errorsmod.Wrap(err, "swapping") } return res, nil } @@ -106,12 +105,12 @@ func PerformSwap(f *marketkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAd func (m *CustomMessenger) swapSend(ctx sdk.Context, contractAddr sdk.AccAddress, contractMsg *bindings.SwapSend) ([]sdk.Event, [][]byte, error) { res, err := PerformSwapSend(m.marketKeeper, ctx, contractAddr, contractMsg) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "perform swap send") + return nil, nil, errorsmod.Wrap(err, "perform swap send") } bz, err := json.Marshal(res) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "error marshal swap send response") + return nil, nil, errorsmod.Wrap(err, "error marshal swap send response") } return nil, [][]byte{bz}, nil @@ -133,7 +132,7 @@ func PerformSwapSend(f *marketkeeper.Keeper, ctx sdk.Context, contractAddr sdk.A msgSwapSend := markettypes.NewMsgSwapSend(contractAddr, toAddr, contractMsg.OfferCoin, contractMsg.AskDenom) if err := msgSwapSend.ValidateBasic(); err != nil { - return nil, sdkerrors.Wrap(err, "failed validating MsgSwapSend") + return nil, errorsmod.Wrap(err, "failed validating MsgSwapSend") } // swap @@ -142,7 +141,7 @@ func PerformSwapSend(f *marketkeeper.Keeper, ctx sdk.Context, contractAddr sdk.A msgSwapSend, ) if err != nil { - return nil, sdkerrors.Wrap(err, "swapping and sending") + return nil, errorsmod.Wrap(err, "swapping and sending") } return res, nil } diff --git a/wasmbinding/query_plugin.go b/wasmbinding/query_plugin.go index bd29e677f..30aab1c1a 100644 --- a/wasmbinding/query_plugin.go +++ b/wasmbinding/query_plugin.go @@ -4,13 +4,16 @@ import ( "encoding/json" "fmt" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" - abci "github.com/cometbft/cometbft/abci/types" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + abci "github.com/cometbft/cometbft/abci/types" + + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/classic-terra/core/v3/wasmbinding/bindings" marketkeeper "github.com/classic-terra/core/v3/x/market/keeper" markettypes "github.com/classic-terra/core/v3/x/market/types" @@ -57,7 +60,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { var contractQuery bindings.TerraQuery if err := json.Unmarshal(request, &contractQuery); err != nil { - return nil, sdkerrors.Wrap(err, "terra query") + return nil, errorsmod.Wrap(err, "terra query") } switch { @@ -73,7 +76,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag bz, err := json.Marshal(bindings.SwapQueryResponse{Receive: ConvertSdkCoinToWasmCoin(res.ReturnCoin)}) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } return bz, nil @@ -105,7 +108,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag ExchangeRates: items, }) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } return bz, nil @@ -114,7 +117,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag taxRate := qp.treasuryKeeper.GetTaxRate(ctx) bz, err := json.Marshal(bindings.TaxRateQueryResponse{Rate: taxRate.String()}) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } return bz, nil @@ -123,7 +126,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag taxCap := qp.treasuryKeeper.GetTaxCap(ctx, contractQuery.TaxCap.Denom) bz, err := json.Marshal(TaxCapQueryResponse{Cap: taxCap.String()}) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } return bz, nil diff --git a/wasmbinding/wasm.go b/wasmbinding/wasm.go index d65378bc8..723cafc39 100644 --- a/wasmbinding/wasm.go +++ b/wasmbinding/wasm.go @@ -1,7 +1,6 @@ package wasmbinding import ( - "github.com/CosmWasm/wasmd/x/wasm" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -30,7 +29,7 @@ func RegisterCustomPlugins( CustomMessageDecorator(marketKeeper), ) - return []wasm.Option{ + return []wasmkeeper.Option{ queryPluginOpt, messengerDecoratorOpt, } @@ -41,7 +40,7 @@ func RegisterStargateQueries(queryRouter baseapp.GRPCQueryRouter, codec codec.Co Stargate: StargateQuerier(queryRouter, codec), }) - return []wasm.Option{ + return []wasmkeeper.Option{ queryPluginOpt, } } diff --git a/x/dyncomm/ante/ante.go b/x/dyncomm/ante/ante.go index cc5fcf327..133c7a1ff 100644 --- a/x/dyncomm/ante/ante.go +++ b/x/dyncomm/ante/ante.go @@ -3,15 +3,18 @@ package ante import ( "fmt" - dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authz "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper" ) // DyncommDecorator checks for EditValidator and rejects @@ -73,7 +76,7 @@ func (dd DyncommDecorator) FilterMsgsAndProcessMsgs(ctx sdk.Context, msgs ...sdk } if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, err.Error()) } } diff --git a/x/market/handler.go b/x/market/handler.go index c889c70d0..65346637c 100644 --- a/x/market/handler.go +++ b/x/market/handler.go @@ -1,6 +1,7 @@ package market import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -23,7 +24,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { res, err := msgServer.SwapSend(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized market message type: %T", msg) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized market message type: %T", msg) } } } diff --git a/x/market/keeper/swap.go b/x/market/keeper/swap.go index 37c951106..75d577b7d 100644 --- a/x/market/keeper/swap.go +++ b/x/market/keeper/swap.go @@ -1,12 +1,12 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" core "github.com/classic-terra/core/v3/types" "github.com/classic-terra/core/v3/x/market/types" - - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // ApplySwapToPool updates each pool with offerCoin and askCoin taken from swap operation, @@ -52,7 +52,7 @@ func (k Keeper) ApplySwapToPool(ctx sdk.Context, offerCoin sdk.Coin, askCoin sdk func (k Keeper) ComputeSwap(ctx sdk.Context, offerCoin sdk.Coin, askDenom string) (retDecCoin sdk.DecCoin, spread sdk.Dec, err error) { // Return invalid recursive swap err if offerCoin.Denom == askDenom { - return sdk.DecCoin{}, sdk.ZeroDec(), sdkerrors.Wrap(types.ErrRecursiveSwap, askDenom) + return sdk.DecCoin{}, sdk.ZeroDec(), errorsmod.Wrap(types.ErrRecursiveSwap, askDenom) } // Swap offer coin to base denom for simplicity of swap process @@ -140,17 +140,17 @@ func (k Keeper) ComputeInternalSwap(ctx sdk.Context, offerCoin sdk.DecCoin, askD offerRate, err := k.OracleKeeper.GetLunaExchangeRate(ctx, offerCoin.Denom) if err != nil { - return sdk.DecCoin{}, sdkerrors.Wrap(types.ErrNoEffectivePrice, offerCoin.Denom) + return sdk.DecCoin{}, errorsmod.Wrap(types.ErrNoEffectivePrice, offerCoin.Denom) } askRate, err := k.OracleKeeper.GetLunaExchangeRate(ctx, askDenom) if err != nil { - return sdk.DecCoin{}, sdkerrors.Wrap(types.ErrNoEffectivePrice, askDenom) + return sdk.DecCoin{}, errorsmod.Wrap(types.ErrNoEffectivePrice, askDenom) } retAmount := offerCoin.Amount.Mul(askRate).Quo(offerRate) if retAmount.LTE(sdk.ZeroDec()) { - return sdk.DecCoin{}, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, offerCoin.String()) + return sdk.DecCoin{}, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, offerCoin.String()) } return sdk.NewDecCoinFromDec(askDenom, retAmount), nil @@ -159,16 +159,16 @@ func (k Keeper) ComputeInternalSwap(ctx sdk.Context, offerCoin sdk.DecCoin, askD // simulateSwap interface for simulate swap func (k Keeper) simulateSwap(ctx sdk.Context, offerCoin sdk.Coin, askDenom string) (sdk.Coin, error) { if askDenom == offerCoin.Denom { - return sdk.Coin{}, sdkerrors.Wrap(types.ErrRecursiveSwap, askDenom) + return sdk.Coin{}, errorsmod.Wrap(types.ErrRecursiveSwap, askDenom) } if offerCoin.Amount.BigInt().BitLen() > 100 { - return sdk.Coin{}, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, offerCoin.String()) + return sdk.Coin{}, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, offerCoin.String()) } swapCoin, spread, err := k.ComputeSwap(ctx, offerCoin, askDenom) if err != nil { - return sdk.Coin{}, sdkerrors.Wrap(sdkerrors.ErrPanic, err.Error()) + return sdk.Coin{}, errorsmod.Wrap(sdkerrors.ErrPanic, err.Error()) } if spread.IsPositive() { diff --git a/x/market/types/errors.go b/x/market/types/errors.go index d35be021e..e56caa48d 100644 --- a/x/market/types/errors.go +++ b/x/market/types/errors.go @@ -1,12 +1,12 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // Market errors var ( - ErrRecursiveSwap = sdkerrors.Register(ModuleName, 2, "recursive swap") - ErrNoEffectivePrice = sdkerrors.Register(ModuleName, 3, "no price registered with oracle") - ErrZeroSwapCoin = sdkerrors.Register(ModuleName, 4, "zero swap coin") + ErrRecursiveSwap = errorsmod.Register(ModuleName, 2, "recursive swap") + ErrNoEffectivePrice = errorsmod.Register(ModuleName, 3, "no price registered with oracle") + ErrZeroSwapCoin = errorsmod.Register(ModuleName, 4, "zero swap coin") ) diff --git a/x/market/types/msgs.go b/x/market/types/msgs.go index cb76e35db..79434e1ac 100644 --- a/x/market/types/msgs.go +++ b/x/market/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -54,15 +55,15 @@ func (msg MsgSwap) GetSigners() []sdk.AccAddress { func (msg MsgSwap) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Trader) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid trader address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid trader address (%s)", err) } if msg.OfferCoin.Amount.LTE(sdk.ZeroInt()) || msg.OfferCoin.Amount.BigInt().BitLen() > 100 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.OfferCoin.String()) + return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.OfferCoin.String()) } if msg.OfferCoin.Denom == msg.AskDenom { - return sdkerrors.Wrap(ErrRecursiveSwap, msg.AskDenom) + return errorsmod.Wrap(ErrRecursiveSwap, msg.AskDenom) } return nil @@ -103,20 +104,20 @@ func (msg MsgSwapSend) GetSigners() []sdk.AccAddress { func (msg MsgSwapSend) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.FromAddress) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid from address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid from address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.ToAddress) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid to address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid to address (%s)", err) } if msg.OfferCoin.Amount.LTE(sdk.ZeroInt()) || msg.OfferCoin.Amount.BigInt().BitLen() > 100 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.OfferCoin.String()) + return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.OfferCoin.String()) } if msg.OfferCoin.Denom == msg.AskDenom { - return sdkerrors.Wrap(ErrRecursiveSwap, msg.AskDenom) + return errorsmod.Wrap(ErrRecursiveSwap, msg.AskDenom) } return nil diff --git a/x/oracle/handler.go b/x/oracle/handler.go index c030ba5b6..fa653e928 100644 --- a/x/oracle/handler.go +++ b/x/oracle/handler.go @@ -1,6 +1,7 @@ package oracle import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -26,7 +27,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { res, err := msgServer.AggregateExchangeRateVote(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized oracle message type: %T", msg) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized oracle message type: %T", msg) } } } diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 33050cd1f..05d9b9665 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -7,10 +7,10 @@ import ( gogotypes "github.com/gogo/protobuf/types" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -82,7 +82,7 @@ func (k Keeper) GetLunaExchangeRate(ctx sdk.Context, denom string) (sdk.Dec, err store := ctx.KVStore(k.storeKey) b := store.Get(types.GetExchangeRateKey(denom)) if b == nil { - return sdk.ZeroDec(), sdkerrors.Wrap(types.ErrUnknownDenom, denom) + return sdk.ZeroDec(), errorsmod.Wrap(types.ErrUnknownDenom, denom) } dp := sdk.DecProto{} @@ -225,7 +225,7 @@ func (k Keeper) GetAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAd store := ctx.KVStore(k.storeKey) b := store.Get(types.GetAggregateExchangeRatePrevoteKey(voter)) if b == nil { - err = sdkerrors.Wrap(types.ErrNoAggregatePrevote, voter.String()) + err = errorsmod.Wrap(types.ErrNoAggregatePrevote, voter.String()) return } k.cdc.MustUnmarshal(b, &aggregatePrevote) @@ -270,7 +270,7 @@ func (k Keeper) GetAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddre store := ctx.KVStore(k.storeKey) b := store.Get(types.GetAggregateExchangeRateVoteKey(voter)) if b == nil { - err = sdkerrors.Wrap(types.ErrNoAggregateVote, voter.String()) + err = errorsmod.Wrap(types.ErrNoAggregateVote, voter.String()) return } k.cdc.MustUnmarshal(b, &aggregateVote) @@ -311,7 +311,7 @@ func (k Keeper) GetTobinTax(ctx sdk.Context, denom string) (sdk.Dec, error) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetTobinTaxKey(denom)) if bz == nil { - err := sdkerrors.Wrap(types.ErrNoTobinTax, denom) + err := errorsmod.Wrap(types.ErrNoTobinTax, denom) return sdk.Dec{}, err } @@ -359,13 +359,13 @@ func (k Keeper) ValidateFeeder(ctx sdk.Context, feederAddr sdk.AccAddress, valid if !feederAddr.Equals(validatorAddr) { delegate := k.GetFeederDelegation(ctx, validatorAddr) if !delegate.Equals(feederAddr) { - return sdkerrors.Wrap(types.ErrNoVotingPermission, feederAddr.String()) + return errorsmod.Wrap(types.ErrNoVotingPermission, feederAddr.String()) } } // Check that the given validator exists if val := k.StakingKeeper.Validator(ctx, validatorAddr); val == nil || !val.IsBonded() { - return sdkerrors.Wrapf(stakingtypes.ErrNoValidatorFound, "validator %s is not active set", validatorAddr.String()) + return errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "validator %s is not active set", validatorAddr.String()) } return nil diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index 9953be832..a1a8d1ebc 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -3,6 +3,7 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -40,7 +41,7 @@ func (ms msgServer) AggregateExchangeRatePrevote(goCtx context.Context, msg *typ // Convert hex string to votehash voteHash, err := types.AggregateVoteHashFromHexString(msg.Hash) if err != nil { - return nil, sdkerrors.Wrap(types.ErrInvalidHash, err.Error()) + return nil, errorsmod.Wrap(types.ErrInvalidHash, err.Error()) } aggregatePrevote := types.NewAggregateExchangeRatePrevote(voteHash, valAddr, uint64(ctx.BlockHeight())) @@ -82,7 +83,7 @@ func (ms msgServer) AggregateExchangeRateVote(goCtx context.Context, msg *types. aggregatePrevote, err := ms.GetAggregateExchangeRatePrevote(ctx, valAddr) if err != nil { - return nil, sdkerrors.Wrap(types.ErrNoAggregatePrevote, msg.Validator) + return nil, errorsmod.Wrap(types.ErrNoAggregatePrevote, msg.Validator) } // Check a msg is submitted proper period @@ -92,20 +93,20 @@ func (ms msgServer) AggregateExchangeRateVote(goCtx context.Context, msg *types. exchangeRateTuples, err := types.ParseExchangeRateTuples(msg.ExchangeRates) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, err.Error()) } // check all denoms are in the vote target for _, tuple := range exchangeRateTuples { if !ms.IsVoteTarget(ctx, tuple.Denom) { - return nil, sdkerrors.Wrap(types.ErrUnknownDenom, tuple.Denom) + return nil, errorsmod.Wrap(types.ErrUnknownDenom, tuple.Denom) } } // Verify a exchange rate with aggregate prevote hash hash := types.GetAggregateVoteHash(msg.Salt, msg.ExchangeRates, valAddr) if aggregatePrevote.Hash != hash.String() { - return nil, sdkerrors.Wrapf(types.ErrVerificationFailed, "must be given %s not %s", aggregatePrevote.Hash, hash) + return nil, errorsmod.Wrapf(types.ErrVerificationFailed, "must be given %s not %s", aggregatePrevote.Hash, hash) } // Move aggregate prevote to aggregate vote with given exchange rates @@ -144,7 +145,7 @@ func (ms msgServer) DelegateFeedConsent(goCtx context.Context, msg *types.MsgDel // Check the delegator is a validator val := ms.StakingKeeper.Validator(ctx, operatorAddr) if val == nil { - return nil, sdkerrors.Wrap(stakingtypes.ErrNoValidatorFound, msg.Operator) + return nil, errorsmod.Wrap(stakingtypes.ErrNoValidatorFound, msg.Operator) } // Set the delegation diff --git a/x/oracle/types/errors.go b/x/oracle/types/errors.go index df20082b4..91bc7898d 100644 --- a/x/oracle/types/errors.go +++ b/x/oracle/types/errors.go @@ -5,22 +5,22 @@ import ( "github.com/cometbft/cometbft/crypto/tmhash" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // Oracle Errors var ( - ErrInvalidExchangeRate = sdkerrors.Register(ModuleName, 2, "invalid exchange rate") - ErrNoPrevote = sdkerrors.Register(ModuleName, 3, "no prevote") - ErrNoVote = sdkerrors.Register(ModuleName, 4, "no vote") - ErrNoVotingPermission = sdkerrors.Register(ModuleName, 5, "unauthorized voter") - ErrInvalidHash = sdkerrors.Register(ModuleName, 6, "invalid hash") - ErrInvalidHashLength = sdkerrors.Register(ModuleName, 7, fmt.Sprintf("invalid hash length; should equal %d", tmhash.TruncatedSize)) - ErrVerificationFailed = sdkerrors.Register(ModuleName, 8, "hash verification failed") - ErrRevealPeriodMissMatch = sdkerrors.Register(ModuleName, 9, "reveal period of submitted vote do not match with registered prevote") - ErrInvalidSaltLength = sdkerrors.Register(ModuleName, 10, "invalid salt length; should be 1~4") - ErrNoAggregatePrevote = sdkerrors.Register(ModuleName, 11, "no aggregate prevote") - ErrNoAggregateVote = sdkerrors.Register(ModuleName, 12, "no aggregate vote") - ErrNoTobinTax = sdkerrors.Register(ModuleName, 13, "no tobin tax") - ErrUnknownDenom = sdkerrors.Register(ModuleName, 14, "unknown denom") + ErrInvalidExchangeRate = errorsmod.Register(ModuleName, 2, "invalid exchange rate") + ErrNoPrevote = errorsmod.Register(ModuleName, 3, "no prevote") + ErrNoVote = errorsmod.Register(ModuleName, 4, "no vote") + ErrNoVotingPermission = errorsmod.Register(ModuleName, 5, "unauthorized voter") + ErrInvalidHash = errorsmod.Register(ModuleName, 6, "invalid hash") + ErrInvalidHashLength = errorsmod.Register(ModuleName, 7, fmt.Sprintf("invalid hash length; should equal %d", tmhash.TruncatedSize)) + ErrVerificationFailed = errorsmod.Register(ModuleName, 8, "hash verification failed") + ErrRevealPeriodMissMatch = errorsmod.Register(ModuleName, 9, "reveal period of submitted vote do not match with registered prevote") + ErrInvalidSaltLength = errorsmod.Register(ModuleName, 10, "invalid salt length; should be 1~4") + ErrNoAggregatePrevote = errorsmod.Register(ModuleName, 11, "no aggregate prevote") + ErrNoAggregateVote = errorsmod.Register(ModuleName, 12, "no aggregate vote") + ErrNoTobinTax = errorsmod.Register(ModuleName, 13, "no tobin tax") + ErrUnknownDenom = errorsmod.Register(ModuleName, 14, "unknown denom") ) diff --git a/x/oracle/types/msgs.go b/x/oracle/types/msgs.go index 332aac4ef..8c7cfa6af 100644 --- a/x/oracle/types/msgs.go +++ b/x/oracle/types/msgs.go @@ -3,6 +3,7 @@ package types import ( "github.com/cometbft/cometbft/crypto/tmhash" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -58,7 +59,7 @@ func (msg MsgAggregateExchangeRatePrevote) GetSigners() []sdk.AccAddress { func (msg MsgAggregateExchangeRatePrevote) ValidateBasic() error { _, err := AggregateVoteHashFromHexString(msg.Hash) if err != nil { - return sdkerrors.Wrapf(ErrInvalidHash, "Invalid vote hash (%s)", err) + return errorsmod.Wrapf(ErrInvalidHash, "Invalid vote hash (%s)", err) } // HEX encoding doubles the hash length @@ -68,12 +69,12 @@ func (msg MsgAggregateExchangeRatePrevote) ValidateBasic() error { _, err = sdk.AccAddressFromBech32(msg.Feeder) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid feeder address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid feeder address (%s)", err) } _, err = sdk.ValAddressFromBech32(msg.Validator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid operator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid operator address (%s)", err) } return nil @@ -114,34 +115,34 @@ func (msg MsgAggregateExchangeRateVote) GetSigners() []sdk.AccAddress { func (msg MsgAggregateExchangeRateVote) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Feeder) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid feeder address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid feeder address (%s)", err) } _, err = sdk.ValAddressFromBech32(msg.Validator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid operator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid operator address (%s)", err) } if l := len(msg.ExchangeRates); l == 0 { - return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "must provide at least one oracle exchange rate") + return errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "must provide at least one oracle exchange rate") } else if l > 4096 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "exchange rates string can not exceed 4096 characters") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "exchange rates string can not exceed 4096 characters") } exchangeRates, err := ParseExchangeRateTuples(msg.ExchangeRates) if err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "failed to parse exchange rates string cause: "+err.Error()) + return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "failed to parse exchange rates string cause: "+err.Error()) } for _, exchangeRate := range exchangeRates { // Check overflow bit length if exchangeRate.ExchangeRate.BigInt().BitLen() > 255+sdk.DecimalPrecisionBits { - return sdkerrors.Wrap(ErrInvalidExchangeRate, "overflow") + return errorsmod.Wrap(ErrInvalidExchangeRate, "overflow") } } if len(msg.Salt) > 4 || len(msg.Salt) < 1 { - return sdkerrors.Wrap(ErrInvalidSaltLength, "salt length must be [1, 4]") + return errorsmod.Wrap(ErrInvalidSaltLength, "salt length must be [1, 4]") } return nil @@ -180,12 +181,12 @@ func (msg MsgDelegateFeedConsent) GetSigners() []sdk.AccAddress { func (msg MsgDelegateFeedConsent) ValidateBasic() error { _, err := sdk.ValAddressFromBech32(msg.Operator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid operator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid operator address (%s)", err) } _, err = sdk.AccAddressFromBech32(msg.Delegate) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegate address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegate address (%s)", err) } return nil diff --git a/x/treasury/proposal_handler.go b/x/treasury/proposal_handler.go index 5d33d1fdb..3d42e35fa 100644 --- a/x/treasury/proposal_handler.go +++ b/x/treasury/proposal_handler.go @@ -1,11 +1,13 @@ package treasury import ( - "github.com/classic-terra/core/v3/x/treasury/keeper" - "github.com/classic-terra/core/v3/x/treasury/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + "github.com/classic-terra/core/v3/x/treasury/keeper" + "github.com/classic-terra/core/v3/x/treasury/types" ) func NewProposalHandler(k keeper.Keeper) govv1beta1.Handler { @@ -16,7 +18,7 @@ func NewProposalHandler(k keeper.Keeper) govv1beta1.Handler { case *types.RemoveBurnTaxExemptionAddressProposal: return handleRemoveBurnTaxExemptionAddressProposal(ctx, k, c) default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized treasury proposal content type: %T", c) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized treasury proposal content type: %T", c) } } } diff --git a/x/treasury/types/errors.go b/x/treasury/types/errors.go index 1d76a4662..d24e15eef 100644 --- a/x/treasury/types/errors.go +++ b/x/treasury/types/errors.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) -var ErrNoSuchBurnTaxExemptionAddress = sdkerrors.Register(ModuleName, 1, "no such address in extemption list") +var ErrNoSuchBurnTaxExemptionAddress = errorsmod.Register(ModuleName, 1, "no such address in extemption list") diff --git a/x/treasury/types/gov.go b/x/treasury/types/gov.go index 6501d9db8..f71d43c29 100644 --- a/x/treasury/types/gov.go +++ b/x/treasury/types/gov.go @@ -3,10 +3,11 @@ package types import ( fmt "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) const ( @@ -63,7 +64,7 @@ func (p *AddBurnTaxExemptionAddressProposal) ValidateBasic() error { for _, address := range p.Addresses { _, err = sdk.AccAddressFromBech32(address) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s: %s", err, address) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s: %s", err, address) } } @@ -107,7 +108,7 @@ func (p *RemoveBurnTaxExemptionAddressProposal) ValidateBasic() error { for _, address := range p.Addresses { _, err = sdk.AccAddressFromBech32(address) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s: %s", err, address) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s: %s", err, address) } }