Skip to content

Commit

Permalink
fix(x/auth/tx): propagate tx options to signing handlers (#17996)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <[email protected]>
  • Loading branch information
kocubinski and tac0turtle authored Oct 11, 2023
1 parent 54701b7 commit 758d3a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
23 changes: 10 additions & 13 deletions x/auth/tx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ func NewDefaultSigningOptions() (*txsigning.Options, error) {
// NewSigningHandlerMap returns a new txsigning.HandlerMap using the provided ConfigOptions.
// It is recommended to use types.InterfaceRegistry in the field ConfigOptions.FileResolver as shown in
// NewTxConfigWithOptions but this fn does not enforce it.
func NewSigningHandlerMap(configOptions ConfigOptions) (*txsigning.HandlerMap, error) {
func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) {
var err error
configOpts := &configOptions
if configOpts.SigningOptions == nil {
configOpts.SigningOptions, err = NewDefaultSigningOptions()
if err != nil {
Expand Down Expand Up @@ -187,27 +186,25 @@ func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions)
}

var err error
opts := &configOptions
if opts.SigningContext == nil {
signingOpts := configOptions.SigningOptions
if signingOpts == nil {
signingOpts, err = NewDefaultSigningOptions()
if configOptions.SigningContext == nil {
if configOptions.SigningOptions == nil {
configOptions.SigningOptions, err = NewDefaultSigningOptions()
if err != nil {
return nil, err
}
}
if signingOpts.FileResolver == nil {
signingOpts.FileResolver = protoCodec.InterfaceRegistry()
if configOptions.SigningOptions.FileResolver == nil {
configOptions.SigningOptions.FileResolver = protoCodec.InterfaceRegistry()
}
opts.SigningContext, err = txsigning.NewContext(*signingOpts)
configOptions.SigningContext, err = txsigning.NewContext(*configOptions.SigningOptions)
if err != nil {
return nil, err
}
}
txConfig.signingContext = opts.SigningContext
txConfig.signingContext = configOptions.SigningContext

if opts.SigningHandler != nil {
txConfig.handler = opts.SigningHandler
if configOptions.SigningHandler != nil {
txConfig.handler = configOptions.SigningHandler
return txConfig, nil
}

Expand Down
18 changes: 16 additions & 2 deletions x/auth/tx/config_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package tx
package tx_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
txtestutil "github.com/cosmos/cosmos-sdk/x/auth/tx/testutil"
)

Expand All @@ -18,5 +21,16 @@ func TestGenerator(t *testing.T) {
std.RegisterInterfaces(interfaceRegistry)
interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{})
protoCodec := codec.NewProtoCodec(interfaceRegistry)
suite.Run(t, txtestutil.NewTxConfigTestSuite(NewTxConfig(protoCodec, DefaultSignModes)))
suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes)))
}

func TestConfigOptions(t *testing.T) {
interfaceRegistry := types.NewInterfaceRegistry()
protoCodec := codec.NewProtoCodec(interfaceRegistry)
configOptions := tx.ConfigOptions{}
txConfig, err := tx.NewTxConfigWithOptions(protoCodec, configOptions)
require.NoError(t, err)
require.NotNil(t, txConfig)
handler := txConfig.SignModeHandler()
require.NotNil(t, handler)
}

0 comments on commit 758d3a1

Please sign in to comment.