Skip to content

Commit

Permalink
fix lint & simulation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Oct 27, 2023
1 parent 14969f5 commit e5754bf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- '**.go'

env:
GO_VERSION: '1.20.0'
GO_VERSION: '1.21.0'

permissions:
contents: read
Expand All @@ -26,10 +26,10 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: ${{env.GO_VERSION}}
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions x/onft/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//nolint: goconst

package cli

import (
Expand Down
11 changes: 3 additions & 8 deletions x/onft/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(DefaultGenesisState())
}

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 types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand All @@ -56,10 +56,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
return types.ValidateGenesis(data)
}

func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}

func (AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
Expand Down Expand Up @@ -100,7 +96,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.Acc

func (AppModule) Name() string { return types.ModuleName }

func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {
}

func (AppModule) QuerierRoute() string { return types.RouterKey }
Expand Down Expand Up @@ -158,8 +154,7 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc)
}

// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}

Expand Down
34 changes: 10 additions & 24 deletions x/onft/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,38 +431,24 @@ func SimulateMsgUpdateDenom(k keeper.Keeper, ak types.AccountKeeper, bk types.Ba
}

func getRandomNFTFromOwner(ctx sdk.Context, k keeper.Keeper, r *rand.Rand) (address sdk.AccAddress, denomID, nftID string) {
owners := k.GetOwners(ctx)

ownersLen := len(owners)
if ownersLen == 0 {
denom, err := getRandomDenom(ctx, k, r)
if err != nil {
return nil, "", ""
}

// get random owner
i := r.Intn(ownersLen)
owner := owners[i]

idCollectionsLen := len(owner.IDCollections)
if idCollectionsLen == 0 {
onfts, err := k.GetONFTs(ctx, denom.Id)
if err != nil {
return nil, "", ""
}

// get random collection from owner's balance
i = r.Intn(idCollectionsLen)
idCollection := owner.IDCollections[i] // nfts IDs
denomID = idCollection.DenomId

idsLen := len(idCollection.OnftIds)
if idsLen == 0 {
nftsLen := len(onfts)
if nftsLen == 0 {
return nil, "", ""
}

// get random nft from collection
i = r.Intn(idsLen)
nftID = idCollection.OnftIds[i]
// get random nft
i := r.Intn(nftsLen)
_nft := onfts[i]

ownerAddress, _ := sdk.AccAddressFromBech32(owner.Address)
return ownerAddress, denomID, nftID
return _nft.GetOwner(), denomID, nftID
}

func getRandomDenom(ctx sdk.Context, k keeper.Keeper, r *rand.Rand) (types.Denom, error) {
Expand Down
1 change: 0 additions & 1 deletion x/onft/types/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func ValidateMediaURI(uri string) error {
ErrInvalidURI,
"invalid uri %s, media uri should not be empty",
uri,
0,
)
}
if len(uri) > MaxURILen {
Expand Down

0 comments on commit e5754bf

Please sign in to comment.