Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
scaffold resolver module
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Sep 14, 2023
1 parent aa9feba commit 5c8fbca
Show file tree
Hide file tree
Showing 40 changed files with 2,279 additions and 12 deletions.
22 changes: 22 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ import (
epochsmodulekeeper "github.com/mycel-domain/mycel/x/epochs/keeper"
epochsmoduletypes "github.com/mycel-domain/mycel/x/epochs/types"

resolvermodule "github.com/mycel-domain/mycel/x/resolver"
resolvermodulekeeper "github.com/mycel-domain/mycel/x/resolver/keeper"
resolvermoduletypes "github.com/mycel-domain/mycel/x/resolver/types"
// this line is used by starport scaffolding # stargate/app/moduleImport

appparams "github.com/mycel-domain/mycel/app/params"
Expand Down Expand Up @@ -232,6 +235,7 @@ var (
// my modules
registrymodule.AppModuleBasic{},
epochsmodule.AppModuleBasic{},
resolvermodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -317,6 +321,8 @@ type App struct {
// my mnodules
RegistryKeeper registrymodulekeeper.Keeper
EpochsKeeper epochsmodulekeeper.Keeper

ResolverKeeper resolvermodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -403,6 +409,7 @@ func NewApp(
// my modules
registrymoduletypes.StoreKey,
epochsmoduletypes.StoreKey,
resolvermoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -683,6 +690,16 @@ func NewApp(
)
registryModule := registrymodule.NewAppModule(appCodec, app.RegistryKeeper, app.AccountKeeper, app.BankKeeper)

app.ResolverKeeper = *resolvermodulekeeper.NewKeeper(
appCodec,
keys[resolvermoduletypes.StoreKey],
keys[resolvermoduletypes.MemStoreKey],
app.GetSubspace(resolvermoduletypes.ModuleName),

app.RegistryKeeper,
)
resolverModule := resolvermodule.NewAppModule(appCodec, app.ResolverKeeper, app.AccountKeeper, app.BankKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition

/**** IBC Routing ****/
Expand Down Expand Up @@ -754,6 +771,7 @@ func NewApp(
// my modules
registryModule,
epochsModule,
resolverModule,
// this line is used by starport scaffolding # stargate/app/appModule

crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
Expand Down Expand Up @@ -791,6 +809,7 @@ func NewApp(
// my modules
registrymoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
resolvermoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -821,6 +840,7 @@ func NewApp(
// my modules
registrymoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
resolvermoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand Down Expand Up @@ -857,6 +877,7 @@ func NewApp(
// my modules
registrymoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
resolvermoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -1119,6 +1140,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// my modules
paramsKeeper.Subspace(registrymoduletypes.ModuleName)
paramsKeeper.Subspace(epochsmoduletypes.ModuleName)
paramsKeeper.Subspace(resolvermoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
1 change: 0 additions & 1 deletion app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func BenchmarkSimulation(b *testing.B) {
appOptions[flags.FlagHome] = app.DefaultNodeHome
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue


wasmOpt := []wasmkeeper.Option{}

bApp := app.New(
Expand Down
46 changes: 46 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50697,6 +50697,42 @@ paths:
type: string
tags:
- Query
/mycel-domain/mycel/resolver/params:
get:
summary: Parameters queries the parameters of the module.
operationId: MycelResolverParams
responses:
'200':
description: A successful response.
schema:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
tags:
- Query
definitions:
cosmos.auth.v1beta1.AddressBytesToStringResponse:
type: object
Expand Down Expand Up @@ -81499,3 +81535,13 @@ definitions:
title: 'Rule: CHAINNAME_ENVIROMENT_NETWORK'
value:
type: string
mycel.resolver.Params:
type: object
description: Params defines the parameters for the module.
mycel.resolver.QueryParamsResponse:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
12 changes: 12 additions & 0 deletions proto/mycel/resolver/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package mycel.resolver;

import "gogoproto/gogo.proto";
import "mycel/resolver/params.proto";

option go_package = "github.com/mycel-domain/mycel/x/resolver/types";

// GenesisState defines the resolver module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
}
12 changes: 12 additions & 0 deletions proto/mycel/resolver/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package mycel.resolver;

import "gogoproto/gogo.proto";

option go_package = "github.com/mycel-domain/mycel/x/resolver/types";

// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;

}
26 changes: 26 additions & 0 deletions proto/mycel/resolver/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package mycel.resolver;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "mycel/resolver/params.proto";

option go_package = "github.com/mycel-domain/mycel/x/resolver/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/mycel-domain/mycel/resolver/params";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}
7 changes: 7 additions & 0 deletions proto/mycel/resolver/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package mycel.resolver;

option go_package = "github.com/mycel-domain/mycel/x/resolver/types";

// Msg defines the Msg service.
service Msg {}
53 changes: 53 additions & 0 deletions testutil/keeper/resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package keeper

import (
"testing"

tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/mycel-domain/mycel/x/resolver/keeper"
"github.com/mycel-domain/mycel/x/resolver/types"
"github.com/stretchr/testify/require"
)

func ResolverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"ResolverParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
nil,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
}
2 changes: 1 addition & 1 deletion x/registry/client/cli/query_top_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func networkWithTopLevelDomainObjects(t *testing.T, n int) (*network.Network, []
state := types.GenesisState{}
for i := 0; i < n; i++ {
topLevelDomain := types.TopLevelDomain{
Name: strconv.Itoa(i),
Name: strconv.Itoa(i),
Metadata: make(map[string]string),
AccessControl: make(map[string]*types.TopLevelDomainRole),
}
Expand Down
12 changes: 6 additions & 6 deletions x/registry/types/message_register_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ func TestMsgRegisterDomain_ValidateBasic(t *testing.T) {
{
name: "invalid address",
msg: MsgRegisterDomain{
Creator: "invalid_address",
Name: "foo",
Parent: "cel",
Creator: "invalid_address",
Name: "foo",
Parent: "cel",
RegistrationPeriodInYear: 1,
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgRegisterDomain{
Creator: sample.AccAddress(),
Name: "foo",
Parent: "cel",
Creator: sample.AccAddress(),
Name: "foo",
Parent: "cel",
RegistrationPeriodInYear: 1,
},
},
Expand Down
8 changes: 4 additions & 4 deletions x/registry/types/message_register_top_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ func TestMsgRegisterTopLevelDomain_ValidateBasic(t *testing.T) {
{
name: "invalid address",
msg: MsgRegisterTopLevelDomain{
Creator: "invalid_address",
Name: "cel",
Creator: "invalid_address",
Name: "cel",
RegistrationPeriodInYear: 1,
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgRegisterTopLevelDomain{
Creator: sample.AccAddress(),
Name: "cel",
Creator: sample.AccAddress(),
Name: "cel",
RegistrationPeriodInYear: 1,
},
},
Expand Down
31 changes: 31 additions & 0 deletions x/resolver/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cli

import (
"fmt"
// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/mycel-domain/mycel/x/resolver/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group resolver queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
// this line is used by starport scaffolding # 1

return cmd
}
36 changes: 36 additions & 0 deletions x/resolver/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/mycel-domain/mycel/x/resolver/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit 5c8fbca

Please sign in to comment.