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

refactor(x/ecocredit): remove deprecated params keeper #1543

Merged
merged 6 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions api/regen/ecocredit/v1/tx_grpc.pb.go

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

2 changes: 1 addition & 1 deletion proto/regen/ecocredit/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ service Msg {
rpc AddClassCreator(MsgAddClassCreator) returns (MsgAddClassCreatorResponse);

// RemoveClassCreator is a governance method that removes
// address from the creation allowlist.
// address from the class creation allowlist.
//
// Since Revision 1
rpc RemoveClassCreator(MsgRemoveClassCreator)
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/base/types/v1/tx.pb.go

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

3 changes: 0 additions & 3 deletions x/ecocredit/basket/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Keeper struct {
stateStore api.StateStore
baseStore baseapi.StateStore
bankKeeper ecocredit.BankKeeper
paramsKeeper ecocredit.ParamKeeper
moduleAddress sdk.AccAddress
authority sdk.AccAddress
}
Expand All @@ -29,15 +28,13 @@ func NewKeeper(
ss api.StateStore,
cs baseapi.StateStore,
bk ecocredit.BankKeeper,
pk ecocredit.ParamKeeper,
ma sdk.AccAddress,
authority sdk.AccAddress,
) Keeper {
return Keeper{
stateStore: ss,
baseStore: cs,
bankKeeper: bk,
paramsKeeper: pk,
moduleAddress: ma,
authority: authority,
}
Expand Down
26 changes: 12 additions & 14 deletions x/ecocredit/basket/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ const (
)

type baseSuite struct {
t gocuke.TestingT
db ormdb.ModuleDB
ctx context.Context
k Keeper
ctrl *gomock.Controller
addrs []sdk.AccAddress
stateStore api.StateStore
baseStore baseapi.StateStore
bankKeeper *mocks.MockBankKeeper
paramsKeeper *mocks.MockParamKeeper
storeKey *storetypes.KVStoreKey
sdkCtx sdk.Context
t gocuke.TestingT
db ormdb.ModuleDB
ctx context.Context
k Keeper
ctrl *gomock.Controller
addrs []sdk.AccAddress
stateStore api.StateStore
baseStore baseapi.StateStore
bankKeeper *mocks.MockBankKeeper
storeKey *storetypes.KVStoreKey
sdkCtx sdk.Context
}

func setupBase(t gocuke.TestingT) *baseSuite {
Expand All @@ -70,13 +69,12 @@ func setupBase(t gocuke.TestingT) *baseSuite {
s.ctrl = gomock.NewController(t)
assert.NilError(t, err)
s.bankKeeper = mocks.NewMockBankKeeper(s.ctrl)
s.paramsKeeper = mocks.NewMockParamKeeper(s.ctrl)

_, _, moduleAddress := testdata.KeyTestPubAddr()
authority, err := sdk.AccAddressFromBech32("regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68")
assert.NilError(t, err)

s.k = NewKeeper(s.stateStore, s.baseStore, s.bankKeeper, s.paramsKeeper, moduleAddress, authority)
s.k = NewKeeper(s.stateStore, s.baseStore, s.bankKeeper, moduleAddress, authority)
s.baseStore, err = baseapi.NewStateStore(s.db)
assert.NilError(t, err)

Expand Down
11 changes: 0 additions & 11 deletions x/ecocredit/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/params/types"
)

//go:generate mockgen -source=expected_keepers.go -package mocks -destination mocks/expected_keepers.go
Expand Down Expand Up @@ -43,13 +42,3 @@ type GovKeeper interface {
// GetDepositParams queries governance module deposit params
GetDepositParams(ctx sdk.Context) govv1.DepositParams
}

type ParamKeeper interface {

// Get fetches a parameter by key from the Subspace's KVStore and sets the provided pointer to the fetched value.
// If the value does not exist, this method will panic.
Get(ctx sdk.Context, key []byte, ptr interface{})

// GetParamSet fetches each parameter in the ParamSet.
GetParamSet(ctx sdk.Context, ps types.ParamSet)
}
20 changes: 9 additions & 11 deletions x/ecocredit/marketplace/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ var (
)

type Keeper struct {
stateStore marketapi.StateStore
baseStore baseapi.StateStore
bankKeeper ecocredit.BankKeeper
paramsKeeper ecocredit.ParamKeeper
authority sdk.AccAddress
stateStore marketapi.StateStore
baseStore baseapi.StateStore
bankKeeper ecocredit.BankKeeper
authority sdk.AccAddress
}

func NewKeeper(ss marketapi.StateStore, cs baseapi.StateStore, bk ecocredit.BankKeeper,
params ecocredit.ParamKeeper, authority sdk.AccAddress) Keeper {
authority sdk.AccAddress) Keeper {
return Keeper{
baseStore: cs,
stateStore: ss,
bankKeeper: bk,
paramsKeeper: params,
authority: authority,
baseStore: cs,
stateStore: ss,
bankKeeper: bk,
authority: authority,
}
}
26 changes: 12 additions & 14 deletions x/ecocredit/marketplace/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ const (
)

type baseSuite struct {
t gocuke.TestingT
db ormdb.ModuleDB
baseStore baseapi.StateStore
marketStore api.StateStore
ctx context.Context
k Keeper
ctrl *gomock.Controller
addrs []sdk.AccAddress
bankKeeper *mocks.MockBankKeeper
paramsKeeper *mocks.MockParamKeeper
storeKey *storetypes.KVStoreKey
sdkCtx sdk.Context
t gocuke.TestingT
db ormdb.ModuleDB
baseStore baseapi.StateStore
marketStore api.StateStore
ctx context.Context
k Keeper
ctrl *gomock.Controller
addrs []sdk.AccAddress
bankKeeper *mocks.MockBankKeeper
storeKey *storetypes.KVStoreKey
sdkCtx sdk.Context
}

func setupBase(t gocuke.TestingT, numAddresses int) *baseSuite {
Expand All @@ -74,11 +73,10 @@ func setupBase(t gocuke.TestingT, numAddresses int) *baseSuite {
s.ctrl = gomock.NewController(t)
assert.NilError(t, err)
s.bankKeeper = mocks.NewMockBankKeeper(s.ctrl)
s.paramsKeeper = mocks.NewMockParamKeeper(s.ctrl)

authority, err := sdk.AccAddressFromBech32("regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68")
assert.NilError(s.t, err)
s.k = NewKeeper(s.marketStore, s.baseStore, s.bankKeeper, s.paramsKeeper, authority)
s.k = NewKeeper(s.marketStore, s.baseStore, s.bankKeeper, authority)

// set test accounts
for i := 0; i < numAddresses; i++ {
Expand Down
53 changes: 21 additions & 32 deletions x/ecocredit/mocks/expected_keepers.go

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

2 changes: 1 addition & 1 deletion x/ecocredit/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (m Module) RegisterInterfaces(registry types.InterfaceRegistry) {

// RegisterServices implements AppModule/RegisterServices.
func (m *Module) RegisterServices(cfg module.Configurator) {
svr := server.NewServer(m.key, m.legacySubspace, m.accountKeeper, m.bankKeeper, m.authority)
svr := server.NewServer(m.key, m.accountKeeper, m.bankKeeper, m.authority)
basetypes.RegisterMsgServer(cfg.MsgServer(), svr.BaseKeeper)
basetypes.RegisterQueryServer(cfg.QueryServer(), svr.BaseKeeper)

Expand Down
17 changes: 7 additions & 10 deletions x/ecocredit/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/orm/model/ormdb"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

basketapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/basket/v1"
marketapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1"
Expand All @@ -23,9 +22,8 @@ import (
)

type serverImpl struct {
legacySubspace paramtypes.Subspace
bankKeeper ecocredit.BankKeeper
accountKeeper ecocredit.AccountKeeper
bankKeeper ecocredit.BankKeeper
accountKeeper ecocredit.AccountKeeper

BaseKeeper basekeeper.Keeper
BasketKeeper basketkeeper.Keeper
Expand All @@ -38,12 +36,11 @@ type serverImpl struct {
}

//nolint:revive
func NewServer(storeKey storetypes.StoreKey, legacySubspace paramtypes.Subspace,
func NewServer(storeKey storetypes.StoreKey,
accountKeeper ecocredit.AccountKeeper, bankKeeper ecocredit.BankKeeper, authority sdk.AccAddress) serverImpl {
s := serverImpl{
legacySubspace: legacySubspace,
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
}

// ensure ecocredit module account is set
Expand All @@ -69,8 +66,8 @@ func NewServer(storeKey storetypes.StoreKey, legacySubspace paramtypes.Subspace,
s.basketStore = basketStore
s.marketplaceStore = marketStore
s.BaseKeeper = basekeeper.NewKeeper(baseStore, bankKeeper, baseAddr, basketStore, marketStore, authority)
s.BasketKeeper = basketkeeper.NewKeeper(basketStore, baseStore, bankKeeper, s.legacySubspace, basketAddr, authority)
s.MarketplaceKeeper = marketkeeper.NewKeeper(marketStore, baseStore, bankKeeper, s.legacySubspace, authority)
s.BasketKeeper = basketkeeper.NewKeeper(basketStore, baseStore, bankKeeper, basketAddr, authority)
s.MarketplaceKeeper = marketkeeper.NewKeeper(marketStore, baseStore, bankKeeper, authority)

return s
}
Expand Down