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

refactor(x/ecocredit): convert class fee argument to optional flag #1475

Merged
merged 8 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1429](https://github.com/regen-network/regen-ledger/pull/1429) Migrated `ecocredit/simulation` core operations to `ecocredit/base/simulation`
- [#1447](https://github.com/regen-network/regen-ledger/pull/1447) Rename `CoreKeeper` to `BaseKeeper`
- [#1452](https://github.com/regen-network/regen-ledger/pull/1452) Migrated `BeginBlocker` to `ecocredit/module`
- [#1475](https://github.com/regen-network/regen-ledger/pull/1475) Convert `CreateClass` command `fee` argument to optional flag

### Fixed

Expand Down
30 changes: 24 additions & 6 deletions x/ecocredit/base/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ const (
FlagRemoveIssuers string = "remove-issuers"
FlagReferenceID string = "reference-id"
FlagRetirementJurisdiction string = "retirement-jurisdiction"
FlagClassFee string = "class-fee"
)

// TxCreateClassCmd returns a transaction command that creates a credit class.
func TxCreateClassCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-class [issuers] [credit-type-abbrev] [metadata] [fee] [flags]",
Use: "create-class [issuers] [credit-type-abbrev] [metadata] [flags]",
Short: "Creates a new credit class with transaction author (--from) as admin",
Long: fmt.Sprintf(`Creates a new credit class with transaction author (--from) as admin.

Expand All @@ -44,13 +45,21 @@ Parameters:
- issuers: comma separated (no spaces) list of issuer account addresses
- credit-type-abbrev: the abbreviation of a credit type
- metadata: arbitrary data attached to the credit class info
- fee: fee to pay for the creation of the credit class`,

Flags:

- class-fee: the fee that the class creator will pay to create the credit class. It must be >= the
required credit_class_fee param. We include the fee explicitly here so that the
class creator explicitly acknowledges paying this fee and is not surprised to learn that they
paid a big fee and didn't know beforehand.

aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
`,
types.KeyAllowedClassCreators,
types.KeyCreditClassFee,
),
Example: `regen tx ecocredit create-class regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw C regen:13toVgf5UjYBz6J29x28pLQyjKz5FpcW3f4bT5uRKGxGREWGKjEdXYG.rdf 20000000uregen
regen tx ecocredit create-class regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw,regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6 C regen:13toVgf5UjYBz6J29x28pLQyjKz5FpcW3f4bT5uRKGxGREWGKjEdXYG.rdf 20000000uregen`,
Args: cobra.ExactArgs(4),
Example: `regen tx ecocredit create-class regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw C regen:13toVgf5UjYBz6J29x28pLQyjKz5FpcW3f4bT5uRKGxGREWGKjEdXYG.rdf --class-fee 20000000uregen
regen tx ecocredit create-class regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw,regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6 C regen:13toVgf5UjYBz6J29x28pLQyjKz5FpcW3f4bT5uRKGxGREWGKjEdXYG.rdf --class-fee 20000000uregen`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := sdkclient.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -67,10 +76,17 @@ regen tx ecocredit create-class regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw,reg
}

// Parse and normalize credit class fee
fee, err := sdk.ParseCoinNormalized(args[3])
var fee sdk.Coin
feeString, err := cmd.Flags().GetString(FlagClassFee)
if err != nil {
return err
}
if feeString != "" {
fee, err = sdk.ParseCoinNormalized(feeString)
if err != nil {
return fmt.Errorf("failed to parse class-fee: %w", err)
}
}

msg := types.MsgCreateClass{
Admin: admin.String(),
Expand All @@ -84,6 +100,8 @@ regen tx ecocredit create-class regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw,reg
},
}

cmd.Flags().String(FlagClassFee, "", "the fee that the class creator will pay to create the credit class (e.g. \"20regen\")")

return txFlags(cmd)
}

Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/basket/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Flags:
false unless the credits were previously put into the basket by the address
picking them from the basket, in which case they will remain tradable.
- credit-type-abbrev: filters against credits from this credit type abbreviation (e.g. "BIO").
- allowed_classes: comma separated (no spaces) list of credit classes allowed to be put in
- allowed-classes: comma separated (no spaces) list of credit classes allowed to be put in
the basket (e.g. "C01,C02").
- min-start-date: the earliest start date for batches of credits allowed into the basket.
- start-date-window: the duration of time (in seconds) measured into the past which sets a
Expand All @@ -56,7 +56,7 @@ Flags:
curator explicitly acknowledges paying this fee and is not surprised to learn that they
paid a big fee and didn't know beforehand.
- description: the description to be used in the basket coin's bank denom metadata.`),
Example: `regen tx ecocredit create-basket NCT --credit-type-abbrev C --allowed_classes C01,C02 basket-fee 100000000uregen description "NCT basket"`,
Example: `regen tx ecocredit create-basket NCT --credit-type-abbrev C --allowed-classes C01,C02 --basket-fee 100000000uregen --description "NCT basket"`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
16 changes: 5 additions & 11 deletions x/ecocredit/client/testsuite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type IntegrationTestSuite struct {
addr2 sdk.AccAddress

// test values
creditClassFee sdk.Coins
creditClassFee *sdk.Coin
basketFee sdk.Coins
creditTypeAbbrev string
allowedDenoms []string
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
Issuers: []string{s.addr1.String()},
Metadata: "metadata",
CreditTypeAbbrev: s.creditTypeAbbrev,
Fee: &s.creditClassFee[0],
Fee: s.creditClassFee,
})

// set test reference id
Expand Down Expand Up @@ -260,15 +260,9 @@ func (s *IntegrationTestSuite) setupGenesis() {
err = mdb.ExportJSON(ctx, target)
require.NoError(err)

params := genesis.DefaultParams()

// set credit class and basket fees
s.creditClassFee = params.CreditClassFee
s.basketFee = params.BasketFee

// merge the params into the json target
err = genesis.MergeParamsIntoTarget(s.cfg.Codec, &params, target)
require.NoError(err)
s.creditClassFee = genesis.DefaultClassFee().Fee
s.basketFee = sdk.NewCoins(*genesis.DefaultBasketFee().Fee)

// get raw json from target
json, err := target.JSON()
Expand Down Expand Up @@ -336,8 +330,8 @@ func (s *IntegrationTestSuite) createClass(clientCtx client.Context, msg *basety
strings.Join(msg.Issuers, ","),
msg.CreditTypeAbbrev,
msg.Metadata,
msg.Fee.String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, msg.Admin),
fmt.Sprintf("--%s=%s", baseclient.FlagClassFee, msg.Fee.String()),
}
args = append(args, s.commonTxFlags()...)
out, err := cli.ExecTestCLICmd(clientCtx, cmd, args)
Expand Down
34 changes: 23 additions & 11 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ func (s *IntegrationTestSuite) TestTxCreateClassCmd() {
name: "missing args",
args: []string{},
expErr: true,
expErrMsg: "Error: accepts 4 arg(s), received 0",
expErrMsg: "Error: accepts 3 arg(s), received 0",
},
{
name: "too many args",
args: []string{"foo", "bar", "baz", "bar", "foo"},
args: []string{"foo", "bar", "baz", "bar"},
expErr: true,
expErrMsg: "Error: accepts 4 arg(s), received 5",
expErrMsg: "Error: accepts 3 arg(s), received 4",
},
{
name: "missing from flag",
args: []string{
admin,
s.creditTypeAbbrev,
"metadata",
creditClassFee,
fmt.Sprintf("--%s=%s", client.FlagClassFee, creditClassFee),
},
expErr: true,
expErrMsg: "Error: required flag(s) \"from\" not set",
Expand All @@ -55,8 +55,8 @@ func (s *IntegrationTestSuite) TestTxCreateClassCmd() {
admin,
s.creditTypeAbbrev,
"metadata",
"foo",
fmt.Sprintf("--%s=%s", flags.FlagFrom, admin),
fmt.Sprintf("--%s=%s", client.FlagClassFee, "foo"),
},
expErr: true,
expErrMsg: "invalid decimal coin expression",
Expand All @@ -67,8 +67,8 @@ func (s *IntegrationTestSuite) TestTxCreateClassCmd() {
admin,
s.creditTypeAbbrev,
"metadata",
creditClassFee,
fmt.Sprintf("--%s=%s", flags.FlagFrom, admin),
fmt.Sprintf("--%s=%s", client.FlagClassFee, creditClassFee),
},
},
{
Expand All @@ -77,8 +77,8 @@ func (s *IntegrationTestSuite) TestTxCreateClassCmd() {
admin,
s.creditTypeAbbrev,
"metadata",
creditClassFee,
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.val.Moniker),
fmt.Sprintf("--%s=%s", client.FlagClassFee, creditClassFee),
},
},
{
Expand All @@ -87,11 +87,23 @@ func (s *IntegrationTestSuite) TestTxCreateClassCmd() {
admin,
s.creditTypeAbbrev,
"metadata",
creditClassFee,
fmt.Sprintf("--%s=%s", flags.FlagFrom, admin),
fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON),
fmt.Sprintf("--%s=%s", client.FlagClassFee, creditClassFee),
},
},
{
name: "fee cannot be empty",
args: []string{
admin,
s.creditTypeAbbrev,
"metadata",
fmt.Sprintf("--%s=%s", flags.FlagFrom, admin),
fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON),
},
expErr: true,
expErrMsg: "fee denom cannot be empty: invalid request",
},
ryanchristo marked this conversation as resolved.
Show resolved Hide resolved
}

for _, tc := range testCases {
Expand Down Expand Up @@ -797,7 +809,7 @@ func (s *IntegrationTestSuite) TestTxUpdateClassAdmin() {
Issuers: []string{admin},
Metadata: "metadata",
CreditTypeAbbrev: s.creditTypeAbbrev,
Fee: &s.creditClassFee[0],
Fee: s.creditClassFee,
})

// create new credit class to not interfere with other tests
Expand All @@ -806,7 +818,7 @@ func (s *IntegrationTestSuite) TestTxUpdateClassAdmin() {
Issuers: []string{admin},
Metadata: "metadata",
CreditTypeAbbrev: s.creditTypeAbbrev,
Fee: &s.creditClassFee[0],
Fee: s.creditClassFee,
})

// create new credit class to not interfere with other tests
Expand All @@ -815,7 +827,7 @@ func (s *IntegrationTestSuite) TestTxUpdateClassAdmin() {
Issuers: []string{admin},
Metadata: "metadata",
CreditTypeAbbrev: s.creditTypeAbbrev,
Fee: &s.creditClassFee[0],
Fee: s.creditClassFee,
})

testCases := []struct {
Expand Down