From 2855c5da60c7e2716e700cbe8924451e539d3723 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 4 Mar 2022 10:08:40 -0800 Subject: [PATCH 1/2] feat: query project info --- x/ecocredit/server/core/query_project_info.go | 19 +++++++++++ .../server/core/query_project_info_test.go | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 x/ecocredit/server/core/query_project_info.go create mode 100644 x/ecocredit/server/core/query_project_info_test.go diff --git a/x/ecocredit/server/core/query_project_info.go b/x/ecocredit/server/core/query_project_info.go new file mode 100644 index 0000000000..c2e55b3527 --- /dev/null +++ b/x/ecocredit/server/core/query_project_info.go @@ -0,0 +1,19 @@ +package core + +import ( + "context" + "github.com/regen-network/regen-ledger/x/ecocredit/v1beta1" +) + +// ProjectInfo queries project info from the given project name. +func (k Keeper) ProjectInfo(ctx context.Context, request *v1beta1.QueryProjectInfoRequest) (*v1beta1.QueryProjectInfoResponse, error) { + pInfo, err := k.stateStore.ProjectInfoStore().GetByName(ctx, request.ProjectId) + if err != nil { + return nil, err + } + var pi v1beta1.ProjectInfo + if err = PulsarToGogoSlow(pInfo, &pi); err != nil { + return nil, err + } + return &v1beta1.QueryProjectInfoResponse{Info: &pi}, nil +} diff --git a/x/ecocredit/server/core/query_project_info_test.go b/x/ecocredit/server/core/query_project_info_test.go new file mode 100644 index 0000000000..7a2570d067 --- /dev/null +++ b/x/ecocredit/server/core/query_project_info_test.go @@ -0,0 +1,32 @@ +package core + +import ( + "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" + ecocreditv1beta1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1beta1" + "github.com/regen-network/regen-ledger/x/ecocredit/v1beta1" + "gotest.tools/v3/assert" + "testing" +) + +func TestQuery_ProjectInfo(t *testing.T) { + t.Parallel() + s := setupBase(t) + + // insert 1 project + err := s.stateStore.ProjectInfoStore().Insert(s.ctx, &ecocreditv1beta1.ProjectInfo{ + Name: "P01", + ClassId: 1, + ProjectLocation: "US-CA", + Metadata: nil, + }) + assert.NilError(t, err) + + // valid query + res, err := s.k.ProjectInfo(s.ctx, &v1beta1.QueryProjectInfoRequest{ProjectId: "P01"}) + assert.NilError(t, err) + assert.Equal(t, "P01", res.Info.Name) + + // invalid query + _, err = s.k.ProjectInfo(s.ctx, &v1beta1.QueryProjectInfoRequest{ProjectId: "F01"}) + assert.ErrorContains(t, err, ormerrors.NotFound.Error()) +} From 92bb1bda2e64daaa5bdbfd7fcbae16f5efcb7a45 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 8 Mar 2022 11:39:46 -0800 Subject: [PATCH 2/2] chore: v1beta1 -> v1 --- x/ecocredit/server/core/query_project_info.go | 8 ++++---- x/ecocredit/server/core/query_project_info_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/ecocredit/server/core/query_project_info.go b/x/ecocredit/server/core/query_project_info.go index c2e55b3527..66abb1c130 100644 --- a/x/ecocredit/server/core/query_project_info.go +++ b/x/ecocredit/server/core/query_project_info.go @@ -2,18 +2,18 @@ package core import ( "context" - "github.com/regen-network/regen-ledger/x/ecocredit/v1beta1" + v1 "github.com/regen-network/regen-ledger/x/ecocredit/v1" ) // ProjectInfo queries project info from the given project name. -func (k Keeper) ProjectInfo(ctx context.Context, request *v1beta1.QueryProjectInfoRequest) (*v1beta1.QueryProjectInfoResponse, error) { +func (k Keeper) ProjectInfo(ctx context.Context, request *v1.QueryProjectInfoRequest) (*v1.QueryProjectInfoResponse, error) { pInfo, err := k.stateStore.ProjectInfoStore().GetByName(ctx, request.ProjectId) if err != nil { return nil, err } - var pi v1beta1.ProjectInfo + var pi v1.ProjectInfo if err = PulsarToGogoSlow(pInfo, &pi); err != nil { return nil, err } - return &v1beta1.QueryProjectInfoResponse{Info: &pi}, nil + return &v1.QueryProjectInfoResponse{Info: &pi}, nil } diff --git a/x/ecocredit/server/core/query_project_info_test.go b/x/ecocredit/server/core/query_project_info_test.go index 7a2570d067..998bad72b0 100644 --- a/x/ecocredit/server/core/query_project_info_test.go +++ b/x/ecocredit/server/core/query_project_info_test.go @@ -2,8 +2,8 @@ package core import ( "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" - ecocreditv1beta1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1beta1" - "github.com/regen-network/regen-ledger/x/ecocredit/v1beta1" + ecocreditv1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + v1 "github.com/regen-network/regen-ledger/x/ecocredit/v1" "gotest.tools/v3/assert" "testing" ) @@ -13,7 +13,7 @@ func TestQuery_ProjectInfo(t *testing.T) { s := setupBase(t) // insert 1 project - err := s.stateStore.ProjectInfoStore().Insert(s.ctx, &ecocreditv1beta1.ProjectInfo{ + err := s.stateStore.ProjectInfoStore().Insert(s.ctx, &ecocreditv1.ProjectInfo{ Name: "P01", ClassId: 1, ProjectLocation: "US-CA", @@ -22,11 +22,11 @@ func TestQuery_ProjectInfo(t *testing.T) { assert.NilError(t, err) // valid query - res, err := s.k.ProjectInfo(s.ctx, &v1beta1.QueryProjectInfoRequest{ProjectId: "P01"}) + res, err := s.k.ProjectInfo(s.ctx, &v1.QueryProjectInfoRequest{ProjectId: "P01"}) assert.NilError(t, err) assert.Equal(t, "P01", res.Info.Name) // invalid query - _, err = s.k.ProjectInfo(s.ctx, &v1beta1.QueryProjectInfoRequest{ProjectId: "F01"}) + _, err = s.k.ProjectInfo(s.ctx, &v1.QueryProjectInfoRequest{ProjectId: "F01"}) assert.ErrorContains(t, err, ormerrors.NotFound.Error()) }