Skip to content

Commit

Permalink
migrate and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo committed Oct 6, 2023
1 parent b24aa99 commit da2de9a
Show file tree
Hide file tree
Showing 107 changed files with 433 additions and 425 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
if: env.GIT_DIFF || github.ref == 'refs/heads/main'
- run: make test-coverage
if: env.GIT_DIFF || github.ref == 'refs/heads/main'
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v3
with:
file: coverage.txt
if: env.GIT_DIFF || github.ref == 'refs/heads/main'
2 changes: 1 addition & 1 deletion content/server/config.go → content/keeper/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
File renamed without changes.
File renamed without changes.
31 changes: 15 additions & 16 deletions content/server/server.go → content/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package server
package keeper

import (
"encoding/json"

"cosmossdk.io/orm/model/ormdb"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -14,36 +13,36 @@ import (
)

var (
_ v1.MsgServer = &Server{}
_ v1.QueryServer = &Server{}
_ v1.MsgServer = &Keeper{}
_ v1.QueryServer = &Keeper{}
)

// Server is the server.
type Server struct {
db ormdb.ModuleDB
ss contentv1.StateStore
// Keeper is the keeper.
type Keeper struct {
db ormdb.ModuleDB // module database
ss contentv1.StateStore // module state store
}

// NewServer creates a new server.
func NewServer(key storetypes.StoreKey) Server {
s := Server{}
// NewKeeper creates a new keeper.
func NewKeeper() Keeper {
k := Keeper{}

var err error
s.db, err = ormdb.NewModuleDB(&content.ModuleSchema, ormdb.ModuleDBOptions{})
k.db, err = ormdb.NewModuleDB(&content.ModuleSchema, ormdb.ModuleDBOptions{})
if err != nil {
panic(err)
}

s.ss, err = contentv1.NewStateStore(s.db)
k.ss, err = contentv1.NewStateStore(k.db)
if err != nil {
panic(err)
}

return s
return k
}

// InitGenesis initializes genesis state.
func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error {
func (k Keeper) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error {
//source, err := ormjson.NewRawMessageSource(data)
//if err != nil {
// return err
Expand All @@ -58,7 +57,7 @@ func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMes
}

// ExportGenesis exports genesis state.
func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) {
func (k Keeper) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) {
//target := ormjson.NewRawMessageTarget()
//
//err := s.db.ExportJSON(sdk.WrapSDKContext(ctx), target)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"cosmossdk.io/log"
Expand All @@ -19,7 +19,7 @@ import (
type baseSuite struct {
t gocuke.TestingT
sdkCtx sdk.Context
srv Server
k Keeper
}

func setupBase(t gocuke.TestingT) *baseSuite {
Expand All @@ -46,8 +46,8 @@ func setupBase(t gocuke.TestingT) *baseSuite {
// create and set sdk context from commit multi-store with orm context
s.sdkCtx = sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx)

// create and set server
s.srv = NewServer(key)
// create and set keeper
s.k = NewKeeper()

return s
}
6 changes: 3 additions & 3 deletions content/server/msg_create.go → content/keeper/msg_create.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"context"
Expand All @@ -10,7 +10,7 @@ import (
)

// Create implements Msg/Create.
func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) {
func (k Keeper) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

// get account from curator address
Expand All @@ -20,7 +20,7 @@ func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateRes
}

// insert content into content table
id, err := s.ss.ContentTable().InsertReturningId(ctx, &contentv1.Content{
id, err := k.ss.ContentTable().InsertReturningId(ctx, &contentv1.Content{
Curator: curator,
Metadata: req.Metadata,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"testing"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (s *msgCreate) MsgCreate(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &msg)
require.NoError(s.t, err)

s.res, s.err = s.srv.Create(s.sdkCtx, &msg)
s.res, s.err = s.k.Create(s.sdkCtx, &msg)
}

func (s *msgCreate) ExpectNoError() {
Expand All @@ -53,7 +53,7 @@ func (s *msgCreate) ExpectStateContent(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &expected)
require.NoError(s.t, err)

actual, err := s.srv.ss.ContentTable().Get(s.sdkCtx, expected.Id)
actual, err := s.k.ss.ContentTable().Get(s.sdkCtx, expected.Id)
require.NoError(s.t, err)

require.Equal(s.t, expected.Id, actual.Id)
Expand Down
8 changes: 4 additions & 4 deletions content/server/msg_delete.go → content/keeper/msg_delete.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"context"
Expand All @@ -11,7 +11,7 @@ import (
)

// Delete implements Msg/Delete.
func (s Server) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteResponse, error) {
func (k Keeper) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

// get account from curator address
Expand All @@ -21,7 +21,7 @@ func (s Server) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteRes
}

// get content from content table
content, err := s.ss.ContentTable().Get(ctx, req.Id)
content, err := k.ss.ContentTable().Get(ctx, req.Id)
if err != nil {
if ormerrors.NotFound.Is(err) {
return nil, sdkerrors.ErrNotFound.Wrapf(
Expand All @@ -42,7 +42,7 @@ func (s Server) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteRes
}

// delete content from content table
err = s.ss.ContentTable().Delete(ctx, content)
err = k.ss.ContentTable().Delete(ctx, content)
if err != nil {
return nil, err // internal error
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"strconv"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (s *msgDelete) Content(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &content)
require.NoError(s.t, err)

id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{
id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{
Curator: content.Curator,
Metadata: content.Metadata,
})
Expand All @@ -47,7 +47,7 @@ func (s *msgDelete) MsgDelete(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &msg)
require.NoError(s.t, err)

s.res, s.err = s.srv.Delete(s.sdkCtx, &msg)
s.res, s.err = s.k.Delete(s.sdkCtx, &msg)
}

func (s *msgDelete) ExpectNoError() {
Expand All @@ -70,7 +70,7 @@ func (s *msgDelete) ExpectNoStateContentWithId(a string) {
id, err := strconv.ParseUint(a, 10, 32)
require.NoError(s.t, err)

found, err := s.srv.ss.ContentTable().Has(s.sdkCtx, id)
found, err := s.k.ss.ContentTable().Has(s.sdkCtx, id)
require.NoError(s.t, err)
require.False(s.t, found)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"context"
Expand All @@ -11,7 +11,7 @@ import (
)

// UpdateCurator implements the Msg/UpdateCurator method.
func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v1.MsgUpdateCuratorResponse, error) {
func (k Keeper) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v1.MsgUpdateCuratorResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

// get account from curator address
Expand All @@ -21,7 +21,7 @@ func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v
}

// get content from content table
content, err := s.ss.ContentTable().Get(ctx, req.Id)
content, err := k.ss.ContentTable().Get(ctx, req.Id)
if err != nil {
if ormerrors.NotFound.Is(err) {
return nil, sdkerrors.ErrNotFound.Wrapf("content with id %d: %s", req.Id, err)
Expand Down Expand Up @@ -49,7 +49,7 @@ func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v
content.Curator = newCurator

// update content in content table
err = s.ss.ContentTable().Update(ctx, content)
err = k.ss.ContentTable().Update(ctx, content)
if err != nil {
return nil, err // internal error
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"testing"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (s *msgUpdateCurator) Content(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &content)
require.NoError(s.t, err)

id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{
id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{
Curator: content.Curator,
Metadata: content.Metadata,
})
Expand All @@ -46,7 +46,7 @@ func (s *msgUpdateCurator) MsgUpdateCurator(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &msg)
require.NoError(s.t, err)

s.res, s.err = s.srv.UpdateCurator(s.sdkCtx, &msg)
s.res, s.err = s.k.UpdateCurator(s.sdkCtx, &msg)
}

func (s *msgUpdateCurator) ExpectNoError() {
Expand All @@ -70,7 +70,7 @@ func (s *msgUpdateCurator) ExpectStateContent(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &expected)
require.NoError(s.t, err)

actual, err := s.srv.ss.ContentTable().Get(s.sdkCtx, expected.Id)
actual, err := s.k.ss.ContentTable().Get(s.sdkCtx, expected.Id)
require.NoError(s.t, err)

require.Equal(s.t, expected.Id, actual.Id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"context"
Expand All @@ -11,7 +11,7 @@ import (
)

// UpdateMetadata implements the Msg/UpdateMetadata method.
func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) {
func (k Keeper) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

// get account from curator address
Expand All @@ -21,7 +21,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (
}

// get content from content table
content, err := s.ss.ContentTable().Get(ctx, req.Id)
content, err := k.ss.ContentTable().Get(ctx, req.Id)
if err != nil {
if ormerrors.NotFound.Is(err) {
return nil, sdkerrors.ErrNotFound.Wrapf("content with id %d: %s", req.Id, err)
Expand All @@ -43,7 +43,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (
content.Metadata = req.NewMetadata

// update content in content table
err = s.ss.ContentTable().Update(ctx, content)
err = k.ss.ContentTable().Update(ctx, content)
if err != nil {
return nil, err // internal error
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"testing"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (s *msgUpdateMetadata) Content(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &content)
require.NoError(s.t, err)

id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{
id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{
Curator: content.Curator,
Metadata: content.Metadata,
})
Expand All @@ -46,7 +46,7 @@ func (s *msgUpdateMetadata) MsgUpdateMetadata(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &msg)
require.NoError(s.t, err)

s.res, s.err = s.srv.UpdateMetadata(s.sdkCtx, &msg)
s.res, s.err = s.k.UpdateMetadata(s.sdkCtx, &msg)
}

func (s *msgUpdateMetadata) ExpectNoError() {
Expand All @@ -70,7 +70,7 @@ func (s *msgUpdateMetadata) ExpectStateContent(a gocuke.DocString) {
err := jsonpb.UnmarshalString(a.Content, &expected)
require.NoError(s.t, err)

actual, err := s.srv.ss.ContentTable().Get(s.sdkCtx, expected.Id)
actual, err := s.k.ss.ContentTable().Get(s.sdkCtx, expected.Id)
require.NoError(s.t, err)

require.Equal(s.t, expected.Id, actual.Id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package keeper

import (
"context"
Expand All @@ -11,10 +11,10 @@ import (
)

// Content implements the Query/Content method.
func (s Server) Content(ctx context.Context, req *v1.QueryContentRequest) (*v1.QueryContentResponse, error) {
func (k Keeper) Content(ctx context.Context, req *v1.QueryContentRequest) (*v1.QueryContentResponse, error) {

// get content from content table
content, err := s.ss.ContentTable().Get(ctx, req.Id)
content, err := k.ss.ContentTable().Get(ctx, req.Id)
if err != nil {
if ormerrors.NotFound.Is(err) {
return nil, sdkerrors.ErrNotFound.Wrapf("content with id %d", req.Id)
Expand Down
Loading

0 comments on commit da2de9a

Please sign in to comment.