Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Jan 31, 2024
1 parent f82c581 commit 0835631
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Empty file.
9 changes: 1 addition & 8 deletions x/ecocredit/marketplace/types/v1/msg_set_marketplace_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions x/ecocredit/marketplace/types/v1/state_fee_params.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 0835631

Please sign in to comment.