Skip to content

Commit

Permalink
chore(ecocredit): remove alpha params (#968)
Browse files Browse the repository at this point in the history
* chore: remove alpha params

* chore: imports

Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
  • Loading branch information
technicallyty and technicallyty authored Apr 1, 2022
1 parent e402949 commit ef344a9
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 151 deletions.
13 changes: 6 additions & 7 deletions x/ecocredit/server/core/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
9 changes: 4 additions & 5 deletions x/ecocredit/server/core/create_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/server/core/create_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
if params.AllowlistEnabled && !k.isCreatorAllowListed(sdkCtx, params.AllowedClassCreators, adminAddress) {
return nil, sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to create credit classes", adminAddress.String())
Expand Down
15 changes: 7 additions & 8 deletions x/ecocredit/server/core/create_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions x/ecocredit/server/core/query_credit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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, &params)

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
}
5 changes: 2 additions & 3 deletions x/ecocredit/server/core/query_credit_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
20 changes: 2 additions & 18 deletions x/ecocredit/server/core/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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, &params)
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: &params}, nil
}
5 changes: 2 additions & 3 deletions x/ecocredit/server/core/query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions x/ecocredit/server/core/retire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions x/ecocredit/server/core/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions x/ecocredit/server/keeper.go

This file was deleted.

Loading

0 comments on commit ef344a9

Please sign in to comment.