Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
This commit is contained in:
parent
fb4e8cffaa
commit
1ba896ecb4
@ -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 {
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user