Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for fee events #5706

Merged
merged 27 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
452167b
test: adding TestMsgConnectionOpenInitEvents
chatton Jan 22, 2024
b885208
test: adding TestMsgConnectionOpenTryEvents
chatton Jan 22, 2024
27d266e
test: adding TestMsgConnectionOpenAckEvents
chatton Jan 22, 2024
c2adf1b
test: adding TestMsgConnectionOpenConfirmEvents
chatton Jan 22, 2024
1aa723e
test: adding TestMsgCreateClientEvent
chatton Jan 22, 2024
3e038fd
test: adding TestMsgUpdateClientEvents
chatton Jan 22, 2024
8f8258e
test: adding TestMsgUpgradeClientEvents
chatton Jan 22, 2024
4db951d
test: adding event test for recover client
chatton Jan 23, 2024
c848868
test: refactor upgrade client test to use existing test
chatton Jan 23, 2024
cbd165e
test: add test for ibc software upgrade
chatton Jan 23, 2024
a1a8acb
chore: linting
chatton Jan 23, 2024
29ba8eb
wip: adding ica events test
chatton Jan 23, 2024
9d4a757
test: adding event tests for controller OnRecvPacket
chatton Jan 23, 2024
ff94a32
test: adding test for host recv packet
chatton Jan 23, 2024
4e86201
Merge branch 'main' into cian/issue#2823-ica-events-testing
chatton Jan 23, 2024
6152729
test: adding test for incentivized ibc packet events
chatton Jan 23, 2024
b6cd1dd
test: add events from RegisterPayee
chatton Jan 24, 2024
1907d74
test: adding test for register counterparty payee events
chatton Jan 24, 2024
b87bd3f
chore: run linter
chatton Jan 24, 2024
4a57af9
Merge branch 'main' into cian/issue#2823-fee-events
chatton Jan 24, 2024
be3e930
chore: run linter
chatton Jan 24, 2024
2c0d09c
chore: merge main
chatton Feb 8, 2024
793e869
chore: run linter
chatton Feb 8, 2024
baa2028
chore: remove duplicate import
chatton Feb 8, 2024
3242c26
Merge branch 'main' into cian/issue#2823-fee-events
chatton Feb 12, 2024
757e653
Merge branch 'main' into cian/issue#2823-fee-events
chatton Feb 14, 2024
086e463
Merge branch 'main' into cian/issue#2823-fee-events
chatton Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper_test

