mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-25 15:05:51 +00:00
chore: add mocks for testing
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
ca5055cef6
commit
6a53c4e3f2
@ -36,6 +36,11 @@ func (cm CheckMachineDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
|
|||||||
if ok {
|
if ok {
|
||||||
ctx, err = cm.handlePopResult(ctx, popMsg)
|
ctx, err = cm.handlePopResult(ctx, popMsg)
|
||||||
}
|
}
|
||||||
|
case "planetmintgo.machine.MsgMintProduction":
|
||||||
|
mintProdMsg, ok := msg.(*machinetypes.MsgMintProduction)
|
||||||
|
if ok {
|
||||||
|
ctx, err = cm.handleMintProduction(ctx, mintProdMsg)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -77,3 +82,11 @@ func (cm CheckMachineDecorator) handlePopResult(ctx sdk.Context, popMsg *daotype
|
|||||||
}
|
}
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cm CheckMachineDecorator) handleMintProduction(ctx sdk.Context, mintProdMsg *machinetypes.MsgMintProduction) (sdk.Context, error) {
|
||||||
|
_, found := cm.mk.GetMachineIndexByAddress(ctx, mintProdMsg.GetCreator())
|
||||||
|
if !found {
|
||||||
|
return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, ErrorAnteContext)
|
||||||
|
}
|
||||||
|
return ctx, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -199,6 +199,7 @@ var (
|
|||||||
govtypes.ModuleName: {authtypes.Burner},
|
govtypes.ModuleName: {authtypes.Burner},
|
||||||
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||||
daomoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
|
daomoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
|
||||||
|
machinemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||||
// this line is used by starport scaffolding # stargate/app/maccPerms
|
// this line is used by starport scaffolding # stargate/app/maccPerms
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -550,6 +551,7 @@ func New(
|
|||||||
app.GetSubspace(machinemoduletypes.ModuleName),
|
app.GetSubspace(machinemoduletypes.ModuleName),
|
||||||
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
||||||
homePath,
|
homePath,
|
||||||
|
app.BankKeeper,
|
||||||
)
|
)
|
||||||
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper)
|
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper)
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/planetmint/planetmint-go/x/machine/keeper"
|
"github.com/planetmint/planetmint-go/x/machine/keeper"
|
||||||
"github.com/planetmint/planetmint-go/x/machine/types"
|
"github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||||
|
machinetestutil "github.com/planetmint/planetmint-go/x/machine/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,6 +52,12 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
|||||||
"MachineParams",
|
"MachineParams",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
bk := machinetestutil.NewMockBankKeeper(ctrl)
|
||||||
|
|
||||||
|
bk.EXPECT().MintCoins(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||||
|
bk.EXPECT().BurnCoins(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||||
|
|
||||||
k := keeper.NewKeeper(
|
k := keeper.NewKeeper(
|
||||||
cdc,
|
cdc,
|
||||||
storeKey,
|
storeKey,
|
||||||
@ -62,6 +70,7 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
|||||||
paramsSubspace,
|
paramsSubspace,
|
||||||
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
||||||
"",
|
"",
|
||||||
|
bk,
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
|
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
|
||||||
|
|||||||
@ -23,6 +23,7 @@ type (
|
|||||||
paramstore paramtypes.Subspace
|
paramstore paramtypes.Subspace
|
||||||
authority string
|
authority string
|
||||||
rootDir string
|
rootDir string
|
||||||
|
bankKeeper types.BankKeeper
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ func NewKeeper(
|
|||||||
ps paramtypes.Subspace,
|
ps paramtypes.Subspace,
|
||||||
authority string,
|
authority string,
|
||||||
rootDir string,
|
rootDir string,
|
||||||
|
bankKeeper types.BankKeeper,
|
||||||
) *Keeper {
|
) *Keeper {
|
||||||
// set KeyTable if it has not already been set
|
// set KeyTable if it has not already been set
|
||||||
if !ps.HasKeyTable() {
|
if !ps.HasKeyTable() {
|
||||||
@ -56,6 +58,7 @@ func NewKeeper(
|
|||||||
paramstore: ps,
|
paramstore: ps,
|
||||||
authority: authority,
|
authority: authority,
|
||||||
rootDir: rootDir,
|
rootDir: rootDir,
|
||||||
|
bankKeeper: bankKeeper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
115
x/machine/testutil/expected_keepers_mocks.go
Normal file
115
x/machine/testutil/expected_keepers_mocks.go
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: ./types/expected_keepers.go
|
||||||
|
|
||||||
|
// Package testutil is a generated GoMock package.
|
||||||
|
package testutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
types "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
types0 "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockAccountKeeper is a mock of AccountKeeper interface.
|
||||||
|
type MockAccountKeeper struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockAccountKeeperMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper.
|
||||||
|
type MockAccountKeeperMockRecorder struct {
|
||||||
|
mock *MockAccountKeeper
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockAccountKeeper creates a new mock instance.
|
||||||
|
func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper {
|
||||||
|
mock := &MockAccountKeeper{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockAccountKeeperMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccount mocks base method.
|
||||||
|
func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "GetAccount", ctx, addr)
|
||||||
|
ret0, _ := ret[0].(types0.AccountI)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccount indicates an expected call of GetAccount.
|
||||||
|
func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockBankKeeper is a mock of BankKeeper interface.
|
||||||
|
type MockBankKeeper struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockBankKeeperMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper.
|
||||||
|
type MockBankKeeperMockRecorder struct {
|
||||||
|
mock *MockBankKeeper
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockBankKeeper creates a new mock instance.
|
||||||
|
func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper {
|
||||||
|
mock := &MockBankKeeper{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockBankKeeperMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// BurnCoins mocks base method.
|
||||||
|
func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amt types.Coins) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// BurnCoins indicates an expected call of BurnCoins.
|
||||||
|
func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MintCoins mocks base method.
|
||||||
|
func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amt types.Coins) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// MintCoins indicates an expected call of MintCoins.
|
||||||
|
func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amt interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, moduleName, amt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpendableCoins mocks base method.
|
||||||
|
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
|
||||||
|
ret0, _ := ret[0].(types.Coins)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpendableCoins indicates an expected call of SpendableCoins.
|
||||||
|
func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr)
|
||||||
|
}
|
||||||
@ -14,5 +14,7 @@ type AccountKeeper interface {
|
|||||||
// BankKeeper defines the expected interface needed to retrieve account balances.
|
// BankKeeper defines the expected interface needed to retrieve account balances.
|
||||||
type BankKeeper interface {
|
type BankKeeper interface {
|
||||||
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
||||||
|
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
|
||||||
|
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
|
||||||
// Methods imported from bank should be defined here
|
// Methods imported from bank should be defined here
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user