Skip to content

Commit

Permalink
Merge pull request #336 from Lockwarr/interchaintxs-module-update
Browse files Browse the repository at this point in the history
fix: modify interchain keeper's accepted parameteres
  • Loading branch information
pr0n00gler authored Nov 3, 2023
2 parents f4a8acd + e071617 commit 7ec64f3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 85 deletions.
7 changes: 3 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ type App struct {
checkTxHandler mev_lane.CheckTx

// Lanes
Mempool blocksdk.Mempool
MEVLane auctionante.MEVLane
Mempool blocksdk.Mempool
MEVLane auctionante.MEVLane
}

func (app *App) GetTestBankKeeper() integration.TestBankKeeper {
Expand Down Expand Up @@ -655,7 +655,7 @@ func New(
contractmanager.NewSudoLimitWrapper(app.ContractManagerKeeper, &app.WasmKeeper),
app.FeeKeeper,
app.BankKeeper,
app.FeeBurnerKeeper,
func(ctx sdk.Context) string { return app.FeeBurnerKeeper.GetParams(ctx).TreasuryAddress },
authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(),
)

Expand Down Expand Up @@ -977,7 +977,6 @@ func New(
mevLane.SetAnteHandler(anteHandler)
baseLane.SetAnteHandler(anteHandler)


app.SetEndBlocker(app.EndBlocker)

handler := blocksdkabci.NewProposalHandler(
Expand Down
4 changes: 2 additions & 2 deletions testutil/interchaintxs/keeper/interchaintxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func InterchainTxsKeeper(
icaControllerKeeper types.ICAControllerKeeper,
channelKeeper types.ChannelKeeper,
bankKeeper types.BankKeeper,
feeburnerKeeper types.FeeBurnerKeeper,
getFeeCollectorAddr types.GetFeeCollectorAddr,
) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
Expand All @@ -50,7 +50,7 @@ func InterchainTxsKeeper(
managerKeeper,
refunderKeeper,
bankKeeper,
feeburnerKeeper,
getFeeCollectorAddr,
authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(),
)

Expand Down
46 changes: 4 additions & 42 deletions testutil/mocks/interchaintxs/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions x/interchaintxs/keeper/ibc_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ func TestHandleAcknowledgement(t *testing.T) {
wmKeeper := mock_types.NewMockWasmKeeper(ctrl)
feeKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl)
bankKeeper := mock_types.NewMockBankKeeper(ctrl)
feeburnerKeeper := mock_types.NewMockFeeBurnerKeeper(ctrl)
icak, infCtx := testkeeper.InterchainTxsKeeper(t, wmKeeper, feeKeeper, icaKeeper, nil, bankKeeper, feeburnerKeeper)
icak, infCtx := testkeeper.InterchainTxsKeeper(t, wmKeeper, feeKeeper, icaKeeper, nil, bankKeeper, func(ctx sdk.Context) string {
return TestFeeCollectorAddr
})
ctx := infCtx.WithGasMeter(sdk.NewGasMeter(1_000_000_000_000))

resACK := channeltypes.Acknowledgement{
Expand Down Expand Up @@ -75,8 +76,9 @@ func TestHandleTimeout(t *testing.T) {
wmKeeper := mock_types.NewMockWasmKeeper(ctrl)
feeKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl)
bankKeeper := mock_types.NewMockBankKeeper(ctrl)
feeburnerKeeper := mock_types.NewMockFeeBurnerKeeper(ctrl)
icak, infCtx := testkeeper.InterchainTxsKeeper(t, wmKeeper, feeKeeper, icaKeeper, nil, bankKeeper, feeburnerKeeper)
icak, infCtx := testkeeper.InterchainTxsKeeper(t, wmKeeper, feeKeeper, icaKeeper, nil, bankKeeper, func(ctx sdk.Context) string {
return TestFeeCollectorAddr
})
ctx := infCtx.WithGasMeter(sdk.NewGasMeter(1_000_000_000_000))
contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)
relayerBech32 := "neutron1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z"
Expand Down Expand Up @@ -113,8 +115,9 @@ func TestHandleChanOpenAck(t *testing.T) {
defer ctrl.Finish()
wmKeeper := mock_types.NewMockWasmKeeper(ctrl)
bankKeeper := mock_types.NewMockBankKeeper(ctrl)
feeburnerKeeper := mock_types.NewMockFeeBurnerKeeper(ctrl)
icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, nil, nil, nil, bankKeeper, feeburnerKeeper)
icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, nil, nil, nil, bankKeeper, func(ctx sdk.Context) string {
return TestFeeCollectorAddr
})
portID := icatypes.ControllerPortPrefix + testutil.TestOwnerAddress + ".ica0"
contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)
channelID := "channel-0"
Expand Down
16 changes: 8 additions & 8 deletions x/interchaintxs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type (
icaControllerKeeper types.ICAControllerKeeper
sudoKeeper types.WasmKeeper
bankKeeper types.BankKeeper
feeBurnerKeeper types.FeeBurnerKeeper
getFeeCollectorAddr types.GetFeeCollectorAddr
authority string
}
)
Expand All @@ -46,7 +46,7 @@ func NewKeeper(
sudoKeeper types.WasmKeeper,
feeKeeper types.FeeRefunderKeeper,
bankKeeper types.BankKeeper,
feeBurnerKeeper types.FeeBurnerKeeper,
getFeeCollectorAddr types.GetFeeCollectorAddr,
authority string,
) *Keeper {
return &Keeper{
Expand All @@ -58,7 +58,7 @@ func NewKeeper(
sudoKeeper: sudoKeeper,
feeKeeper: feeKeeper,
bankKeeper: bankKeeper,
feeBurnerKeeper: feeBurnerKeeper,
getFeeCollectorAddr: getFeeCollectorAddr,
authority: authority,
}
}
Expand All @@ -76,15 +76,15 @@ func (k Keeper) ChargeFee(ctx sdk.Context, payer sdk.AccAddress, fee sdk.Coins)
return errors.Wrapf(sdkerrors.ErrInsufficientFee, "provided fee is less than min governance set ack fee: %s < %s", fee, params.RegisterFee)
}

