diff --git a/e2e/testsuite/tx.go b/e2e/testsuite/tx.go index c037ebb3d3b..3ed4e496d07 100644 --- a/e2e/testsuite/tx.go +++ b/e2e/testsuite/tx.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" @@ -153,14 +154,13 @@ func (s *E2ETestSuite) ExecuteAndPassGovV1Proposal(ctx context.Context, msg sdk. // ExecuteGovV1Proposal submits a v1 governance proposal using the provided user and message and uses all validators // to vote yes on the proposal. func (s *E2ETestSuite) ExecuteGovV1Proposal(ctx context.Context, msg sdk.Msg, chain ibc.Chain, user ibc.Wallet) error { + sender := s.ConvertToAccAddress(chain, user.FormattedAddress()) + cosmosChain, ok := chain.(*cosmos.CosmosChain) if !ok { - panic("ExecuteAndPassGovV1Proposal must be passed a cosmos.CosmosChain") + panic("ExecuteGovV1Proposal must be passed a cosmos.CosmosChain") } - sender, err := sdk.AccAddressFromBech32(user.FormattedAddress()) - s.Require().NoError(err) - proposalID := s.proposalIDs[cosmosChain.Config().ChainID] defer func() { s.proposalIDs[cosmosChain.Config().ChainID] = proposalID + 1 @@ -189,6 +189,19 @@ func (s *E2ETestSuite) ExecuteGovV1Proposal(ctx context.Context, msg sdk.Msg, ch return s.waitForGovV1ProposalToPass(ctx, cosmosChain, proposalID) } +func (s *E2ETestSuite) ConvertToAccAddress(chain ibc.Chain, formattedAddress string) sdk.AccAddress { + cosmosChain, ok := chain.(*cosmos.CosmosChain) + if !ok { + panic("ConvertToAccAddress must be passed a cosmos.CosmosChain") + } + + addrCdc := addresscodec.NewBech32Codec(cosmosChain.Config().Bech32Prefix) + senderBytes, err := addrCdc.StringToBytes(formattedAddress) + s.Require().NoError(err) + + return sdk.AccAddress(senderBytes) +} + // waitForGovV1ProposalToPass polls for the entire voting period to see if the proposal has passed. // if the proposal has not passed within the duration of the voting period, an error is returned. func (s *E2ETestSuite) waitForGovV1ProposalToPass(ctx context.Context, chain ibc.Chain, proposalID uint64) error { @@ -276,10 +289,13 @@ func (*E2ETestSuite) waitForGovV1Beta1ProposalToPass(ctx context.Context, chain // ExecuteGovV1Beta1Proposal submits a v1beta1 governance proposal using the provided content. func (s *E2ETestSuite) ExecuteGovV1Beta1Proposal(ctx context.Context, chain ibc.Chain, user ibc.Wallet, content govtypesv1beta1.Content) sdk.TxResponse { - sender, err := sdk.AccAddressFromBech32(user.FormattedAddress()) - s.Require().NoError(err) + sender := s.ConvertToAccAddress(chain, user.FormattedAddress()) - msgSubmitProposal, err := govtypesv1beta1.NewMsgSubmitProposal(content, sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, govtypesv1beta1.DefaultMinDepositTokens)), sender.String()) + msgSubmitProposal, err := govtypesv1beta1.NewMsgSubmitProposal( + content, + sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, govtypesv1beta1.DefaultMinDepositTokens)), + sender.String(), + ) s.Require().NoError(err) return s.BroadcastMessages(ctx, chain, user, msgSubmitProposal) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index 33f89d81faf..8f1933b6ba2 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -9,6 +9,7 @@ import ( banktypes "cosmossdk.io/x/bank/types" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -108,7 +109,10 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { } func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { - expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) + addrCdc := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + expSigerBytes, err := addrCdc.StringToBytes(ibctesting.TestAccAddress) + expSigner := sdk.AccAddress(expSigerBytes) + require.NoError(t, err) msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "", channeltypes.ORDERED) diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index e365e260f44..3f0bb978165 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -470,6 +470,7 @@ func NewSimApp( // NOTE: the Transfer Keeper's ICS4Wrapper can later be replaced. app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, + signingCtx.AddressCodec(), runtime.NewEnvironment(runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), logger.With(log.ModuleKey, fmt.Sprintf("x/%s-%s", ibcexported.ModuleName, ibctransfertypes.ModuleName))), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware diff --git a/modules/apps/transfer/keeper/forwarding.go b/modules/apps/transfer/keeper/forwarding.go index fbf015d0413..4d3df776000 100644 --- a/modules/apps/transfer/keeper/forwarding.go +++ b/modules/apps/transfer/keeper/forwarding.go @@ -104,7 +104,8 @@ func (k Keeper) getReceiverFromPacketData(data types.FungibleTokenPacketDataV2) return k.authKeeper.GetModuleAddress(types.ModuleName), nil } - receiver, err := sdk.AccAddressFromBech32(data.Receiver) + receiverBytes, err := k.addrCdc.StringToBytes(data.Receiver) + receiver := sdk.AccAddress(receiverBytes) if err != nil { return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "failed to decode receiver address %s: %v", data.Receiver, err) } diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 786ae1b536c..3300d25df29 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" sdkmath "cosmossdk.io/math" "cosmossdk.io/store/prefix" @@ -29,6 +30,7 @@ import ( type Keeper struct { appmodule.Environment + addrCdc address.Codec cdc codec.BinaryCodec legacySubspace types.ParamSubspace @@ -45,6 +47,7 @@ type Keeper struct { // NewKeeper creates a new IBC transfer Keeper instance func NewKeeper( cdc codec.BinaryCodec, + addrCdc address.Codec, env appmodule.Environment, legacySubspace types.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, @@ -64,6 +67,7 @@ func NewKeeper( return Keeper{ cdc: cdc, + addrCdc: addrCdc, Environment: env, legacySubspace: legacySubspace, ics4Wrapper: ics4Wrapper, diff --git a/modules/apps/transfer/keeper/keeper_test.go b/modules/apps/transfer/keeper/keeper_test.go index 3ff56bd7998..c48eed91846 100644 --- a/modules/apps/transfer/keeper/keeper_test.go +++ b/modules/apps/transfer/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( minttypes "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -58,6 +59,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"success", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), + address.NewBech32Codec(suite.chainA.Bech32Prefix), runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()), suite.chainA.GetSimApp().GetSubspace(types.ModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -70,6 +72,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: transfer module account does not exist", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), + address.NewBech32Codec(suite.chainA.Bech32Prefix), runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()), suite.chainA.GetSimApp().GetSubspace(types.ModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -82,6 +85,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: empty authority", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), + address.NewBech32Codec(suite.chainA.Bech32Prefix), runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()), suite.chainA.GetSimApp().GetSubspace(types.ModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index de57080adeb..13b0f556075 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -20,10 +20,11 @@ func (k Keeper) Transfer(ctx context.Context, msg *types.MsgTransfer) (*types.Ms return nil, types.ErrSendDisabled } - sender, err := sdk.AccAddressFromBech32(msg.Sender) + senderBytes, err := k.addrCdc.StringToBytes(msg.Sender) if err != nil { return nil, err } + sender := sdk.AccAddress(senderBytes) coins := msg.GetCoins() diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 07043402a4c..721a2133938 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -348,7 +348,8 @@ func (k Keeper) OnTimeoutPacket(ctx context.Context, packet channeltypes.Packet, func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { // NOTE: packet data type already checked in handler.go - sender, err := sdk.AccAddressFromBech32(data.Sender) + senderBytes, err := k.addrCdc.StringToBytes(data.Sender) + sender := sdk.AccAddress(senderBytes) if err != nil { return err } diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index a9392292191..83e4ba70dd3 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -5,6 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -35,7 +36,8 @@ func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams { // ValidateBasic implements sdk.Msg func (msg MsgUpdateParams) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.Signer) + addrCdc := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + _, err := addrCdc.StringToBytes(msg.Signer) if err != nil { return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index d7f4d678527..351194fd6c0 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -596,6 +596,7 @@ func NewSimApp( // since fee middleware will wrap the IBCKeeper for underlying application. app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, + signingCtx.AddressCodec(), runtime.NewEnvironment(runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), logger.With(log.ModuleKey, fmt.Sprintf("x/%s-%s", ibcexported.ModuleName, ibctransfertypes.ModuleName))), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware diff --git a/simapp/app.go b/simapp/app.go index f6c6294bad6..74109c1e8da 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -578,6 +578,7 @@ func NewSimApp( // since fee middleware will wrap the IBCKeeper for underlying application. app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, + signingCtx.AddressCodec(), runtime.NewEnvironment(runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), logger.With(log.ModuleKey, fmt.Sprintf("x/%s-%s", ibcexported.ModuleName, ibctransfertypes.ModuleName))), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware diff --git a/testing/chain.go b/testing/chain.go index 357406cb6f5..75e4d6c83c8 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -61,6 +61,7 @@ type TestChain struct { ProposedHeader cmtproto.Header // proposed (uncommitted) header for current block height TxConfig client.TxConfig Codec codec.Codec + Bech32Prefix string Vals *cmttypes.ValidatorSet NextVals *cmttypes.ValidatorSet @@ -162,6 +163,7 @@ func NewTestChainWithValSet(tb testing.TB, coord *Coordinator, chainID string, v SenderPrivKey: senderAccs[0].SenderPrivKey, SenderAccount: senderAccs[0].SenderAccount, SenderAccounts: senderAccs, + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), } // commit genesis block diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 67d2ef173ee..619b0cca006 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -548,6 +548,7 @@ func NewSimApp( // since fee middleware will wrap the IBCKeeper for underlying application. app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, + signingCtx.AddressCodec(), runtime.NewEnvironment(runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), logger.With(log.ModuleKey, fmt.Sprintf("x/%s-%s", ibcexported.ModuleName, ibctransfertypes.ModuleName))), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware