Skip to content

Commit

Permalink
test(x/ecocredit): basket integration test (#771)
Browse files Browse the repository at this point in the history
* wip

* more wip

* chore: fixup 1 final thing

* fix: oof

* chore: cleanup comments

* chore: add basket submodule to app.go

* chore: fix testss

* wip

* test: add retire test

* chore: comment

* wip: need to fix coin validate stuff

* fix: add and set sdk regex for basket coins

* chore: ecocredit doesnt need minter

* chore: dont need account keeper in suite

* chore: goimport files

* chore: goimport app.go

Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
  • Loading branch information
technicallyty and technicallyty authored Feb 15, 2022
1 parent 1cb3728 commit 398824e
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 26 deletions.
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)
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

0 comments on commit 398824e

Please sign in to comment.