Skip to content
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

Open
wants to merge 97 commits into
base: main
Choose a base branch
from

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Feb 13, 2024

Description

Closes #1313

Review instructions:

  • please check the CHANGELOG and modified .proto files first
  • to review new code, I suggest looking at the new .feature files first
  • changes to existing code have mostly involved removing the assumption that the class is implied by the project and that an enrollment is needed
  • you will need to look at some large diffs that github has hidden by default because they're so big, sorry

Author 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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@aaronc aaronc changed the title feat(x/ecocredit):c independent projects feat(x/ecocredit): implement independent projects Feb 13, 2024
Copy link

codecov bot commented Mar 31, 2024

Codecov Report

Attention: Patch coverage is 62.42545% with 189 lines in your changes are missing coverage. Please review.

Project coverage is 72.61%. Comparing base (3d818cf) to head (5d5249e).

Current head 5d5249e differs from pull request most recent head 7c6fdb2

Please upload reports for the commit 7c6fdb2 to get more accurate results.

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     
Files Coverage Δ
x/ecocredit/base/keeper/keeper.go 100.00% <ø> (ø)
x/ecocredit/base/keeper/msg_bridge_receive.go 80.00% <100.00%> (+2.30%) ⬆️
x/ecocredit/base/keeper/msg_burn_regen.go 51.61% <ø> (ø)
x/ecocredit/base/keeper/msg_cancel.go 60.86% <100.00%> (ø)
x/ecocredit/base/keeper/msg_create_class.go 64.55% <100.00%> (-2.11%) ⬇️
x/ecocredit/base/keeper/msg_mint_batch_credits.go 57.02% <100.00%> (+1.02%) ⬆️
x/ecocredit/base/keeper/msg_retire.go 59.75% <100.00%> (ø)
x/ecocredit/base/keeper/msg_send.go 69.23% <100.00%> (ø)
x/ecocredit/base/keeper/query_project_info.go 100.00% <ø> (+14.28%) ⬆️
x/ecocredit/base/keeper/query_projects.go 66.66% <ø> (+3.25%) ⬆️
... and 26 more

... and 35 files with indirect coverage changes

@aaronc aaronc marked this pull request as ready for review March 31, 2024 23:47
@aaronc
Copy link
Member Author

aaronc commented Mar 31, 2024

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.

Copy link
Contributor

@paul121 paul121 left a 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?

x/ecocredit/server/utils/utils.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -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"
Copy link
Contributor

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"

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

proto/regen/ecocredit/v1/query.proto Outdated Show resolved Hide resolved
Comment on lines 52 to 56
if msg.Withdraw {
action = types.EventUpdateApplication_ACTION_WITHDRAW
if err := k.stateStore.ProjectEnrollmentTable().Delete(ctx, enrollment); err != nil {
return nil, err
}
Copy link
Contributor

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 ?

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test scenario here: 7c6fdb2 and turns out this logic wasn't properly implemented. So good catch @paul121 👍

Copy link
Contributor

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

Comment on lines +51 to +55
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
}
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

@aaronc aaronc May 2, 2024

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.

@aaronc
Copy link
Member Author

aaronc commented Apr 11, 2024

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?

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?

@paul121
Copy link
Contributor

paul121 commented Apr 11, 2024

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?

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

aaronc and others added 4 commits May 2, 2024 13:37
@aaronc
Copy link
Member Author

aaronc commented May 2, 2024

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?

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

I went ahead and merged the CLI code into this PR.

@aaronc
Copy link
Member Author

aaronc commented May 28, 2024

@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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Comment on lines +54 to +62
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)
}
Copy link
Contributor

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.

Comment on lines +60 to +61
| I01 accepted to rejected | ACCEPTED | foo123 | I01 | REJECTED | baz789 | invalid | true |
| Bob accepted to rejected | ACCEPTED | foo123 | Bob | REJECTED | baz789 | unauthorized | true |
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Independent Projects
2 participants