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

test(x/ecocredit): basket integration test #771

Merged
merged 19 commits into from
Feb 15, 2022
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
10 changes: 8 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"net/http"
"os"

moduletypes "github.com/regen-network/regen-ledger/types/module"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -92,8 +90,10 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

moduletypes "github.com/regen-network/regen-ledger/types/module"
"github.com/regen-network/regen-ledger/types/module/server"
"github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/regen-network/regen-ledger/x/ecocredit/basket"
ecocreditmodule "github.com/regen-network/regen-ledger/x/ecocredit/module"

// unnamed import of statik for swagger UI support
Expand Down Expand Up @@ -147,13 +147,19 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ecocredit.ModuleName: {authtypes.Burner},
basket.BasketSubModuleName: {authtypes.Burner, authtypes.Minter},
}
)

func init() {
// this changes the power reduction from 10e6 to 10e2, which will give
// every validator 10,000 times more voting power than they currently have
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(2), nil))

// set the denom regex for basket coins.
sdk.SetCoinDenomRegex(func() string {
return `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}`
})
}

// Extended ABCI application
Expand Down
3 changes: 2 additions & 1 deletion x/ecocredit/server/basket/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func (k Keeper) indexAllowedClasses(ctx types.Context, basketID uint64, allowedC
return sdkerrors.ErrInvalidRequest.Wrapf("credit class %q doesn't exist", class)
}

err := k.stateStore.BasketClassStore().Insert(ctx,
wrappedCtx := sdk.WrapSDKContext(ctx.Context)
err := k.stateStore.BasketClassStore().Insert(wrappedCtx,
&basketv1.BasketClass{
BasketId: basketID,
ClassId: class,
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/server/basket/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (k Keeper) Put(ctx context.Context, req *baskettypes.MsgPut) (*baskettypes.
func (k Keeper) canBasketAcceptCredit(ctx context.Context, basket *basketv1.Basket, batchInfo *ecocredit.BatchInfo) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
blockTime := sdkCtx.BlockTime()
errInvalidReq := sdkerrors.ErrInvalidAddress
errInvalidReq := sdkerrors.ErrInvalidRequest

if basket.DateCriteria != nil && basket.DateCriteria.Sum != nil {
// check time window match
Expand Down
11 changes: 4 additions & 7 deletions x/ecocredit/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type serverImpl struct {
}

func newServer(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace,
accountKeeper ecocredit.AccountKeeper, bankKeeper ecocredit.BankKeeper, cdc codec.Codec) serverImpl {
accountKeeper ecocredit.AccountKeeper, bankKeeper ecocredit.BankKeeper, distKeeper ecocredit.DistributionKeeper, cdc codec.Codec) serverImpl {
s := serverImpl{
storeKey: storeKey,
paramSpace: paramSpace,
Expand Down Expand Up @@ -73,6 +73,8 @@ func newServer(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace,
panic(err)
}

s.basketKeeper = basket.NewKeeper(s.db, s, bankKeeper, distKeeper, storeKey)

return s
}

Expand All @@ -83,12 +85,7 @@ func RegisterServices(
bankKeeper ecocredit.BankKeeper,
distKeeper ecocredit.DistributionKeeper,
) {
impl := newServer(configurator.ModuleKey(), paramSpace, accountKeeper, bankKeeper, configurator.Marshaler())
db, err := ormutil.NewStoreKeyDB(ModuleSchema, configurator.ModuleKey(), ormdb.ModuleDBOptions{})
if err != nil {
panic(err)
}
impl.basketKeeper = basket.NewKeeper(db, impl, bankKeeper, distKeeper, impl.storeKey)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for moving to the constructor

impl := newServer(configurator.ModuleKey(), paramSpace, accountKeeper, bankKeeper, distKeeper, configurator.Marshaler())
ecocredit.RegisterMsgServer(configurator.MsgServer(), impl)
ecocredit.RegisterQueryServer(configurator.QueryServer(), impl)
configurator.RegisterGenesisHandlers(impl.InitGenesis, impl.ExportGenesis)
Expand Down
9 changes: 6 additions & 3 deletions x/ecocredit/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package server_test
import (
"testing"

"github.com/regen-network/regen-ledger/x/ecocredit/basket"

"github.com/golang/mock/gomock"
mocks2 "github.com/regen-network/regen-ledger/x/ecocredit/mocks"

Expand Down Expand Up @@ -50,8 +52,9 @@ func TestServer(t *testing.T) {
ecocreditSubspace := paramstypes.NewSubspace(cdc, amino, paramsKey, tkey, ecocredittypes.ModuleName)

maccPerms := map[string][]string{
minttypes.ModuleName: {authtypes.Minter},
ecocredittypes.ModuleName: {authtypes.Burner},
minttypes.ModuleName: {authtypes.Minter},
ecocredittypes.ModuleName: {authtypes.Burner},
basket.BasketSubModuleName: {authtypes.Burner, authtypes.Minter},
}

accountKeeper := authkeeper.NewAccountKeeper(
Expand All @@ -67,6 +70,6 @@ func TestServer(t *testing.T) {
ecocreditModule := ecocredit.NewModule(ecocreditSubspace, accountKeeper, bankKeeper, distKeeper)
ff.SetModules([]module.Module{ecocreditModule})

s := testsuite.NewIntegrationTestSuite(ff, ecocreditSubspace, bankKeeper)
s := testsuite.NewIntegrationTestSuite(ff, ecocreditSubspace, bankKeeper, distKeeper)
suite.Run(t, s)
}
Loading