Skip to content

Commit

Permalink
fix(ecocredit): use open field when creating batch (#1278) (#1283)
Browse files Browse the repository at this point in the history
* fix(ecocredit): use open field when creating batch

* chore: changelog entry

Co-authored-by: tyler <{ID}+{username}@users.noreply.github.com>
(cherry picked from commit a57af9c)

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
  • Loading branch information
mergify[bot] and technicallyty authored Jul 20, 2022
1 parent 0922d65 commit 7cd4b47
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#1274](https://github.com/regen-network/regen-ledger/pull/1274) Add `cancel-sell-order` command

#### Fixed
- [#1278](https://github.com/regen-network/regen-ledger/pull/1278) Fix `open` not set in `Msg/CreateBatch`

## [v4.0.0-rc1](https://github.com/regen-network/regen-ledger/releases/tag/v4.0.0-rc1) - 2022-07-15

### General
Expand Down
6 changes: 4 additions & 2 deletions x/ecocredit/server/core/features/msg_create_batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ Feature: Msg/CreateBatch
"project_id": "C01-001",
"metadata": "regen:13toVfvC2YxrrfSXWB5h2BGHiXZURsKxWUz72uDRDSPMCrYPguGUXSC.rdf",
"start_date": "2020-01-01T00:00:00Z",
"end_date": "2021-01-01T00:00:00Z"
"end_date": "2021-01-01T00:00:00Z",
"open": true
}
"""
Then expect batch properties
Expand All @@ -356,7 +357,8 @@ Feature: Msg/CreateBatch
"denom": "C01-001-20200101-20210101-001",
"metadata": "regen:13toVfvC2YxrrfSXWB5h2BGHiXZURsKxWUz72uDRDSPMCrYPguGUXSC.rdf",
"start_date": "2020-01-01T00:00:00Z",
"end_date": "2021-01-01T00:00:00Z"
"end_date": "2021-01-01T00:00:00Z",
"open": true
}
"""

Expand Down
3 changes: 2 additions & 1 deletion x/ecocredit/server/core/msg_create_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ func (k Keeper) CreateBatch(ctx context.Context, req *core.MsgCreateBatch) (*cor
startDate, endDate := timestamppb.New(*req.StartDate), timestamppb.New(*req.EndDate)
issuanceDate := timestamppb.New(sdkCtx.BlockTime())
batchKey, err := k.stateStore.BatchTable().InsertReturningID(ctx, &api.Batch{
ProjectKey: project.Key,
Issuer: issuer,
ProjectKey: project.Key,
Denom: batchDenom,
Metadata: req.Metadata,
StartDate: startDate,
EndDate: endDate,
IssuanceDate: issuanceDate,
Open: req.Open,
})
if err != nil {
return nil, err
Expand Down
24 changes: 13 additions & 11 deletions x/ecocredit/server/core/msg_create_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1"
"github.com/regen-network/regen-ledger/types"
"github.com/regen-network/regen-ledger/types/ormutil"
"github.com/regen-network/regen-ledger/x/ecocredit/core"
)

Expand Down Expand Up @@ -293,14 +294,8 @@ func (s *createBatchSuite) AliceAttemptsToCreateABatchWithProperties(a gocuke.Do
err := jsonpb.UnmarshalString(a.Content, &msg)
require.NoError(s.t, err)

s.res, s.err = s.k.CreateBatch(s.ctx, &core.MsgCreateBatch{
Issuer: s.alice.String(),
ProjectId: msg.ProjectId,
Issuance: msg.Issuance,
Metadata: msg.Metadata,
StartDate: msg.StartDate,
EndDate: msg.EndDate,
})
msg.Issuer = s.alice.String()
s.res, s.err = s.k.CreateBatch(s.ctx, &msg)
}

func (s *createBatchSuite) ExpectNoError() {
Expand Down Expand Up @@ -371,9 +366,16 @@ func (s *createBatchSuite) ExpectBatchProperties(a gocuke.DocString) {
batch, err := s.stateStore.BatchTable().GetByDenom(s.ctx, expected.Denom)
require.NoError(s.t, err)

require.Equal(s.t, expected.Metadata, batch.Metadata)
require.Equal(s.t, expected.StartDate.Seconds, batch.StartDate.Seconds)
require.Equal(s.t, expected.EndDate.Seconds, batch.EndDate.Seconds)
coreBatch := new(core.Batch)
require.NoError(s.t, ormutil.PulsarToGogoSlow(batch, coreBatch))

// set the properties that get set during state machine execution.
expected.Key = coreBatch.Key
expected.ProjectKey = coreBatch.ProjectKey
expected.Issuer = coreBatch.Issuer
expected.IssuanceDate = coreBatch.IssuanceDate

require.Equal(s.t, expected, *coreBatch)
}

func (s *createBatchSuite) ExpectBatchContract(a gocuke.DocString) {
Expand Down

0 comments on commit 7cd4b47

Please sign in to comment.