refactor!: remove global config from x/auth and client (#19447)

This commit is contained in:
Julián Toledano
2024-03-06 13:14:16 +00:00
committed by GitHub
parent 06a398931e
commit 25aea8af8a
140 changed files with 572 additions and 300 deletions
+3 -2
View File
@@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
@@ -71,7 +72,7 @@ func TestMarshalAny(t *testing.T) {
func TestMarshalProtoPubKey(t *testing.T) {
require := require.New(t)
ccfg := testutil.MakeTestEncodingConfig()
ccfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{})
privKey := ed25519.GenPrivKey()
pk := privKey.PubKey()
@@ -111,7 +112,7 @@ func TestMarshalProtoPubKey(t *testing.T) {
// helper functions
func TestMarshalProtoInterfacePubKey(t *testing.T) {
require := require.New(t)
ccfg := testutil.MakeTestEncodingConfig()
ccfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{})
privKey := ed25519.GenPrivKey()
pk := privKey.PubKey()
+55 -13
View File
@@ -3,6 +3,7 @@ package testutil
import (
"github.com/cosmos/gogoproto/proto"
coreaddress "cosmossdk.io/core/address"
"cosmossdk.io/x/tx/signing"
"github.com/cosmos/cosmos-sdk/codec"
@@ -10,34 +11,45 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
)
// CodecOptions are options for creating a test codec.
// CodecOptions are options for creating a test codec. If set, provided address codecs will be prioritized when
// building the InterfaceRegistry and ProtoCodec. If not set, new address bech32 codecs will be created using
// the provided prefixes.
type CodecOptions struct {
AccAddressPrefix string
ValAddressPrefix string
AddressCodec coreaddress.Codec
ValidatorCodec coreaddress.Codec
}
// NewCodecOptionsWithPrefixes returns CodecOptions with provided prefixes.
func NewCodecOptionsWithPrefixes(addressPrefix, validatorPrefix string) CodecOptions {
return CodecOptions{
AccAddressPrefix: addressPrefix,
ValAddressPrefix: validatorPrefix,
}
}
// NewCodecOptionsWithCodecs returns CodecOptions with provided address codecs.
func NewCodecOptionsWithCodecs(addressCodec, validatorCodec coreaddress.Codec) CodecOptions {
return CodecOptions{
AddressCodec: addressCodec,
ValidatorCodec: validatorCodec,
}
}
// NewInterfaceRegistry returns a new InterfaceRegistry with the given options.
func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry {
accAddressPrefix := o.AccAddressPrefix
if accAddressPrefix == "" {
accAddressPrefix = "cosmos"
}
valAddressPrefix := o.ValAddressPrefix
if valAddressPrefix == "" {
valAddressPrefix = "cosmosvaloper"
}
ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.NewBech32Codec(accAddressPrefix),
ValidatorAddressCodec: address.NewBech32Codec(valAddressPrefix),
AddressCodec: o.GetAddressCodec(),
ValidatorAddressCodec: o.GetValidatorCodec(),
},
})
if err != nil {
panic(err)
}
return ir
}
@@ -45,3 +57,33 @@ func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry {
func (o CodecOptions) NewCodec() *codec.ProtoCodec {
return codec.NewProtoCodec(o.NewInterfaceRegistry())
}
// GetAddressCodec returns the address codec. If not address codec was provided it'll create a new one based on the
// bech32 prefix.
func (o CodecOptions) GetAddressCodec() coreaddress.Codec {
if o.AddressCodec != nil {
return o.AddressCodec
}
accAddressPrefix := o.AccAddressPrefix
if accAddressPrefix == "" {
accAddressPrefix = "cosmos"
}
return address.NewBech32Codec(accAddressPrefix)
}
// GetValidatorCodec returns the validator address codec. If not validator codec was provided it'll create a new one
// based on the bech32 prefix.
func (o CodecOptions) GetValidatorCodec() coreaddress.Codec {
if o.ValidatorCodec != nil {
return o.ValidatorCodec
}
valAddressPrefix := o.ValAddressPrefix
if valAddressPrefix == "" {
valAddressPrefix = "cosmosvaloper"
}
return address.NewBech32Codec(valAddressPrefix)
}
+2 -1
View File
@@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
)
@@ -14,7 +15,7 @@ import (
// protowire.ConsumeFieldValue. Discovered from fuzzing.
func TestBadBytesPassedIntoDecoder(t *testing.T) {
data, _ := hex.DecodeString("0A9F010A9C200A2D2F6962632E636F72652E636F6E6E656374696F6E2E76312E4D7367436F6E6E656374696F584F75656E496E6974126B0A0D6962637A65726F636C69656E74120B6962637A65726F636F6E6E1A1C0A0C6962636F6E65636C69656E74120A6962636F6E65636F6E6E00002205312E302E302A283235454635364341373935313335453430393336384536444238313130463232413442453035433212080A0612040A0208011A40143342993E25DA936CDDC7BE3D8F603CA6E9661518D536D0C482E18A0154AA096E438A6B9BCADFCFC2F0D689DCCAF55B96399D67A8361B70F5DA13091E2F929")
cfg := testutil.MakeTestEncodingConfig()
cfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{})
decoder := cfg.TxConfig.TxDecoder()
tx, err := decoder(data)