diff --git a/x/ecocredit/basket/features/msg_create.feature b/x/ecocredit/basket/features/msg_create.feature index 774915b80f..b8de1eff16 100644 --- a/x/ecocredit/basket/features/msg_create.feature +++ b/x/ecocredit/basket/features/msg_create.feature @@ -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 @@ -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 @@ -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 diff --git a/x/ecocredit/basket/features/msg_put.feature b/x/ecocredit/basket/features/msg_put.feature index 8d1415dc8d..d433461c4f 100644 --- a/x/ecocredit/basket/features/msg_put.feature +++ b/x/ecocredit/basket/features/msg_put.feature @@ -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 diff --git a/x/ecocredit/basket/msg_create.go b/x/ecocredit/basket/msg_create.go index 43513b6033..db71c27e0b 100644 --- a/x/ecocredit/basket/msg_create.go +++ b/x/ecocredit/basket/msg_create.go @@ -42,12 +42,8 @@ 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 { @@ -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) } diff --git a/x/ecocredit/basket/msg_put.go b/x/ecocredit/basket/msg_put.go index 9904eb039d..ac079b44e2 100644 --- a/x/ecocredit/basket/msg_put.go +++ b/x/ecocredit/basket/msg_put.go @@ -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()) } diff --git a/x/ecocredit/core/features/msg_bridge.feature b/x/ecocredit/core/features/msg_bridge.feature index 2ecbd5f4c0..0fe29996b8 100644 --- a/x/ecocredit/core/features/msg_bridge.feature +++ b/x/ecocredit/core/features/msg_bridge.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_bridge_receive.feature b/x/ecocredit/core/features/msg_bridge_receive.feature index 727a72a949..8dca59ecca 100644 --- a/x/ecocredit/core/features/msg_bridge_receive.feature +++ b/x/ecocredit/core/features/msg_bridge_receive.feature @@ -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 @@ -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 [-[ ]]: parse error: invalid request" Scenario: an error is returned if project jurisdiction is not formatted Given the message diff --git a/x/ecocredit/core/features/msg_cancel.feature b/x/ecocredit/core/features/msg_cancel.feature index 32c0dec877..c848d2052f 100644 --- a/x/ecocredit/core/features/msg_cancel.feature +++ b/x/ecocredit/core/features/msg_cancel.feature @@ -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 diff --git a/x/ecocredit/core/features/msg_create_batch.feature b/x/ecocredit/core/features/msg_create_batch.feature index 8121640ff1..5d27ab0d47 100644 --- a/x/ecocredit/core/features/msg_create_batch.feature +++ b/x/ecocredit/core/features/msg_create_batch.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_create_class.feature b/x/ecocredit/core/features/msg_create_class.feature index 00e6c12b3a..2077e8d424 100644 --- a/x/ecocredit/core/features/msg_create_class.feature +++ b/x/ecocredit/core/features/msg_create_class.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_create_project.feature b/x/ecocredit/core/features/msg_create_project.feature index 33ee78091f..2ea7fa3761 100644 --- a/x/ecocredit/core/features/msg_create_project.feature +++ b/x/ecocredit/core/features/msg_create_project.feature @@ -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 @@ -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 @@ -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 [-[ ]]: parse error: invalid request" Scenario: an error is returned if jurisdiction is not formatted Given the message @@ -114,7 +114,7 @@ Feature: MsgCreateProject } """ When the message is validated - Then expect the error "invalid jurisdiction: foo, expected format [-[ ]]: parse error" + Then expect the error "invalid jurisdiction: foo, expected format [-[ ]]: parse error: invalid request" Scenario: an error is returned if reference id is exceeds 32 characters Given the message diff --git a/x/ecocredit/core/features/msg_mint_batch_credits.feature b/x/ecocredit/core/features/msg_mint_batch_credits.feature index ddb3006b1c..1eec8a1f6a 100644 --- a/x/ecocredit/core/features/msg_mint_batch_credits.feature +++ b/x/ecocredit/core/features/msg_mint_batch_credits.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_retire.feature b/x/ecocredit/core/features/msg_retire.feature index cd9576bbe5..05be4caa65 100644 --- a/x/ecocredit/core/features/msg_retire.feature +++ b/x/ecocredit/core/features/msg_retire.feature @@ -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 @@ -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 [-[ ]]: parse error: invalid request" Scenario: an error is returned if jurisdiction is not formatted Given the message @@ -127,4 +127,4 @@ Feature: MsgRetire } """ When the message is validated - Then expect the error "invalid jurisdiction: foo, expected format [-[ ]]: parse error" + Then expect the error "invalid jurisdiction: foo, expected format [-[ ]]: parse error: invalid request" diff --git a/x/ecocredit/core/features/msg_seal_batch.feature b/x/ecocredit/core/features/msg_seal_batch.feature index 10a9ef71e3..dc0e8741a9 100644 --- a/x/ecocredit/core/features/msg_seal_batch.feature +++ b/x/ecocredit/core/features/msg_seal_batch.feature @@ -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 @@ -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" diff --git a/x/ecocredit/core/features/msg_send.feature b/x/ecocredit/core/features/msg_send.feature index 46743a681d..533b90e68b 100644 --- a/x/ecocredit/core/features/msg_send.feature +++ b/x/ecocredit/core/features/msg_send.feature @@ -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 @@ -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 @@ -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 [-[ ]]: parse error: invalid request" Scenario: an error is returned if credits retired amount is positive and retirement jurisdiction is not formatted Given the message @@ -204,4 +204,4 @@ Feature: MsgSend } """ When the message is validated - Then expect the error "invalid jurisdiction: foo, expected format [-[ ]]: parse error" + Then expect the error "retirement jurisdiction: invalid jurisdiction: foo, expected format [-[ ]]: parse error: invalid request" diff --git a/x/ecocredit/core/features/msg_update_class_admin.feature b/x/ecocredit/core/features/msg_update_class_admin.feature index 27b316e5a6..8c5aa345c8 100644 --- a/x/ecocredit/core/features/msg_update_class_admin.feature +++ b/x/ecocredit/core/features/msg_update_class_admin.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_update_class_issuers.feature b/x/ecocredit/core/features/msg_update_class_issuers.feature index 6e95942172..04a603658a 100644 --- a/x/ecocredit/core/features/msg_update_class_issuers.feature +++ b/x/ecocredit/core/features/msg_update_class_issuers.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_update_class_metadata.feature b/x/ecocredit/core/features/msg_update_class_metadata.feature index d54037be28..ae9f31d736 100644 --- a/x/ecocredit/core/features/msg_update_class_metadata.feature +++ b/x/ecocredit/core/features/msg_update_class_metadata.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_update_project_admin.feature b/x/ecocredit/core/features/msg_update_project_admin.feature index 52cd3853e7..b2e9a745b2 100644 --- a/x/ecocredit/core/features/msg_update_project_admin.feature +++ b/x/ecocredit/core/features/msg_update_project_admin.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/msg_update_project_metadata.feature b/x/ecocredit/core/features/msg_update_project_metadata.feature index 9c4fa79446..f52d45e858 100644 --- a/x/ecocredit/core/features/msg_update_project_metadata.feature +++ b/x/ecocredit/core/features/msg_update_project_metadata.feature @@ -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 @@ -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 diff --git a/x/ecocredit/core/features/types_batch_issuance.feature b/x/ecocredit/core/features/types_batch_issuance.feature index 47379f101e..f4487c1f39 100644 --- a/x/ecocredit/core/features/types_batch_issuance.feature +++ b/x/ecocredit/core/features/types_batch_issuance.feature @@ -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 [-[ ]]: parse error: invalid request" Scenario: an error is returned if issuance retired amount is positive and jurisdiction is not formatted Given the batch issuance @@ -107,4 +107,4 @@ Feature: BatchIssuance } """ When the batch issuance is validated - Then expect the error "retirement jurisdiction: invalid jurisdiction: foo, expected format [-[ ]]: parse error" + Then expect the error "retirement jurisdiction: invalid jurisdiction: foo, expected format [-[ ]]: parse error: invalid request" diff --git a/x/ecocredit/core/features/types_credits.feature b/x/ecocredit/core/features/types_credits.feature index 4ff82873b1..3b5a7ae720 100644 --- a/x/ecocredit/core/features/types_credits.feature +++ b/x/ecocredit/core/features/types_credits.feature @@ -17,7 +17,7 @@ Feature: Credits {} """ 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 @@ -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: parse error: invalid request" Scenario: an error is returned if amount is empty Given the message diff --git a/x/ecocredit/core/msg_bridge.go b/x/ecocredit/core/msg_bridge.go index 669ccb1c59..92f9a061b7 100644 --- a/x/ecocredit/core/msg_bridge.go +++ b/x/ecocredit/core/msg_bridge.go @@ -53,12 +53,8 @@ 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) + return sdkerrors.ErrInvalidRequest.Wrapf("%s: %s", creditIndex, err.Error()) } if credit.Amount == "" { diff --git a/x/ecocredit/core/msg_bridge_receive.go b/x/ecocredit/core/msg_bridge_receive.go index a126ba06d4..1756286f36 100644 --- a/x/ecocredit/core/msg_bridge_receive.go +++ b/x/ecocredit/core/msg_bridge_receive.go @@ -29,10 +29,6 @@ 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()) } @@ -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()) } diff --git a/x/ecocredit/core/msg_create_batch.go b/x/ecocredit/core/msg_create_batch.go index 58e1a02db9..b34aa84638 100644 --- a/x/ecocredit/core/msg_create_batch.go +++ b/x/ecocredit/core/msg_create_batch.go @@ -27,12 +27,8 @@ 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if len(m.Issuance) == 0 { diff --git a/x/ecocredit/core/msg_create_class.go b/x/ecocredit/core/msg_create_class.go index b1a7b23347..83a63ed319 100644 --- a/x/ecocredit/core/msg_create_class.go +++ b/x/ecocredit/core/msg_create_class.go @@ -52,12 +52,8 @@ 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if m.Fee != nil { diff --git a/x/ecocredit/core/msg_create_project.go b/x/ecocredit/core/msg_create_project.go index 123eedcb0c..42ed3a38dc 100644 --- a/x/ecocredit/core/msg_create_project.go +++ b/x/ecocredit/core/msg_create_project.go @@ -29,24 +29,16 @@ 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if len(m.Metadata) > MaxMetadataLength { 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if m.ReferenceId != "" && len(m.ReferenceId) > MaxReferenceIdLength { diff --git a/x/ecocredit/core/msg_mint_batch_credits.go b/x/ecocredit/core/msg_mint_batch_credits.go index e9f01aa938..c79bd150dc 100644 --- a/x/ecocredit/core/msg_mint_batch_credits.go +++ b/x/ecocredit/core/msg_mint_batch_credits.go @@ -27,12 +27,8 @@ 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if len(m.Issuance) == 0 { diff --git a/x/ecocredit/core/msg_retire.go b/x/ecocredit/core/msg_retire.go index 716ab13872..a13f8b8e76 100644 --- a/x/ecocredit/core/msg_retire.go +++ b/x/ecocredit/core/msg_retire.go @@ -37,12 +37,8 @@ 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } return nil diff --git a/x/ecocredit/core/msg_seal_batch.go b/x/ecocredit/core/msg_seal_batch.go index 1db3316789..72e0d9d6d9 100644 --- a/x/ecocredit/core/msg_seal_batch.go +++ b/x/ecocredit/core/msg_seal_batch.go @@ -26,9 +26,8 @@ func (m *MsgSealBatch) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Issuer); err != nil { 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 sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } return ValidateBatchDenom(m.BatchDenom) diff --git a/x/ecocredit/core/msg_send.go b/x/ecocredit/core/msg_send.go index ac30423eb0..b16666b271 100644 --- a/x/ecocredit/core/msg_send.go +++ b/x/ecocredit/core/msg_send.go @@ -37,12 +37,8 @@ func (m *MsgSend) ValidateBasic() error { } for _, credits := range m.Credits { - if credits.BatchDenom == "" { - return sdkerrors.ErrInvalidRequest.Wrap("batch denom cannot be empty") - } - if err := ValidateBatchDenom(credits.BatchDenom); err != nil { - return err + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if credits.TradableAmount == "" && credits.RetiredAmount == "" { @@ -59,12 +55,8 @@ func (m *MsgSend) ValidateBasic() error { } if !retiredAmount.IsZero() { - if credits.RetirementJurisdiction == "" { - return sdkerrors.ErrInvalidRequest.Wrap("retirement jurisdiction required") - } - if err = ValidateJurisdiction(credits.RetirementJurisdiction); err != nil { - return err + return sdkerrors.ErrInvalidRequest.Wrapf("retirement jurisdiction: %s", err.Error()) } } } diff --git a/x/ecocredit/core/msg_update_class_admin.go b/x/ecocredit/core/msg_update_class_admin.go index bb21a264dd..cb55e4bfe5 100644 --- a/x/ecocredit/core/msg_update_class_admin.go +++ b/x/ecocredit/core/msg_update_class_admin.go @@ -23,12 +23,8 @@ func (m *MsgUpdateClassAdmin) 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if _, err := sdk.AccAddressFromBech32(m.NewAdmin); err != nil { diff --git a/x/ecocredit/core/msg_update_class_issuers.go b/x/ecocredit/core/msg_update_class_issuers.go index ccc96c80bc..16604519e7 100644 --- a/x/ecocredit/core/msg_update_class_issuers.go +++ b/x/ecocredit/core/msg_update_class_issuers.go @@ -25,12 +25,8 @@ func (m *MsgUpdateClassIssuers) 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if len(m.AddIssuers) == 0 && len(m.RemoveIssuers) == 0 { diff --git a/x/ecocredit/core/msg_update_class_metadata.go b/x/ecocredit/core/msg_update_class_metadata.go index b2e219f556..58c42923a1 100644 --- a/x/ecocredit/core/msg_update_class_metadata.go +++ b/x/ecocredit/core/msg_update_class_metadata.go @@ -23,12 +23,8 @@ func (m *MsgUpdateClassMetadata) 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 + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if len(m.NewMetadata) > MaxMetadataLength { diff --git a/x/ecocredit/core/msg_update_project_admin.go b/x/ecocredit/core/msg_update_project_admin.go index b3ff80e75c..1482e6e958 100644 --- a/x/ecocredit/core/msg_update_project_admin.go +++ b/x/ecocredit/core/msg_update_project_admin.go @@ -23,12 +23,8 @@ func (m MsgUpdateProjectAdmin) ValidateBasic() error { return sdkerrors.ErrInvalidAddress.Wrapf("admin: %s", err) } - if m.ProjectId == "" { - return sdkerrors.ErrInvalidRequest.Wrap("project id cannot be empty") - } - if err := ValidateProjectId(m.ProjectId); err != nil { - return err + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if _, err := types.AccAddressFromBech32(m.NewAdmin); err != nil { diff --git a/x/ecocredit/core/msg_update_project_metadata.go b/x/ecocredit/core/msg_update_project_metadata.go index 459bb37c73..38e294f122 100644 --- a/x/ecocredit/core/msg_update_project_metadata.go +++ b/x/ecocredit/core/msg_update_project_metadata.go @@ -23,12 +23,8 @@ func (m MsgUpdateProjectMetadata) ValidateBasic() error { return sdkerrors.ErrInvalidAddress.Wrapf("admin: %s", err) } - if m.ProjectId == "" { - return sdkerrors.ErrInvalidRequest.Wrap("project id cannot be empty") - } - if err := ValidateProjectId(m.ProjectId); err != nil { - return err + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if len(m.NewMetadata) > MaxMetadataLength { diff --git a/x/ecocredit/core/types_batch_issuance.go b/x/ecocredit/core/types_batch_issuance.go index f52db72158..e51c290c74 100644 --- a/x/ecocredit/core/types_batch_issuance.go +++ b/x/ecocredit/core/types_batch_issuance.go @@ -30,12 +30,8 @@ func (i *BatchIssuance) Validate() error { } if !retiredAmount.IsZero() { - if i.RetirementJurisdiction == "" { - return sdkerrors.ErrInvalidRequest.Wrap("retirement jurisdiction cannot be empty") - } - if err = ValidateJurisdiction(i.RetirementJurisdiction); err != nil { - return sdkerrors.Wrap(err, "retirement jurisdiction") + return sdkerrors.ErrInvalidRequest.Wrapf("retirement jurisdiction: %s", err.Error()) } } } diff --git a/x/ecocredit/core/types_class.go b/x/ecocredit/core/types_class.go index ecdb415d9a..add78a775b 100644 --- a/x/ecocredit/core/types_class.go +++ b/x/ecocredit/core/types_class.go @@ -17,10 +17,6 @@ func (c Class) Validate() error { return sdkerrors.Wrap(err, "admin") } - if len(c.Id) == 0 { - return sdkerrors.ErrInvalidRequest.Wrap("class id cannot be empty") - } - if err := ValidateClassId(c.Id); err != nil { return err } diff --git a/x/ecocredit/core/types_credit_type_test.go b/x/ecocredit/core/types_credit_type_test.go index 0d60de3873..6bf6f0bf78 100644 --- a/x/ecocredit/core/types_credit_type_test.go +++ b/x/ecocredit/core/types_credit_type_test.go @@ -34,7 +34,7 @@ func TestCreditType_Validate(t *testing.T) { fields: fields{ Abbreviation: "", }, - errMsg: "credit type abbreviation must be 1-3 uppercase latin letters", + errMsg: "credit type abbreviation cannot be empty", }, { name: "invalid: abbreviation too long", diff --git a/x/ecocredit/core/types_credits.go b/x/ecocredit/core/types_credits.go index 8e926a0d7a..747810e4ef 100644 --- a/x/ecocredit/core/types_credits.go +++ b/x/ecocredit/core/types_credits.go @@ -7,12 +7,8 @@ import ( // Validate checks if Credits is valid. func (c *Credits) Validate() error { - if c.BatchDenom == "" { - return sdkerrors.ErrInvalidRequest.Wrap("batch denom cannot be empty") - } - if err := ValidateBatchDenom(c.BatchDenom); err != nil { - return err + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if c.Amount == "" { diff --git a/x/ecocredit/core/utils.go b/x/ecocredit/core/utils.go index bbb4fce673..80ee34c4f3 100644 --- a/x/ecocredit/core/utils.go +++ b/x/ecocredit/core/utils.go @@ -112,9 +112,12 @@ func FormatBatchDenom(projectId string, batchSeqNo uint64, startDate, endDate *t // ValidateCreditTypeAbbreviation validates a credit type abbreviation, ensuring it // is only 1-3 uppercase letters. The return is nil if the abbreviation is valid. func ValidateCreditTypeAbbreviation(abbr string) error { + if abbr == "" { + return ecocredit.ErrParseFailure.Wrap("credit type abbreviation cannot be empty") + } reAbbr := regexp.MustCompile(`^[A-Z]{1,3}$`) if !reAbbr.Match([]byte(abbr)) { - return sdkerrors.ErrInvalidRequest.Wrapf("credit type abbreviation must be 1-3 uppercase latin letters: got %s", abbr) + return ecocredit.ErrParseFailure.Wrapf("credit type abbreviation must be 1-3 uppercase latin letters: got %s", abbr) } return nil } @@ -122,6 +125,9 @@ func ValidateCreditTypeAbbreviation(abbr string) error { // ValidateClassId validates a class ID conforms to the format described in // FormatClassId. The return is nil if the ID is valid. func ValidateClassId(classId string) error { + if classId == "" { + return ecocredit.ErrParseFailure.Wrap("class id cannot be empty") + } matches := regexClassId.FindStringSubmatch(classId) if matches == nil { return ecocredit.ErrParseFailure.Wrapf("class ID didn't match the format: expected A00, got %s", classId) @@ -132,6 +138,9 @@ func ValidateClassId(classId string) error { // ValidateProjectId validates a project ID conforms to the format described // in FormatProjectId. The return is nil if the ID is valid. func ValidateProjectId(projectId string) error { + if projectId == "" { + return ecocredit.ErrParseFailure.Wrap("project id cannot be empty") + } matches := regexProjectId.FindStringSubmatch(projectId) if matches == nil { return sdkerrors.Wrapf(ecocredit.ErrParseFailure, "invalid project id: %s", projectId) @@ -142,6 +151,9 @@ func ValidateProjectId(projectId string) error { // ValidateBatchDenom validates a batch denomination conforms to the format // described in FormatBatchDenom. The return is nil if the denom is valid. func ValidateBatchDenom(denom string) error { + if denom == "" { + return ecocredit.ErrParseFailure.Wrap("batch denom cannot be empty") + } matches := regexBatchDenom.FindStringSubmatch(denom) if matches == nil { return ecocredit.ErrParseFailure.Wrap("invalid batch denom: expected format A00-000-00000000-00000000-000") @@ -155,6 +167,9 @@ func ValidateBatchDenom(denom string) error { // could change at short notice and we don't want to hardfork to keep up-to-date // with that information. The return is nil if the jurisdiction is valid. func ValidateJurisdiction(jurisdiction string) error { + if jurisdiction == "" { + return ecocredit.ErrParseFailure.Wrap("jurisdiction cannot be empty, expected format [-[ ]]") + } matches := regexJurisdiction.FindStringSubmatch(jurisdiction) if matches == nil { return ecocredit.ErrParseFailure.Wrapf("invalid jurisdiction: %s, expected format [-[ ]]", jurisdiction) @@ -250,7 +265,7 @@ func init() { func ExponentToPrefix(exponent uint32) (string, error) { e, ok := exponentPrefixMap[exponent] if !ok { - return "", sdkerrors.ErrInvalidRequest.Wrapf("exponent must be one of %s", validExponents) + return "", ecocredit.ErrParseFailure.Wrapf("exponent must be one of %s", validExponents) } return e, nil } diff --git a/x/ecocredit/marketplace/features/msg_buy_direct.feature b/x/ecocredit/marketplace/features/msg_buy_direct.feature index 8312ab38b9..3b6b1aec9a 100644 --- a/x/ecocredit/marketplace/features/msg_buy_direct.feature +++ b/x/ecocredit/marketplace/features/msg_buy_direct.feature @@ -253,7 +253,7 @@ Feature: MsgBuyDirect } """ When the message is validated - Then expect the error "orders[0]: retirement jurisdiction cannot be empty if auto-retire is disabled: invalid request" + Then expect the error "orders[0]: jurisdiction cannot be empty, expected format [-[ ]]: parse error: invalid request" Scenario: an error is returned if disable auto-retire is true and retirement jurisdiction is not formatted Given the message diff --git a/x/ecocredit/marketplace/features/msg_sell.feature b/x/ecocredit/marketplace/features/msg_sell.feature index b6f950106f..d74c4247ea 100644 --- a/x/ecocredit/marketplace/features/msg_sell.feature +++ b/x/ecocredit/marketplace/features/msg_sell.feature @@ -129,7 +129,7 @@ Feature: MsgSell } """ When the message is validated - Then expect the error "orders[0]: batch denom cannot be empty: invalid request" + Then expect the error "orders[0]: batch denom cannot be empty: parse error: invalid request" Scenario: an error is returned if order batch denom is not formatted Given the message diff --git a/x/ecocredit/marketplace/msg_buy_direct.go b/x/ecocredit/marketplace/msg_buy_direct.go index 35a792661f..14a4991609 100644 --- a/x/ecocredit/marketplace/msg_buy_direct.go +++ b/x/ecocredit/marketplace/msg_buy_direct.go @@ -69,12 +69,6 @@ func (m MsgBuyDirect) ValidateBasic() error { } if !order.DisableAutoRetire { - if len(order.RetirementJurisdiction) == 0 { - return sdkerrors.ErrInvalidRequest.Wrapf( - "%s: retirement jurisdiction cannot be empty if auto-retire is disabled", orderIndex, - ) - } - if err := core.ValidateJurisdiction(order.RetirementJurisdiction); err != nil { return sdkerrors.ErrInvalidRequest.Wrapf("%s: %s", orderIndex, err) } diff --git a/x/ecocredit/marketplace/msg_sell.go b/x/ecocredit/marketplace/msg_sell.go index f493efd997..99446a4593 100644 --- a/x/ecocredit/marketplace/msg_sell.go +++ b/x/ecocredit/marketplace/msg_sell.go @@ -44,10 +44,6 @@ func (m *MsgSell) ValidateBasic() error { // an individual order in a list of orders fails to process orderIndex := fmt.Sprintf("orders[%d]", i) - if len(order.BatchDenom) == 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("%s: batch denom cannot be empty", orderIndex) - } - if err := core.ValidateBatchDenom(order.BatchDenom); err != nil { return sdkerrors.ErrInvalidRequest.Wrapf("%s: %s", orderIndex, err) }