diff --git a/x/ecocredit/base/keeper/features/msg_create_or_update_application.feature b/x/ecocredit/base/keeper/features/msg_create_or_update_application.feature index bc2877059d..3f5cdf2d07 100644 --- a/x/ecocredit/base/keeper/features/msg_create_or_update_application.feature +++ b/x/ecocredit/base/keeper/features/msg_create_or_update_application.feature @@ -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" + diff --git a/x/ecocredit/base/keeper/msg_create_or_update_application.go b/x/ecocredit/base/keeper/msg_create_or_update_application.go index 3e0905ba11..ef8c852321 100644 --- a/x/ecocredit/base/keeper/msg_create_or_update_application.go +++ b/x/ecocredit/base/keeper/msg_create_or_update_application.go @@ -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 } diff --git a/x/ecocredit/base/keeper/msg_create_or_update_application_test.go b/x/ecocredit/base/keeper/msg_create_or_update_application_test.go index 91b43749e5..de40e407b0 100644 --- a/x/ecocredit/base/keeper/msg_create_or_update_application_test.go +++ b/x/ecocredit/base/keeper/msg_create_or_update_application_test.go @@ -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) {