Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/ecocredit)!: migrate add-credit-type proposal to msg based proposal #1337

Merged
merged 25 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
abf6226
feat: add proto msg & server impl
aleem1314 Aug 4, 2022
cb31c27
chore: remove legacy handler
aleem1314 Aug 4, 2022
d05c531
wip: add unit tests
aleem1314 Aug 4, 2022
8f0cb7e
chore: review changes
aleem1314 Aug 5, 2022
3b1b1d4
wip
aleem1314 Aug 8, 2022
2c8f180
feat: add integration tests
aleem1314 Aug 10, 2022
b862af2
Merge branch 'master' into aleem/credit-type-migration
aleem1314 Aug 10, 2022
748e787
chore: run go mod tidy
aleem1314 Aug 10, 2022
ebb30c5
chore: make proto-gen
aleem1314 Aug 10, 2022
49cde68
chore: add changelog
aleem1314 Aug 10, 2022
e2acde3
chore: remove todo
aleem1314 Aug 10, 2022
22d12c9
Merge branch 'master' into aleem/credit-type-migration
aleem1314 Aug 10, 2022
bcd2574
Merge branch 'master' into aleem/credit-type-migration
aleem1314 Aug 10, 2022
8f8c4b7
chore: make tidy
aleem1314 Aug 10, 2022
7868b25
Update x/ecocredit/core/features/msg_add_credit_type.feature
aleem1314 Aug 11, 2022
c8253c2
Update proto/regen/ecocredit/v1/tx.proto
aleem1314 Aug 11, 2022
5fbc0e7
Update proto/regen/ecocredit/v1/tx.proto
aleem1314 Aug 11, 2022
fddd366
Update proto/regen/ecocredit/v1/tx.proto
aleem1314 Aug 11, 2022
3b39da2
Update x/ecocredit/core/features/msg_add_credit_type.feature
aleem1314 Aug 11, 2022
2400513
Update x/ecocredit/server/core/features/msg_add_credit_type.feature
aleem1314 Aug 11, 2022
31fa6db
chore: update feature file
aleem1314 Aug 11, 2022
8c86657
Merge branch 'aleem/credit-type-migration' into aleem/credit-type-mi…
aleem1314 Aug 11, 2022
e0abaa8
chore: review changes
aleem1314 Aug 11, 2022
5b1fa0a
Merge branch 'master' into aleem/credit-type-migration
aleem1314 Aug 11, 2022
2abbbf1
Merge branch 'master' into aleem/credit-type-migration
ryanchristo Aug 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,215 changes: 1,588 additions & 627 deletions api/regen/ecocredit/v1/tx.pulsar.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions api/regen/ecocredit/v1/tx_grpc.pb.go

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

3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
app.GetSubspace(ecocredit.DefaultParamspace),
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName),
)
dataModule := data.NewModule(app.AccountKeeper, app.BankKeeper)
newModules := []moduletypes.Module{ecocreditModule, dataModule}
Expand Down Expand Up @@ -519,7 +520,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// ibc.NewAppModule(app.IBCKeeper),
// transferModule,
ecocreditmodule.NewModule(app.GetSubspace(ecocredit.DefaultParamspace), app.AccountKeeper, app.BankKeeper),
ecocreditmodule.NewModule(app.GetSubspace(ecocredit.DefaultParamspace), app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName)),
data.NewModule(app.AccountKeeper, app.BankKeeper),
}, app.setCustomSimulationManager()...)...,
)
Expand Down
3 changes: 0 additions & 3 deletions app/stable_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"

"github.com/regen-network/regen-ledger/types/module/server"
ecocreditcore "github.com/regen-network/regen-ledger/x/ecocredit/client/core"
"github.com/regen-network/regen-ledger/x/ecocredit/client/marketplace"
)

func setCustomModuleBasics() []module.AppModuleBasic {
Expand All @@ -31,7 +29,6 @@ func setCustomModuleBasics() []module.AppModuleBasic {
[]govclient.ProposalHandler{
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler,
ecocreditcore.CreditTypeProposalHandler, marketplace.AllowDenomProposalHandler,
},
),
}
Expand Down
16 changes: 16 additions & 0 deletions proto/regen/ecocredit/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
import "regen/ecocredit/v1/types.proto";
import "regen/ecocredit/v1/state.proto";

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/core";

Expand Down Expand Up @@ -111,8 +112,23 @@ service Msg {
// project with a matching reference id already exists within the scope of the
// credit class, otherwise a new project will be created.
rpc BridgeReceive(MsgBridgeReceive) returns (MsgBridgeReceiveResponse);

// AddCreditType is a governance method that allows the addition of new credit types to the network.
rpc AddCreditType(MsgAddCreditType) returns (MsgAddCreditTypeResponse);
}

