Skip to content

Commit

Permalink
fix: propagate funds validation errors
Browse files Browse the repository at this point in the history
The validation functions on the `tx` type masquerade the root error
message for the `Funds` validation. Having the original error helps to
save time when debugging the cause for a failed tx.

One example is if someone sends multiple funds to a contract execution
without sorting the denoms, which is one of the validations in the
`Coins.Validate` method. With the error propagation, the developer can
quickly determine why the tx failed.
  • Loading branch information
aelesbao committed Oct 4, 2023
1 parent e0da419 commit 6b8b45c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions x/wasm/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (msg MsgInstantiateContract) ValidateBasic() error {
return errorsmod.Wrap(err, "label")
}

if !msg.Funds.IsValid() {
return sdkerrors.ErrInvalidCoins
if err := msg.Funds.Validate(); err != nil {
return errorsmod.Wrap(err, "funds")
}

if len(msg.Admin) != 0 {
Expand Down Expand Up @@ -142,8 +142,8 @@ func (msg MsgExecuteContract) ValidateBasic() error {
return errorsmod.Wrap(err, "contract")
}

if !msg.Funds.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "sentFunds")
if err := msg.Funds.Validate(); err != nil {
return errorsmod.Wrap(err, "funds")
}
if err := msg.Msg.ValidateBasic(); err != nil {
return errorsmod.Wrap(err, "payload msg")
Expand Down Expand Up @@ -336,8 +336,8 @@ func (msg MsgInstantiateContract2) ValidateBasic() error {
return errorsmod.Wrap(err, "label")
}

if !msg.Funds.IsValid() {
return sdkerrors.ErrInvalidCoins
if err := msg.Funds.Validate(); err != nil {
return errorsmod.Wrap(err, "funds")
}

if len(msg.Admin) != 0 {
Expand Down Expand Up @@ -537,8 +537,8 @@ func (msg MsgStoreAndInstantiateContract) ValidateBasic() error {
return errorsmod.Wrap(err, "label")
}

if !msg.Funds.IsValid() {
return sdkerrors.ErrInvalidCoins
if err := msg.Funds.Validate(); err != nil {
return errorsmod.Wrap(err, "funds")
}

if len(msg.Admin) != 0 {
Expand Down

0 comments on commit 6b8b45c

Please sign in to comment.