Skip to content

Commit

Permalink
fix(x/auth/tx): avoid panic from newWrapperFromDecodedTx
Browse files Browse the repository at this point in the history
when AuthInfo.Fee is optional in decodedTx
  • Loading branch information
mmsqe committed Jan 4, 2025
1 parent d8c8458 commit d8bc36f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### Bug Fixes

* (query) [23002](https://github.com/cosmos/cosmos-sdk/pull/23002) Fix collection filtered pagination.
* (x/auth/tx) [#23170](https://github.com/cosmos/cosmos-sdk/pull/23170) Avoid panic from newWrapperFromDecodedTx when AuthInfo.Fee is optional in decodedTx.

### API Breaking Changes

Expand Down
3 changes: 3 additions & 0 deletions x/auth/tx/gogotx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (
func newWrapperFromDecodedTx(
addrCodec address.Codec, cdc codec.BinaryCodec, decodedTx *decode.DecodedTx,
) (*gogoTxWrapper, error) {
if decodedTx.Tx.AuthInfo.Fee == nil {
return nil, fmt.Errorf("missing fee")
}
var (
fees = sdk.Coins{} // decodedTx.Tx.AuthInfo.Fee.Amount might be nil
err error
Expand Down
26 changes: 26 additions & 0 deletions x/auth/tx/gogotx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tx

import (
"testing"

v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
"cosmossdk.io/x/tx/decode"
"github.com/cosmos/cosmos-sdk/codec"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

func TestNewWrapperFromDecodedTx(t *testing.T) {
addrCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())
codecOpt := codectestutil.CodecOptions{}
interfaceRegistry := codecOpt.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
_, err := newWrapperFromDecodedTx(addrCodec, cdc, &decode.DecodedTx{
Tx: &v1beta1.Tx{
AuthInfo: &v1beta1.AuthInfo{},
},
})
require.NotNil(t, err)
}

0 comments on commit d8bc36f

Please sign in to comment.