Skip to content

Commit

Permalink
refactor(x/ecocredit): remove deprecated params keeper (#1543)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
  • Loading branch information
aleem1314 and ryanchristo authored Oct 19, 2022
1 parent a128c39 commit 98e6571
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 101 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1462](https://github.com/regen-network/regen-ledger/pull/1462) Bridge operations must now specify a target/source that exists in the `AllowedBridgeChain` table.
- [#1476](https://github.com/regen-network/regen-ledger/pull/1476) `DefaultParams` function has been removed.
- [#1476](https://github.com/regen-network/regen-ledger/pull/1476) Remove `params` argument from `ValidateGenesis`.
- [#1543](https://github.com/regen-network/regen-ledger/pull/1543) Remove `paramsKeeper` argument from `base/Keeper`, `basket/Keeper` and `marketplace/Keeper`.

#### Added

Expand Down
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

0 comments on commit 98e6571

Please sign in to comment.