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): genesis and types #800

Merged
merged 39 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e1deb38
add airdropSupply
May 16, 2022
668b872
new types and proto
May 16, 2022
f5225cc
rename query variables
May 16, 2022
98bab1d
new proto and go files
May 16, 2022
525f156
make corresponding changes in tests
May 16, 2022
72f3bb9
make airdropSupply non-nullable
May 16, 2022
61463f1
make airdropSupply non-nullable
May 16, 2022
92d08a6
finalize proto and tests
May 16, 2022
e58bf55
format
May 16, 2022
1e54601
lint fix
May 16, 2022
0c2a927
imports
May 16, 2022
da08d7b
Update proto/claim/mission.proto
May 17, 2022
0055656
Update x/claim/types/genesis.go
May 17, 2022
c3b8fec
Update proto/claim/query.proto
May 17, 2022
97ba6fa
Update x/claim/client/cli/query_airdrop_supply.go
May 17, 2022
a474f56
Update x/campaign/types/special_allocations_test.go
May 17, 2022
20b6277
Update x/claim/client/cli/query_claim_record.go
May 17, 2022
71fffcb
Update x/claim/client/cli/query_claim_record.go
May 17, 2022
617fc05
Update x/claim/client/cli/query_claim_record.go
May 17, 2022
660c33c
Merge branch 'develop' into feat/claim-genesis
May 17, 2022
e346d17
Update x/claim/client/cli/query_mission.go
May 17, 2022
57e5b9b
Update x/claim/client/cli/query_mission.go
May 17, 2022
1a23060
Update x/claim/keeper/grpc_query_claim_record_test.go
May 17, 2022
bb71811
rename proto fields
May 17, 2022
3b0fe46
rename vars in tests
May 17, 2022
88f9ad2
format query.proto
May 17, 2022
ccbb00c
remove unnecessary methods
May 17, 2022
f5000a3
rename ID -> missionID
May 18, 2022
d02322d
add validate methods
May 18, 2022
57c1797
add validation tests
May 18, 2022
bd2363a
Merge branch 'develop' into feat/claim-genesis
May 18, 2022
b003e83
Update x/claim/types/claim_record.go
May 18, 2022
44785a9
Update x/claim/types/mission_test.go
May 18, 2022
f5aa55c
Update x/claim/types/mission_test.go
lumtis May 19, 2022
10ecb3c
Update x/claim/client/cli/query_airdrop_supply_test.go
lumtis May 20, 2022
ec3403a
Update x/claim/client/cli/query_claim_record_test.go
lumtis May 20, 2022
d230cc4
Update x/claim/client/cli/query_mission_test.go
lumtis May 20, 2022
9c25be9
Update x/claim/types/claim_record_test.go
lumtis May 20, 2022
8b50d54
x/claim/types/claim_record_test.go
lumtis May 20, 2022
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
14 changes: 14 additions & 0 deletions proto/claim/claim_record.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package tendermint.spn.claim;

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

import "gogoproto/gogo.proto";

message ClaimRecord {
string address = 1;
string claimable = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false];
repeated uint64 completedMissions = 3;
}
9 changes: 8 additions & 1 deletion proto/claim/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ syntax = "proto3";
package tendermint.spn.claim;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "claim/params.proto";
import "claim/claim_record.proto";
import "claim/mission.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];
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];

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

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

import "gogoproto/gogo.proto";

message Mission {
uint64 missionID = 1;
string description = 2;
string weight = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false];
}
1 change: 0 additions & 1 deletion proto/claim/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ option go_package = "github.com/tendermint/spn/x/claim/types";
// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;

}
78 changes: 74 additions & 4 deletions proto/claim/query.proto
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
syntax = "proto3";

package tendermint.spn.claim;

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

import "claim/params.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";
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.
// Parameters queries the parameters of the module
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/tendermint/spn/claim/params";
}

// Queries a ClaimRecord by address.
rpc ClaimRecord(QueryGetClaimRecordRequest) returns (QueryGetClaimRecordResponse) {
option (google.api.http).get = "/tendermint/spn/claim/claim_record/{address}";
}

// Queries a list of ClaimRecord items.
rpc ClaimRecordAll(QueryAllClaimRecordRequest) returns (QueryAllClaimRecordResponse) {
option (google.api.http).get = "/tendermint/spn/claim/claim_record";
}

// Queries a Mission by ID.
rpc Mission(QueryGetMissionRequest) returns (QueryGetMissionResponse) {
option (google.api.http).get = "/tendermint/spn/claim/mission/{missionID}";
}

// Queries a list of Mission items.
rpc MissionAll(QueryAllMissionRequest) returns (QueryAllMissionResponse) {
option (google.api.http).get = "/tendermint/spn/claim/mission";
}