// MsgAddCreditType is the Msg/AddCreditType request type.
message MsgAddCreditType {
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
// authority is the address of the governance account.
string authority = 1;

// credit_type defines a credit type to add to the credit types parameter.
repeated CreditType credit_type = 2;
}
ryanchristo marked this conversation as resolved.
Show resolved Hide resolved

// MsgAddCreditTypeResponse is the Msg/AddCreditType response type.
message MsgAddCreditTypeResponse {}
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

// MsgCreateClass is the Msg/CreateClass request type.
message MsgCreateClass {

Expand Down
80 changes: 0 additions & 80 deletions x/ecocredit/client/core/proposal.go

This file was deleted.

1 change: 1 addition & 0 deletions x/ecocredit/core/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgUpdateProjectMetadata{}, "regen.core/MsgUpdateProjectMetadata", nil)
cdc.RegisterConcrete(&CreditTypeProposal{}, "regen.core/CreditTypeProposal", nil)
cdc.RegisterConcrete(&MsgBridgeReceive{}, "regen.core/MsgBridgeReceive", nil)
cdc.RegisterConcrete(&MsgAddCreditType{}, "regen.core/MsgAddCreditType", nil)
}

var (
Expand Down
104 changes: 104 additions & 0 deletions x/ecocredit/core/features/msg_add_credit_type.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Feature: CreditTypes
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

Scenario: a valid credit types
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
Given the message
"""
{
"authority":"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credit_type": [
{
"abbreviation":"C",
"precision":6,
"name":"carbon",
"unit":"ton"
}
]
}
"""
When the message is validated
Then expect no error

Scenario: an error is returned if authority address is empty
Given the message
"""
{}
"""
When the message is validated
Then expect the error "invalid authority address: empty address string is not allowed"

Scenario: an error is returned if authority address is not a valid bech32 address
Given the message
"""
{
"authority": "foo"
}
"""
When the message is validated
Then expect the error "invalid authority address: decoding bech32 failed: invalid bech32 string length 3"

Scenario: an error is returned if credit type is empty
Given the message
"""
{
"authority": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
}
"""
When the message is validated
Then expect the error "credit types cannot be empty: invalid request"
Scenario: an error is returned if credit type precision is not 6
Given the message
"""
{
"authority": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credit_type": [
{
"abbreviation":"C",
"precision":60,
"name":"carbon",
"unit":"ton"
}
]
}
"""
When the message is validated
Then expect the error "credit_type[0]: credit type precision is currently locked to 6: invalid request"
Scenario: an error is returned if credit type abbreviation is empty
Given the message
"""
{
"authority": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credit_type": [
{
"abbreviation":"",
"precision":6,
"name":"carbon",
"unit":"ton"
}
]
}
"""
When the message is validated
Then expect the error "credit_type[0]: credit type abbreviation cannot be empty: parse error"
Scenario: an error is returned if credit type duplicate
Given the message
"""
{
"authority": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credit_type": [
{
"abbreviation":"C",
"precision":6,
"name":"carbon",
"unit":"ton"
},
{
"abbreviation":"C",
"precision":6,
"name":"carbon",
"unit":"ton"
}
]
}
"""
When the message is validated
Then expect the error "credit_type[1]: duplicate credit type: invalid request"
58 changes: 58 additions & 0 deletions x/ecocredit/core/msg_add_credit_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package core

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

"github.com/regen-network/regen-ledger/x/ecocredit"
)

var _ legacytx.LegacyMsg = &MsgAddCreditType{}

// Route implements the LegacyMsg interface.
func (m MsgAddCreditType) Route() string { return sdk.MsgTypeURL(&m) }

// Type implements the LegacyMsg interface.
func (m MsgAddCreditType) Type() string { return sdk.MsgTypeURL(&m) }

// GetSignBytes implements the LegacyMsg interface.
func (m MsgAddCreditType) GetSignBytes() []byte {
return sdk.MustSortJSON(ecocredit.ModuleCdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgAddCreditType) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return sdkerrors.Wrapf(err, "invalid authority address")
}

if len(m.CreditType) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("credit types cannot be empty")
}

duplicateAddMap := make(map[string]bool)
for i, creditType := range m.CreditType {
cTypeIndex := fmt.Sprintf("credit_type[%d]", i)

if err := creditType.Validate(); err != nil {
return sdkerrors.Wrapf(err, "%s", cTypeIndex)
}

if _, ok := duplicateAddMap[creditType.Name]; ok {
return sdkerrors.ErrInvalidRequest.Wrapf("%s: duplicate credit type", cTypeIndex)
}

duplicateAddMap[creditType.Name] = true
}

return nil
}

// GetSigners returns the expected signers for MsgAddCreditType.
func (m *MsgAddCreditType) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}
Loading