From 5b800fcd91cf4e33e94df639ebe612167cf9ac0a Mon Sep 17 00:00:00 2001 From: Aris2049 Date: Wed, 24 Jun 2026 16:07:18 +0800 Subject: [PATCH 1/3] fix: low-risk lint errors --- Makefile | 20 ++++++++++++++++--- app/modules.go | 4 ++-- cmd/med/cmd/gen_relayer.go | 5 +++-- cmd/med/cmd/utils.go | 3 +-- x/dao/keeper/msg_server.go | 10 +++++----- x/delayedack/types/params.go | 3 ++- x/denommetadata/ibc_middleware.go | 6 +++--- x/kyc/keeper/did.go | 3 ++- x/kyc/keeper/keeper.go | 3 ++- .../grpc_query_sequencers_by_rollapp.go | 3 ++- x/sequencer/keeper/replace_proposer.go | 7 ++++--- x/sequencer/simulation/create_sequencer.go | 2 +- x/sequencer/types/genesis.go | 7 +++++-- 13 files changed, 49 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 4da178161..a2b484331 100755 --- a/Makefile +++ b/Makefile @@ -350,6 +350,8 @@ proto-download-deps: ############################################################################### golangci_version=v1.64.8 +lint_base_rev?=origin/main +lint_pr_base_rev?=$(lint_base_rev) lint-install: @echo "--> Installing golangci-lint $(golangci_version)" @@ -361,8 +363,20 @@ lint-install: fi lint: lint-install - @echo "--> Running linter" - @golangci-lint run --build-tags=$(GO_BUILD) --out-format=tab + @echo "--> Running linter on changes since $(lint_base_rev)" + @golangci-lint run --config=.golangci.yml --build-tags=$(GO_BUILD) --out-format=tab --new-from-rev=$(lint_base_rev) --timeout=15m + +lint-fix: lint-install + @echo "--> Running linter with fixes on changes since $(lint_base_rev)" + @golangci-lint run --config=.golangci.yml --build-tags=$(GO_BUILD) --out-format=tab --new-from-rev=$(lint_base_rev) --timeout=15m --fix + +lint-pr: lint-install + @echo "--> Running PR linter on changes since $(lint_pr_base_rev)" + @golangci-lint run --config=.golangci.yml --build-tags=$(GO_BUILD) --out-format=tab --new-from-rev=$(lint_pr_base_rev) --timeout=15m + +lint-all: lint-install + @echo "--> Running linter on entire repository" + @golangci-lint run --config=.golangci.yml --build-tags=$(GO_BUILD) --out-format=tab --timeout=15m format: lint-install @golangci-lint run --build-tags=$(GO_BUILD) --out-format=tab --fix @@ -376,7 +390,7 @@ shell-format: #go install mvdan.cc/sh/v3/cmd/shfmt@v3.8.0 grep -r '^#!/usr/bin/env bash' --exclude-dir={node_modules,build} . | cut -d: -f1 | xargs shfmt -l -w -i 2 -.PHONY: format lint shell-lint shell-format +.PHONY: format lint lint-fix lint-pr lint-all shell-lint shell-format ############################################################################### ### Tests & Simulation ### diff --git a/app/modules.go b/app/modules.go index a95c5c143..186ebd77c 100644 --- a/app/modules.go +++ b/app/modules.go @@ -36,9 +36,9 @@ import ( "github.com/openmetaearth/me-hub/x/delayedack" "github.com/openmetaearth/me-hub/x/denommetadata" denommetadatamoduleclient "github.com/openmetaearth/me-hub/x/denommetadata/client" - did "github.com/openmetaearth/me-hub/x/did" + "github.com/openmetaearth/me-hub/x/did" "github.com/openmetaearth/me-hub/x/eibc" - kyc "github.com/openmetaearth/me-hub/x/kyc" + "github.com/openmetaearth/me-hub/x/kyc" groupmodule "github.com/openmetaearth/me-hub/x/megroup" "github.com/openmetaearth/me-hub/x/rollapp" rollappmoduleclient "github.com/openmetaearth/me-hub/x/rollapp/client" diff --git a/cmd/med/cmd/gen_relayer.go b/cmd/med/cmd/gen_relayer.go index e2cf400eb..6e3d5fdc0 100644 --- a/cmd/med/cmd/gen_relayer.go +++ b/cmd/med/cmd/gen_relayer.go @@ -2,6 +2,7 @@ package cmd import ( "encoding/json" + "errors" "fmt" "strings" @@ -38,7 +39,7 @@ func GenRelayersCmd(defaultNodeHome string) *cobra.Command { return fmt.Errorf("parse coins: %w", err) } if !coins.IsValid() { - return fmt.Errorf("invalid coins") + return errors.New("invalid coins") } rawAddrList := strings.Split(args[0], ",") @@ -64,7 +65,7 @@ func GenRelayersCmd(defaultNodeHome string) *cobra.Command { proposalRelayers = append(proposalRelayers, addrStr) } if len(addrs) == 0 { - return fmt.Errorf("no valid addresses provided") + return errors.New("no valid addresses provided") } genFile := config.GenesisFile() diff --git a/cmd/med/cmd/utils.go b/cmd/med/cmd/utils.go index ba47c9b76..e722bd2ca 100644 --- a/cmd/med/cmd/utils.go +++ b/cmd/med/cmd/utils.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/types/tx" txtypes "github.com/cosmos/cosmos-sdk/types/tx" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/gogoproto/proto" @@ -80,7 +79,7 @@ func GetDecodeRawTxCommand() *cobra.Command { } else { txBz = []byte(args[0]) } - var rawTx tx.TxRaw + var rawTx txtypes.TxRaw err := json.Unmarshal(txBz, &rawTx) if err != nil { return fmt.Errorf("failed to unmarshal raw tx: %w", err) diff --git a/x/dao/keeper/msg_server.go b/x/dao/keeper/msg_server.go index 5e727711f..70cd97139 100755 --- a/x/dao/keeper/msg_server.go +++ b/x/dao/keeper/msg_server.go @@ -67,17 +67,17 @@ func (k msgServer) FreeGasAccount(goCtx context.Context, msg *types.MsgFreeGasAc if isExist { if account.IsFree { return nil, sdkerrors.Wrap(types.ErrFreeGasAccountAlreadyExist, account.Address) - } else { - k.RemoveFreeGasAccount(ctx, account.Address) } + + k.RemoveFreeGasAccount(ctx, account.Address) } if !isExist { - if account.IsFree { - k.SetFreeGasAccount(ctx, account.Address) - } else { + if !account.IsFree { return nil, sdkerrors.Wrap(types.ErrAccountIsNotFree, account.Address) } + + k.SetFreeGasAccount(ctx, account.Address) } } diff --git a/x/delayedack/types/params.go b/x/delayedack/types/params.go index 868c0c4a9..aff7d569c 100755 --- a/x/delayedack/types/params.go +++ b/x/delayedack/types/params.go @@ -1,6 +1,7 @@ package types import ( + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -83,7 +84,7 @@ func validateEpochIdentifier(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } if len(v) == 0 { - return fmt.Errorf("epoch identifier cannot be empty") + return errors.New("epoch identifier cannot be empty") } return nil } diff --git a/x/denommetadata/ibc_middleware.go b/x/denommetadata/ibc_middleware.go index 4b34afc84..57674b80d 100755 --- a/x/denommetadata/ibc_middleware.go +++ b/x/denommetadata/ibc_middleware.go @@ -1,7 +1,7 @@ package denommetadata import ( - . "slices" + "slices" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -142,7 +142,7 @@ func (im IBCModule) OnAcknowledgementPacket( return gerrc.ErrNotFound } - if !Contains(rollapp.RegisteredDenoms, dm.Base) { + if !slices.Contains(rollapp.RegisteredDenoms, dm.Base) { // add the new token denom base to the list of rollapp's registered denoms rollapp.RegisteredDenoms = append(rollapp.RegisteredDenoms, dm.Base) @@ -215,7 +215,7 @@ func (m *ICS4Wrapper) SendPacket( // At the first match, we assume that the rollapp already contains the metadata. // It would be technically possible to have a race condition where the denom metadata is added to the rollapp // from another packet before this packet is acknowledged. - if Contains(rollapp.RegisteredDenoms, packet.Denom) { + if slices.Contains(rollapp.RegisteredDenoms, packet.Denom) { return m.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) } diff --git a/x/kyc/keeper/did.go b/x/kyc/keeper/did.go index ddb4cdd60..ef53a100c 100755 --- a/x/kyc/keeper/did.go +++ b/x/kyc/keeper/did.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -44,7 +45,7 @@ func (k Keeper) SetKycIssers(ctx sdk.Context, oldDaoAddress, newDaoAddress []str service, ok := k.GetService(ctx) if !ok { - return fmt.Errorf("kyc service not found") + return errors.New("kyc service not found") } dids := []string{} diff --git a/x/kyc/keeper/keeper.go b/x/kyc/keeper/keeper.go index 8a07bd416..c791a4d55 100755 --- a/x/kyc/keeper/keeper.go +++ b/x/kyc/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "github.com/cometbft/cometbft/libs/log" @@ -63,7 +64,7 @@ func (k *Keeper) MustAccAddressFromPubkeyString(s string) (sdk.AccAddress, error } return sdk.AccAddress(pk.Address()), nil } - return sdk.AccAddress{}, fmt.Errorf("pubkey is empty") + return sdk.AccAddress{}, errors.New("pubkey is empty") } func (k *Keeper) RegisterEventHandler(eventType string, priority int, module string, handler handler.HandlerFunc) { diff --git a/x/sequencer/keeper/grpc_query_sequencers_by_rollapp.go b/x/sequencer/keeper/grpc_query_sequencers_by_rollapp.go index e980e9308..acb651517 100755 --- a/x/sequencer/keeper/grpc_query_sequencers_by_rollapp.go +++ b/x/sequencer/keeper/grpc_query_sequencers_by_rollapp.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -87,7 +88,7 @@ func (k Keeper) UnConfirmSequencerAddressByRollappByStatus(goCtx context.Context "cacheHeight", k.replaceSequencerCacheHeight) } */ - return nil, fmt.Errorf("unsupport function") + return nil, errors.New("unsupport function") } func (k Keeper) ReplaceProposerInfo(goCtx context.Context, req *types.QueryReplaceProposerInfoRequest) (*types.QueryReplaceProposerInfoResponse, error) { diff --git a/x/sequencer/keeper/replace_proposer.go b/x/sequencer/keeper/replace_proposer.go index ef5efc6de..bc2f09564 100644 --- a/x/sequencer/keeper/replace_proposer.go +++ b/x/sequencer/keeper/replace_proposer.go @@ -1,18 +1,19 @@ package keeper import ( + "errors" "fmt" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - rollappTypes "github.com/openmetaearth/me-hub/x/rollapp/types" + rollapptypes "github.com/openmetaearth/me-hub/x/rollapp/types" "github.com/openmetaearth/me-hub/x/sequencer/types" ) func (k Keeper) SetReplaceProposer(ctx sdk.Context, data *types.MsgRepalceProposer) error { if nil == data { - return fmt.Errorf("SetReplaceProposer data is nil") + return errors.New("SetReplaceProposer data is nil") } store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{}) val := store.Get(types.RepalceRollappProposerKey(data.RollappId)) @@ -93,7 +94,7 @@ func (k Keeper) IsReplacedSequencerAddress(ctx sdk.Context, rollappId, addr stri */ -func (k Keeper) ProcSequencerByPendingStates(ctx sdk.Context, rollappId, creator string, rollappState *rollappTypes.StateInfo) error { +func (k Keeper) ProcSequencerByPendingStates(ctx sdk.Context, rollappId, creator string, rollappState *rollapptypes.StateInfo) error { val, err := k.GetReplaceProposer(ctx, rollappId) if err != nil { return err diff --git a/x/sequencer/simulation/create_sequencer.go b/x/sequencer/simulation/create_sequencer.go index 2323a8ff8..1ed225328 100755 --- a/x/sequencer/simulation/create_sequencer.go +++ b/x/sequencer/simulation/create_sequencer.go @@ -68,7 +68,7 @@ func SimulateMsgCreateSequencer( for _, item := range simulation.GlobalSequencerAddressesList { // check how many sequencers already attached to this rollapp if item.RollappIndex == rollappIndex { - rollappSeqNum += 1 + rollappSeqNum++ } // check if we already created it if item.Account.Address.String() == seqAddress { diff --git a/x/sequencer/types/genesis.go b/x/sequencer/types/genesis.go index 4d0c02512..4d38348ad 100755 --- a/x/sequencer/types/genesis.go +++ b/x/sequencer/types/genesis.go @@ -1,6 +1,9 @@ package types -import "fmt" +import ( + "errors" + "fmt" +) // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { @@ -25,7 +28,7 @@ func (gs GenesisState) Validate() error { index := string(SequencerKey(elem.SequencerAddress)) if _, ok := sequencerIndexMap[index]; ok { - return fmt.Errorf("duplicated index for sequencer") + return errors.New("duplicated index for sequencer") } sequencerIndexMap[index] = struct{}{} From 4a648b0e6875a86f8e65c6f239379a0984bae99b Mon Sep 17 00:00:00 2001 From: Aris2049 Date: Wed, 24 Jun 2026 16:17:54 +0800 Subject: [PATCH 2/3] fix: low-risk lint errors --- app/apptesting/test_helpers.go | 8 ++++---- app/keepers/keys.go | 4 ++-- app/keepers/wasm_me_msg.go | 2 +- cmd/med/cmd/genmoduleaccount.go | 1 - .../client/cli/tx_replace_consensus_pubkey.go | 8 ++++---- x/wstaking/keeper/alias_functions.go | 16 ++++++++-------- x/wstaking/keeper/fixed_deposit_cfg.go | 4 ++-- x/wstaking/keeper/kyc_reward.go | 8 ++++---- x/wstaking/keeper/msg_server.go | 6 +++--- x/wstaking/keeper/msg_server_delegate.go | 3 ++- x/wstaking/keeper/msg_server_fixed_deposit.go | 3 ++- ...g_server_ibc_transfer_from_region_treasure.go | 2 +- x/wstaking/keeper/msg_server_undelegate.go | 2 ++ x/wstaking/keeper/msg_server_validator.go | 2 +- x/wstaking/keeper/update_pub_key.go | 2 +- 15 files changed, 37 insertions(+), 34 deletions(-) diff --git a/app/apptesting/test_helpers.go b/app/apptesting/test_helpers.go index 9b56e7eb3..ebc7e2f9c 100755 --- a/app/apptesting/test_helpers.go +++ b/app/apptesting/test_helpers.go @@ -363,9 +363,9 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress { // start at 100 so we can make up to 999 test addresses with valid test addresses for i := 100; i < (accNum + 100); i++ { numString := strconv.Itoa(i) - buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string + _, _ = buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string - buffer.WriteString(numString) // adding on final two digits to make addresses unique + _, _ = buffer.WriteString(numString) // adding on final two digits to make addresses unique res, _ := sdk.AccAddressFromHexUnsafe(buffer.String()) bech := res.String() addr, _ := TestAddr(buffer.String(), bech) @@ -555,8 +555,8 @@ func CreateTestPubKeys(numPubKeys int) []cryptotypes.PubKey { // start at 10 to avoid changing 1 to 01, 2 to 02, etc for i := 100; i < (numPubKeys + 100); i++ { numString := strconv.Itoa(i) - buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") // base pubkey string - buffer.WriteString(numString) // adding on final two digits to make pubkeys unique + _, _ = buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") // base pubkey string + _, _ = buffer.WriteString(numString) // adding on final two digits to make pubkeys unique publicKeys = append(publicKeys, NewPubKeyFromHex(buffer.String())) buffer.Reset() } diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 7926e1069..6f9bde075 100755 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -32,7 +32,7 @@ import ( didtypes "github.com/openmetaearth/me-hub/x/did/types" eibcmoduletypes "github.com/openmetaearth/me-hub/x/eibc/types" kyctypes "github.com/openmetaearth/me-hub/x/kyc/types" - gourpTypes "github.com/openmetaearth/me-hub/x/megroup/types" + grouptypes "github.com/openmetaearth/me-hub/x/megroup/types" rollappmoduletypes "github.com/openmetaearth/me-hub/x/rollapp/types" sequencermoduletypes "github.com/openmetaearth/me-hub/x/sequencer/types" trontypes "github.com/openmetaearth/me-hub/x/tron/types" @@ -127,7 +127,7 @@ var KVStoreKeys = sdk.NewKVStoreKeys( nftkeeper.StoreKey, wasmtypes.StoreKey, // megroup - gourpTypes.StoreKey, + grouptypes.StoreKey, // gravity bridge bsctypes.StoreKey, trontypes.StoreKey, diff --git a/app/keepers/wasm_me_msg.go b/app/keepers/wasm_me_msg.go index 40b939c04..3011a125e 100644 --- a/app/keepers/wasm_me_msg.go +++ b/app/keepers/wasm_me_msg.go @@ -37,7 +37,7 @@ func EncodeMeMsg(sender sdk.AccAddress, msg *MeMsg) ([]sdk.Msg, error) { return nil, err } - var outputs []banktypes.Output + outputs := make([]banktypes.Output, 0, len(msg.MultiSend.Output)) for _, o := range msg.MultiSend.Output { amt, err := wasmkeeper.ConvertWasmCoinsToSdkCoins(o.Amount) if err != nil { diff --git a/cmd/med/cmd/genmoduleaccount.go b/cmd/med/cmd/genmoduleaccount.go index a6e11f64b..71a9575a1 100755 --- a/cmd/med/cmd/genmoduleaccount.go +++ b/cmd/med/cmd/genmoduleaccount.go @@ -173,7 +173,6 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa // Add the new account to the set of genesis accounts and sanitize the // accounts afterwards. accs = append(accs, genAccount) - } accs = authtypes.SanitizeGenesisAccounts(accs) diff --git a/x/wstaking/client/cli/tx_replace_consensus_pubkey.go b/x/wstaking/client/cli/tx_replace_consensus_pubkey.go index 90626bfa0..af4c489a7 100644 --- a/x/wstaking/client/cli/tx_replace_consensus_pubkey.go +++ b/x/wstaking/client/cli/tx_replace_consensus_pubkey.go @@ -1,7 +1,7 @@ package cli import ( - "fmt" + "errors" "strconv" "github.com/cosmos/cosmos-sdk/client" @@ -21,7 +21,7 @@ func CmdReplaceConsensusPubKey() *cobra.Command { Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) (err error) { operator := args[0] - blocl_number, err := strconv.ParseInt(args[2], 10, 64) + bloclNumber, err := strconv.ParseInt(args[2], 10, 64) if err != nil { return err } @@ -36,7 +36,7 @@ func CmdReplaceConsensusPubKey() *cobra.Command { return err } if pk.Bytes() == nil { - return fmt.Errorf("pubkey by UnmarshalInterfaceJSON cannot be nil") + return errors.New("pubkey by UnmarshalInterfaceJSON cannot be nil") } codecPubKey, err := codectypes.NewAnyWithValue(pk) if err != nil { @@ -48,7 +48,7 @@ func CmdReplaceConsensusPubKey() *cobra.Command { ReplacePubKey: &types.MsgReplaceConsensusPubKey{ OperatorAddress: operator, PubKey: codecPubKey, - BlockNumber: blocl_number, + BlockNumber: bloclNumber, }, } diff --git a/x/wstaking/keeper/alias_functions.go b/x/wstaking/keeper/alias_functions.go index 7a22ac9d8..1aad7c6ce 100755 --- a/x/wstaking/keeper/alias_functions.go +++ b/x/wstaking/keeper/alias_functions.go @@ -9,7 +9,7 @@ import ( "github.com/openmetaearth/me-hub/app/params" "github.com/openmetaearth/me-hub/x/wmint" - mintTypes "github.com/openmetaearth/me-hub/x/wmint/types" + wminttypes "github.com/openmetaearth/me-hub/x/wmint/types" "github.com/openmetaearth/me-hub/x/wstaking/types" ) @@ -25,13 +25,13 @@ func (k Keeper) CalculateInterest(ctx sdk.Context, totalStaking cmath.Int, heigh func (k Keeper) getRewardsByHeight(fromHeight, toHeight int64) (coin sdk.Dec) { totalCoins := sdk.ZeroInt() - lowMul := (fromHeight - 1) / mintTypes.OneYearTotalBlocks - highMul := (toHeight - 1) / mintTypes.OneYearTotalBlocks + lowMul := (fromHeight - 1) / wminttypes.OneYearTotalBlocks + highMul := (toHeight - 1) / wminttypes.OneYearTotalBlocks for i := lowMul; i <= highMul; i++ { halvingDivisor := sdk.NewDecFromBigInt(new(big.Int).Lsh(big.NewInt(1), uint(i))) - amountDec := sdk.NewDec(int64(mintTypes.InitOneYearMintAmount)). - Quo(sdk.NewDec(int64(mintTypes.OneYearTotalBlocks))). + amountDec := sdk.NewDec(int64(wminttypes.InitOneYearMintAmount)). + Quo(sdk.NewDec(int64(wminttypes.OneYearTotalBlocks))). Quo(halvingDivisor) mintUMECAmount := wmint.RoundUpToFourDecimalsDec(amountDec).MulInt64(100_000_000).TruncateInt() @@ -41,13 +41,13 @@ func (k Keeper) getRewardsByHeight(fromHeight, toHeight int64) (coin sdk.Dec) { blockCount = toHeight - fromHeight // Calculate the number of tokens between fromHeight and its first halving boundary } else if i == lowMul { - blockCount = int64(mintTypes.OneYearTotalBlocks)*(lowMul+1) - fromHeight + 1 + blockCount = int64(wminttypes.OneYearTotalBlocks)*(lowMul+1) - fromHeight + 1 // Calculate the number of tokens between the last halving boundary and toHeight } else if i == highMul { - blockCount = toHeight - int64(mintTypes.OneYearTotalBlocks)*i - 1 + blockCount = toHeight - int64(wminttypes.OneYearTotalBlocks)*i - 1 } else { // Calculate the number of tokens for each full halving interval - blockCount = int64(mintTypes.OneYearTotalBlocks) + blockCount = int64(wminttypes.OneYearTotalBlocks) } totalCoins = totalCoins.Add(mintUMECAmount.MulRaw(blockCount)) diff --git a/x/wstaking/keeper/fixed_deposit_cfg.go b/x/wstaking/keeper/fixed_deposit_cfg.go index 37af81f05..2a646001d 100755 --- a/x/wstaking/keeper/fixed_deposit_cfg.go +++ b/x/wstaking/keeper/fixed_deposit_cfg.go @@ -77,7 +77,7 @@ func (k Keeper) IncreaseFixedDepositCountOfCfg(ctx sdk.Context, regionId string, return types.ErrNoFixedDepositCountOfCfgFound } count := binary.BigEndian.Uint64(bz) - count += 1 + count++ buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, count) @@ -96,7 +96,7 @@ func (k Keeper) DecreaseFixedDepositCountOfCfg(ctx sdk.Context, regionId string, if count == 0 { return types.ErrFixedDepositCountOfCfgIsZero } - count -= 1 + count-- buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, count) diff --git a/x/wstaking/keeper/kyc_reward.go b/x/wstaking/keeper/kyc_reward.go index 202ab7cde..881c01113 100755 --- a/x/wstaking/keeper/kyc_reward.go +++ b/x/wstaking/keeper/kyc_reward.go @@ -47,7 +47,7 @@ func (k Keeper) KycReward(ctx sdk.Context, account sdk.AccAddress, regionId, cre // validator rewards ownerAddress := validator.OwnerAddress - if len(validator.OwnerAddress) <= 0 { + if len(validator.OwnerAddress) == 0 { ownerAddress = k.daoKeeper.GetDevOperator(ctx) } @@ -72,12 +72,12 @@ func (k Keeper) RemoveKycReward(ctx sdk.Context, account sdk.AccAddress, regionI valAddr, err := sdk.ValAddressFromBech32(region.OperatorAddress) if err != nil { - return fmt.Errorf("invalid region operator address") + return errors.New("invalid region operator address") } validator, ok := k.GetValidator(ctx, valAddr) if !ok { - return fmt.Errorf("region bonded validator not found") + return errors.New("region bonded validator not found") } delegation, found := k.GetDelegation(ctx, account, valAddr) @@ -202,7 +202,7 @@ func (k Keeper) sendKycRewards(ctx sdk.Context, delAddr sdk.AccAddress, validato experienceVal, ok := k.GetValidator(ctx, experienceValAddress) if !ok { - return fmt.Errorf("experience region validator no found") + return errors.New("experience region validator no found") } if experienceVal.DelegationAmount.GTE(delegation.UnMeidAmount) { experienceVal.DelegationAmount = experienceVal.DelegationAmount.Sub(delegation.UnMeidAmount) diff --git a/x/wstaking/keeper/msg_server.go b/x/wstaking/keeper/msg_server.go index 5675729dd..c823c1eb7 100755 --- a/x/wstaking/keeper/msg_server.go +++ b/x/wstaking/keeper/msg_server.go @@ -18,7 +18,7 @@ type MsgServer struct { stakingtypes.MsgServer *Keeper - IbcTransferKeeper ibctransferkeeper.Keeper + ibcTransferKeeper ibctransferkeeper.Keeper } var _ types.MsgServer = MsgServer{} @@ -26,12 +26,12 @@ var _ types.MsgServer = MsgServer{} // NewMsgServerImpl returns an implementation of the staking wrapped MsgServer. func NewMsgServerImpl( keeper *Keeper, - IbcTransferKeeper ibctransferkeeper.Keeper, + ibcTransferKeeper ibctransferkeeper.Keeper, stakingMsgSrv stakingtypes.MsgServer, ) MsgServer { return MsgServer{ Keeper: keeper, - IbcTransferKeeper: IbcTransferKeeper, + ibcTransferKeeper: ibcTransferKeeper, MsgServer: stakingMsgSrv, } } diff --git a/x/wstaking/keeper/msg_server_delegate.go b/x/wstaking/keeper/msg_server_delegate.go index 57199cf7d..f34508700 100755 --- a/x/wstaking/keeper/msg_server_delegate.go +++ b/x/wstaking/keeper/msg_server_delegate.go @@ -69,7 +69,8 @@ func (k MsgServer) Delegate(goCtx context.Context, msg *stakingtypes.MsgDelegate } if region.DelegateInterest.GTE(rewards) { region.DelegateInterest = region.DelegateInterest.Sub(rewards) - } else { + } + if !region.DelegateInterest.GTE(rewards) { return nil, fmt.Errorf("region(%s) total interest not enough.need pay %s,only have %s", region.RegionId, rewards.String(), region.DelegateInterest.String()) } diff --git a/x/wstaking/keeper/msg_server_fixed_deposit.go b/x/wstaking/keeper/msg_server_fixed_deposit.go index 5e5b976de..3b794cd4a 100755 --- a/x/wstaking/keeper/msg_server_fixed_deposit.go +++ b/x/wstaking/keeper/msg_server_fixed_deposit.go @@ -305,7 +305,8 @@ func (k MsgServer) WithdrawFixedDeposit(goCtx context.Context, msg *types.MsgWit "decrease fixed deposit count under the current config error, region(%s) term (%s) error(%s)", region.RegionId, fixedDeposit.Term, err) } - } else { + } + if !expired { return nil, types.ErrDoFixedWithDraw.Wrapf("withdraw fixed deposit error (%s)", types.ErrFixedDepositNotExpired) } diff --git a/x/wstaking/keeper/msg_server_ibc_transfer_from_region_treasure.go b/x/wstaking/keeper/msg_server_ibc_transfer_from_region_treasure.go index 7bb4fee7f..17cdd4932 100644 --- a/x/wstaking/keeper/msg_server_ibc_transfer_from_region_treasure.go +++ b/x/wstaking/keeper/msg_server_ibc_transfer_from_region_treasure.go @@ -25,7 +25,7 @@ func (k MsgServer) IbcTransferFromRegionTreasure(goCtx context.Context, msg *typ treasureAddress := region.RegionTreasureAddr - _, err := k.IbcTransferKeeper.Transfer(ctx, ibctransfertypes.NewMsgTransfer( + _, err := k.ibcTransferKeeper.Transfer(ctx, ibctransfertypes.NewMsgTransfer( msg.SourcePort, msg.SourceChannel, msg.Token, diff --git a/x/wstaking/keeper/msg_server_undelegate.go b/x/wstaking/keeper/msg_server_undelegate.go index 6efe0ba15..a6355bd94 100755 --- a/x/wstaking/keeper/msg_server_undelegate.go +++ b/x/wstaking/keeper/msg_server_undelegate.go @@ -52,6 +52,8 @@ func (k MsgServer) Undelegate(goCtx context.Context, msg *stakingtypes.MsgUndele return nil, types.ErrValidatorDelegationAmount.Wrapf("validator amount: %s, requested value: %s", val.DelegationAmount.String(), msg.Amount.Amount.String()) } + } else { + return nil, stakingtypes.ErrNoValidatorFound } // current interest balance * personal withdrawal pledge limit / district total pledge limit diff --git a/x/wstaking/keeper/msg_server_validator.go b/x/wstaking/keeper/msg_server_validator.go index 2884ae228..f4a367d2d 100755 --- a/x/wstaking/keeper/msg_server_validator.go +++ b/x/wstaking/keeper/msg_server_validator.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - ed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/wstaking/keeper/update_pub_key.go b/x/wstaking/keeper/update_pub_key.go index 0f107dcfe..173944a75 100644 --- a/x/wstaking/keeper/update_pub_key.go +++ b/x/wstaking/keeper/update_pub_key.go @@ -7,7 +7,7 @@ import ( "time" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - ed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" From 3c8451f20af121410f23ec06e300835f4047aafe Mon Sep 17 00:00:00 2001 From: Aris2049 Date: Wed, 24 Jun 2026 16:30:35 +0800 Subject: [PATCH 3/3] fix: low-risk lint errors --- x/kyc/keeper/grpc_query_test.go | 12 ++++---- x/kyc/keeper/msg_server_test.go | 12 ++++---- x/megroup/types/expected_keepers.go | 8 ++--- x/wdistri/keeper/keeper.go | 4 +-- x/wdistri/keeper/keeper_test.go | 46 ++++++++++++++--------------- x/wnft/keeper/grpc_query.go | 17 +++-------- 6 files changed, 45 insertions(+), 54 deletions(-) diff --git a/x/kyc/keeper/grpc_query_test.go b/x/kyc/keeper/grpc_query_test.go index 8385c920b..9084479e6 100755 --- a/x/kyc/keeper/grpc_query_test.go +++ b/x/kyc/keeper/grpc_query_test.go @@ -11,14 +11,14 @@ import ( "github.com/openmetaearth/me-hub/x/kyc/types" "github.com/openmetaearth/me-hub/x/wdistri" "github.com/openmetaearth/me-hub/x/wmint" - wmintTypes "github.com/openmetaearth/me-hub/x/wmint/types" + wminttypes "github.com/openmetaearth/me-hub/x/wmint/types" wstakingtypes "github.com/openmetaearth/me-hub/x/wstaking/types" ) func (s *KeeperTestSuite) TestProtocol() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -36,7 +36,7 @@ func (s *KeeperTestSuite) TestProtocol() { func (s *KeeperTestSuite) TestDID() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -71,7 +71,7 @@ func (s *KeeperTestSuite) TestDID() { func (s *KeeperTestSuite) TestDIDs() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -108,7 +108,7 @@ func (s *KeeperTestSuite) TestDIDs() { func (s *KeeperTestSuite) TestKYC() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -144,7 +144,7 @@ func (s *KeeperTestSuite) TestKYC() { func (s *KeeperTestSuite) TestKYCs() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) diff --git a/x/kyc/keeper/msg_server_test.go b/x/kyc/keeper/msg_server_test.go index bc914bc88..e07652404 100755 --- a/x/kyc/keeper/msg_server_test.go +++ b/x/kyc/keeper/msg_server_test.go @@ -12,12 +12,12 @@ import ( "github.com/openmetaearth/me-hub/x/kyc/types" "github.com/openmetaearth/me-hub/x/wdistri" "github.com/openmetaearth/me-hub/x/wmint" - wmintTypes "github.com/openmetaearth/me-hub/x/wmint/types" + wminttypes "github.com/openmetaearth/me-hub/x/wmint/types" wstakingtypes "github.com/openmetaearth/me-hub/x/wstaking/types" ) func (s *KeeperTestSuite) TestApprove() { - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -65,7 +65,7 @@ func (s *KeeperTestSuite) TestApprove() { func (s *KeeperTestSuite) TestRemove() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -119,7 +119,7 @@ func (s *KeeperTestSuite) TestRemove() { func (s *KeeperTestSuite) TestUpdate() { s.SetupTest() - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks).WithChainID(apptesting.TestChainID) wmint.BeginBlocker(s.Ctx, s.App.MintKeeper, nil) wdistri.EndBlock(s.Ctx, abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}, *s.App.DistrKeeper) @@ -153,7 +153,7 @@ func (s *KeeperTestSuite) TestUpdate() { s.Require().Equal(delegation.Unmovable.String(), wstakingtypes.Bonus.String()) s.Require().Equal(delegation.ValidatorAddress, s.meEarthValidator.OperatorAddress) - s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wmintTypes.OneDayTotalBlocks + 1).WithChainID(apptesting.TestChainID) + s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{}).WithBlockHeight(wminttypes.OneDayTotalBlocks + 1).WithChainID(apptesting.TestChainID) // transfer kyc region _, err = s.msgServer.Update(s.Ctx, &types.MsgUpdate{ Issuer: s.Dao.GlobalDao, @@ -168,5 +168,5 @@ func (s *KeeperTestSuite) TestUpdate() { s.Require().True(f) s.Require().Equal(delegation.Unmovable.String(), wstakingtypes.Bonus.String()) s.Require().Equal(s.usaValidator.OperatorAddress, delegation.ValidatorAddress) - s.Require().EqualValues(delegation.StartHeight, wmintTypes.OneDayTotalBlocks+1) + s.Require().EqualValues(delegation.StartHeight, wminttypes.OneDayTotalBlocks+1) } diff --git a/x/megroup/types/expected_keepers.go b/x/megroup/types/expected_keepers.go index 7b3a599b2..d6cb7ed9f 100755 --- a/x/megroup/types/expected_keepers.go +++ b/x/megroup/types/expected_keepers.go @@ -7,7 +7,7 @@ import ( didtypes "github.com/openmetaearth/me-hub/x/did/types" "github.com/openmetaearth/me-hub/x/kyc/handler" bankkeeper "github.com/openmetaearth/me-hub/x/wbank/keeper" - stakingTypes "github.com/openmetaearth/me-hub/x/wstaking/types" + wstakingtypes "github.com/openmetaearth/me-hub/x/wstaking/types" ) type StakingKeeper interface { @@ -15,14 +15,14 @@ type StakingKeeper interface { // FIXME: wait wstaking keep and types.Meid ;Temporarily use MockMeid instead of MEID and MockRegion instead types.Region // GetMeid(ctx sdk.Context, account string) (val types.Meid, found bool) - GetMeid(ctx sdk.Context, account string) (val stakingTypes.Meid, found bool) + GetMeid(ctx sdk.Context, account string) (val wstakingtypes.Meid, found bool) // SetMeid(ctx sdk.Context, meid types.Meid) - SetMeid(ctx sdk.Context, meid stakingTypes.Meid) + SetMeid(ctx sdk.Context, meid wstakingtypes.Meid) // GetRegion(ctx sdk.Context, regionId string) (val types.Region, found bool) // GetRegion(ctx sdk.Context, regionId string) (val mock.MockRegion, found bool) - GetRegion(ctx sdk.Context, regionId string) (region stakingTypes.Region, found bool) + GetRegion(ctx sdk.Context, regionId string) (region wstakingtypes.Region, found bool) } // AccountKeeper defines the expected account keeper used for simulations (noalias) diff --git a/x/wdistri/keeper/keeper.go b/x/wdistri/keeper/keeper.go index 8d791306e..faac73d33 100755 --- a/x/wdistri/keeper/keeper.go +++ b/x/wdistri/keeper/keeper.go @@ -46,7 +46,7 @@ func NewKeeper( feeCollectorName string, authority string, ) *Keeper { - DistrKeeper := distriKeeper.NewKeeper( + distriKeeperImpl := distriKeeper.NewKeeper( cdc, storeKey, accountKeeper, @@ -56,7 +56,7 @@ func NewKeeper( authority, ) return &Keeper{ - Keeper: DistrKeeper, + Keeper: distriKeeperImpl, cdc: cdc, storeKey: storeKey, paramstore: ps, diff --git a/x/wdistri/keeper/keeper_test.go b/x/wdistri/keeper/keeper_test.go index b5b595a24..4b3e58426 100755 --- a/x/wdistri/keeper/keeper_test.go +++ b/x/wdistri/keeper/keeper_test.go @@ -154,7 +154,7 @@ func (s *KeeperTestSuite) TestGetTreasuryModuleAccount() { } } -func (suite *KeeperTestSuite) TestEndBlocker() { +func (s *KeeperTestSuite) TestEndBlocker() { /* first year per block reward is :792.7448 mec 79274480000 umec first year daily reward is :13698630.1440 mec 1369863014400000 umec @@ -207,8 +207,8 @@ func (suite *KeeperTestSuite) TestEndBlocker() { } runCase := func(index int) { testcase := testsCases[index] - ctx := suite.HelperNewContextWith(int64(testcase.height)) - addrs := suite.mockGetRegionI(ctx, testcase.regionShares...) + ctx := s.HelperNewContextWith(int64(testcase.height)) + addrs := s.mockGetRegionI(ctx, testcase.regionShares...) var wantReward []coinAndAddr totalWantReward := 0 for i, addr := range addrs { @@ -219,30 +219,30 @@ func (suite *KeeperTestSuite) TestEndBlocker() { totalWantReward += testcase.regionWantGetReward[i] } if totalWantReward != 0 { - suite.SetMockGetBalance(ctx, sdk.NewInt(int64(totalWantReward))) + s.SetMockGetBalance(ctx, sdk.NewInt(int64(totalWantReward))) } - suite.setMockSendCoinsFromModuleToAccountExpect(ctx, wantReward...) + s.setMockSendCoinsFromModuleToAccountExpect(ctx, wantReward...) - err := suite.App.DistrKeeper.AllocateBlockRewardEveryday(ctx, abci.RequestEndBlock{Height: ctx.BlockHeight()}) + err := s.App.DistrKeeper.AllocateBlockRewardEveryday(ctx, abci.RequestEndBlock{Height: ctx.BlockHeight()}) events := ctx.EventManager().ABCIEvents() - suite.Require().NoError(err, "case %d: %s", index, testcase.name) - assert.Equal(suite.T(), len(addrs), len(events)) + s.Require().NoError(err, "case %d: %s", index, testcase.name) + assert.Equal(s.T(), len(addrs), len(events)) } for i := range testsCases { - suite.Run(testsCases[i].name, func() { + s.Run(testsCases[i].name, func() { runCase(i) }) } } -func (suite *KeeperTestSuite) mockGetRegionI(ctx sdk.Context, regionShare ...int) []string { - var addrs []string +func (s *KeeperTestSuite) mockGetRegionI(ctx sdk.Context, regionShare ...int) []string { + addrs := make([]string, 0, len(regionShare)) if len(regionShare) == 0 { return addrs } - var regions []wstakingtypes.RegionI + regions := make([]wstakingtypes.RegionI, 0, len(regionShare)) for i, share := range regionShare { - region := mocks.NewMockRegionI(suite.T()) + region := mocks.NewMockRegionI(s.T()) region.EXPECT().GetRegionShare().Return(sdk.NewInt(int64(share))) addr := authtypes.NewModuleAddress(fmt.Sprintf("region_%d", i)).String() addrs = append(addrs, addr) @@ -250,18 +250,18 @@ func (suite *KeeperTestSuite) mockGetRegionI(ctx sdk.Context, regionShare ...int region.EXPECT().GetRegionId().Return(fmt.Sprintf("region_ID_%d", i)) regions = append(regions, region) } - suite.stakingKeeper.EXPECT().GetAllRegionI(ctx).Return(regions) + s.stakingKeeper.EXPECT().GetAllRegionI(ctx).Return(regions) return addrs } -func (suite *KeeperTestSuite) SetMockGetBalance(ctx sdk.Context, amount sdkmath.Int) { - acc := authtypes.NewModuleAddress(suite.App.DistrKeeper.GetTreasuryModuleAccount()) - suite.authKeeper.EXPECT().GetModuleAddress(suite.App.DistrKeeper.GetTreasuryModuleAccount()).Return(acc) - suite.bankKeeper.EXPECT().GetAllBalances(ctx, acc).Return(sdk.NewCoins(sdk.NewCoin(params.BaseDenom, amount))) +func (s *KeeperTestSuite) SetMockGetBalance(ctx sdk.Context, amount sdkmath.Int) { + acc := authtypes.NewModuleAddress(s.App.DistrKeeper.GetTreasuryModuleAccount()) + s.authKeeper.EXPECT().GetModuleAddress(s.App.DistrKeeper.GetTreasuryModuleAccount()).Return(acc) + s.bankKeeper.EXPECT().GetAllBalances(ctx, acc).Return(sdk.NewCoins(sdk.NewCoin(params.BaseDenom, amount))) } -func (suite *KeeperTestSuite) HelperNewContextWith(height int64) sdk.Context { - return sdk.NewContext(suite.Ctx.MultiStore(), tmproto.Header{Time: tmtime.Now(), Height: height}, false, log.NewNopLogger()) +func (s *KeeperTestSuite) HelperNewContextWith(height int64) sdk.Context { + return sdk.NewContext(s.Ctx.MultiStore(), tmproto.Header{Time: tmtime.Now(), Height: height}, false, log.NewNopLogger()) } type coinAndAddr struct { @@ -269,13 +269,13 @@ type coinAndAddr struct { addr string } -func (suite *KeeperTestSuite) setMockSendCoinsFromModuleToAccountExpect(ctx sdk.Context, want ...coinAndAddr) { +func (s *KeeperTestSuite) setMockSendCoinsFromModuleToAccountExpect(ctx sdk.Context, want ...coinAndAddr) { baseDenom := params.BaseDenom for _, w := range want { - suite.bankKeeper.EXPECT(). + s.bankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, - suite.App.DistrKeeper.GetTreasuryModuleAccount(), + s.App.DistrKeeper.GetTreasuryModuleAccount(), sdk.MustAccAddressFromBech32(w.addr), sdk.NewCoins(sdk.NewCoin(baseDenom, sdk.NewInt(w.num))), ).Return(nil) diff --git a/x/wnft/keeper/grpc_query.go b/x/wnft/keeper/grpc_query.go index 10989b721..dcd7c43af 100755 --- a/x/wnft/keeper/grpc_query.go +++ b/x/wnft/keeper/grpc_query.go @@ -35,7 +35,7 @@ func (k Keeper) ClassAddress(goCtx context.Context, r *types.QueryClassAddressRe nfts := k.GetNFTsOfClassByOwner(ctx, r.ClassId, address) - var tokenIds []string + tokenIds := make([]string, 0, len(nfts)) for _, nft := range nfts { tokenIds = append(tokenIds, nft.Id) } @@ -74,10 +74,7 @@ func (k Keeper) NftFilter(goCtx context.Context, r *types.QueryNftFilterRequest) Uri: nftInfo.Uri, }) - return &types.QueryNftFilterResponse{ - Nfts: list, - }, nil - + return &types.QueryNftFilterResponse{Nfts: list}, nil } else if r.ClassId != "" && r.Owner != "" && r.TokenId == "" { // query the holdings of a specific type of nft _, has := k.GetClass(ctx, r.ClassId) @@ -96,10 +93,7 @@ func (k Keeper) NftFilter(goCtx context.Context, r *types.QueryNftFilterRequest) }) } - return &types.QueryNftFilterResponse{ - Nfts: list, - }, nil - + return &types.QueryNftFilterResponse{Nfts: list}, nil } else if r.Owner != "" && r.TokenId == "" && r.ClassId == "" { // query the nft information held by the address classes := k.GetClasses(ctx) @@ -117,10 +111,7 @@ func (k Keeper) NftFilter(goCtx context.Context, r *types.QueryNftFilterRequest) } } - return &types.QueryNftFilterResponse{ - Nfts: list, - }, nil - + return &types.QueryNftFilterResponse{Nfts: list}, nil } return nil, nil }