// Queries a AirdropSupply by index.
rpc AirdropSupply(QueryGetAirdropSupplyRequest) returns (QueryGetAirdropSupplyResponse) {
option (google.api.http).get = "/tendermint/spn/claim/airdrop_supply";
}
// this line is used by starport scaffolding # 2
}

Expand All @@ -27,4 +57,44 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}

message QueryGetClaimRecordRequest {
string address = 1;
}

message QueryGetClaimRecordResponse {
ClaimRecord claimRecord = 1 [(gogoproto.nullable) = false];
}

message QueryAllClaimRecordRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllClaimRecordResponse {
repeated ClaimRecord claimRecord = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetMissionRequest {
uint64 missionID = 1;
}

message QueryGetMissionResponse {
Mission Mission = 1 [(gogoproto.nullable) = false];
}

message QueryAllMissionRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllMissionResponse {
repeated Mission Mission = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetAirdropSupplyRequest {}

message QueryGetAirdropSupplyResponse {
cosmos.base.v1beta1.Coin AirdropSupply = 1 [(gogoproto.nullable) = false];
}
// this line is used by starport scaffolding # 3

40 changes: 40 additions & 0 deletions testutil/sample/claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package sample

import (
"math/rand"

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

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

func ClaimRecord(r *rand.Rand) claim.ClaimRecord {
return claim.ClaimRecord{
Address: Address(r),
Claimable: sdk.NewInt(r.Int63n(100000)),
CompletedMissions: uint64Sequence(r),
}
}

func Mission(r *rand.Rand) claim.Mission {
const max = 1_000_000
maxInt := sdk.NewDec(max)
weight := sdk.NewDec(r.Int63n(max)).Quo(maxInt)

return claim.Mission{
MissionID: Uint64(r),
Description: String(r, 20),
Weight: weight,
}
}

func uint64Sequence(r *rand.Rand) []uint64 {
listLen := r.Int63n(10)
list := make([]uint64, int(listLen))

for i := range list {
list[i] = r.Uint64()
}

return list
}
1 change: 1 addition & 0 deletions vue/src/views/Types.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div>
<div class="container">
<!-- this line is used by starport scaffolding # 4 -->
<SpType modulePath="tendermint.spn.claim" moduleType="Mission" />
<SpType modulePath="tendermint.spn.campaign" moduleType="Campaign" />
<SpType modulePath="tendermint.spn.profile" moduleType="Coordinator" />
</div>
Expand Down
3 changes: 2 additions & 1 deletion x/campaign/types/special_allocations_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package types_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"testing"

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

"github.com/tendermint/spn/testutil/sample"
"github.com/tendermint/spn/x/campaign/types"
)
Expand Down
5 changes: 5 additions & 0 deletions x/claim/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
}

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

return cmd
Expand Down
37 changes: 37 additions & 0 deletions x/claim/client/cli/query_airdrop_supply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 CmdShowAirdropSupply() *cobra.Command {
cmd := &cobra.Command{
Use: "show-airdrop-supply",
Short: "shows the airdrop supply",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetAirdropSupplyRequest{}

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

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
73 changes: 73 additions & 0 deletions x/claim/client/cli/query_airdrop_supply_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cli_test

import (
"fmt"
"testing"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
tmcli "github.com/tendermint/tendermint/libs/cli"
"google.golang.org/grpc/status"

"github.com/tendermint/spn/testutil/network"
"github.com/tendermint/spn/testutil/nullify"
"github.com/tendermint/spn/testutil/sample"
"github.com/tendermint/spn/x/claim/client/cli"
"github.com/tendermint/spn/x/claim/types"
)

func networkWithAirdropSupplyObjects(t *testing.T) (*network.Network, sdk.Coin) {
t.Helper()
r := sample.Rand()
cfg := network.DefaultConfig()
state := types.GenesisState{}
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))

state.AirdropSupply = sample.Coin(r)
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
return network.New(t, cfg), state.AirdropSupply
}

func TestShowAirdropSupply(t *testing.T) {
net, obj := networkWithAirdropSupplyObjects(t)

ctx := net.Validators[0].ClientCtx
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
args []string
err error
obj sdk.Coin
}{
{
desc: "get",
args: common,
obj: obj,
},
} {
t.Run(tc.desc, func(t *testing.T) {
var args []string
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowAirdropSupply(), args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
} else {
require.NoError(t, err)
var resp types.QueryGetAirdropSupplyResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.AirdropSupply)
require.Equal(t,
nullify.Fill(&tc.obj),
nullify.Fill(&resp.AirdropSupply),
)
}
})
}
}
Loading