Skip to content

Commit

Permalink
feat(x/ecocredit): add fields to EventBridgeReceive (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo authored Feb 22, 2023
1 parent 3a973cf commit 8ddf8a1
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 76 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]()

### x/ecocredit

#### Added

- [#1785](https://github.com/regen-network/regen-ledger/pull/1785) Add `amount` and `origin_tx` to `EventBridgeReceive`

## [v5.0.0](https://github.com/regen-network/regen-ledger/releases/tag/v5.0.0) - 2023-01-05

### General
Expand Down
220 changes: 194 additions & 26 deletions api/regen/ecocredit/v1/events.pulsar.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions proto/regen/ecocredit/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,11 @@ message EventBridgeReceive {
// batch_denom is the unique identifier of the credit batch either created
// or within which the credits were dynamically minted.
string batch_denom = 2;

// amount is the amount of credits.
string amount = 3;

// origin_tx is the transaction from another chain or registry that triggered
// the minting of credits within the credit batch.
OriginTx origin_tx = 4;
}
33 changes: 32 additions & 1 deletion x/ecocredit/base/keeper/features/msg_bridge_receive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,35 @@ Feature: Msg/BridgeReceive

Scenario: the OriginTx source is not in the AllowedBridgeChain table
When alice attempts to bridge credits with OriginTx Source "solana"
Then expect the error "solana is not an authorized bridge source: unauthorized"
Then expect the error "solana is not an authorized bridge source: unauthorized"

Rule: Event is emitted

Scenario: EventBridgeReceive is emitted
Given a credit type with abbreviation "C"
And a credit class with id "C01" and issuer alice
And allowed bridge chain "polygon"
And a project with id "C01-001"
And a credit batch with denom "C01-001-20200101-20210101-001" and issuer alice
And the batch contract
"""
{
"batch_key": 1,
"class_key": 1,
"contract": "0x0E65079a29d7793ab5CA500c2d88e60EE99Ba606"
}
"""
When alice attempts to bridge credits with contract "0x0E65079a29d7793ab5CA500c2d88e60EE99Ba606"
Then expect event with properties
"""
{
"project_id": "C01-001",
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "10",
"origin_tx": {
"id": "0x7a70692a348e8688f54ab2bdfe87d925d8cc88932520492a11eaa02dc128243e",
"source": "polygon",
"contract": "0x0E65079a29d7793ab5CA500c2d88e60EE99Ba606"
}
}
"""
8 changes: 6 additions & 2 deletions x/ecocredit/base/keeper/msg_bridge_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ func (k Keeper) BridgeReceive(ctx context.Context, req *types.MsgBridgeReceive)

// set bridge receive event
event = &types.EventBridgeReceive{
BatchDenom: batch.Denom,
ProjectId: project.Id,
BatchDenom: batch.Denom,
Amount: req.Batch.Amount,
OriginTx: req.OriginTx,
}

// set bridge receive response
Expand Down Expand Up @@ -138,8 +140,10 @@ func (k Keeper) BridgeReceive(ctx context.Context, req *types.MsgBridgeReceive)

// set bridge receive event
event = &types.EventBridgeReceive{
BatchDenom: batchRes.BatchDenom,
ProjectId: project.Id,
BatchDenom: batchRes.BatchDenom,
Amount: req.Batch.Amount,
OriginTx: req.OriginTx,
}

// set bridge receive response
Expand Down
14 changes: 14 additions & 0 deletions x/ecocredit/base/keeper/msg_bridge_receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package keeper

import (
"encoding/json"
"strconv"
"strings"
"testing"
Expand All @@ -15,6 +16,7 @@ import (

api "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1"
regentypes "github.com/regen-network/regen-ledger/types/v2"
"github.com/regen-network/regen-ledger/types/v2/testutil"
"github.com/regen-network/regen-ledger/x/ecocredit/v3/base"
types "github.com/regen-network/regen-ledger/x/ecocredit/v3/base/types/v1"
)
Expand Down Expand Up @@ -488,6 +490,18 @@ func (s *bridgeReceiveSuite) ExpectBatchSupply(a gocuke.DocString) {
require.Equal(s.t, expected.CancelledAmount, balance.CancelledAmount)
}

func (s *bridgeReceiveSuite) ExpectEventWithProperties(a gocuke.DocString) {
var event types.EventBridgeReceive
err := json.Unmarshal([]byte(a.Content), &event)
require.NoError(s.t, err)

sdkEvent, found := testutil.GetEvent(&event, s.sdkCtx.EventManager().Events())
require.True(s.t, found)

err = testutil.MatchEvent(&event, sdkEvent)
require.NoError(s.t, err)
}

func (s *bridgeReceiveSuite) getProjectSequence(projectID string) uint64 {
str := strings.Split(projectID, "-")
seq, err := strconv.ParseUint(str[1], 10, 32)
Expand Down
198 changes: 156 additions & 42 deletions x/ecocredit/base/types/v1/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8ddf8a1

Please sign in to comment.