From ef344a9ca8081e7806f6d65a07d265f14954d68a Mon Sep 17 00:00:00 2001 From: Tyler <48813565+technicallyty@users.noreply.github.com> Date: Fri, 1 Apr 2022 10:54:01 -0700 Subject: [PATCH] chore(ecocredit): remove alpha params (#968) * chore: remove alpha params * chore: imports Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com> --- x/ecocredit/server/core/cancel_test.go | 13 +++++----- x/ecocredit/server/core/create_batch_test.go | 9 +++---- x/ecocredit/server/core/create_class.go | 2 +- x/ecocredit/server/core/create_class_test.go | 15 +++++------ x/ecocredit/server/core/query_credit_types.go | 15 ++--------- .../server/core/query_credit_types_test.go | 5 ++-- x/ecocredit/server/core/query_params.go | 20 ++------------ x/ecocredit/server/core/query_params_test.go | 5 ++-- x/ecocredit/server/core/retire_test.go | 9 +++---- x/ecocredit/server/core/send_test.go | 9 +++---- x/ecocredit/server/keeper.go | 19 -------------- x/ecocredit/server/marketplace/buy_test.go | 26 +++++++++---------- .../marketplace/cancel_sell_order_test.go | 14 +++++----- x/ecocredit/server/marketplace/prune_test.go | 14 +++++----- .../marketplace/query_sell_order_test.go | 7 +++-- .../marketplace/query_sell_orders_test.go | 4 +-- x/ecocredit/server/marketplace/sell_test.go | 22 ++++++++-------- .../server/marketplace/update_sell_orders.go | 8 +++--- .../marketplace/update_sell_orders_test.go | 22 ++++++++-------- x/ecocredit/server/utils/utils.go | 11 ++++---- 20 files changed, 98 insertions(+), 151 deletions(-) delete mode 100644 x/ecocredit/server/keeper.go diff --git a/x/ecocredit/server/core/cancel_test.go b/x/ecocredit/server/core/cancel_test.go index d2d75ad9e1..2740ee4eb1 100644 --- a/x/ecocredit/server/core/cancel_test.go +++ b/x/ecocredit/server/core/cancel_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -18,8 +17,8 @@ func TestCancel_Valid(t *testing.T) { _, _, batchDenom := s.setupClassProjectBatch(t) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) // Supply -> tradable: 10.5 , retired: 10.5 @@ -55,8 +54,8 @@ func TestCancel_InsufficientFunds(t *testing.T) { s.setupClassProjectBatch(t) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) _, err := s.k.Cancel(s.ctx, &core.MsgCancel{ @@ -78,8 +77,8 @@ func TestCancel_BadPrecision(t *testing.T) { s.setupClassProjectBatch(t) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) _, err := s.k.Cancel(s.ctx, &core.MsgCancel{ diff --git a/x/ecocredit/server/core/create_batch_test.go b/x/ecocredit/server/core/create_batch_test.go index 3cd4f179fb..15c02f8ba9 100644 --- a/x/ecocredit/server/core/create_batch_test.go +++ b/x/ecocredit/server/core/create_batch_test.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -28,10 +27,10 @@ func TestCreateBatch_Valid(t *testing.T) { s.ctx = types.WrapSDKContext(s.sdkCtx) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { p.AllowlistEnabled = false p.CreditClassFee = types.NewCoins(types.NewInt64Coin("foo", 20)) - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) start, end := time.Now(), time.Now() @@ -93,10 +92,10 @@ func TestCreateBatch_BadPrecision(t *testing.T) { batchTestSetup(t, s.ctx, s.stateStore, s.addr) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { p.AllowlistEnabled = false p.CreditClassFee = types.NewCoins(types.NewInt64Coin("foo", 20)) - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) start, end := time.Now(), time.Now() diff --git a/x/ecocredit/server/core/create_class.go b/x/ecocredit/server/core/create_class.go index 9ddb36ff50..e429bd4520 100644 --- a/x/ecocredit/server/core/create_class.go +++ b/x/ecocredit/server/core/create_class.go @@ -27,7 +27,7 @@ func (k Keeper) CreateClass(goCtx context.Context, req *core.MsgCreateClass) (*c } // TODO: remove params https://github.com/regen-network/regen-ledger/issues/729 - var params ecocredit.Params + var params core.Params k.paramsKeeper.GetParamSet(sdkCtx, ¶ms) if params.AllowlistEnabled && !k.isCreatorAllowListed(sdkCtx, params.AllowedClassCreators, adminAddress) { return nil, sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to create credit classes", adminAddress.String()) diff --git a/x/ecocredit/server/core/create_class_test.go b/x/ecocredit/server/core/create_class_test.go index 1eeb858e7b..feb9461a01 100644 --- a/x/ecocredit/server/core/create_class_test.go +++ b/x/ecocredit/server/core/create_class_test.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -17,10 +16,10 @@ func TestCreateClass_Valid(t *testing.T) { s := setupBase(t) any := gomock.Any() ccFee := &sdk.Coin{Denom: "foo", Amount: sdk.NewInt(20)} - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *ecocredit.Params) { + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *core.Params) { p.AllowlistEnabled = false p.CreditClassFee = sdk.NewCoins(sdk.NewInt64Coin(ccFee.Denom, 20)) - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) s.bankKeeper.EXPECT().SendCoinsFromAccountToModule(any, any, any, any).Return(nil).Times(1) @@ -57,7 +56,7 @@ func TestCreateClass_Unauthorized(t *testing.T) { any := gomock.Any() // allowlist = true and sender is not in allowlist - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *ecocredit.Params) { + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *core.Params) { p.AllowlistEnabled = true p.AllowedClassCreators = append(p.AllowedClassCreators, "foo") }).Times(1) @@ -75,10 +74,10 @@ func TestCreateClass_Sequence(t *testing.T) { s := setupBase(t) ccFee := &sdk.Coin{Denom: "foo", Amount: sdk.NewInt(20)} any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *ecocredit.Params) { + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *core.Params) { p.AllowlistEnabled = false p.CreditClassFee = sdk.NewCoins(sdk.NewInt64Coin("foo", 20)) - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(2) s.bankKeeper.EXPECT().SendCoinsFromAccountToModule(any, any, any, any).Return(nil).Times(2) @@ -110,10 +109,10 @@ func TestCreateClass_Fees(t *testing.T) { t.Parallel() s := setupBase(t) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *ecocredit.Params) { + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(ctx interface{}, p *core.Params) { p.AllowlistEnabled = false p.CreditClassFee = sdk.NewCoins(sdk.NewInt64Coin("foo", 20)) - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(2) // wrong denom diff --git a/x/ecocredit/server/core/query_credit_types.go b/x/ecocredit/server/core/query_credit_types.go index db6509d9fa..4f1d3ca5f4 100644 --- a/x/ecocredit/server/core/query_credit_types.go +++ b/x/ecocredit/server/core/query_credit_types.go @@ -3,7 +3,6 @@ package core import ( "context" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,17 +11,7 @@ import ( // CreditTypes queries the list of allowed types that credit classes can have. func (k Keeper) CreditTypes(ctx context.Context, _ *core.QueryCreditTypesRequest) (*core.QueryCreditTypesResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - var params ecocredit.Params + var params core.Params k.paramsKeeper.GetParamSet(sdkCtx, ¶ms) - - cTypes := make([]*core.CreditType, len(params.CreditTypes)) - for i, ct := range params.CreditTypes { - cTypes[i] = &core.CreditType{ - Abbreviation: ct.Abbreviation, - Name: ct.Name, - Unit: ct.Unit, - Precision: ct.Precision, - } - } - return &core.QueryCreditTypesResponse{CreditTypes: cTypes}, nil + return &core.QueryCreditTypesResponse{CreditTypes: params.CreditTypes}, nil } diff --git a/x/ecocredit/server/core/query_credit_types_test.go b/x/ecocredit/server/core/query_credit_types_test.go index c4d8ae60f1..40e76a3999 100644 --- a/x/ecocredit/server/core/query_credit_types_test.go +++ b/x/ecocredit/server/core/query_credit_types_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/regen-network/regen-ledger/x/ecocredit" "gotest.tools/v3/assert" "github.com/regen-network/regen-ledger/x/ecocredit/core" @@ -14,8 +13,8 @@ func TestQuery_CreditTypes(t *testing.T) { t.Parallel() s := setupBase(t) gmAny := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "foobar", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "foobar", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) // base query should return all types diff --git a/x/ecocredit/server/core/query_params.go b/x/ecocredit/server/core/query_params.go index b830cc620c..59c8089a06 100644 --- a/x/ecocredit/server/core/query_params.go +++ b/x/ecocredit/server/core/query_params.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -15,22 +14,7 @@ import ( // will be gone with #729. func (k Keeper) Params(ctx context.Context, _ *core.QueryParamsRequest) (*core.QueryParamsResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - var params ecocredit.Params + var params core.Params k.paramsKeeper.GetParamSet(sdkCtx, ¶ms) - v1beta1types := make([]*core.CreditType, len(params.CreditTypes)) - for i, typ := range params.CreditTypes { - v1beta1types[i] = &core.CreditType{ - Abbreviation: typ.Abbreviation, - Name: typ.Name, - Unit: typ.Unit, - Precision: typ.Precision, - } - } - v1beta1Params := core.Params{ - CreditClassFee: params.CreditClassFee, - AllowedClassCreators: params.AllowedClassCreators, - AllowlistEnabled: params.AllowlistEnabled, - CreditTypes: v1beta1types, - } - return &core.QueryParamsResponse{Params: &v1beta1Params}, nil + return &core.QueryParamsResponse{Params: ¶ms}, nil } diff --git a/x/ecocredit/server/core/query_params_test.go b/x/ecocredit/server/core/query_params_test.go index 6c8a16e4a3..00d8376870 100644 --- a/x/ecocredit/server/core/query_params_test.go +++ b/x/ecocredit/server/core/query_params_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -25,11 +24,11 @@ func TestQuery_Params(t *testing.T) { Precision: 6, })) - s.paramsKeeper.EXPECT().GetParamSet(any, any).SetArg(1, ecocredit.Params{ + s.paramsKeeper.EXPECT().GetParamSet(any, any).SetArg(1, core.Params{ CreditClassFee: types.NewCoins(types.NewInt64Coin("foo", 30)), AllowedClassCreators: []string{s.addr.String()}, AllowlistEnabled: false, - CreditTypes: []*ecocredit.CreditType{{ + CreditTypes: []*core.CreditType{{ Abbreviation: "C", Name: "carbon", Unit: "a ton", diff --git a/x/ecocredit/server/core/retire_test.go b/x/ecocredit/server/core/retire_test.go index 264a468b05..d0da0d6567 100644 --- a/x/ecocredit/server/core/retire_test.go +++ b/x/ecocredit/server/core/retire_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -23,8 +22,8 @@ func TestRetire_Valid(t *testing.T) { // retired: 10.5 any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(1) // starting balance -> 10.5 tradable, 10.5 retired @@ -68,8 +67,8 @@ func TestRetire_Invalid(t *testing.T) { assert.ErrorContains(t, err, ormerrors.NotFound.Error()) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(2) // out of precision diff --git a/x/ecocredit/server/core/send_test.go b/x/ecocredit/server/core/send_test.go index c49025f920..b81036bc73 100644 --- a/x/ecocredit/server/core/send_test.go +++ b/x/ecocredit/server/core/send_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" - "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -18,8 +17,8 @@ func TestSend_Valid(t *testing.T) { _, _, recipient := testdata.KeyTestPubAddr() s.setupClassProjectBatch(t) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(2) // this will be called for each batchDenom we send // s.Addr starting balance -> 10.5 tradable, 10.5 retired @@ -66,8 +65,8 @@ func TestSend_Errors(t *testing.T) { _, _, recipient := testdata.KeyTestPubAddr() s.setupClassProjectBatch(t) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(_ interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{{Name: "carbon", Abbreviation: "C", Unit: "tonne", Precision: 6}} }).Times(2) // test sending more than user balance diff --git a/x/ecocredit/server/keeper.go b/x/ecocredit/server/keeper.go deleted file mode 100644 index 44cf8ea1fd..0000000000 --- a/x/ecocredit/server/keeper.go +++ /dev/null @@ -1,19 +0,0 @@ -package server - -import ( - "context" - - "github.com/regen-network/regen-ledger/types" - "github.com/regen-network/regen-ledger/x/ecocredit" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// In this keeper.go files we expose methods the basket.Keeper needs. - -func (s serverImpl) GetCreateBasketFee(ctx context.Context) sdk.Coins { - sdkCtx := types.UnwrapSDKContext(ctx).Context - var params ecocredit.Params - s.paramSpace.GetParamSet(sdkCtx, ¶ms) - return params.BasketCreationFee -} diff --git a/x/ecocredit/server/marketplace/buy_test.go b/x/ecocredit/server/marketplace/buy_test.go index 0a0fc6518c..371bcfc61e 100644 --- a/x/ecocredit/server/marketplace/buy_test.go +++ b/x/ecocredit/server/marketplace/buy_test.go @@ -9,7 +9,7 @@ import ( "gotest.tools/v3/assert" "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" @@ -26,7 +26,7 @@ func TestBuy_ValidTradable(t *testing.T) { start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) userCoinBalance := sdk.NewInt64Coin("ufoo", 30) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -35,8 +35,8 @@ func TestBuy_ValidTradable(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) // make a sell order gmAny := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) sellExp := time.Now() res, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -83,7 +83,7 @@ func TestBuy_ValidRetired(t *testing.T) { start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) userBalance := sdk.NewInt64Coin("ufoo", 30) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -92,8 +92,8 @@ func TestBuy_ValidRetired(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) // make a sell order gmAny := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) sellExp := time.Now() res, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -139,7 +139,7 @@ func TestBuy_OrderFilled(t *testing.T) { start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) userBalance := sdk.NewInt64Coin("ufoo", 100) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -148,8 +148,8 @@ func TestBuy_OrderFilled(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) // make a sell order gmAny := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) sellExp := time.Now() res, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -192,7 +192,7 @@ func TestBuy_Invalid(t *testing.T) { start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) userBalance := sdk.NewInt64Coin("ufoo", 150) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -201,8 +201,8 @@ func TestBuy_Invalid(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) // make a sell order gmAny := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).AnyTimes() sellExp := time.Now() res, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ diff --git a/x/ecocredit/server/marketplace/cancel_sell_order_test.go b/x/ecocredit/server/marketplace/cancel_sell_order_test.go index 9f99261679..8482158667 100644 --- a/x/ecocredit/server/marketplace/cancel_sell_order_test.go +++ b/x/ecocredit/server/marketplace/cancel_sell_order_test.go @@ -14,7 +14,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) @@ -25,7 +25,7 @@ func TestSell_CancelOrder(t *testing.T) { start, end := timestamppb.Now(), timestamppb.Now() expir := time.Now() ask := sdk.NewInt64Coin("ufoo", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -34,8 +34,8 @@ func TestSell_CancelOrder(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(1) balBefore, err := s.coreStore.BatchBalanceTable().Get(s.ctx, s.addr, 1) @@ -70,7 +70,7 @@ func TestSell_CancelOrderInvalid(t *testing.T) { start, end := timestamppb.Now(), timestamppb.Now() expir := time.Now() ask := sdk.NewInt64Coin("ufoo", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -79,8 +79,8 @@ func TestSell_CancelOrderInvalid(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(1) _, _, otherAddr := testdata.KeyTestPubAddr() diff --git a/x/ecocredit/server/marketplace/prune_test.go b/x/ecocredit/server/marketplace/prune_test.go index e1bfed82f9..9f57ee0fde 100644 --- a/x/ecocredit/server/marketplace/prune_test.go +++ b/x/ecocredit/server/marketplace/prune_test.go @@ -12,8 +12,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit" - v1 "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" + "github.com/regen-network/regen-ledger/x/ecocredit/core" + "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) func TestSell_Prune(t *testing.T) { @@ -23,15 +23,15 @@ func TestSell_Prune(t *testing.T) { batchDenom := "C01-20200101-20200201-001" start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", Precision: 6, } testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) blockTime, err := time.Parse("2006-01-02", "2020-01-01") @@ -41,9 +41,9 @@ func TestSell_Prune(t *testing.T) { notExpired, err := time.Parse("2006-01-02", "2022-01-01") assert.NilError(t, err) - res, err := s.k.Sell(s.ctx, &v1.MsgSell{ + res, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ Owner: s.addr.String(), - Orders: []*v1.MsgSell_Order{ + Orders: []*marketplace.MsgSell_Order{ {BatchDenom: batchDenom, Quantity: "10", AskPrice: &ask, Expiration: &expired}, {BatchDenom: batchDenom, Quantity: "10", AskPrice: &ask, Expiration: ¬Expired}, }, diff --git a/x/ecocredit/server/marketplace/query_sell_order_test.go b/x/ecocredit/server/marketplace/query_sell_order_test.go index 86cce98395..b811e90a1d 100644 --- a/x/ecocredit/server/marketplace/query_sell_order_test.go +++ b/x/ecocredit/server/marketplace/query_sell_order_test.go @@ -3,16 +3,15 @@ package marketplace import ( "testing" - "gotest.tools/v3/assert" - "google.golang.org/protobuf/types/known/timestamppb" + "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" "github.com/regen-network/regen-ledger/types/ormutil" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) @@ -22,7 +21,7 @@ func TestQuery_SellOrder(t *testing.T) { batchDenom := "C01-20200101-20200201-001" start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", diff --git a/x/ecocredit/server/marketplace/query_sell_orders_test.go b/x/ecocredit/server/marketplace/query_sell_orders_test.go index 296cd15902..56b8f784c6 100644 --- a/x/ecocredit/server/marketplace/query_sell_orders_test.go +++ b/x/ecocredit/server/marketplace/query_sell_orders_test.go @@ -13,7 +13,7 @@ import ( api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" ecocreditApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) @@ -22,7 +22,7 @@ var ( batchDenom = "C01-20200101-20200201-001" start, end = timestamppb.Now(), timestamppb.Now() ask = sdk.NewInt64Coin("ufoo", 10) - creditType = ecocredit.CreditType{Name: "carbon", Abbreviation: "C", Unit: "tonnes", Precision: 6} + creditType = core.CreditType{Name: "carbon", Abbreviation: "C", Unit: "tonnes", Precision: 6} ) func TestSellOrders(t *testing.T) { diff --git a/x/ecocredit/server/marketplace/sell_test.go b/x/ecocredit/server/marketplace/sell_test.go index 2929df14af..39e41af459 100644 --- a/x/ecocredit/server/marketplace/sell_test.go +++ b/x/ecocredit/server/marketplace/sell_test.go @@ -13,7 +13,7 @@ import ( api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" ecoApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" "github.com/regen-network/regen-ledger/x/ecocredit/server/utils" ) @@ -24,7 +24,7 @@ func TestSell_Valid(t *testing.T) { batchDenom := "C01-20200101-20200201-001" start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -33,8 +33,8 @@ func TestSell_Valid(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) any := gomock.Any() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) balanceBefore, err := s.coreStore.BatchBalanceTable().Get(s.ctx, s.addr, 1) @@ -80,7 +80,7 @@ func TestSell_CreatesMarket(t *testing.T) { batchDenom := "C01-20200101-20200201-001" start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ubar", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -88,8 +88,8 @@ func TestSell_CreatesMarket(t *testing.T) { } testSellSetup(t, s, batchDenom, "ufoo", "foo", "C01", start, end, creditType) sellTime := time.Now() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(1) // market shouldn't exist before sell call @@ -119,7 +119,7 @@ func TestSell_Invalid(t *testing.T) { batchDenom := "C01-20200101-20200201-001" start, end := timestamppb.Now(), timestamppb.Now() ask := sdk.NewInt64Coin("ufoo", 10) - creditType := ecocredit.CreditType{ + creditType := core.CreditType{ Name: "carbon", Abbreviation: "C", Unit: "tonnes", @@ -128,8 +128,8 @@ func TestSell_Invalid(t *testing.T) { testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], "C01", start, end, creditType) sellTime := time.Now() - s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(any, any).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) // invalid batch @@ -183,7 +183,7 @@ func assertCreditsEscrowed(t *testing.T, balanceBefore, balanceAfter *ecoApi.Bat } // testSellSetup sets up a batch, class, market, and issues a balance of 100 retired and tradable to the base suite's addr. -func testSellSetup(t *testing.T, s *baseSuite, batchDenom, bankDenom, displayDenom, classId string, start, end *timestamppb.Timestamp, creditType ecocredit.CreditType) { +func testSellSetup(t *testing.T, s *baseSuite, batchDenom, bankDenom, displayDenom, classId string, start, end *timestamppb.Timestamp, creditType core.CreditType) { assert.NilError(t, s.coreStore.BatchInfoTable().Insert(s.ctx, &ecoApi.BatchInfo{ ProjectId: 1, BatchDenom: batchDenom, diff --git a/x/ecocredit/server/marketplace/update_sell_orders.go b/x/ecocredit/server/marketplace/update_sell_orders.go index 750e5e6e60..0d9f080fd6 100644 --- a/x/ecocredit/server/marketplace/update_sell_orders.go +++ b/x/ecocredit/server/marketplace/update_sell_orders.go @@ -3,7 +3,6 @@ package marketplace import ( "context" - "github.com/regen-network/regen-ledger/x/ecocredit/server/utils" "google.golang.org/protobuf/types/known/timestamppb" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,8 +10,9 @@ import ( api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" + "github.com/regen-network/regen-ledger/x/ecocredit/server/utils" ) // UpdateSellOrders updates the sellOrder with the provided values. @@ -44,7 +44,7 @@ func (k Keeper) UpdateSellOrders(ctx context.Context, req *marketplace.MsgUpdate // applySellOrderUpdates applies the updates to the order. func (k Keeper) applySellOrderUpdates(ctx context.Context, order *api.SellOrder, update *marketplace.MsgUpdateSellOrders_Update) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - var creditType *ecocredit.CreditType + var creditType *core.CreditType event := marketplace.EventUpdateSellOrder{} order.DisableAutoRetire = update.DisableAutoRetire @@ -136,7 +136,7 @@ func (k Keeper) applySellOrderUpdates(ctx context.Context, order *api.SellOrder, } // getCreditTypeFromBatchId gets the credit type given a batch id. -func (k Keeper) getCreditTypeFromBatchId(ctx context.Context, id uint64) (*ecocredit.CreditType, error) { +func (k Keeper) getCreditTypeFromBatchId(ctx context.Context, id uint64) (*core.CreditType, error) { batch, err := k.coreStore.BatchInfoTable().Get(ctx, id) if err != nil { return nil, err diff --git a/x/ecocredit/server/marketplace/update_sell_orders_test.go b/x/ecocredit/server/marketplace/update_sell_orders_test.go index 5d240101ff..2b1fa8cdc9 100644 --- a/x/ecocredit/server/marketplace/update_sell_orders_test.go +++ b/x/ecocredit/server/marketplace/update_sell_orders_test.go @@ -15,7 +15,7 @@ import ( ecoApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) @@ -26,8 +26,8 @@ func TestUpdateSellOrders_QuantityAndAutoRetire(t *testing.T) { s := setupBase(t) testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(4) expiration := time.Now() _, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -77,8 +77,8 @@ func TestUpdateSellOrders_QuantityInvalid(t *testing.T) { s := setupBase(t) testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(4) expiration := time.Now() _, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -123,8 +123,8 @@ func TestUpdateSellOrders_Unauthorized(t *testing.T) { s := setupBase(t) testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) _, _, unauthorized := testdata.KeyTestPubAddr() - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) expiration := time.Now() _, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -151,8 +151,8 @@ func TestUpdateSellOrder_AskPrice(t *testing.T) { s := setupBase(t) testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(2) expiration := time.Now() _, err := s.k.Sell(s.ctx, &marketplace.MsgSell{ @@ -203,8 +203,8 @@ func TestUpdateSellOrder_Expiration(t *testing.T) { s := setupBase(t) testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) - s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *ecocredit.Params) { - p.CreditTypes = []*ecocredit.CreditType{&creditType} + s.paramsKeeper.EXPECT().GetParamSet(gmAny, gmAny).Do(func(any interface{}, p *core.Params) { + p.CreditTypes = []*core.CreditType{&creditType} }).Times(1) future := time.Date(2077, 1, 1, 1, 1, 1, 1, time.Local) diff --git a/x/ecocredit/server/utils/utils.go b/x/ecocredit/server/utils/utils.go index 55d6b19a6c..65091d28ad 100644 --- a/x/ecocredit/server/utils/utils.go +++ b/x/ecocredit/server/utils/utils.go @@ -6,26 +6,27 @@ import ( "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/types/math" "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/core" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" ) // GetCreditTypeFromBatchDenom extracts the classId from a batch denom string, then retrieves it from the params. -func GetCreditTypeFromBatchDenom(ctx context.Context, store ecocreditv1.StateStore, k ecocredit.ParamKeeper, denom string) (ecocredit.CreditType, error) { +func GetCreditTypeFromBatchDenom(ctx context.Context, store ecocreditv1.StateStore, k ecocredit.ParamKeeper, denom string) (core.CreditType, error) { sdkCtx := types.UnwrapSDKContext(ctx) classId := ecocredit.GetClassIdFromBatchDenom(denom) classInfo, err := store.ClassInfoTable().GetByName(ctx, classId) if err != nil { - return ecocredit.CreditType{}, err + return core.CreditType{}, err } - p := &ecocredit.Params{} + p := &core.Params{} k.GetParamSet(sdkCtx, p) return GetCreditType(classInfo.CreditType, p.CreditTypes) } // GetCreditType searches for a credit type that matches the given abbreviation within a credit type slice. -func GetCreditType(ctAbbrev string, creditTypes []*ecocredit.CreditType) (ecocredit.CreditType, error) { +func GetCreditType(ctAbbrev string, creditTypes []*core.CreditType) (core.CreditType, error) { //creditTypeName = ecocredit.NormalizeCreditTypeName(creditTypeName) for _, creditType := range creditTypes { // credit type name's stored via params have enforcement on normalization, so we can be sure they will already @@ -34,7 +35,7 @@ func GetCreditType(ctAbbrev string, creditTypes []*ecocredit.CreditType) (ecocre return *creditType, nil } } - return ecocredit.CreditType{}, errors.ErrInvalidType.Wrapf("%s is not a valid credit type", ctAbbrev) + return core.CreditType{}, errors.ErrInvalidType.Wrapf("%s is not a valid credit type", ctAbbrev) } // GetNonNegativeFixedDecs takes an arbitrary amount of decimal strings, and returns their corresponding fixed decimals