Skip to content

Commit

Permalink
Revert "chore: migrate to address codec in transfer (#7892)"
Browse files Browse the repository at this point in the history
This reverts commit c0365a3.
  • Loading branch information
gjermundgaraba committed Feb 7, 2025
1 parent 56dde40 commit 3719757
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 51 deletions.
30 changes: 7 additions & 23 deletions e2e/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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"
Expand Down Expand Up @@ -154,13 +153,14 @@ 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("ExecuteGovV1Proposal must be passed a cosmos.CosmosChain")
panic("ExecuteAndPassGovV1Proposal 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
Expand Down Expand Up @@ -189,19 +189,6 @@ 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 {
Expand Down Expand Up @@ -289,13 +276,10 @@ 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 := s.ConvertToAccAddress(chain, user.FormattedAddress())
sender, err := sdk.AccAddressFromBech32(user.FormattedAddress())
s.Require().NoError(err)

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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"
Expand Down Expand Up @@ -109,10 +108,7 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
}

func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) {
addrCdc := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())
expSigerBytes, err := addrCdc.StringToBytes(ibctesting.TestAccAddress)
expSigner := sdk.AccAddress(expSigerBytes)

expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress)
require.NoError(t, err)

msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "", channeltypes.ORDERED)
Expand Down
1 change: 0 additions & 1 deletion modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ 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
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/transfer/keeper/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func (k Keeper) getReceiverFromPacketData(data types.FungibleTokenPacketDataV2)
return k.authKeeper.GetModuleAddress(types.ModuleName), nil
}

receiverBytes, err := k.addrCdc.StringToBytes(data.Receiver)
receiver := sdk.AccAddress(receiverBytes)
receiver, err := sdk.AccAddressFromBech32(data.Receiver)
if err != nil {
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "failed to decode receiver address %s: %v", data.Receiver, err)
}
Expand Down
4 changes: 0 additions & 4 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"strings"

"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
sdkmath "cosmossdk.io/math"
"cosmossdk.io/store/prefix"
Expand All @@ -30,7 +29,6 @@ import (
type Keeper struct {
appmodule.Environment

addrCdc address.Codec
cdc codec.BinaryCodec
legacySubspace types.ParamSubspace

Expand All @@ -47,7 +45,6 @@ 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,
Expand All @@ -67,7 +64,6 @@ func NewKeeper(

return Keeper{
cdc: cdc,
addrCdc: addrCdc,
Environment: env,
legacySubspace: legacySubspace,
ics4Wrapper: ics4Wrapper,
Expand Down
4 changes: 0 additions & 4 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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"
Expand Down Expand Up @@ -59,7 +58,6 @@ 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,
Expand All @@ -72,7 +70,6 @@ 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,
Expand All @@ -85,7 +82,6 @@ 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,
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ func (k Keeper) Transfer(ctx context.Context, msg *types.MsgTransfer) (*types.Ms
return nil, types.ErrSendDisabled
}

senderBytes, err := k.addrCdc.StringToBytes(msg.Sender)
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return nil, err
}
sender := sdk.AccAddress(senderBytes)

coins := msg.GetCoins()

Expand Down
3 changes: 1 addition & 2 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ 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

senderBytes, err := k.addrCdc.StringToBytes(data.Sender)
sender := sdk.AccAddress(senderBytes)
sender, err := sdk.AccAddressFromBech32(data.Sender)
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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"
Expand Down Expand Up @@ -36,8 +35,7 @@ func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams {

// ValidateBasic implements sdk.Msg
func (msg MsgUpdateParams) ValidateBasic() error {
addrCdc := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())
_, err := addrCdc.StringToBytes(msg.Signer)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}
Expand Down
1 change: 0 additions & 1 deletion modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ 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
Expand Down
1 change: 0 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ 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
Expand Down
2 changes: 0 additions & 2 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ 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
Expand Down Expand Up @@ -163,7 +162,6 @@ 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
Expand Down
1 change: 0 additions & 1 deletion testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ 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
Expand Down

0 comments on commit 3719757

Please sign in to comment.