Skip to content

Commit

Permalink
update: NewTxConfig takes address.Codec
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano committed Mar 1, 2024
1 parent e5a743e commit 4d50fff
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 24 deletions.
6 changes: 4 additions & 2 deletions baseapp/abci_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection()
// create a codec for marshaling
cdc := codectestutil.CodecOptions{}.NewCodec()
baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry())
signingCtx := cdc.InterfaceRegistry().SigningContext()

// create a baseapp along with a tx config for tx generation
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder())

// create a proposal handler
Expand Down Expand Up @@ -422,7 +423,8 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection()
func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSelection() {
cdc := codectestutil.CodecOptions{}.NewCodec()
baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry())
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
signingCtx := cdc.InterfaceRegistry().SigningContext()
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)

var (
secret1 = []byte("secret1")
Expand Down
6 changes: 4 additions & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
t.Helper()
cdc := codectestutil.CodecOptions{}.NewCodec()
baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry())
signingCtx := cdc.InterfaceRegistry().SigningContext()

txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
db := dbm.NewMemDB()
logBuffer := new(bytes.Buffer)
logger := log.NewLogger(logBuffer, log.ColorOption(false))
Expand Down Expand Up @@ -500,9 +501,10 @@ func TestBaseAppOptionSeal(t *testing.T) {
func TestTxDecoder(t *testing.T) {
cdc := codectestutil.CodecOptions{}.NewCodec()
baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry())
signingCtx := cdc.InterfaceRegistry().SigningContext()

// patch in TxConfig instead of using an output from x/auth/tx
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)

tx := newTxCounter(t, txConfig, 1, 0)
txBytes, err := txConfig.TxEncoder()(tx)
Expand Down
3 changes: 2 additions & 1 deletion baseapp/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ func TestMsgService(t *testing.T) {
), &appBuilder, &cdc, &interfaceRegistry)
require.NoError(t, err)
app := appBuilder.Build(dbm.NewMemDB(), nil)
signingCtx := interfaceRegistry.SigningContext()

// patch in TxConfig instead of using an output from x/auth/tx
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
// set the TxDecoder in the BaseApp for minimal tx simulations
app.SetTxDecoder(txConfig.TxDecoder())

Expand Down
3 changes: 2 additions & 1 deletion client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (
func newTestTxConfig() (client.TxConfig, codec.Codec) {
encodingConfig := moduletestutil.MakeTestEncodingConfig()
cdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry)
return authtx.NewTxConfig(cdc, authtx.DefaultSignModes), encodingConfig.Codec
signingCtx := encodingConfig.InterfaceRegistry.SigningContext()
return authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), encodingConfig.Codec
}

// mockContext is a mock client.Context to return arbitrary simulation response, used to
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func NewSimApp(
appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
signingCtx := interfaceRegistry.SigningContext()
txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)
Expand Down
3 changes: 2 additions & 1 deletion testutil/integration/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func NewIntegrationApp(
interfaceRegistry := codectypes.NewInterfaceRegistry()
moduleManager := module.NewManagerFromMap(modules)
moduleManager.RegisterInterfaces(interfaceRegistry)
signingCtx := interfaceRegistry.SigningContext()

txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName))
bApp.MountKVStores(keys)

Expand Down
3 changes: 2 additions & 1 deletion testutil/sims/simulation_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose,
// SimulationOperations retrieves the simulation params from the provided file path
// and returns all the modules weighted operations
func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes.Config) []simtypes.WeightedOperation {
signingCtx := cdc.InterfaceRegistry().SigningContext()
simState := module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: cdc,
TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes), // TODO(tip): we should extract this from app
TxConfig: authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), // TODO(tip): we should extract this from app
BondDenom: sdk.DefaultBondDenom,
}

Expand Down
7 changes: 5 additions & 2 deletions types/module/testutil/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig {
aminoCodec := codec.NewLegacyAmino()
interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
signingCtx := cdc.InterfaceRegistry().SigningContext()

encCfg := TestEncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: cdc,
TxConfig: tx.NewTxConfig(cdc, tx.DefaultSignModes),
TxConfig: tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes),
Amino: aminoCodec,
}