import (
"fmt"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -72,7 +74,8 @@ func (suite *KeeperTestSuite) TestRegisterPayee() {

tc.malleate()

res, err := suite.chainA.GetSimApp().IBCFeeKeeper.RegisterPayee(suite.chainA.GetContext(), msg)
ctx := suite.chainA.GetContext()
res, err := suite.chainA.GetSimApp().IBCFeeKeeper.RegisterPayee(ctx, msg)

if tc.expPass {
suite.Require().NoError(err)
Expand All @@ -86,6 +89,19 @@ func (suite *KeeperTestSuite) TestRegisterPayee() {

suite.Require().True(found)
suite.Require().Equal(suite.chainA.SenderAccounts[1].SenderAccount.GetAddress().String(), payeeAddr)

expectedEvents := sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterPayee,
sdk.NewAttribute(types.AttributeKeyRelayer, suite.chainA.SenderAccount.GetAddress().String()),
sdk.NewAttribute(types.AttributeKeyPayee, payeeAddr),
sdk.NewAttribute(types.AttributeKeyChannelID, suite.path.EndpointA.ChannelID),
),
}.ToABCIEvents()

expectedEvents = sdk.MarkEventsToIndex(expectedEvents, map[string]struct{}{})
ibctesting.AssertEvents(&suite.Suite, expectedEvents, ctx.EventManager().Events().ToABCIEvents())

} else {
suite.Require().Error(err)
}
Expand Down Expand Up @@ -148,7 +164,8 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyPayee() {

tc.malleate()

res, err := suite.chainA.GetSimApp().IBCFeeKeeper.RegisterCounterpartyPayee(suite.chainA.GetContext(), msg)
ctx := suite.chainA.GetContext()
res, err := suite.chainA.GetSimApp().IBCFeeKeeper.RegisterCounterpartyPayee(ctx, msg)

if tc.expPass {
suite.Require().NoError(err)
Expand All @@ -162,6 +179,19 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyPayee() {

suite.Require().True(found)
suite.Require().Equal(expCounterpartyPayee, counterpartyPayee)

expectedEvents := sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterCounterpartyPayee,
sdk.NewAttribute(types.AttributeKeyRelayer, suite.chainA.SenderAccount.GetAddress().String()),
sdk.NewAttribute(types.AttributeKeyCounterpartyPayee, counterpartyPayee),
sdk.NewAttribute(types.AttributeKeyChannelID, ibctesting.FirstChannelID),
),
}.ToABCIEvents()

expectedEvents = sdk.MarkEventsToIndex(expectedEvents, map[string]struct{}{})
ibctesting.AssertEvents(&suite.Suite, expectedEvents, ctx.EventManager().Events().ToABCIEvents())

} else {
suite.Require().Error(err)
}
Expand All @@ -174,6 +204,7 @@ func (suite *KeeperTestSuite) TestPayPacketFee() {
expFeesInEscrow []types.PacketFee
msg *types.MsgPayPacketFee
fee types.Fee
eventFee types.Fee
)

testCases := []struct {
Expand All @@ -189,18 +220,20 @@ func (suite *KeeperTestSuite) TestPayPacketFee() {
{
"success with existing packet fees in escrow",
func() {
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
escrowFee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)

packetID := channeltypes.NewPacketID(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 1)
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), nil)
packetFee := types.NewPacketFee(escrowFee, suite.chainA.SenderAccount.GetAddress().String(), nil)
feesInEscrow := types.NewPacketFees([]types.PacketFee{packetFee})

suite.chainA.GetSimApp().IBCFeeKeeper.SetFeesInEscrow(suite.chainA.GetContext(), packetID, feesInEscrow)
err := suite.chainA.GetSimApp().BankKeeper.SendCoinsFromAccountToModule(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), types.ModuleName, fee.Total())
err := suite.chainA.GetSimApp().BankKeeper.SendCoinsFromAccountToModule(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), types.ModuleName, escrowFee.Total())
suite.Require().NoError(err)

expEscrowBalance = expEscrowBalance.Add(fee.Total()...)
expEscrowBalance = expEscrowBalance.Add(escrowFee.Total()...)
expFeesInEscrow = append(expFeesInEscrow, packetFee)

eventFee = types.NewFee(defaultRecvFee.Add(escrowFee.RecvFee...), defaultAckFee.Add(escrowFee.AckFee...), defaultTimeoutFee.Add(escrowFee.TimeoutFee...))
},
true,
},
Expand Down Expand Up @@ -317,10 +350,12 @@ func (suite *KeeperTestSuite) TestPayPacketFee() {
expEscrowBalance = fee.Total()
expPacketFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), nil)
expFeesInEscrow = []types.PacketFee{expPacketFee}
eventFee = fee

tc.malleate()

_, err := suite.chainA.GetSimApp().IBCFeeKeeper.PayPacketFee(suite.chainA.GetContext(), msg)
ctx := suite.chainA.GetContext()
_, err := suite.chainA.GetSimApp().IBCFeeKeeper.PayPacketFee(ctx, msg)

if tc.expPass {
suite.Require().NoError(err) // message committed
Expand All @@ -332,6 +367,22 @@ func (suite *KeeperTestSuite) TestPayPacketFee() {

escrowBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.DefaultBondDenom)
suite.Require().Equal(expEscrowBalance.AmountOf(sdk.DefaultBondDenom), escrowBalance.Amount)

expectedEvents := sdk.Events{
sdk.NewEvent(
types.EventTypeIncentivizedPacket,
sdk.NewAttribute(channeltypes.AttributeKeyPortID, packetID.PortId),
sdk.NewAttribute(channeltypes.AttributeKeyChannelID, packetID.ChannelId),
sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(packetID.Sequence)),
sdk.NewAttribute(types.AttributeKeyRecvFee, eventFee.RecvFee.String()),
sdk.NewAttribute(types.AttributeKeyAckFee, eventFee.AckFee.String()),
sdk.NewAttribute(types.AttributeKeyTimeoutFee, eventFee.TimeoutFee.String()),
),
}.ToABCIEvents()

expectedEvents = sdk.MarkEventsToIndex(expectedEvents, map[string]struct{}{})
ibctesting.AssertEvents(&suite.Suite, expectedEvents, ctx.EventManager().Events().ToABCIEvents())

} else {
suite.Require().Error(err)

Expand Down
Loading