Skip to content

Commit

Permalink
add test for project not accepted to credit class
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed May 28, 2024
1 parent c262750 commit 4336def
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
19 changes: 13 additions & 6 deletions x/ecocredit/base/keeper/features/msg_create_batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ Feature: Msg/CreateBatch
- the batch contract mapping is added
- the response includes the batch denom

Rule: The project must exist
Rule: The project must exist and have an accepted enrollment to the credit class

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 "P001" enrolled in "C01"

Scenario: the project exists
Scenario: the project exists and has an accepted enrollment
Given a project with project id "P001"
And project "P001" has an "ACCEPTED" enrollment to class "C01"
When alice attempts to create a batch with project id "P001" and class id "C01"
Then expect no error

Scenario: the project does not exist
When alice attempts to create a batch with project id "P002" and class id "C02"
Then expect error contains "could not get project with id P002: not found: invalid request"
When alice attempts to create a batch with project id "P001" and class id "C01"
Then expect error contains "could not get project with id P001: not found: invalid request"

Scenario: the project exists but has an unaccepted enrollment
Given a project with project id "P001"
And project "P001" has an "UNSPECIFIED" enrollment to class "C01"
When alice attempts to create a batch with project id "P001" and class id "C01"
Then expect error contains "project enrollment status is not accepted: invalid request"

Rule: The issuer must be an allowed credit class issuer

Expand Down Expand Up @@ -528,4 +535,4 @@ Feature: Msg/CreateBatch
"note": "credits from VCS-001"
}
}
"""
"""
30 changes: 30 additions & 0 deletions x/ecocredit/base/keeper/msg_create_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package keeper

import (
"encoding/json"
"fmt"
"strconv"
"testing"
"time"

"github.com/gogo/protobuf/jsonpb"
"github.com/regen-network/gocuke"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/reflect/protoreflect"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -138,6 +140,34 @@ func (s *createBatchSuite) AProjectWithProjectIdEnrolledIn(a, b string) {
require.NoError(s.t, err)
}

func (s *createBatchSuite) AProjectWithProjectId(id string) {
pKey, err := s.k.stateStore.ProjectTable().InsertReturningID(s.ctx, &api.Project{
Id: id,
})
require.NoError(s.t, err)

s.projectKey = pKey
}

func (s *createBatchSuite) ProjectHasAnEnrollmentToClass(projId, statusStr, clsId string) {
cls, err := s.k.stateStore.ClassTable().GetById(s.ctx, clsId)
require.NoError(s.t, err)

proj, err := s.k.stateStore.ProjectTable().GetById(s.ctx, projId)
require.NoError(s.t, err)

var status api.ProjectEnrollmentStatus
statusDesc := status.Descriptor().Values().ByName(protoreflect.Name(fmt.Sprintf("PROJECT_ENROLLMENT_STATUS_%s", statusStr)))
status = api.ProjectEnrollmentStatus(statusDesc.Number())

err = s.k.stateStore.ProjectEnrollmentTable().Insert(s.ctx, &api.ProjectEnrollment{
ProjectKey: proj.Key,
ClassKey: cls.Key,
Status: status,
})
require.NoError(s.t, err)
}

func (s *createBatchSuite) ABatchSequenceWithProjectIdAndNextSequence(a string, b string) {
project, err := s.stateStore.ProjectTable().GetById(s.ctx, a)
require.NoError(s.t, err)
Expand Down

0 comments on commit 4336def

Please sign in to comment.