treasury := k.feeBurnerKeeper.GetParams(ctx).TreasuryAddress
treasuryAddress, err := sdk.AccAddressFromBech32(treasury)
feeCollector := k.getFeeCollectorAddr(ctx)
feeCollectorAddress, err := sdk.AccAddressFromBech32(feeCollector)
if err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to convert treasury, bech32 to AccAddress: %s: %s", treasury, err.Error())
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to convert fee collector, bech32 to AccAddress: %s: %s", feeCollector, err.Error())
}

err = k.bankKeeper.SendCoins(ctx, payer, treasuryAddress, fee)
err = k.bankKeeper.SendCoins(ctx, payer, feeCollectorAddress, fee)
if err != nil {
return errors.Wrapf(err, "failed send fee(%s) from %s to %s", fee, payer, treasury)
return errors.Wrapf(err, "failed send fee(%s) from %s to %s", fee, payer, feeCollectorAddress)
}
return nil
}
Expand Down
28 changes: 10 additions & 18 deletions x/interchaintxs/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/neutron-org/neutron/app/params"
feeburnertypes "github.com/neutron-org/neutron/x/feeburner/types"

icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
feerefundertypes "github.com/neutron-org/neutron/x/feerefunder/types"
Expand All @@ -24,16 +23,17 @@ import (
"github.com/neutron-org/neutron/x/interchaintxs/types"
)

const TestTreasury = "neutron1dua3d89szsmd3vwg0y5a2689ah0g4x68ps8vew"
const TestFeeCollectorAddr = "neutron1dua3d89szsmd3vwg0y5a2689ah0g4x68ps8vew"

func TestRegisterInterchainAccount(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
icaKeeper := mock_types.NewMockICAControllerKeeper(ctrl)
wmKeeper := mock_types.NewMockWasmKeeper(ctrl)
bankKeeper := mock_types.NewMockBankKeeper(ctrl)
feeburnerKeeper := mock_types.NewMockFeeBurnerKeeper(ctrl)
icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, nil, icaKeeper, nil, bankKeeper, feeburnerKeeper)
icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, nil, icaKeeper, nil, bankKeeper, func(ctx sdk.Context) string {
return TestFeeCollectorAddr
})
goCtx := sdk.WrapSDKContext(ctx)

