Skip to content

Commit

Permalink
[WIP - POC] revert transfer test (#7315)
Browse files Browse the repository at this point in the history
* revert transfer test

* revert additional commit

* delete files

* remove multiack v1 logic

* remove getcounterpartyv2

* revert packetv1 to packetv2 conversions
  • Loading branch information
bznein authored Sep 19, 2024
1 parent a004929 commit 4de5e72
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 819 deletions.
169 changes: 0 additions & 169 deletions modules/apps/transfer/ibc_module_v2.go

This file was deleted.

5 changes: 5 additions & 0 deletions modules/apps/transfer/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (k Keeper) GetAllForwardedPackets(ctx sdk.Context) []types.ForwardedPacket
return k.getAllForwardedPackets(ctx)
}

// IsBlockedAddr is a wrapper around isBlockedAddr for testing purposes
func (k Keeper) IsBlockedAddr(addr sdk.AccAddress) bool {
return k.isBlockedAddr(addr)
}

// CreatePacketDataBytesFromVersion is a wrapper around createPacketDataBytesFromVersion for testing purposes
func CreatePacketDataBytesFromVersion(appVersion, sender, receiver, memo string, tokens types.Tokens, hops []types.Hop) ([]byte, error) {
return createPacketDataBytesFromVersion(appVersion, sender, receiver, memo, tokens, hops)
Expand Down
46 changes: 5 additions & 41 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper"
)

// Keeper defines the IBC fungible transfer keeper
Expand All @@ -33,51 +32,16 @@ type Keeper struct {
cdc codec.BinaryCodec
legacySubspace types.ParamSubspace

ics4Wrapper porttypes.ICS4Wrapper
channelKeeper types.ChannelKeeper
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
packetServerKeeper packetserverkeeper.Keeper
ics4Wrapper porttypes.ICS4Wrapper
channelKeeper types.ChannelKeeper
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
}

// NewKeeperWithPacketServer creates a new IBC transfer Keeper instance
func NewKeeperWithPacketServer(
cdc codec.BinaryCodec,
storeService corestore.KVStoreService,
legacySubspace types.ParamSubspace,
ics4Wrapper porttypes.ICS4Wrapper,
channelKeeper types.ChannelKeeper,
authKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
packetserverKeeper packetserverkeeper.Keeper,
authority string,
) Keeper {
// ensure ibc transfer module account is set
if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic(errors.New("the IBC transfer module account has not been set"))
}

if strings.TrimSpace(authority) == "" {
panic(errors.New("authority must be non-empty"))
}

return Keeper{
cdc: cdc,
storeService: storeService,
legacySubspace: legacySubspace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
authority: authority,
packetServerKeeper: packetserverKeeper,
}
}

// NewKeeper creates a new IBC transfer Keeper instance
func NewKeeper(
cdc codec.BinaryCodec,
Expand Down Expand Up @@ -421,7 +385,7 @@ func (k Keeper) iterateForwardedPackets(ctx context.Context, cb func(packet type

// IsBlockedAddr checks if the given address is allowed to send or receive tokens.
// The module account is always allowed to send and receive tokens.
func (k Keeper) IsBlockedAddr(addr sdk.AccAddress) bool {
func (k Keeper) isBlockedAddr(addr sdk.AccAddress) bool {
moduleAddr := k.authKeeper.GetModuleAddress(types.ModuleName)
if addr.Equals(moduleAddr) {
return false
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
return nil, errorsmod.Wrapf(types.ErrSendDisabled, err.Error())
}

if k.IsBlockedAddr(sender) {
if k.isBlockedAddr(sender) {
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
}

Expand Down
48 changes: 2 additions & 46 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet, da
return err
}

if k.IsBlockedAddr(receiver) {
if k.isBlockedAddr(receiver) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver)
}

Expand Down Expand Up @@ -346,7 +346,7 @@ func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Pack
if err != nil {
return err
}
if k.IsBlockedAddr(sender) {
if k.isBlockedAddr(sender) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", sender)
}

Expand Down Expand Up @@ -383,50 +383,6 @@ func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Pack
return nil
}

func (k Keeper) refundPacketTokensV2(ctx context.Context, packet channeltypes.PacketV2, data types.FungibleTokenPacketDataV2) error {
// NOTE: packet data type already checked in handler.go

sender, err := sdk.AccAddressFromBech32(data.Sender)
if err != nil {
return err
}
if k.IsBlockedAddr(sender) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", sender)
}

// escrow address for unescrowing tokens back to sender
escrowAddress := types.GetEscrowAddress(types.ModuleName, packet.SourceId)

moduleAccountAddr := k.authKeeper.GetModuleAddress(types.ModuleName)
for _, token := range data.Tokens {
coin, err := token.ToCoin()
if err != nil {
return err
}

// if the token we must refund is prefixed by the source port and channel
// then the tokens were burnt when the packet was sent and we must mint new tokens
if token.Denom.HasPrefix(types.ModuleName, packet.SourceId) {
// mint vouchers back to sender
if err := k.bankKeeper.MintCoins(
ctx, types.ModuleName, sdk.NewCoins(coin),
); err != nil {
return err
}

if err := k.bankKeeper.SendCoins(ctx, moduleAccountAddr, sender, sdk.NewCoins(coin)); err != nil {
panic(fmt.Errorf("unable to send coins from module to account despite previously minting coins to module account: %v", err))
}
} else {
if err := k.unescrowCoin(ctx, escrowAddress, sender, coin); err != nil {
return err
}
}
}

return nil
}

// escrowCoin will send the given coin from the provided sender to the escrow address. It will also
// update the total escrowed amount by adding the escrowed coin's amount to the current total escrow.
func (k Keeper) escrowCoin(ctx context.Context, sender, escrowAddress sdk.AccAddress, coin sdk.Coin) error {
Expand Down
Loading

0 comments on commit 4de5e72

Please sign in to comment.