Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hygiene: add validate fn for Fee #748

Merged
merged 8 commits into from
Jan 21, 2022
35 changes: 20 additions & 15 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,9 @@ func (msg MsgPayPacketFee) ValidateBasic() error {
return ErrRelayersNotNil
}

// if any of the fee's are invalid return an error
if !msg.Fee.AckFee.IsValid() || !msg.Fee.ReceiveFee.IsValid() || !msg.Fee.TimeoutFee.IsValid() {
return sdkerrors.ErrInvalidCoins
}

// if all three fee's are zero or empty return an error
if msg.Fee.AckFee.IsZero() && msg.Fee.ReceiveFee.IsZero() && msg.Fee.TimeoutFee.IsZero() {
return sdkerrors.ErrInvalidCoins
// validate Fee
seantking marked this conversation as resolved.
Show resolved Hide resolved
if err := msg.Fee.Validate(); err != nil {
return err
}

return nil
Expand Down Expand Up @@ -156,20 +151,30 @@ func (fee IdentifiedPacketFee) Validate() error {
return sdkerrors.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress")
}

// enforce relayer is nil
if fee.Relayers != nil {
return ErrRelayersNotNil
}

// validate Fee
seantking marked this conversation as resolved.
Show resolved Hide resolved
if err := fee.Fee.Validate(); err != nil {
return err
}

return nil
}

// Validates that each Fee is valid or if all three Fees are empty or zero
seantking marked this conversation as resolved.
Show resolved Hide resolved
func (fee Fee) Validate() error {
seantking marked this conversation as resolved.
Show resolved Hide resolved
// if any of the fee's are invalid return an error
if !fee.Fee.AckFee.IsValid() || !fee.Fee.ReceiveFee.IsValid() || !fee.Fee.TimeoutFee.IsValid() {
if !fee.AckFee.IsValid() || !fee.ReceiveFee.IsValid() || !fee.TimeoutFee.IsValid() {
return sdkerrors.ErrInvalidCoins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can wrap these errors too like in #741

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// if all three fee's are zero or empty return an error
if fee.Fee.AckFee.IsZero() && fee.Fee.ReceiveFee.IsZero() && fee.Fee.TimeoutFee.IsZero() {
if fee.AckFee.IsZero() && fee.ReceiveFee.IsZero() && fee.TimeoutFee.IsZero() {
return sdkerrors.ErrInvalidCoins
}

// enforce relayer is nil
if fee.Relayers != nil {
return ErrRelayersNotNil
}

return nil
}