Skip to content

Commit

Permalink
postCount to be not null
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Jan 6, 2023
1 parent 83d4ac0 commit 458c3a2
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 39 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ require (
github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0/go.mod h1:YDZoGHuwE+ov0c8smSH49WLF3F2LaWnYYuDVd+EWrc0=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
2 changes: 1 addition & 1 deletion proto/blog/blog/genesis.proto
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option go_package = "blog/x/blog/types";
// GenesisState defines the blog module's genesis state. // GenesisState defines the blog module's genesis state.
message GenesisState { message GenesisState {
Params params = 1 [(gogoproto.nullable) = false]; Params params = 1 [(gogoproto.nullable) = false];
PostCount postCount = 2; PostCount postCount = 2 [(gogoproto.nullable) = false];
repeated StoredPost storedPostList = 3 [(gogoproto.nullable) = false]; repeated StoredPost storedPostList = 3 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state // this line is used by starport scaffolding # genesis/proto/state
} }
8 changes: 3 additions & 5 deletions x/blog/genesis.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package blog
import ( import (
"blog/x/blog/keeper" "blog/x/blog/keeper"
"blog/x/blog/types" "blog/x/blog/types"

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


// InitGenesis initializes the module's state from a provided genesis state. // InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// Set if defined k.SetPostCount(ctx, genState.PostCount)
if genState.PostCount != nil {
k.SetPostCount(ctx, *genState.PostCount)
}
// Set all the storedPost // Set all the storedPost
for _, elem := range genState.StoredPostList { for _, elem := range genState.StoredPostList {
k.SetStoredPost(ctx, elem) k.SetStoredPost(ctx, elem)
Expand All @@ -28,7 +26,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
// Get all postCount // Get all postCount
postCount, found := k.GetPostCount(ctx) postCount, found := k.GetPostCount(ctx)
if found { if found {
genesis.PostCount = &postCount genesis.PostCount = postCount
} }
genesis.StoredPostList = k.GetAllStoredPost(ctx) genesis.StoredPostList = k.GetAllStoredPost(ctx)
// this line is used by starport scaffolding # genesis/module/export // this line is used by starport scaffolding # genesis/module/export
Expand Down
3 changes: 2 additions & 1 deletion x/blog/genesis_test.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"blog/testutil/nullify" "blog/testutil/nullify"
"blog/x/blog" "blog/x/blog"
"blog/x/blog/types" "blog/x/blog/types"

"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )


func TestGenesis(t *testing.T) { func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{ genesisState := types.GenesisState{
Params: types.DefaultParams(), Params: types.DefaultParams(),


PostCount: &types.PostCount{ PostCount: types.PostCount{
Count: 39, Count: 39,
}, },
StoredPostList: []types.StoredPost{ StoredPostList: []types.StoredPost{
Expand Down
4 changes: 3 additions & 1 deletion x/blog/types/genesis.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const DefaultIndex uint64 = 1
// DefaultGenesis returns the default genesis state // DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState { func DefaultGenesis() *GenesisState {
return &GenesisState{ return &GenesisState{
PostCount: nil, PostCount: PostCount{
Count: uint64(0),
},
StoredPostList: []StoredPost{}, StoredPostList: []StoredPost{},
// this line is used by starport scaffolding # genesis/types/default // this line is used by starport scaffolding # genesis/types/default
Params: DefaultParams(), Params: DefaultParams(),
Expand Down
53 changes: 23 additions & 30 deletions x/blog/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion x/blog/types/genesis_test.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing" "testing"


"blog/x/blog/types" "blog/x/blog/types"

"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )


Expand All @@ -22,7 +23,7 @@ func TestGenesisState_Validate(t *testing.T) {
desc: "valid genesis state", desc: "valid genesis state",
genState: &types.GenesisState{ genState: &types.GenesisState{


PostCount: &types.PostCount{ PostCount: types.PostCount{
Count: 23, Count: 23,
}, },
StoredPostList: []types.StoredPost{ StoredPostList: []types.StoredPost{
Expand Down

0 comments on commit 458c3a2

Please sign in to comment.