-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(x/ecocredit)!: implement independent projects #2167
base: main
Are you sure you want to change the base?
Conversation
…onc/independent-projects
Co-authored-by: Cory <cjlevinson@gmail.com>
Co-authored-by: Cory <cjlevinson@gmail.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2167 +/- ##
===========================================
+ Coverage 62.24% 72.61% +10.36%
===========================================
Files 277 251 -26
Lines 16434 14374 -2060
===========================================
+ Hits 10230 10437 +207
+ Misses 5449 3134 -2315
- Partials 755 803 +48
|
I am finally marking this as ready for review. The remaining lint errors are in my mind overly pedantic and I'm considering updating the lint config to disable them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @aaronc this is a lot but looking pretty good to me. I think I have reviewed most of these changes but might take a second look with fresh eyes later.
I was going to try and run this locally to test a few things out but just saw the separate PR #2202 that adds CLI commands. Would this be worth testing at this point?
@@ -18,40 +18,40 @@ Feature: Msg/CreateBatch | |||
Background: | |||
Given a credit type with abbreviation "C" | |||
And a credit class with class id "C01" and issuer alice | |||
And a project with project id "C01-001" | |||
And a project with project id "P001" enrolled in "C01" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no scenario to cover issuing a credit batch for a project that does not have an ACCEPTED
enrollment status. Maybe this Rule could be expanded: "The project must exist and have an accepted enrollment to a credit class"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test to cover this: 4336def
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
if msg.Withdraw { | ||
action = types.EventUpdateApplication_ACTION_WITHDRAW | ||
if err := k.stateStore.ProjectEnrollmentTable().Delete(ctx, enrollment); err != nil { | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should a project admin be able to withdraw their application if it already has project enrollment status ACCEPTED
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I discussed this with @S4mmyb and because of programmatic requirements sometimes in legal contracts, only an issuer should be able to terminate an approved project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. This logic might require a change then because there doesn't seem to be a check for the enrollment status here. Could use a test scenario as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks good, left a suggestion re: the test rule text
if req.ReferenceId != "" { | ||
project.ReferenceId = req.ReferenceId | ||
// only set deprecated class key if reference id is not empty to support the use case of reference IDs | ||
project.ClassKey = classInfo.Key //nolint:staticcheck | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the reference ID can only be set by credit class issuers when directly creating + enrolling a project into a credit class via MsgCreateProject
and there is no way to update this value. If a project is created by an admin and applies to a credit class it doesn't seem that the reference ID could be set. Is this intentional? Would it make sense to move the reference ID to the ProjectEnrollmentTable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference ID is only relevant in the case of bridging and I can consider it a legacy use case. It needs to be in the project table to impose an unique constraint on it, again only needed for bridging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference ID is only relevant in the case of bridging and I can consider it a legacy use case.
Oh interesting, I did not realize this was only intended for bridging. In fact we are using the reference ID field in another way on some projects we are working on (SeaTrees, ZFP). It is useful as a key to reference on-chain projects with existing "external IDs" programs may already be using. This makes it much easier to create scripts that update projects in bulk when metadata might be changing in an external CMS of some kind.
It would be good to know if this will be supported going forward. These projects/processes are being deployed on Redwood now and could be deployed on mainnet in the coming months.
// reference_id is any arbitrary string that can be use to reference project.
https://buf.build/regen/regen-ledger/docs/main:regen.ecocredit.v1#regen.ecocredit.v1.ProjectInfo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're planning to remove the support, but I'd prefer not to add or update the functionality much unless there's a specific use case. Basically, it can only be added at creation, not modified and there will be an unique constraint on reference ID and originally enrolled credit class.
If you're going to test manually, the CLI commands would be useful. How should we handle this? Would you test in that branch? Or should I just merge the CLI into here? |
I can do either way. Comparing the two branches, looks like there aren't many changes. Maybe merging here is easiest. aaronc/independent-projects-impl...aaronc/independent-projects-cli |
Co-authored-by: Paul Weidner <paul.weidner@gmail.com>
Co-authored-by: Paul Weidner <paul.weidner@gmail.com>
I went ahead and merged the CLI code into this PR. |
Co-authored-by: Paul Weidner <paul.weidner@gmail.com>
@paul121 I believe I've addressed all your comments. Can you re-review when you get a chance please? |
@@ -61,4 +61,11 @@ Feature: Msg/CreateOrUpdateApplication | |||
Then expect error contains "unauthorized" | |||
And expect the application for "P001" to "C01" exists with metadata "abc123" | |||
|
|||
Rule: events get emitted | |||
Rule: project admins cannot withdraw a project with an accepted enrollment (a credit class issuer must do that) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule: project admins cannot withdraw a project with an accepted enrollment (a credit class issuer must do that) | |
Rule: project admins cannot withdraw a project with an accepted enrollment |
Just got hung up on this getting my head back into things.. this implies a credit class issuer can withdraw a project. But only project admins can attempt a withdraw via MsgCreateorUpdateApplication
. To remove the project enrollment from state credit class issuers must change enrollment status from ACCEPTED
-> TERMINATED
. Maybe just drop (a credit class issuer must do that)
for clarity?
case ecocreditv1.ProjectEnrollmentStatus_PROJECT_ENROLLMENT_STATUS_ACCEPTED: | ||
switch newStatus { | ||
case ecocreditv1.ProjectEnrollmentStatus_PROJECT_ENROLLMENT_STATUS_ACCEPTED: | ||
// Valid case for just updating metadata of an accepted project | ||
case ecocreditv1.ProjectEnrollmentStatus_PROJECT_ENROLLMENT_STATUS_TERMINATED: | ||
remove = true | ||
default: | ||
return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid status transition from %s to %s", existingStatus, newStatus) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these state transitions from enrollment status ACCEPTED
could have better tests. Right now I only see one test case for the valid ACCEPTED
-> TERMINATED
transition, and one for the invalid ACCEPTED
-> REJECTED
transition.
| I01 accepted to rejected | ACCEPTED | foo123 | I01 | REJECTED | baz789 | invalid | true | | ||
| Bob accepted to rejected | ACCEPTED | foo123 | Bob | REJECTED | baz789 | unauthorized | true | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to my other comment, I think this is the only test for an invalid state transition from enrollment status ACCEPTED
.
Description
Closes #1313
Review instructions:
CHANGELOG
and modified.proto
files first.feature
files firstAuthor Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change