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

add tests for msg server #15

Merged
merged 2 commits into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/rjeczalik/notify v0.9.3 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,9 @@ github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY=
github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down Expand Up @@ -1402,6 +1403,7 @@ golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
77 changes: 77 additions & 0 deletions x/asset/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package keeper_test

import (
"context"
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
"github.com/spf13/cobra"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
"github.com/realiotech/realio-network/app"
"github.com/realiotech/realio-network/x/asset/keeper"
Expand All @@ -21,6 +26,7 @@ type KeeperTestSuite struct {
assetKeeper *keeper.Keeper
govkeeper govkeeper.Keeper
msgServer types.MsgServer
bankKeeper bankkeeper.Keeper
}

func (suite *KeeperTestSuite) SetupTest() {
Expand All @@ -31,8 +37,79 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.assetKeeper = &app.AssetKeeper
suite.govkeeper = app.GovKeeper
suite.msgServer = keeper.NewMsgServerImpl(app.AssetKeeper)
suite.bankKeeper = app.BankKeeper
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func init() {
proto.RegisterType((*MockPrivilegeMsg)(nil), "MockPrivilegeMsg")
}

// MockPrivilegeMsg defines a mock type PrivilegeMsg
type MockPrivilegeMsg struct {
privName string
}

var _ proto.Message = &MockPrivilegeMsg{}

func (m *MockPrivilegeMsg) ValidateBasic() error {
if m.privName == "" {
return fmt.Errorf("empty")
}
return nil
}

func (m *MockPrivilegeMsg) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{userAddr1}
}

func (m *MockPrivilegeMsg) Reset() { *m = MockPrivilegeMsg{} }
func (m *MockPrivilegeMsg) String() string { return proto.CompactTextString(m) }
func (m *MockPrivilegeMsg) ProtoMessage() {}

func (m *MockPrivilegeMsg) NeedPrivilege() string {
return m.privName
}
func (m *MockPrivilegeMsg) XXX_MessageName() string {
return "MockPrivilegeMsg"
}

func (m *MockPrivilegeMsg) XXX_Unmarshal(b []byte) error {
return nil
}

// // MockPrivilegeI defines a mock type PrivilegeI
type MockPrivilegeI struct {
privName string
}

var _ types.PrivilegeI = MockPrivilegeI{}

func (m MockPrivilegeI) Name() string {
return m.privName
}

func (m MockPrivilegeI) RegisterInterfaces() {

}

func (m MockPrivilegeI) MsgHandler() types.MsgHandler {
return func(context context.Context, privMsg proto.Message) (proto.Message, error) {
return nil, nil
}
}

func (m MockPrivilegeI) QueryHandler() types.QueryHandler {
return func(context context.Context, privQuery proto.Message) (proto.Message, error) {
return nil, nil
}
}

func (m MockPrivilegeI) CLI() *cobra.Command {
return &cobra.Command{
Use: "mock",
}
}
Loading
Loading