Expand All @@ -45,7 +46,9 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig {

func MakeTestTxConfig() client.TxConfig {
interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry()
return tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), tx.DefaultSignModes)
cdc := codec.NewProtoCodec(interfaceRegistry)
signingCtx := interfaceRegistry.SigningContext()
return tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes)
}

type TestBuilderTxConfig struct {
Expand Down
3 changes: 2 additions & 1 deletion x/auth/ante/feegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func TestDeductFeesNoDelegation(t *testing.T) {
t.Run(name, func(t *testing.T) {
suite := SetupTestSuite(t, false)
cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry)
protoTxCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes)
signingCtx := suite.encCfg.InterfaceRegistry.SigningContext()
protoTxCfg := tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes)
// this just tests our handler
dfd := ante.NewDeductFeeDecorator(suite.accountKeeper, suite.bankKeeper, suite.feeGrantKeeper, nil)
feeAnteHandler := sdk.ChainAnteDecorators(dfd)
Expand Down
13 changes: 6 additions & 7 deletions x/auth/tx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"cosmossdk.io/core/address"
authcodec "cosmossdk.io/x/auth/codec"
txdecode "cosmossdk.io/x/tx/decode"
txsigning "cosmossdk.io/x/tx/signing"
"cosmossdk.io/x/tx/signing/aminojson"
Expand Down Expand Up @@ -77,14 +76,14 @@ var DefaultSignModes = []signingtypes.SignMode{
// We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK,
// this constructor is primarily used in tests, but also sees usage in app chains like:
// https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37
func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler,
func NewTxConfig(protoCodec codec.Codec, addressCodec, validatorAddressCodec address.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler,
) client.TxConfig {
txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{
EnabledSignModes: enabledSignModes,
CustomSignModes: customSignModes,
SigningOptions: &txsigning.Options{
AddressCodec: protoCodec.InterfaceRegistry().SigningContext().AddressCodec(),
ValidatorAddressCodec: protoCodec.InterfaceRegistry().SigningContext().ValidatorAddressCodec(),
AddressCodec: addressCodec,
ValidatorAddressCodec: validatorAddressCodec,
},
})
if err != nil {
Expand All @@ -95,10 +94,10 @@ func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMod

// NewSigningOptions returns signing options used by x/tx. This includes account and
// validator address prefix enabled codecs.
func NewSigningOptions(addressPrefix, validatorPrefix string) (*txsigning.Options, error) {
func NewSigningOptions(addressCodec, validatorAddressCodec address.Codec) (*txsigning.Options, error) {
return &txsigning.Options{
AddressCodec: authcodec.NewBech32Codec(addressPrefix),
ValidatorAddressCodec: authcodec.NewBech32Codec(validatorPrefix),
AddressCodec: addressCodec,
ValidatorAddressCodec: validatorAddressCodec,
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions x/auth/tx/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"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"
Expand All @@ -24,15 +23,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(tx.NewTxConfig(protoCodec, tx.DefaultSignModes)))
signingCtx := protoCodec.InterfaceRegistry().SigningContext()
suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes)))
}

func TestConfigOptions(t *testing.T) {
interfaceRegistry := types.NewInterfaceRegistry()
interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry()
protoCodec := codec.NewProtoCodec(interfaceRegistry)
configOptions := tx.ConfigOptions{SigningOptions: &signing.Options{
AddressCodec: protoCodec.InterfaceRegistry().SigningContext().AddressCodec(),
ValidatorAddressCodec: protoCodec.InterfaceRegistry().SigningContext().ValidatorAddressCodec(),
AddressCodec: interfaceRegistry.SigningContext().AddressCodec(),
ValidatorAddressCodec: interfaceRegistry.SigningContext().ValidatorAddressCodec(),
}}
txConfig, err := tx.NewTxConfigWithOptions(protoCodec, configOptions)
require.NoError(t, err)
Expand Down

0 comments on commit 4d50fff

Please sign in to comment.