Skip to content

Commit

Permalink
refactor(x/ecocredit): move empty string validation into utils.go (#1317
Browse files Browse the repository at this point in the history
)

* refactor: move empty string validation into core utils.go

* chore: remove duplicate scenario in msg_retire.feature
  • Loading branch information
wgwz authored Aug 3, 2022
1 parent cb68013 commit 682e4de
Show file tree
Hide file tree
Showing 44 changed files with 81 additions and 164 deletions.
6 changes: 3 additions & 3 deletions x/ecocredit/basket/features/msg_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Feature: MsgCreate
}
"""
When the message is validated
Then expect the error "credit type abbreviation cannot be empty: invalid request"
Then expect the error "credit type abbreviation cannot be empty: parse error: invalid request"

Scenario: an error is returned if credit type abbreviation is not formatted
Given the message
Expand All @@ -200,7 +200,7 @@ Feature: MsgCreate
}
"""
When the message is validated
Then expect the error "credit type abbreviation must be 1-3 uppercase latin letters: got foobar: invalid request"
Then expect the error "credit type abbreviation must be 1-3 uppercase latin letters: got foobar: parse error: invalid request"

Scenario: an error is returned if allowed credit classes is empty
Given the message
Expand All @@ -227,7 +227,7 @@ Feature: MsgCreate
}
"""
When the message is validated
Then expect the error "allowed_classes[0] cannot be empty: invalid request"
Then expect the error "allowed_classes[0] is not a valid class ID: class id cannot be empty: parse error: invalid request"

Scenario: an error is returned if an allowed credit class is not formatted
Given the message
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/basket/features/msg_put.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Feature: MsgPut
}
"""
When the message is validated
Then expect the error "credit batch denom cannot be empty: invalid request"
Then expect the error "batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if a credit batch denom is not formatted
Given the message
Expand Down
9 changes: 1 addition & 8 deletions x/ecocredit/basket/msg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,15 @@ func (m MsgCreate) ValidateBasic() error {
return sdkerrors.ErrInvalidRequest.Wrapf("description length cannot be greater than %d characters", descrMaxLen)
}

if len(m.CreditTypeAbbrev) == 0 {
return sdkerrors.ErrInvalidRequest.Wrapf("credit type abbreviation cannot be empty")
}

if err := core.ValidateCreditTypeAbbreviation(m.CreditTypeAbbrev); err != nil {
return err
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

if len(m.AllowedClasses) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("allowed classes cannot be empty")
}

for i := range m.AllowedClasses {
if m.AllowedClasses[i] == "" {
return sdkerrors.ErrInvalidRequest.Wrapf("allowed_classes[%d] cannot be empty", i)
}
if err := core.ValidateClassId(m.AllowedClasses[i]); err != nil {
return sdkerrors.ErrInvalidRequest.Wrapf("allowed_classes[%d] is not a valid class ID: %s", i, err)
}
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/basket/msg_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func (m MsgPut) ValidateBasic() error {

if len(m.Credits) > 0 {
for _, credit := range m.Credits {
if len(credit.BatchDenom) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("credit batch denom cannot be empty")
}

if err := core.ValidateBatchDenom(credit.BatchDenom); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_bridge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Feature: MsgBridge
}
"""
When the message is validated
Then expect the error "credits[0]: batch denom cannot be empty: invalid request"
Then expect the error "credits[0]: batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if credits batch denom is not formatted
Given the message
Expand All @@ -144,7 +144,7 @@ Feature: MsgBridge
}
"""
When the message is validated
Then expect the error "credits[0]: invalid batch denom: expected format A00-000-00000000-00000000-000: parse error"
Then expect the error "credits[0]: invalid batch denom: expected format A00-000-00000000-00000000-000: parse error: invalid request"

Scenario: an error is returned if credits amount is empty
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_bridge_receive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Feature: MsgBridgeReceive
}
"""
When the message is validated
Then expect the error "class id cannot be empty: invalid request"
Then expect the error "class id cannot be empty: parse error: invalid request"

Scenario: an error is returned if class id is not formatted
Given the message
Expand Down Expand Up @@ -114,7 +114,7 @@ Feature: MsgBridgeReceive
}
"""
When the message is validated
Then expect the error "project jurisdiction cannot be empty: invalid request"
Then expect the error "jurisdiction cannot be empty, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"

Scenario: an error is returned if project jurisdiction is not formatted
Given the message
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/msg_cancel.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Feature: MsgCancel
}
"""
When the message is validated
Then expect the error "credits[0]: batch denom cannot be empty: invalid request"
Then expect the error "credits[0]: batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if credits amount is empty
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_create_batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Feature: MsgCreateBatch
}
"""
When the message is validated
Then expect the error "project id cannot be empty: invalid request"
Then expect the error "project id cannot be empty: parse error: invalid request"

