diff --git a/x/ecocredit/marketplace/types/v1/features/msg_set_marketplace_fees.feature b/x/ecocredit/marketplace/types/v1/features/msg_set_marketplace_fees.feature new file mode 100644 index 0000000000..5b727956f3 --- /dev/null +++ b/x/ecocredit/marketplace/types/v1/features/msg_set_marketplace_fees.feature @@ -0,0 +1,41 @@ +Feature: MsgSetMarketplaceFees + + Scenario: a valid message + Given the message + """ + { + "authority": "regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw", + "buyer_percentage_fee": "0.01", + "seller_percentage_fee": "0.01", + } + """ + When the message is validated + Then expect no error + + Scenario: an error is returned if authority 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 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 fee params is empty + Given the message + """ + { + "authority": "regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw" + } + """ + When the message is validated + Then expect the error "buyer_percentage_fee: non-empty value required" \ No newline at end of file diff --git a/x/ecocredit/marketplace/types/v1/features/state_fee_params.feature b/x/ecocredit/marketplace/types/v1/features/state_fee_params.feature new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/ecocredit/marketplace/types/v1/msg_set_marketplace_fees.go b/x/ecocredit/marketplace/types/v1/msg_set_marketplace_fees.go index 377418dce9..b1cdffa7b0 100644 --- a/x/ecocredit/marketplace/types/v1/msg_set_marketplace_fees.go +++ b/x/ecocredit/marketplace/types/v1/msg_set_marketplace_fees.go @@ -3,20 +3,13 @@ package v1 import ( "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - - "github.com/regen-network/regen-ledger/types/v2/math" ) var _ legacytx.LegacyMsg = &MsgSetMarketplaceFees{} // ValidateBasic does a sanity check on the provided data. func (m *MsgSetMarketplaceFees) ValidateBasic() error { - _, err := math.NewPositiveDecFromString(m.Fees.BuyerPercentageFee) - if err != nil { - return err - } - - _, err = math.NewPositiveDecFromString(m.Fees.SellerPercentageFee) + err := m.Fees.Validate() if err != nil { return err } diff --git a/x/ecocredit/marketplace/types/v1/state_fee_params.go b/x/ecocredit/marketplace/types/v1/state_fee_params.go new file mode 100644 index 0000000000..ba8a30ca5b --- /dev/null +++ b/x/ecocredit/marketplace/types/v1/state_fee_params.go @@ -0,0 +1,18 @@ +package v1 + +import "github.com/regen-network/regen-ledger/types/v2/math" + +// Validate performs basic validation of the FeeParams state type. +func (m *FeeParams) Validate() error { + _, err := math.NewPositiveDecFromString(m.BuyerPercentageFee) + if err != nil { + return err + } + + _, err = math.NewPositiveDecFromString(m.SellerPercentageFee) + if err != nil { + return err + } + + return nil +}