From 7f349553abf3d5d1b4fac2566239375a595637c9 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Fri, 9 Feb 2024 05:02:45 +0900 Subject: [PATCH] style: lint --- .golangci.yml | 12 ++-- simapp/app_test.go | 2 +- simapp/simd/cmd/commands.go | 4 +- simapp/simd/cmd/root_v2.go | 2 +- simapp/test_helpers.go | 1 + x/collection/collection.go | 17 +++--- x/collection/collection_test.go | 7 +-- x/collection/genesis.go | 9 +-- x/collection/keeper/alias.go | 3 +- x/collection/keeper/class.go | 1 + x/collection/keeper/genesis.go | 8 +-- x/collection/keeper/grpc_query.go | 7 ++- x/collection/keeper/grpc_query_test.go | 4 +- x/collection/keeper/keeper_test.go | 1 + x/collection/keeper/migrations.go | 1 + x/collection/keeper/migrations/v3/store.go | 6 +- x/collection/keeper/msg_server.go | 12 ++-- x/collection/keeper/msg_server_test.go | 4 +- x/collection/keeper/nft.go | 65 +++++++++++++++++----- x/collection/keeper/supply.go | 50 ++++++++++++----- x/collection/keeper/supply_test.go | 6 +- x/collection/module/module.go | 12 ++-- x/collection/msgs_test.go | 1 - 23 files changed, 157 insertions(+), 78 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 37d5c4b41d..6392dc50c8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,22 +1,23 @@ run: tests: true timeout: 15m - sort-results: true allow-parallel-runners: true skip-files: - ".*\\.pb\\.go$" - ".*\\.pb\\.gw\\.go$" - ".*\\.pulsar\\.go$" +output: + sort-results: true + linters: disable-all: true enable: - - depguard - dogsled - exportloopref + - gci - goconst - gocritic - - gci - gofumpt - gosec - gosimple @@ -25,8 +26,8 @@ linters: - misspell - nakedret - nolintlint - - staticcheck - revive + - staticcheck - stylecheck - typecheck - unconvert @@ -59,6 +60,9 @@ issues: - text: "leading space" linters: - nolintlint + - text: "SA1019: collection." # TODO: remove deprecated collection features later + linters: + - staticcheck max-issues-per-linter: 10000 max-same-issues: 10000 diff --git a/simapp/app_test.go b/simapp/app_test.go index 4cc736ecaf..151327b1ad 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -46,7 +46,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" - collectionmodule "github.com/Finschia/finschia-sdk/x/foundation/module" + collectionmodule "github.com/Finschia/finschia-sdk/x/collection/module" foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module" ) diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go index 8381969ee0..53fb4640f9 100644 --- a/simapp/simd/cmd/commands.go +++ b/simapp/simd/cmd/commands.go @@ -107,8 +107,8 @@ custom-field = "{{ .Custom.CustomField }}"` func initRootCmd( rootCmd *cobra.Command, txConfig client.TxConfig, - interfaceRegistry codectypes.InterfaceRegistry, - appCodec codec.Codec, + _ codectypes.InterfaceRegistry, + _ codec.Codec, basicManager module.BasicManager, ) { cfg := sdk.GetConfig() diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 4251e79c73..1aa0cf30ef 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -123,7 +123,7 @@ func ProvideClientContext( return clientCtx } -func ProvideKeyring(clientCtx client.Context, addressCodec address.Codec) (clientv2keyring.Keyring, error) { +func ProvideKeyring(clientCtx client.Context, _ address.Codec) (clientv2keyring.Keyring, error) { kb, err := client.NewKeyringFromBackend(clientCtx, clientCtx.Keyring.Backend()) if err != nil { return nil, err diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 7043f2eba3..968ba93e1d 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -95,6 +95,7 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio // Setup initializes a new SimApp. A Nop logger is set in SimApp. func Setup(t *testing.T, isCheckTx bool) *SimApp { + _ = isCheckTx t.Helper() privVal := mock.NewPV() diff --git a/x/collection/collection.go b/x/collection/collection.go index ec4159eed9..9701fe0749 100644 --- a/x/collection/collection.go +++ b/x/collection/collection.go @@ -5,9 +5,10 @@ import ( "regexp" "strings" - "cosmossdk.io/math" "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -34,7 +35,7 @@ func DefaultNextClassIDs(contractID string) NextClassIDs { } } -func validateParams(params Params) error { +func validateParams(_ Params) error { // limits are uint32, so no need to validate them. return nil } @@ -43,7 +44,7 @@ type TokenClass interface { proto.Message GetId() string - SetId(ids *NextClassIDs) + SetID(ids *NextClassIDs) SetName(name string) @@ -55,12 +56,12 @@ type TokenClass interface { func TokenClassToAny(class TokenClass) *codectypes.Any { msg := class.(proto.Message) - any, err := codectypes.NewAnyWithValue(msg) + anyv, err := codectypes.NewAnyWithValue(msg) if err != nil { panic(err) } - return any + return anyv } func TokenClassFromAny(any *codectypes.Any) TokenClass { @@ -77,8 +78,7 @@ func TokenClassUnpackInterfaces(any *codectypes.Any, unpacker codectypes.AnyUnpa // FTClass var _ TokenClass = (*FTClass)(nil) -//lint:ignore var-naming -func (c *FTClass) SetId(ids *NextClassIDs) { +func (c *FTClass) SetID(ids *NextClassIDs) { id := ids.Fungible ids.Fungible = id.Incr() c.Id = fmt.Sprintf("%08x", id.Uint64()) @@ -114,8 +114,7 @@ func (c FTClass) ValidateBasic() error { // NFTClass var _ TokenClass = (*NFTClass)(nil) -//lint:ignore var-naming -func (c *NFTClass) SetId(ids *NextClassIDs) { +func (c *NFTClass) SetID(ids *NextClassIDs) { id := ids.NonFungible ids.NonFungible = id.Incr() c.Id = fmt.Sprintf("%08x", id.Uint64()) diff --git a/x/collection/collection_test.go b/x/collection/collection_test.go index 60898b0a6e..4ced059d4d 100644 --- a/x/collection/collection_test.go +++ b/x/collection/collection_test.go @@ -41,14 +41,13 @@ func TestFTClass(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - var class collection.TokenClass - class = &collection.FTClass{ + var class collection.TokenClass = &collection.FTClass{ Id: tc.id, Decimals: tc.decimals, } if len(tc.id) == 0 { - class.SetId(&nextIDs) + class.SetID(&nextIDs) } class.SetName(tc.name) class.SetMeta(tc.meta) @@ -84,7 +83,7 @@ func TestNFTClass(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var class collection.TokenClass = &collection.NFTClass{} - class.SetId(&nextIDs) + class.SetID(&nextIDs) class.SetName(tc.name) class.SetMeta(tc.meta) diff --git a/x/collection/genesis.go b/x/collection/genesis.go index ed0e06f5f6..dc6431c130 100644 --- a/x/collection/genesis.go +++ b/x/collection/genesis.go @@ -4,6 +4,7 @@ import ( "math" cmath "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -51,8 +52,8 @@ func ValidateGenesis(data GenesisState) error { return sdkerrors.ErrInvalidRequest.Wrap("classes cannot be empty") } for i := range contractClasses.Classes { - any := &contractClasses.Classes[i] - class := TokenClassFromAny(any) + anyv := &contractClasses.Classes[i] + class := TokenClassFromAny(anyv) if err := class.ValidateBasic(); err != nil { return err } @@ -228,8 +229,8 @@ func DefaultGenesisState() *GenesisState { func (data GenesisState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { for _, contractClasses := range data.Classes { for i := range contractClasses.Classes { - any := &contractClasses.Classes[i] - if err := TokenClassUnpackInterfaces(any, unpacker); err != nil { + anyv := &contractClasses.Classes[i] + if err := TokenClassUnpackInterfaces(anyv, unpacker); err != nil { return err } } diff --git a/x/collection/keeper/alias.go b/x/collection/keeper/alias.go index bce8e90302..b007118805 100644 --- a/x/collection/keeper/alias.go +++ b/x/collection/keeper/alias.go @@ -1,9 +1,10 @@ package keeper import ( + gogotypes "github.com/cosmos/gogoproto/types" + "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" - gogotypes "github.com/cosmos/gogoproto/types" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/collection/keeper/class.go b/x/collection/keeper/class.go index dea57ea01f..a11c311d70 100644 --- a/x/collection/keeper/class.go +++ b/x/collection/keeper/class.go @@ -8,6 +8,7 @@ import ( cmath "cosmossdk.io/math" "cosmossdk.io/store/prefix" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/collection/keeper/genesis.go b/x/collection/keeper/genesis.go index bcc10c5ed9..e1e5d3d210 100644 --- a/x/collection/keeper/genesis.go +++ b/x/collection/keeper/genesis.go @@ -81,8 +81,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *collection.GenesisState) { contractID := contractClasses.ContractId for i := range contractClasses.Classes { - any := &contractClasses.Classes[i] - class := collection.TokenClassFromAny(any) + anyv := &contractClasses.Classes[i] + class := collection.TokenClassFromAny(anyv) k.setTokenClass(ctx, contractID, class) // legacy @@ -254,8 +254,8 @@ func (k Keeper) getClasses(ctx sdk.Context, contracts []collection.Contract) []c } k.iterateContractClasses(ctx, contractID, func(class collection.TokenClass) (stop bool) { - any := collection.TokenClassToAny(class) - contractClasses.Classes = append(contractClasses.Classes, *any) + anyv := collection.TokenClassToAny(class) + contractClasses.Classes = append(contractClasses.Classes, *anyv) return false }) if len(contractClasses.Classes) != 0 { diff --git a/x/collection/keeper/grpc_query.go b/x/collection/keeper/grpc_query.go index 71a266bc47..4c2d22ef6f 100644 --- a/x/collection/keeper/grpc_query.go +++ b/x/collection/keeper/grpc_query.go @@ -3,18 +3,19 @@ package keeper import ( "context" + "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" "cosmossdk.io/store/prefix" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/gogoproto/proto" "github.com/Finschia/finschia-sdk/x/collection" ) @@ -426,12 +427,12 @@ func (s queryServer) Token(c context.Context, req *collection.QueryTokenRequest) return nil, status.Error(codes.NotFound, err.Error()) } - any, err := codectypes.NewAnyWithValue(legacyToken) + anyv, err := codectypes.NewAnyWithValue(legacyToken) if err != nil { panic(err) } - return &collection.QueryTokenResponse{Token: *any}, nil + return &collection.QueryTokenResponse{Token: *anyv}, nil } func (s queryServer) Root(c context.Context, req *collection.QueryRootRequest) (*collection.QueryRootResponse, error) { diff --git a/x/collection/keeper/grpc_query_test.go b/x/collection/keeper/grpc_query_test.go index db6241148e..62f02536f7 100644 --- a/x/collection/keeper/grpc_query_test.go +++ b/x/collection/keeper/grpc_query_test.go @@ -1,10 +1,12 @@ package keeper_test import ( + "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/gogoproto/proto" "github.com/Finschia/finschia-sdk/x/collection" ) diff --git a/x/collection/keeper/keeper_test.go b/x/collection/keeper/keeper_test.go index c474d0991c..998993fc33 100644 --- a/x/collection/keeper/keeper_test.go +++ b/x/collection/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" diff --git a/x/collection/keeper/migrations.go b/x/collection/keeper/migrations.go index fd709820ef..4883c92c88 100644 --- a/x/collection/keeper/migrations.go +++ b/x/collection/keeper/migrations.go @@ -2,6 +2,7 @@ package keeper import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/collection/keeper/migrations/v3/store.go b/x/collection/keeper/migrations/v3/store.go index e21d21ec64..88b4841591 100644 --- a/x/collection/keeper/migrations/v3/store.go +++ b/x/collection/keeper/migrations/v3/store.go @@ -3,19 +3,23 @@ package v3 import ( cmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Finschia/finschia-sdk/x/collection" ) -// TODO: need to implement lggics for migrating ClassState and generate new genesis state for Collection +// TODO: need to implement logics for migrating ClassState and generate new genesis state for Collection func MigrateStore(store, classStore storetypes.KVStore, cdc codec.BinaryCodec) error { _, err := getClassState(classStore) if err != nil { return err } + _ = store + _ = cdc + return nil } diff --git a/x/collection/keeper/msg_server.go b/x/collection/keeper/msg_server.go index 19b31f788f..cd11bd6663 100644 --- a/x/collection/keeper/msg_server.go +++ b/x/collection/keeper/msg_server.go @@ -3,9 +3,10 @@ package keeper import ( "context" - "cosmossdk.io/math" "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -628,7 +629,7 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec panic(err) } - return s.keeper.ModifyNFT(ctx, req.ContractId, tokenID, operator, changes) + return s.keeper.ModifyNFT(ctx, req.ContractId, tokenID, changes) } event := collection.EventModifiedTokenClass{ @@ -642,7 +643,7 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec panic(err) } - return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, operator, changes) + return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, changes) } event := collection.EventModifiedTokenClass{ @@ -656,7 +657,7 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec panic(err) } - return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, operator, changes) + return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, changes) } if req.TokenIndex == "" { event := collection.EventModifiedContract{ @@ -668,7 +669,8 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec panic(err) } - return s.keeper.ModifyContract(ctx, req.ContractId, operator, changes) + s.keeper.ModifyContract(ctx, req.ContractId, changes) + return nil } panic(sdkerrors.ErrInvalidRequest.Wrap("token index without type")) diff --git a/x/collection/keeper/msg_server_test.go b/x/collection/keeper/msg_server_test.go index 524d607692..09c8c730a9 100644 --- a/x/collection/keeper/msg_server_test.go +++ b/x/collection/keeper/msg_server_test.go @@ -4,8 +4,10 @@ import ( "encoding/json" "fmt" - "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" diff --git a/x/collection/keeper/nft.go b/x/collection/keeper/nft.go index f31eaf322e..ef0216488c 100644 --- a/x/collection/keeper/nft.go +++ b/x/collection/keeper/nft.go @@ -1,9 +1,10 @@ package keeper import ( - "cosmossdk.io/math" gogotypes "github.com/cosmos/gogoproto/types" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/Finschia/finschia-sdk/x/collection" @@ -59,17 +60,23 @@ func (k Keeper) setNFT(ctx sdk.Context, contractID string, token collection.NFT) if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } func (k Keeper) deleteNFT(ctx sdk.Context, contractID, tokenID string) { store := k.storeService.OpenKVStore(ctx) key := nftKey(contractID, tokenID) - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } func (k Keeper) pruneNFT(ctx sdk.Context, contractID, tokenID string) []string { - burnt := []string{} + var burnt []string for _, child := range k.GetChildren(ctx, contractID, tokenID) { k.deleteChild(ctx, contractID, tokenID, child) k.deleteParent(ctx, contractID, child) @@ -216,13 +223,19 @@ func (k Keeper) setOwner(ctx sdk.Context, contractID, tokenID string, owner sdk. if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } func (k Keeper) deleteOwner(ctx sdk.Context, contractID, tokenID string) { store := k.storeService.OpenKVStore(ctx) key := ownerKey(contractID, tokenID) - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } func (k Keeper) GetParent(ctx sdk.Context, contractID, tokenID string) (*string, error) { @@ -244,13 +257,19 @@ func (k Keeper) setParent(ctx sdk.Context, contractID, tokenID, parentID string) val := &gogotypes.StringValue{Value: parentID} bz := k.cdc.MustMarshal(val) - store.Set(key, bz) + err := store.Set(key, bz) + if err != nil { + panic(err) + } } func (k Keeper) deleteParent(ctx sdk.Context, contractID, tokenID string) { store := k.storeService.OpenKVStore(ctx) key := parentKey(contractID, tokenID) - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } func (k Keeper) GetChildren(ctx sdk.Context, contractID, tokenID string) []string { @@ -286,21 +305,30 @@ func (k Keeper) iterateDescendantsImpl(ctx sdk.Context, contractID, tokenID stri func (k Keeper) setChild(ctx sdk.Context, contractID, tokenID, childID string) { store := k.storeService.OpenKVStore(ctx) key := childKey(contractID, tokenID, childID) - store.Set(key, []byte{}) + err := store.Set(key, []byte{}) + if err != nil { + panic(err) + } } func (k Keeper) deleteChild(ctx sdk.Context, contractID, tokenID, childID string) { store := k.storeService.OpenKVStore(ctx) key := childKey(contractID, tokenID, childID) - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } func (k Keeper) GetRoot(ctx sdk.Context, contractID, tokenID string) string { id := tokenID - k.iterateAncestors(ctx, contractID, tokenID, func(tokenID string) error { + err := k.iterateAncestors(ctx, contractID, tokenID, func(tokenID string) error { id = tokenID return nil }) + if err != nil { + panic(err) + } return id } @@ -309,21 +337,30 @@ func (k Keeper) GetRoot(ctx sdk.Context, contractID, tokenID string) string { func (k Keeper) setLegacyToken(ctx sdk.Context, contractID, tokenID string) { store := k.storeService.OpenKVStore(ctx) key := legacyTokenKey(contractID, tokenID) - store.Set(key, []byte{}) + err := store.Set(key, []byte{}) + if err != nil { + panic(err) + } } // Deprecated func (k Keeper) deleteLegacyToken(ctx sdk.Context, contractID, tokenID string) { store := k.storeService.OpenKVStore(ctx) key := legacyTokenKey(contractID, tokenID) - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } // Deprecated func (k Keeper) setLegacyTokenType(ctx sdk.Context, contractID, tokenType string) { store := k.storeService.OpenKVStore(ctx) key := legacyTokenTypeKey(contractID, tokenType) - store.Set(key, []byte{}) + err := store.Set(key, []byte{}) + if err != nil { + panic(err) + } } // Deprecated diff --git a/x/collection/keeper/supply.go b/x/collection/keeper/supply.go index 4c9a66c3b8..bb8023bcb5 100644 --- a/x/collection/keeper/supply.go +++ b/x/collection/keeper/supply.go @@ -68,7 +68,10 @@ func (k Keeper) setContract(ctx sdk.Context, contract collection.Contract) { if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } func (k Keeper) CreateTokenClass(ctx sdk.Context, contractID string, class collection.TokenClass) (*string, error) { @@ -77,7 +80,7 @@ func (k Keeper) CreateTokenClass(ctx sdk.Context, contractID string, class colle } nextClassIDs := k.getNextClassIDs(ctx, contractID) - class.SetId(&nextClassIDs) + class.SetID(&nextClassIDs) k.setNextClassIDs(ctx, nextClassIDs) if err := class.ValidateBasic(); err != nil { @@ -124,7 +127,10 @@ func (k Keeper) setTokenClass(ctx sdk.Context, contractID string, class collecti if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } func (k Keeper) getNextClassIDs(ctx sdk.Context, contractID string) collection.NextClassIDs { @@ -150,7 +156,10 @@ func (k Keeper) setNextClassIDs(ctx sdk.Context, ids collection.NextClassIDs) { if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } func (k Keeper) MintFT(ctx sdk.Context, contractID string, to sdk.AccAddress, amount []collection.Coin) error { @@ -299,10 +308,13 @@ func (k Keeper) setNextTokenID(ctx sdk.Context, contractID, classID string, toke if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } -func (k Keeper) ModifyContract(ctx sdk.Context, contractID string, operator sdk.AccAddress, changes []collection.Attribute) error { +func (k Keeper) ModifyContract(ctx sdk.Context, contractID string, changes []collection.Attribute) { contract, err := k.GetContract(ctx, contractID) if err != nil { panic(err) @@ -325,11 +337,9 @@ func (k Keeper) ModifyContract(ctx sdk.Context, contractID string, operator sdk. } k.setContract(ctx, *contract) - - return nil } -func (k Keeper) ModifyTokenClass(ctx sdk.Context, contractID, classID string, operator sdk.AccAddress, changes []collection.Attribute) error { +func (k Keeper) ModifyTokenClass(ctx sdk.Context, contractID, classID string, changes []collection.Attribute) error { class, err := k.GetTokenClass(ctx, contractID, classID) if err != nil { // legacy error split @@ -362,7 +372,7 @@ func (k Keeper) ModifyTokenClass(ctx sdk.Context, contractID, classID string, op return nil } -func (k Keeper) ModifyNFT(ctx sdk.Context, contractID, tokenID string, operator sdk.AccAddress, changes []collection.Attribute) error { +func (k Keeper) ModifyNFT(ctx sdk.Context, contractID, tokenID string, changes []collection.Attribute) error { token, err := k.GetNFT(ctx, contractID, tokenID) if err != nil { return err @@ -431,13 +441,19 @@ func (k Keeper) GetGrant(ctx sdk.Context, contractID string, grantee sdk.AccAddr func (k Keeper) setGrant(ctx sdk.Context, contractID string, grantee sdk.AccAddress, permission collection.Permission) { store := k.storeService.OpenKVStore(ctx) key := grantKey(contractID, grantee, permission) - store.Set(key, []byte{}) + err := store.Set(key, []byte{}) + if err != nil { + panic(err) + } } func (k Keeper) deleteGrant(ctx sdk.Context, contractID string, grantee sdk.AccAddress, permission collection.Permission) { store := k.storeService.OpenKVStore(ctx) key := grantKey(contractID, grantee, permission) - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } func (k Keeper) getStatistic(ctx sdk.Context, keyPrefix []byte, contractID, classID string) math.Int { @@ -457,13 +473,19 @@ func (k Keeper) setStatistic(ctx sdk.Context, keyPrefix []byte, contractID, clas store := k.storeService.OpenKVStore(ctx) key := statisticKey(keyPrefix, contractID, classID) if amount.IsZero() { - store.Delete(key) + err := store.Delete(key) + if err != nil { + panic(err) + } } else { bz, err := amount.Marshal() if err != nil { panic(err) } - store.Set(key, bz) + err = store.Set(key, bz) + if err != nil { + panic(err) + } } } diff --git a/x/collection/keeper/supply_test.go b/x/collection/keeper/supply_test.go index ec87bb13c8..c86a1b4f75 100644 --- a/x/collection/keeper/supply_test.go +++ b/x/collection/keeper/supply_test.go @@ -267,7 +267,7 @@ func (s *KeeperTestSuite) TestModifyContract() { ctx, _ := s.ctx.CacheContext() call := func() { - s.keeper.ModifyContract(ctx, contractID, s.vendor, changes) + s.keeper.ModifyContract(ctx, contractID, changes) } if contractID != s.contractID { @@ -301,7 +301,7 @@ func (s *KeeperTestSuite) TestModifyTokenClass() { s.Run(name, func() { ctx, _ := s.ctx.CacheContext() - err := s.keeper.ModifyTokenClass(ctx, s.contractID, classID, s.vendor, changes) + err := s.keeper.ModifyTokenClass(ctx, s.contractID, classID, changes) if classID != s.nftClassID { s.Require().ErrorIs(err, collection.ErrTokenTypeNotExist) return @@ -336,7 +336,7 @@ func (s *KeeperTestSuite) TestModifyNFT() { s.Run(name, func() { ctx, _ := s.ctx.CacheContext() - err := s.keeper.ModifyNFT(ctx, s.contractID, tokenID, s.vendor, changes) + err := s.keeper.ModifyNFT(ctx, s.contractID, tokenID, changes) if tokenID != validTokenID { s.Require().ErrorIs(err, collection.ErrTokenNotExist) return diff --git a/x/collection/module/module.go b/x/collection/module/module.go index ec06b38b6c..d5a4d5e9e6 100644 --- a/x/collection/module/module.go +++ b/x/collection/module/module.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" modulev1 "github.com/Finschia/finschia-sdk/api/lbm/collection/module/v1" - "github.com/Finschia/finschia-sdk/x/collection" "github.com/Finschia/finschia-sdk/x/collection/client/cli" "github.com/Finschia/finschia-sdk/x/collection/keeper" @@ -37,7 +36,9 @@ var ( ) // AppModuleBasic defines the basic application module used by the collection module. -type AppModuleBasic struct{} +type AppModuleBasic struct { + cdc codec.Codec +} // Name returns the ModuleName func (AppModuleBasic) Name() string { @@ -45,7 +46,7 @@ func (AppModuleBasic) Name() string { } // RegisterLegacyAminoCodec registers the collection types on the LegacyAmino codec -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} +func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {} // RegisterInterfaces registers the collection module's interface types func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { @@ -59,7 +60,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { } // ValidateGenesis performs genesis state validation for the collection module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { var data collection.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", collection.ModuleName, err) @@ -97,7 +98,8 @@ type AppModule struct { // NewAppModule creates a new AppModule object func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { return AppModule{ - keeper: keeper, + AppModuleBasic: AppModuleBasic{cdc}, + keeper: keeper, } } diff --git a/x/collection/msgs_test.go b/x/collection/msgs_test.go index 8aa03e3f53..0d4958fdc1 100644 --- a/x/collection/msgs_test.go +++ b/x/collection/msgs_test.go @@ -1735,7 +1735,6 @@ func TestMsgOperatorDetach(t *testing.T) { From: tc.from.String(), TokenId: tc.tokenID, } - fmt.Println(tc.err.Error()) require.ErrorIs(t, msg.ValidateBasic(), tc.err) if tc.err != nil { return