Scenario: an error is returned if project id is not formatted
Given the message
Expand All @@ -133,7 +133,7 @@ Feature: MsgCreateBatch
}
"""
When the message is validated
Then expect the error "invalid project id: foo: parse error"
Then expect the error "invalid project id: foo: parse error: invalid request"

Scenario: an error is returned if issuance is empty
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_create_class.feature
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Feature: MsgCreateClass
}
"""
When the message is validated
Then expect the error "credit type abbreviation cannot be empty: invalid request"
Then expect the error "credit type abbreviation cannot be empty: parse error: invalid request"

Scenario: an error is returned if credit type abbreviation is not formatted
Given the message
Expand All @@ -150,7 +150,7 @@ Feature: MsgCreateClass
}
"""
When the message is validated
Then expect the error "credit type abbreviation must be 1-3 uppercase latin letters: got foobar: invalid request"
Then expect the error "credit type abbreviation must be 1-3 uppercase latin letters: got foobar: parse error: invalid request"

Scenario: an error is returned if fee denom is empty
Given the message
Expand Down
8 changes: 4 additions & 4 deletions x/ecocredit/core/features/msg_create_project.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Feature: MsgCreateProject
}
"""
When the message is validated
Then expect the error "class id cannot be empty: invalid request"
Then expect the error "class id cannot be empty: parse error: invalid request"

Scenario: an error is returned if class id is not formatted
Given the message
Expand All @@ -77,7 +77,7 @@ Feature: MsgCreateProject
}
"""
When the message is validated
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error"
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error: invalid request"

Scenario: an error is returned if metadata is exceeds 256 characters
Given the message
Expand All @@ -101,7 +101,7 @@ Feature: MsgCreateProject
}
"""
When the message is validated
Then expect the error "jurisdiction cannot be empty: invalid request"
Then expect the error "jurisdiction cannot be empty, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"

Scenario: an error is returned if jurisdiction is not formatted
Given the message
Expand All @@ -114,7 +114,7 @@ Feature: MsgCreateProject
}
"""
When the message is validated
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error"
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"

Scenario: an error is returned if reference id is exceeds 32 characters
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_mint_batch_credits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Feature: MsgMintBatchCredits
}
"""
When the message is validated
Then expect the error "batch denom cannot be empty: invalid request"
Then expect the error "batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if batch denom is not formatted
Given the message
Expand All @@ -86,7 +86,7 @@ Feature: MsgMintBatchCredits
}
"""
When the message is validated
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error"
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error: invalid request"

Scenario: an error is returned if issuance is empty
Given the message
Expand Down
6 changes: 3 additions & 3 deletions x/ecocredit/core/features/msg_retire.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Feature: MsgRetire
}
"""
When the message is validated
Then expect the error "credits[0]: batch denom cannot be empty: invalid request"
Then expect the error "credits[0]: batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if credits amount is empty
Given the message
Expand Down Expand Up @@ -110,7 +110,7 @@ Feature: MsgRetire
}
"""
When the message is validated
Then expect the error "jurisdiction cannot be empty: invalid request"
Then expect the error "jurisdiction cannot be empty, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"

Scenario: an error is returned if jurisdiction is not formatted
Given the message
Expand All @@ -127,4 +127,4 @@ Feature: MsgRetire
}
"""
When the message is validated
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error"
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_seal_batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: MsgSealBatch
}
"""
When the message is validated
Then expect the error "batch denom cannot be empty: invalid request"
Then expect the error "batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if batch denom is not formatted
Given the message
Expand All @@ -48,4 +48,4 @@ Feature: MsgSealBatch
}
"""
When the message is validated
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error"
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error: invalid request"
8 changes: 4 additions & 4 deletions x/ecocredit/core/features/msg_send.feature
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Feature: MsgSend
}
"""
When the message is validated
Then expect the error "batch denom cannot be empty: invalid request"
Then expect the error "batch denom cannot be empty: parse error: invalid request"

Scenario: an error is returned if credits batch denom is not formatted
Given the message
Expand All @@ -119,7 +119,7 @@ Feature: MsgSend
}
"""
When the message is validated
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error"
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error: invalid request"

