-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x/ecocredit): query
Params
ORM (#846)
* 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
1 parent
8ab92e7
commit 37c2b90
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ¶ms) | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} |