Skip to content

Commit

Permalink
refactor: move empty string validation into core utils.go
Browse files Browse the repository at this point in the history
  • Loading branch information
wgwz committed Jul 29, 2022
1 parent 43d155f commit 0b52f5d
Show file tree
Hide file tree
Showing 40 changed files with 68 additions and 137 deletions.
4 changes: 2 additions & 2 deletions x/ecocredit/basket/features/msg_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: invalid request: invalid request"

Scenario: an error is returned if an allowed credit class is not formatted
Given the message
Expand All @@ -242,7 +242,7 @@ Feature: MsgCreate
}
"""
When the message is validated
Then expect the error "allowed_classes[0] is not a valid class ID: class ID didn't match the format: expected A00, got foo: parse error: invalid request"
Then expect the error "allowed_classes[0] is not a valid class ID: class ID didn't match the format: expected A00, got foo: invalid request: invalid request"

Scenario Outline: an error is returned if more than one data criteria is provided
Given the message
Expand Down
4 changes: 2 additions & 2 deletions 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: invalid request"

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

Scenario: an error is returned if a credit amount is empty
Given the message
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/basket/features/msg_take.feature
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Feature: MsgTake
}
"""
When the message is validated
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error: invalid request"
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: invalid request: invalid request"

Scenario: no error is returned if retirement jurisdiction is not formatted and retire on take is false
Given the message
Expand Down
7 changes: 0 additions & 7 deletions x/ecocredit/basket/msg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ 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
}
Expand All @@ -55,9 +51,6 @@ func (m MsgCreate) ValidateBasic() error {
}

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
6 changes: 1 addition & 5 deletions x/ecocredit/basket/msg_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ 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())
return err
}

if len(credit.Amount) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/msg_bridge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: invalid request"

Scenario: an error is returned if credits amount is empty
Given the message
Expand Down
6 changes: 3 additions & 3 deletions x/ecocredit/core/features/msg_bridge_receive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Feature: MsgBridgeReceive
}
"""
When the message is validated
Then expect the error "class ID didn't match the format: expected A00, got foo: parse error: invalid request"
Then expect the error "class ID didn't match the format: expected A00, got foo: invalid request"

Scenario: an error is returned if project is empty
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>]]: invalid request: invalid request"

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

Scenario: an error is returned if project metadata is empty
Given the message
Expand Down
6 changes: 3 additions & 3 deletions x/ecocredit/core/features/msg_create_project.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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>]]: 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>]]: invalid request"

Scenario: an error is returned if reference id is exceeds 32 characters
Given the message
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/msg_mint_batch_credits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: invalid request"

Scenario: an error is returned if issuance is empty
Given the message
Expand Down
21 changes: 19 additions & 2 deletions x/ecocredit/core/features/msg_retire.feature
Original file line number Diff line number Diff line change
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>]]: invalid request"

Scenario: an error is returned if jurisdiction is not formatted
Given the message
Expand All @@ -127,4 +127,21 @@ 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>]]: invalid request"

Scenario: an error is returned if jurisdiction is an empty string
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
],
"jurisdiction": ""
}
"""
When the message is validated
Then expect the error "jurisdiction cannot be empty, expected format <country-code>[-<region-code>[ <postal-code>]]: invalid request"
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/msg_seal_batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: invalid request"
6 changes: 3 additions & 3 deletions x/ecocredit/core/features/msg_send.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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>]]: 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>]]: invalid request"
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/msg_update_class_admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: invalid request"

Scenario: an error is returned if new admin is empty
Given the message
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/msg_update_class_issuers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: invalid request"

Scenario: an error is returned if new issuers and remove issuers is empty
Given the message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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>]]: 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>]]: invalid request"
2 changes: 1 addition & 1 deletion x/ecocredit/core/features/types_credits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Feature: Credits
}
"""
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: invalid request"

Scenario: an error is returned if amount is empty
Given the message
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/core/msg_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ func (m *MsgBridge) ValidateBasic() error {
for i, credit := range m.Credits {
creditIndex := fmt.Sprintf("credits[%d]", i)

if credit.BatchDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrapf("%s: batch denom cannot be empty", creditIndex)
}

if err := ValidateBatchDenom(credit.BatchDenom); err != nil {
return sdkerrors.Wrapf(err, "%s", creditIndex)
}
Expand Down
10 changes: 1 addition & 9 deletions x/ecocredit/core/msg_bridge_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ func (m *MsgBridgeReceive) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("issuer: %s", err)
}

if m.ClassId == "" {
return sdkerrors.ErrInvalidRequest.Wrap("class id cannot be empty")
}

if err := ValidateClassId(m.ClassId); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
return err
}

// project validation
Expand All @@ -51,10 +47,6 @@ func (m *MsgBridgeReceive) ValidateBasic() error {
return ecocredit.ErrMaxLimit.Wrapf("project reference id: max length %d", MaxReferenceIdLength)
}

if m.Project.Jurisdiction == "" {
return sdkerrors.ErrInvalidRequest.Wrap("project jurisdiction cannot be empty")
}

if err := ValidateJurisdiction(m.Project.Jurisdiction); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/core/msg_create_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func (m *MsgCreateBatch) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("issuer: %s", err)
}

if m.ProjectId == "" {
return sdkerrors.ErrInvalidRequest.Wrap("project id cannot be empty")
}

if err := ValidateProjectId(m.ProjectId); err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/core/msg_create_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ func (m *MsgCreateClass) ValidateBasic() error {
return ecocredit.ErrMaxLimit.Wrapf("metadata: max length %d", MaxMetadataLength)
}

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

if err := ValidateCreditTypeAbbreviation(m.CreditTypeAbbrev); err != nil {
return err
}
Expand Down
8 changes: 0 additions & 8 deletions x/ecocredit/core/msg_create_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func (m *MsgCreateProject) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("admin: %s", err)
}

if m.ClassId == "" {
return sdkerrors.ErrInvalidRequest.Wrap("class id cannot be empty")
}

if err := ValidateClassId(m.ClassId); err != nil {
return err
}
Expand All @@ -41,10 +37,6 @@ func (m *MsgCreateProject) ValidateBasic() error {
return ecocredit.ErrMaxLimit.Wrapf("metadata: max length %d", MaxMetadataLength)
}

if m.Jurisdiction == "" {
return sdkerrors.ErrInvalidRequest.Wrap("jurisdiction cannot be empty")
}

if err := ValidateJurisdiction(m.Jurisdiction); err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/core/msg_mint_batch_credits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func (m *MsgMintBatchCredits) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("issuer: %s", err)
}

if m.BatchDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("batch denom cannot be empty")
}

if err := ValidateBatchDenom(m.BatchDenom); err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/core/msg_retire.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func (m *MsgRetire) ValidateBasic() error {
}
}

if m.Jurisdiction == "" {
return sdkerrors.ErrInvalidRequest.Wrap("jurisdiction cannot be empty")
}

if err := ValidateJurisdiction(m.Jurisdiction); err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions x/ecocredit/core/msg_seal_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func (m *MsgSealBatch) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("issuer: %s", err)
}

if m.BatchDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("batch denom cannot be empty")
}

return ValidateBatchDenom(m.BatchDenom)
}

Expand Down
Loading

0 comments on commit 0b52f5d

Please sign in to comment.