Skip to content

Commit

Permalink
Merge branch 'main' into update_module_newmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba authored Jan 29, 2025
2 parents 1834e39 + c0365a3 commit c631be5
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 12 deletions.
30 changes: 23 additions & 7 deletions e2e/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/keeper/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

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

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

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

return Keeper{
cdc: cdc,
addrCdc: addrCdc,
Environment: env,
legacySubspace: legacySubspace,
ics4Wrapper: ics4Wrapper,
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c631be5

Please sign in to comment.