Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zavgorodnii committed Dec 20, 2024
1 parent b3c00a2 commit 6faa789
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/upgrades/v5.0.5/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func CreateUpgradeHandler(
transferChannels := keepers.ChannelKeeper.GetAllChannelsWithPortPrefix(ctx, keepers.TransferKeeper.GetPort(ctx))
for _, channel := range transferChannels {
escrowAddress := transfertypes.GetEscrowAddress(channel.PortId, channel.ChannelId)
ctx.Logger().Info("Saving escrow address", "port_id", channel.PortId, "channel_id",
channel.ChannelId, "address", escrowAddress.String())
keepers.TokenFactoryKeeper.StoreEscrowAddress(ctx, escrowAddress)
}

Expand Down
16 changes: 15 additions & 1 deletion app/upgrades/v5.0.5/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v505_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"testing"

upgradetypes "cosmossdk.io/x/upgrade/types"
Expand All @@ -23,7 +25,7 @@ func (suite *UpgradeTestSuite) SetupTest() {
suite.IBCConnectionTestSuite.SetupTest()
}

func (suite *UpgradeTestSuite) TestOracleUpgrade() {
func (suite *UpgradeTestSuite) TestUpgrade() {
app := suite.GetNeutronZoneApp(suite.ChainA)
ctx := suite.ChainA.GetContext().WithChainID("neutron-1")
t := suite.T()
Expand All @@ -33,5 +35,17 @@ func (suite *UpgradeTestSuite) TestOracleUpgrade() {
Info: "some text here",
Height: 100,
}

var escrowAddresses []sdk.AccAddress
transferChannels := app.IBCKeeper.ChannelKeeper.GetAllChannelsWithPortPrefix(ctx, app.TransferKeeper.GetPort(ctx))
for _, channel := range transferChannels {
escrowAddresses = append(escrowAddresses, transfertypes.GetEscrowAddress(channel.PortId, channel.ChannelId))
}
require.Greater(t, len(escrowAddresses), 0)
require.NoError(t, app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade))

for _, escrowAddress := range escrowAddresses {
require.True(t, app.TokenFactoryKeeper.IsEscrowAddress(ctx, escrowAddress))
}
require.False(t, app.TokenFactoryKeeper.IsEscrowAddress(ctx, []byte{1, 2, 3, 4, 5}))
}
6 changes: 3 additions & 3 deletions x/tokenfactory/keeper/bankactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro
return status.Errorf(codes.Internal, "burning from module accounts is forbidden")
}

if k.isEscrowAddress(ctx, burnFromAcc) {
if k.IsEscrowAddress(ctx, burnFromAcc) {
return status.Errorf(codes.Internal, "burning from escrow accounts is forbidden")
}

Expand Down Expand Up @@ -90,11 +90,11 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr
return status.Errorf(codes.Internal, "force transfer to module accounts is forbidden")
}

if k.isEscrowAddress(ctx, transferFromAcc) {
if k.IsEscrowAddress(ctx, transferFromAcc) {
return status.Errorf(codes.Internal, "force transfer from IBC escrow accounts is forbidden")
}

if k.isEscrowAddress(ctx, transferToAcc) {
if k.IsEscrowAddress(ctx, transferToAcc) {
return status.Errorf(codes.Internal, "force transfer to IBC escrow accounts is forbidden")
}

Expand Down
2 changes: 1 addition & 1 deletion x/tokenfactory/keeper/escrow_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (k Keeper) StoreEscrowAddress(ctx sdk.Context, address sdk.AccAddress) {
prefixStore.Set(address.Bytes(), []byte{0})
}

func (k Keeper) isEscrowAddress(ctx sdk.Context, address sdk.AccAddress) bool {
func (k Keeper) IsEscrowAddress(ctx sdk.Context, address sdk.AccAddress) bool {
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.EscrowAddressKey)
bz := prefixStore.Get(address.Bytes())

Expand Down

0 comments on commit 6faa789

Please sign in to comment.