Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(claim): implement MsgClaimInitial message #878

Merged
merged 12 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ genesis:
- address: "spn1pkdk6m2nh77nlaep84cylmkhjder3arey7rll5" # carol
claimable: "100"
missions:
- missionID: "0"
description: "initial claim"
weight: "0.2"
- missionID: "1"
description: "staking"
weight: "0.6"
weight: "0.5"
- missionID: "2"
description: "voting"
weight: "0.4"
weight: "0.3"
initialClaim:
enabled: true
missionID: "0"
client:
typescript:
path: "ignite-ui/src/generated"
4 changes: 3 additions & 1 deletion proto/claim/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "claim/params.proto";
import "claim/claim_record.proto";
import "claim/mission.proto";
import "claim/initial_claim.proto";
// this line is used by starport scaffolding # genesis/proto/import

option go_package = "github.com/tendermint/spn/x/claim/types";
Expand All @@ -15,7 +16,8 @@ message GenesisState {
cosmos.base.v1beta1.Coin airdropSupply = 1 [(gogoproto.nullable) = false];
repeated ClaimRecord claimRecords = 2 [(gogoproto.nullable) = false];
repeated Mission missions = 3 [(gogoproto.nullable) = false];
Params params = 4 [(gogoproto.nullable) = false];
InitialClaim initialClaim = 4 [(gogoproto.nullable) = false];
Params params = 5 [(gogoproto.nullable) = false];

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

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

message InitialClaim {
bool enabled = 1;
uint64 missionID = 2;
}
12 changes: 11 additions & 1 deletion proto/claim/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tendermint.spn.claim;

import "claim/claim_record.proto";
import "claim/mission.proto";
import "claim/initial_claim.proto";
// this line is used by starport scaffolding # 1

import "claim/params.proto";
Expand Down Expand Up @@ -45,7 +46,11 @@ service Query {
rpc AirdropSupply(QueryGetAirdropSupplyRequest) returns (QueryGetAirdropSupplyResponse) {
option (google.api.http).get = "/tendermint/spn/claim/airdrop_supply";
}
// this line is used by starport scaffolding # 2
// Queries a InitialClaim by index.
rpc InitialClaim(QueryGetInitialClaimRequest) returns (QueryGetInitialClaimResponse) {
option (google.api.http).get = "/tendermint/spn/claim/initial_claim";
}
// this line is used by starport scaffolding # 2
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -96,5 +101,10 @@ message QueryGetAirdropSupplyRequest {}
message QueryGetAirdropSupplyResponse {
cosmos.base.v1beta1.Coin AirdropSupply = 1 [(gogoproto.nullable) = false];
}
message QueryGetInitialClaimRequest {}

message QueryGetInitialClaimResponse {
InitialClaim InitialClaim = 1 [(gogoproto.nullable) = false];
}
// this line is used by starport scaffolding # 3

10 changes: 9 additions & 1 deletion proto/claim/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ 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
rpc ClaimInitial(MsgClaimInitial) returns (MsgClaimInitialResponse);
// this line is used by starport scaffolding # proto/tx/rpc
}

message MsgClaimInitial {
string claimer = 1;
}

message MsgClaimInitialResponse {
}

// this line is used by starport scaffolding # proto/tx/message
3 changes: 3 additions & 0 deletions testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type TestMsgServers struct {
RewardSrv rewardtypes.MsgServer
MonitoringcSrv monitoringctypes.MsgServer
ParticipationSrv participationtypes.MsgServer
ClaimSrv claimtypes.MsgServer
}

// NewTestSetup returns initialized instances of all the keepers and message servers of the modules
Expand Down Expand Up @@ -136,6 +137,7 @@ func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
rewardSrv := rewardkeeper.NewMsgServerImpl(*rewardKeeper)
monitoringcSrv := monitoringckeeper.NewMsgServerImpl(*monitoringConsumerKeeper)
participationSrv := participationkeeper.NewMsgServerImpl(*participationKeeper)
claimSrv := claimkeeper.NewMsgServerImpl(*claimKeeper)

// set max shares - only set during app InitGenesis
campaignKeeper.SetTotalShares(ctx, spntypes.TotalShareNumber)
Expand All @@ -162,6 +164,7 @@ func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
RewardSrv: rewardSrv,
MonitoringcSrv: monitoringcSrv,
ParticipationSrv: participationSrv,
ClaimSrv: claimSrv,
}
}

Expand Down
1 change: 1 addition & 0 deletions x/campaign/keeper/campaign_auction_event_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

fundraisingtypes "github.com/tendermint/fundraising/x/fundraising/types"

"github.com/tendermint/spn/x/campaign/types"
profiletypes "github.com/tendermint/spn/x/profile/types"
)
Expand Down
1 change: 1 addition & 0 deletions x/campaign/keeper/campaign_auction_event_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

