Skip to content

Commit

Permalink
feat(x/ecocredit): query Params ORM (#846)
Browse files Browse the repository at this point in the history
* feat: query params

* Update x/ecocredit/server/core/query_params_test.go

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>

Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 8, 2022
1 parent 8ab92e7 commit 37c2b90
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
34 changes: 34 additions & 0 deletions x/ecocredit/server/core/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package core

import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/regen-network/regen-ledger/x/ecocredit/v1beta1"
)

// Params queries the ecocredit module parameters.
// TODO: remove params https://github.com/regen-network/regen-ledger/issues/729
// Currently this is an ugly hack that grabs v1alpha types and converts them into v1beta types.
// will be gone with #729.
func (k Keeper) Params(ctx context.Context, _ *v1beta1.QueryParamsRequest) (*v1beta1.QueryParamsResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
var params ecocredit.Params
k.params.GetParamSet(sdkCtx, &params)
v1beta1types := make([]*v1beta1.CreditType, len(params.CreditTypes))
for i, typ := range params.CreditTypes {
v1beta1types[i] = &v1beta1.CreditType{
Abbreviation: typ.Abbreviation,
Name: typ.Name,
Unit: typ.Unit,
Precision: typ.Precision,
}
}
v1beta1Params := v1beta1.Params{
CreditClassFee: params.CreditClassFee,
AllowedClassCreators: params.AllowedClassCreators,
AllowlistEnabled: params.AllowlistEnabled,
CreditTypes: v1beta1types,
}
return &v1beta1.QueryParamsResponse{Params: &v1beta1Params}, nil
}
41 changes: 41 additions & 0 deletions x/ecocredit/server/core/query_params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package core

import (
"github.com/cosmos/cosmos-sdk/types"
"github.com/golang/mock/gomock"
ecocreditv1beta1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1beta1"
"github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/regen-network/regen-ledger/x/ecocredit/v1beta1"
"gotest.tools/v3/assert"
"testing"
)

func TestQuery_Params(t *testing.T) {
t.Parallel()
s := setupBase(t)
any := gomock.Any()

assert.NilError(t, s.stateStore.CreditTypeStore().Insert(s.ctx, &ecocreditv1beta1.CreditType{
Abbreviation: "C",
Name: "carbon",
Unit: "a ton",
Precision: 6,
}))

s.paramsKeeper.EXPECT().GetParamSet(any, any).SetArg(1, ecocredit.Params{
CreditClassFee: types.NewCoins(types.NewInt64Coin("foo", 30)),
AllowedClassCreators: []string{s.addr.String()},
AllowlistEnabled: false,
CreditTypes: []*ecocredit.CreditType{{
Abbreviation: "C",
Name: "carbon",
Unit: "a ton",
Precision: 6,
}},
})

res, err := s.k.Params(s.ctx, &v1beta1.QueryParamsRequest{})
assert.NilError(t, err)
assert.Equal(t,false, res.Params.AllowlistEnabled)
assert.Equal(t, s.addr.String(), res.Params.AllowedClassCreators[0])
}

0 comments on commit 37c2b90

Please sign in to comment.