Scenario: an error is returned if credits tradable amount and retired amount are empty
Given the message
Expand Down Expand Up @@ -186,7 +186,7 @@ Feature: MsgSend
}
"""
When the message is validated
Then expect the error "retirement jurisdiction required: invalid request"
Then expect the error "retirement jurisdiction: jurisdiction cannot be empty, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"

Scenario: an error is returned if credits retired amount is positive and retirement jurisdiction is not formatted
Given the message
Expand All @@ -204,4 +204,4 @@ Feature: MsgSend
}
"""
When the message is validated
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error"
Then expect the error "retirement jurisdiction: invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_update_class_admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Feature: MsgUpdateClassAdmin
}
"""
When the message is validated
Then expect the error "class id cannot be empty: invalid request"
Then expect the error "class id cannot be empty: parse error: invalid request"

Scenario: an error is returned if class id is not formatted
Given the message
Expand All @@ -49,7 +49,7 @@ Feature: MsgUpdateClassAdmin
}
"""
When the message is validated
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error"
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error: invalid request"

Scenario: an error is returned if new admin is empty
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_update_class_issuers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Feature: MsgUpdateClassIssuers
}
"""
When the message is validated
Then expect the error "class id cannot be empty: invalid request"
Then expect the error "class id cannot be empty: parse error: invalid request"

Scenario: an error is returned if class id is not formatted
Given the message
Expand All @@ -82,7 +82,7 @@ Feature: MsgUpdateClassIssuers
}
"""
When the message is validated
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error"
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error: invalid request"

Scenario: an error is returned if new issuers and remove issuers is empty
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_update_class_metadata.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: MsgUpdateClassMetadata
}
"""
When the message is validated
Then expect the error "class id cannot be empty: invalid request"
Then expect the error "class id cannot be empty: parse error: invalid request"

Scenario: an error is returned if class id is not formatted
Given the message
Expand All @@ -60,7 +60,7 @@ Feature: MsgUpdateClassMetadata
}
"""
When the message is validated
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error"
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error: invalid request"

Scenario: an error is returned if new metadata exceeds 256 characters
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_update_project_admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Feature: MsgUpdateProjectAdmin
}
"""
When the message is validated
Then expect the error "project id cannot be empty: invalid request"
Then expect the error "project id cannot be empty: parse error: invalid request"

Scenario: an error is returned if project id is not formatted
Given the message
Expand All @@ -49,7 +49,7 @@ Feature: MsgUpdateProjectAdmin
}
"""
When the message is validated
Then expect the error "invalid project id: foo: parse error"
Then expect the error "invalid project id: foo: parse error: invalid request"

Scenario: an error is returned if new admin is empty
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/msg_update_project_metadata.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: MsgUpdateProjectMetadata
}
"""
When the message is validated
Then expect the error "project id cannot be empty: invalid request"
Then expect the error "project id cannot be empty: parse error: invalid request"

Scenario: an error is returned if project id is not formatted
Given the message
Expand All @@ -60,7 +60,7 @@ Feature: MsgUpdateProjectMetadata
}
"""
When the message is validated
Then expect the error "invalid project id: foo: parse error"
Then expect the error "invalid project id: foo: parse error: invalid request"

Scenario: an error is returned if new metadata exceeds 256 characters
Given the message
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/core/features/types_batch_issuance.feature
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Feature: BatchIssuance
}
"""
When the batch issuance is validated
Then expect the error "retirement jurisdiction cannot be empty: invalid request"
Then expect the error "retirement jurisdiction: jurisdiction cannot be empty, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"

Scenario: an error is returned if issuance retired amount is positive and jurisdiction is not formatted
Given the batch issuance
Expand All @@ -107,4 +107,4 @@ Feature: BatchIssuance
}
"""
When the batch issuance is validated
Then expect the error "retirement jurisdiction: invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error"
Then expect the error "retirement jurisdiction: invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"
Loading

0 comments on commit 682e4de

Please sign in to comment.