tc "github.com/tendermint/spn/testutil/constructor"
testkeeper "github.com/tendermint/spn/testutil/keeper"
"github.com/tendermint/spn/testutil/sample"
Expand Down
15 changes: 9 additions & 6 deletions x/claim/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdListClaimRecord())
cmd.AddCommand(CmdShowClaimRecord())
cmd.AddCommand(CmdListMission())
cmd.AddCommand(CmdShowMission())
cmd.AddCommand(CmdShowAirdropSupply())
cmd.AddCommand(
CmdQueryParams(),
CmdShowAirdropSupply(),
CmdListClaimRecord(),
CmdShowClaimRecord(),
CmdListMission(),
CmdShowMission(),
CmdShowInitialClaim(),
)
// this line is used by starport scaffolding # 1

return cmd
Expand Down
38 changes: 38 additions & 0 deletions x/claim/client/cli/query_initial_claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 CmdShowInitialClaim() *cobra.Command {
cmd := &cobra.Command{
Use: "show-initial-claim",
Short: "shows information about initial claim",
Long: "shows if initial claim is enabled and what is the mission ID completed by initial claim",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetInitialClaimRequest{}

res, err := queryClient.InitialClaim(context.Background(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
1 change: 1 addition & 0 deletions x/claim/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func GetTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

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

return cmd
Expand Down
37 changes: 37 additions & 0 deletions x/claim/client/cli/tx_claim_initial.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cli

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

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

func CmdClaimInitial() *cobra.Command {
cmd := &cobra.Command{
Use: "claim-initial",
Short: "claim the initial airdrop allocation",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgClaimInitial(
clientCtx.GetFromAddress().String(),
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
10 changes: 9 additions & 1 deletion x/claim/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
panic("airdrop supply failed to initialize: " + err.Error())
}

// this line is used by starport scaffolding # genesis/module/init
k.SetInitialClaim(ctx, genState.InitialClaim)

k.SetParams(ctx, genState.Params)

// this line is used by starport scaffolding # genesis/module/init
}

// ExportGenesis returns the claim module's exported genesis.
Expand All @@ -41,6 +44,11 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
// set to 0uspn otherwise
genesis.AirdropSupply = types.DefaultGenesis().AirdropSupply
}
// Get all initialClaim
initialClaim, found := k.GetInitialClaim(ctx)
if found {
genesis.InitialClaim = initialClaim
}
// this line is used by starport scaffolding # genesis/module/export

return genesis
Expand Down
5 changes: 5 additions & 0 deletions x/claim/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func TestGenesis(t *testing.T) {
},
},
AirdropSupply: sample.Coin(r),
InitialClaim: types.InitialClaim{
Enabled: true,
MissionID: 35,
},
// this line is used by starport scaffolding # genesis/test/state
}

Expand All @@ -56,5 +60,6 @@ func TestGenesis(t *testing.T) {
require.ElementsMatch(t, genesisState.ClaimRecords, got.ClaimRecords)
require.ElementsMatch(t, genesisState.Missions, got.Missions)
require.Equal(t, genesisState.AirdropSupply, got.AirdropSupply)
require.Equal(t, genesisState.InitialClaim, got.InitialClaim)
// this line is used by starport scaffolding # genesis/test/assert
}
7 changes: 5 additions & 2 deletions x/claim/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import (

// NewHandler ...
func NewHandler(k keeper.Keeper) sdk.Handler {
// this line is used by starport scaffolding # handler/msgServer
msgServer := keeper.NewMsgServerImpl(k)

return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())

switch msg := msg.(type) {
// this line is used by starport scaffolding # 1
case *types.MsgClaimInitial:
res, err := msgServer.ClaimInitial(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
// this line is used by starport scaffolding # 1
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
Expand Down
25 changes: 25 additions & 0 deletions x/claim/keeper/grpc_query_initial_claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

func (k Keeper) InitialClaim(c context.Context, req *types.QueryGetInitialClaimRequest) (*types.QueryGetInitialClaimResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

val, found := k.GetInitialClaim(ctx)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}

return &types.QueryGetInitialClaimResponse{InitialClaim: val}, nil
}
49 changes: 49 additions & 0 deletions x/claim/keeper/grpc_query_initial_claim_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package keeper_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

func TestInitialClaimQuery(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
wctx := sdk.WrapSDKContext(ctx)
item := createTestInitialClaim(tk.ClaimKeeper, ctx)
for _, tc := range []struct {
desc string
request *types.QueryGetInitialClaimRequest
response *types.QueryGetInitialClaimResponse
err error
}{
{
desc: "First",
request: &types.QueryGetInitialClaimRequest{},
response: &types.QueryGetInitialClaimResponse{InitialClaim: item},
},
{
desc: "InvalidRequest",
err: status.Error(codes.InvalidArgument, "invalid request"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
response, err := tk.ClaimKeeper.InitialClaim(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.NoError(t, err)
require.Equal(t,
nullify.Fill(tc.response),
nullify.Fill(response),
)
}
})
}
}
Loading