Skip to content

Commit

Permalink
feat(claim): scaffold claim module (#797)
Browse files Browse the repository at this point in the history
* scaffold `claim` module

* fix typo

* Update x/claim/client/cli/query.go

Co-authored-by: Lucas Bertrand <lucas.bertrand.22@gmail.com>

* Update x/claim/client/cli/tx.go

Co-authored-by: Lucas Bertrand <lucas.bertrand.22@gmail.com>

* address comments

* format

Co-authored-by: Lucas Bertrand <lucas.bertrand.22@gmail.com>
Co-authored-by: aljo242 <alex.johnson@tendermint.com>
  • Loading branch information
3 people authored May 16, 2022
1 parent b8c079a commit e1cca3e
Show file tree
Hide file tree
Showing 37 changed files with 2,311 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ import (
participationmodulekeeper "github.com/tendermint/spn/x/participation/keeper"
participationmoduletypes "github.com/tendermint/spn/x/participation/types"

claimmodule "github.com/tendermint/spn/x/claim"
claimmodulekeeper "github.com/tendermint/spn/x/claim/keeper"
claimmoduletypes "github.com/tendermint/spn/x/claim/types"

"github.com/tendermint/spn/x/mint"
mintkeeper "github.com/tendermint/spn/x/mint/keeper"
minttypes "github.com/tendermint/spn/x/mint/types"
Expand Down Expand Up @@ -175,6 +179,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
participationmodule.AppModuleBasic{},
claimmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
profilemodule.AppModuleBasic{},
launchmodule.AppModuleBasic{},
Expand Down Expand Up @@ -267,6 +272,7 @@ type App struct {
MonitoringpKeeper monitoringpmodulekeeper.Keeper
RewardKeeper rewardmodulekeeper.Keeper
ParticipationKeeper participationmodulekeeper.Keeper
ClaimKeeper claimmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

transferModule transfer.AppModule
Expand Down Expand Up @@ -325,6 +331,7 @@ func New(
rewardmoduletypes.StoreKey,
fundraisingtypes.StoreKey,
participationmoduletypes.StoreKey,
claimmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -521,6 +528,14 @@ func New(
app.StakingKeeper,
)

app.ClaimKeeper = *claimmodulekeeper.NewKeeper(
appCodec,
keys[claimmoduletypes.StoreKey],
keys[claimmoduletypes.MemStoreKey],
app.GetSubspace(claimmoduletypes.ModuleName),
app.BankKeeper,
)

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

// Create static IBC router, add transfer route, then set and seal it
Expand Down Expand Up @@ -570,6 +585,7 @@ func New(
rewardmodule.NewAppModule(appCodec, app.RewardKeeper, app.AuthKeeper, app.BankKeeper),
fundraisingmodule.NewAppModule(appCodec, app.FundraisingKeeper, app.AuthKeeper, app.BankKeeper, app.DistrKeeper),
participationmodule.NewAppModule(appCodec, app.ParticipationKeeper, app.AuthKeeper, app.BankKeeper, app.FundraisingKeeper),
claimmodule.NewAppModule(appCodec, app.ClaimKeeper, app.AuthKeeper, app.BankKeeper),
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand Down Expand Up @@ -604,6 +620,7 @@ func New(
monitoringpmoduletypes.ModuleName,
participationmoduletypes.ModuleName,
launchmoduletypes.ModuleName,
claimmoduletypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -633,6 +650,7 @@ func New(
monitoringpmoduletypes.ModuleName,
participationmoduletypes.ModuleName,
launchmoduletypes.ModuleName,
claimmoduletypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -667,6 +685,7 @@ func New(
rewardmoduletypes.ModuleName,
fundraisingtypes.ModuleName,
participationmoduletypes.ModuleName,
claimmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down Expand Up @@ -697,6 +716,7 @@ func New(
participationmodule.NewAppModule(appCodec, app.ParticipationKeeper, app.AuthKeeper, app.BankKeeper, app.FundraisingKeeper),
fundraisingmodule.NewAppModule(appCodec, app.FundraisingKeeper, app.AuthKeeper, app.BankKeeper, app.DistrKeeper),
monitoringpModule,
claimmodule.NewAppModule(appCodec, app.ClaimKeeper, app.AuthKeeper, app.BankKeeper),
)
app.sm.RegisterStoreDecoders()

Expand Down Expand Up @@ -891,6 +911,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(rewardmoduletypes.ModuleName)
paramsKeeper.Subspace(fundraisingtypes.ModuleName)
paramsKeeper.Subspace(participationmoduletypes.ModuleName)
paramsKeeper.Subspace(claimmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
14 changes: 14 additions & 0 deletions proto/claim/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package tendermint.spn.claim;

import "gogoproto/gogo.proto";
import "claim/params.proto";
// this line is used by starport scaffolding # genesis/proto/import

option go_package = "github.com/tendermint/spn/x/claim/types";

// GenesisState defines the claim module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}
12 changes: 12 additions & 0 deletions proto/claim/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package tendermint.spn.claim;

import "gogoproto/gogo.proto";

option go_package = "github.com/tendermint/spn/x/claim/types";

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

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

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "claim/params.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/tendermint/spn/x/claim/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 = "/tendermint/spn/claim/params";
}
// this line is used by starport scaffolding # 2
}

// 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];
}

// this line is used by starport scaffolding # 3
13 changes: 13 additions & 0 deletions proto/claim/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package tendermint.spn.claim;

// this line is used by starport scaffolding # proto/tx/import

option go_package = "github.com/tendermint/spn/x/claim/types";

// Msg defines the Msg service.
service Msg {
// this line is used by starport scaffolding # proto/tx/rpc
}

// this line is used by starport scaffolding # proto/tx/message
54 changes: 54 additions & 0 deletions testutil/keeper/claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package keeper

import (
"testing"

"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/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"

"github.com/tendermint/spn/x/claim/keeper"
"github.com/tendermint/spn/x/claim/types"
)

func ClaimKeeper(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, sdk.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

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

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"ClaimParams",
)
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
}
24 changes: 24 additions & 0 deletions testutil/keeper/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/tendermint/spn/testutil/sample"
campaignkeeper "github.com/tendermint/spn/x/campaign/keeper"
campaigntypes "github.com/tendermint/spn/x/campaign/types"
claimkeeper "github.com/tendermint/spn/x/claim/keeper"
claimtypes "github.com/tendermint/spn/x/claim/types"
launchkeeper "github.com/tendermint/spn/x/launch/keeper"
launchtypes "github.com/tendermint/spn/x/launch/types"
minttypes "github.com/tendermint/spn/x/mint/types"
Expand Down Expand Up @@ -410,3 +412,25 @@ func (i initializer) Participation(
stakingKeeper,
)
}

func (i initializer) Claim(
paramKeeper paramskeeper.Keeper,
bankKeeper bankkeeper.Keeper,
) *claimkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(claimtypes.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(claimtypes.MemStoreKey)

i.StateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, i.DB)
i.StateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil)

paramKeeper.Subspace(claimtypes.ModuleName)
subspace, _ := paramKeeper.GetSubspace(participationtypes.ModuleName)

return claimkeeper.NewKeeper(
i.Codec,
storeKey,
memStoreKey,
subspace,
bankKeeper,
)
}
9 changes: 9 additions & 0 deletions testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
spntypes "github.com/tendermint/spn/pkg/types"
campaignkeeper "github.com/tendermint/spn/x/campaign/keeper"
campaigntypes "github.com/tendermint/spn/x/campaign/types"
claimkeeper "github.com/tendermint/spn/x/claim/keeper"
claimtypes "github.com/tendermint/spn/x/claim/types"
launchkeeper "github.com/tendermint/spn/x/launch/keeper"
launchtypes "github.com/tendermint/spn/x/launch/types"
monitoringckeeper "github.com/tendermint/spn/x/monitoringc/keeper"
Expand Down Expand Up @@ -57,6 +59,7 @@ type TestKeepers struct {
StakingKeeper stakingkeeper.Keeper
FundraisingKeeper fundraisingkeeper.Keeper
ParticipationKeeper *participationkeeper.Keeper
ClaimKeeper *claimkeeper.Keeper
}

// TestMsgServers holds all message servers used during keeper tests for all modules
Expand Down Expand Up @@ -98,6 +101,7 @@ func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
[]Channel{},
)
launchKeeper.SetMonitoringcKeeper(monitoringConsumerKeeper)
claimKeeper := initializer.Claim(paramKeeper, bankKeeper)
require.NoError(t, initializer.StateStore.LoadLatestVersion())

// Create a context using a custom timestamp
Expand All @@ -120,6 +124,7 @@ func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
fundraisingKeeper.SetParams(ctx, fundraisingParams)
participationKeeper.SetParams(ctx, participationtypes.DefaultParams())
monitoringConsumerKeeper.SetParams(ctx, monitoringctypes.DefaultParams())
claimKeeper.SetParams(ctx, claimtypes.DefaultParams())
setIBCDefaultParams(ctx, ibcKeeper)

profileSrv := profilekeeper.NewMsgServerImpl(*profileKeeper)
Expand All @@ -144,6 +149,7 @@ func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
StakingKeeper: stakingKeeper,
FundraisingKeeper: fundraisingKeeper,
ParticipationKeeper: participationKeeper,
ClaimKeeper: claimKeeper,
}, TestMsgServers{
T: t,
ProfileSrv: profileSrv,
Expand Down Expand Up @@ -187,6 +193,7 @@ func NewTestSetupWithIBCMocks(
channelMock,
)
launchKeeper.SetMonitoringcKeeper(monitoringConsumerKeeper)
claimKeeper := initializer.Claim(paramKeeper, bankKeeper)
require.NoError(t, initializer.StateStore.LoadLatestVersion())

// Create a context using a custom timestamp
Expand All @@ -207,6 +214,7 @@ func NewTestSetupWithIBCMocks(
fundraisingKeeper.SetParams(ctx, fundraisingtypes.DefaultParams())
participationKeeper.SetParams(ctx, participationtypes.DefaultParams())
monitoringConsumerKeeper.SetParams(ctx, monitoringctypes.DefaultParams())
claimKeeper.SetParams(ctx, claimtypes.DefaultParams())
setIBCDefaultParams(ctx, ibcKeeper)

profileSrv := profilekeeper.NewMsgServerImpl(*profileKeeper)
Expand All @@ -231,6 +239,7 @@ func NewTestSetupWithIBCMocks(
StakingKeeper: stakingKeeper,
FundraisingKeeper: fundraisingKeeper,
ParticipationKeeper: participationKeeper,
ClaimKeeper: claimKeeper,
}, TestMsgServers{
T: t,
ProfileSrv: profileSrv,
Expand Down
31 changes: 31 additions & 0 deletions x/claim/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/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

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

"github.com/tendermint/spn/x/claim/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group claim 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
}
35 changes: 35 additions & 0 deletions x/claim/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"context"

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

"github.com/tendermint/spn/x/claim/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 := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

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

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit e1cca3e

Please sign in to comment.