-
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.
Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
- Loading branch information
1 parent
ba44c7e
commit 6b8229f
Showing
2 changed files
with
51 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,19 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
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 *v1.QueryProjectInfoRequest) (*v1.QueryProjectInfoResponse, error) { | ||
pInfo, err := k.stateStore.ProjectInfoStore().GetByName(ctx, request.ProjectId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var pi v1.ProjectInfo | ||
if err = PulsarToGogoSlow(pInfo, &pi); err != nil { | ||
return nil, err | ||
} | ||
return &v1.QueryProjectInfoResponse{Info: &pi}, 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,32 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/orm/types/ormerrors" | ||
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" | ||
) | ||
|
||
func TestQuery_ProjectInfo(t *testing.T) { | ||
t.Parallel() | ||
s := setupBase(t) | ||
|
||
// insert 1 project | ||
err := s.stateStore.ProjectInfoStore().Insert(s.ctx, &ecocreditv1.ProjectInfo{ | ||
Name: "P01", | ||
ClassId: 1, | ||
ProjectLocation: "US-CA", | ||
Metadata: nil, | ||
}) | ||
assert.NilError(t, err) | ||
|
||
// valid query | ||
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, &v1.QueryProjectInfoRequest{ProjectId: "F01"}) | ||
assert.ErrorContains(t, err, ormerrors.NotFound.Error()) | ||
} |