Skip to content

Commit

Permalink
add test for withdrawing an accepted enrollment and fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed May 28, 2024
1 parent 4336def commit 7c6fdb2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Scenario: project is accepted and admin attempts to withdraw the application
Given an application for "P001" to "C01" with metadata "abc123"
And the application for "P001" to "C01" is accepted
When "Alice" attempts to withdraw the application for "P001" to "C01" with metadata "foobar379"
Then expect error contains "cannot withdraw accepted enrollment"
And expect the application for "P001" to "C01" exists with metadata "abc123"

4 changes: 4 additions & 0 deletions x/ecocredit/base/keeper/msg_create_or_update_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (k Keeper) CreateOrUpdateApplication(ctx context.Context, msg *types.MsgCre

if msg.Withdraw {
action = types.EventUpdateApplication_ACTION_WITHDRAW
if enrollment.Status == ecocreditv1.ProjectEnrollmentStatus_PROJECT_ENROLLMENT_STATUS_ACCEPTED {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("cannot withdraw accepted enrollment")
}

if err := k.stateStore.ProjectEnrollmentTable().Delete(ctx, enrollment); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func (s *createOrUpdateApplicationSuite) AnApplicationForToWithMetadata(projId,
}))
}

func (s *createOrUpdateApplicationSuite) TheApplicationForToIsAccepted(projId, clsId string) {
enrollment, err := s.getEnrollment(projId, clsId)
require.NoError(s.t, err)
enrollment.Status = api.ProjectEnrollmentStatus_PROJECT_ENROLLMENT_STATUS_ACCEPTED
require.NoError(s.t, s.stateStore.ProjectEnrollmentTable().Save(s.ctx, enrollment))
}

func (s *createOrUpdateApplicationSuite) AnApplicationForToDoesNotExist(projId, clsId string) {
enrollment, err := s.getEnrollment(projId, clsId)
if !ormerrors.IsNotFound(err) {
Expand Down

0 comments on commit 7c6fdb2

Please sign in to comment.