msgRegAcc := types.MsgRegisterInterchainAccount{
Expand Down Expand Up @@ -61,31 +61,22 @@ func TestRegisterInterchainAccount(t *testing.T) {
msgRegAcc.RegisterFee = sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdk.NewInt(1000)))

wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true)
feeburnerKeeper.EXPECT().GetParams(ctx).Return(feeburnertypes.Params{
TreasuryAddress: TestTreasury,
})
bankKeeper.EXPECT().SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestTreasury), msgRegAcc.RegisterFee)
bankKeeper.EXPECT().SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestFeeCollectorAddr), msgRegAcc.RegisterFee)
icaKeeper.EXPECT().RegisterInterchainAccount(ctx, msgRegAcc.ConnectionId, icaOwner.String(), "").Return(fmt.Errorf("failed to register ica"))
resp, err = icak.RegisterInterchainAccount(goCtx, &msgRegAcc)
require.ErrorContains(t, err, "failed to RegisterInterchainAccount")
require.Nil(t, resp)

wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true)
feeburnerKeeper.EXPECT().GetParams(ctx).Return(feeburnertypes.Params{
TreasuryAddress: TestTreasury,
})
bankKeeper.EXPECT().
SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestTreasury), msgRegAcc.RegisterFee).
SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestFeeCollectorAddr), msgRegAcc.RegisterFee).
Return(fmt.Errorf("failed to send coins"))
resp, err = icak.RegisterInterchainAccount(goCtx, &msgRegAcc)
require.ErrorContains(t, err, "failed to send coins")
require.Nil(t, resp)

wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true)
feeburnerKeeper.EXPECT().GetParams(ctx).Return(feeburnertypes.Params{
TreasuryAddress: TestTreasury,
})
bankKeeper.EXPECT().SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestTreasury), msgRegAcc.RegisterFee)
bankKeeper.EXPECT().SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestFeeCollectorAddr), msgRegAcc.RegisterFee)
icaKeeper.EXPECT().RegisterInterchainAccount(ctx, msgRegAcc.ConnectionId, icaOwner.String(), "").Return(nil)
resp, err = icak.RegisterInterchainAccount(goCtx, &msgRegAcc)
require.NoError(t, err)
Expand All @@ -100,8 +91,9 @@ func TestSubmitTx(t *testing.T) {
refundKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl)
channelKeeper := mock_types.NewMockChannelKeeper(ctrl)
bankKeeper := mock_types.NewMockBankKeeper(ctrl)
feeburnerKeeper := mock_types.NewMockFeeBurnerKeeper(ctrl)
icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, refundKeeper, icaKeeper, channelKeeper, bankKeeper, feeburnerKeeper)
icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, refundKeeper, icaKeeper, channelKeeper, bankKeeper, func(ctx sdk.Context) string {
return TestFeeCollectorAddr
})
goCtx := sdk.WrapSDKContext(ctx)

cosmosMsg := codectypes.Any{
Expand Down
5 changes: 0 additions & 5 deletions x/interchaintxs/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
feeburnertypes "github.com/neutron-org/neutron/x/feeburner/types"

feerefundertypes "github.com/neutron-org/neutron/x/feerefunder/types"
)
Expand Down Expand Up @@ -48,7 +47,3 @@ type ChannelKeeper interface {
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
GetConnection(ctx sdk.Context, connectionID string) (ibcexported.ConnectionI, error)
}

type FeeBurnerKeeper interface {
GetParams(ctx sdk.Context) feeburnertypes.Params
}
3 changes: 3 additions & 0 deletions x/interchaintxs/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ func (i ICAOwner) GetContract() sdk.AccAddress {
func (i ICAOwner) GetInterchainAccountID() string {
return i.interchainAccountID
}

// GetFeeCollectorAddr is a function to return the current fee collector address
type GetFeeCollectorAddr func(ctx sdk.Context) string

0 comments on commit 7ec64f3

Please sign in to comment.