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 testing for ICA events #5687

Merged
merged 24 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
ec8f18a
Merge branch 'main' into cian/issue#2823-ica-events-testing
chatton Jan 23, 2024
81eb7cc
Merge branch 'main' into cian/issue#2823-ica-events-testing
chatton Jan 24, 2024
c7916b5
Merge branch 'main' into cian/issue#2823-ica-events-testing
chatton Jan 24, 2024
5d62f43
chore: merge main
chatton Jan 25, 2024
2616555
Merge branch 'main' into cian/issue#2823-ica-events-testing
chatton Jan 25, 2024
3d2f1da
Merge branch 'main' into cian/issue#2823-ica-events-testing
crodriguezvega Feb 2, 2024
54b10be
Merge branch 'main' into cian/issue#2823-ica-events-testing
chatton Feb 8, 2024
12dc297
chore: fixing linting errors
chatton Feb 8, 2024
9f18b59
chore: reverted name change
chatton Feb 8, 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
52 changes: 22 additions & 30 deletions e2e/tests/transfer/incentivized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the changes in E2E are linter fixes

)

const (
legacyMessage = "balance should be lowered by sum of recv_fee, ack_fee and timeout_fee"
capitalEfficientMessage = "balance should be lowered by max(recv_fee + ack_fee, timeout_fee)"
)

type IncentivizedTransferTestSuite struct {
TransferTestSuite
}
Expand Down Expand Up @@ -118,12 +123,7 @@ func (s *IncentivizedTransferTestSuite) TestMsgPayPacketFee_AsyncSingleSender_Su
s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee))
})

msg := "balance should be lowered by max(recv_fee + ack_fee, timeout_fee)"
escrowTotalFee := testFee.Total()
if !testvalues.CapitalEfficientFeeEscrowFeatureReleases.IsSupported(chainAVersion) {
msg = "balance should be lowered by sum of recv_fee, ack_fee and timeout_fee"
escrowTotalFee = testFee.RecvFee.Add(testFee.AckFee...).Add(testFee.TimeoutFee...)
}
msg, escrowTotalFee := getMessageAndFee(testFee, chainAVersion)
t.Run(msg, func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
Expand Down Expand Up @@ -237,12 +237,7 @@ func (s *IncentivizedTransferTestSuite) TestMsgPayPacketFee_InvalidReceiverAccou
s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee))
})

msg := "balance should be lowered by max(recv_fee + ack_fee, timeout_fee)"
escrowTotalFee := testFee.Total()
if !testvalues.CapitalEfficientFeeEscrowFeatureReleases.IsSupported(chainAVersion) {
msg = "balance should be lowered by sum of recv_fee, ack_fee and timeout_fee"
escrowTotalFee = testFee.RecvFee.Add(testFee.AckFee...).Add(testFee.TimeoutFee...)
}
msg, escrowTotalFee := getMessageAndFee(testFee, chainAVersion)
t.Run(msg, func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
Expand Down Expand Up @@ -342,12 +337,7 @@ func (s *IncentivizedTransferTestSuite) TestMultiMsg_MsgPayPacketFeeSingleSender
s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee))
})

msg := "balance should be lowered by max(recv_fee + ack_fee, timeout_fee)"
escrowTotalFee := testFee.Total()
if !testvalues.CapitalEfficientFeeEscrowFeatureReleases.IsSupported(chainAVersion) {
msg = "balance should be lowered by sum of recv_fee, ack_fee and timeout_fee"
escrowTotalFee = testFee.RecvFee.Add(testFee.AckFee...).Add(testFee.TimeoutFee...)
}
msg, escrowTotalFee := getMessageAndFee(testFee, chainAVersion)
t.Run(msg, func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
Expand Down Expand Up @@ -470,12 +460,7 @@ func (s *IncentivizedTransferTestSuite) TestMsgPayPacketFee_SingleSender_TimesOu
s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee))
})

msg := "balance should be lowered by max(recv_fee + ack_fee, timeout_fee)"
escrowTotalFee := testFee.Total()
if !testvalues.CapitalEfficientFeeEscrowFeatureReleases.IsSupported(chainAVersion) {
msg = "balance should be lowered by sum of recv_fee, ack_fee and timeout_fee"
escrowTotalFee = testFee.RecvFee.Add(testFee.AckFee...).Add(testFee.TimeoutFee...)
}
msg, escrowTotalFee := getMessageAndFee(testFee, chainAVersion)
t.Run(msg, func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
Expand Down Expand Up @@ -574,12 +559,7 @@ func (s *IncentivizedTransferTestSuite) TestPayPacketFeeAsync_SingleSender_NoCou
})
})

msg := "balance should be lowered by max(recv_fee + ack_fee, timeout_fee)"
escrowTotalFee := testFee.Total()
if !testvalues.CapitalEfficientFeeEscrowFeatureReleases.IsSupported(chainAVersion) {
msg = "balance should be lowered by sum of recv_fee, ack_fee and timeout_fee"
escrowTotalFee = testFee.RecvFee.Add(testFee.AckFee...).Add(testFee.TimeoutFee...)
}
msg, escrowTotalFee := getMessageAndFee(testFee, chainAVersion)
t.Run(msg, func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
Expand Down Expand Up @@ -760,3 +740,15 @@ func (s *IncentivizedTransferTestSuite) TestMsgPayPacketFee_AsyncMultipleSenders
s.Require().Equal(expected2, actualBalance2)
})
}

// getMessageAndFee returns the message that should be used for t.Run as well as the expected fee based on
// whether or not capital efficient fee escrow is supported.
func getMessageAndFee(fee feetypes.Fee, chainVersion string) (string, sdk.Coins) {
msg := capitalEfficientMessage
escrowTotalFee := fee.Total()
if !testvalues.CapitalEfficientFeeEscrowFeatureReleases.IsSupported(chainVersion) {
msg = legacyMessage
escrowTotalFee = fee.RecvFee.Add(fee.AckFee...).Add(fee.TimeoutFee...)
}
return msg, escrowTotalFee
}
8 changes: 6 additions & 2 deletions e2e/testsuite/sanitize/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
panic(err)
}
sanitizedMsgs := Messages(tag, msgs...)
msg.SetMsgs(sanitizedMsgs)
if err := msg.SetMsgs(sanitizedMsgs); err != nil {
panic(err)
}
return msg
case *grouptypes.MsgSubmitProposal:
if !groupsv1ProposalTitleAndSummary.IsSupported(tag) {
Expand All @@ -66,7 +68,9 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
panic(err)
}
sanitizedMsgs := Messages(tag, msgs...)
msg.SetMsgs(sanitizedMsgs)
if err := msg.SetMsgs(sanitizedMsgs); err != nil {
panic(err)
}
return msg
case *icacontrollertypes.MsgRegisterInterchainAccount:
if !icaUnorderedChannelFeatureReleases.IsSupported(tag) {
Expand Down
1 change: 1 addition & 0 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
sdkmath "cosmossdk.io/math"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/ibc-go/e2e/relayer"
"github.com/cosmos/ibc-go/e2e/testsuite/diagnostics"
feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,22 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
0,
)

ack := cbs.OnRecvPacket(suite.chainA.GetContext(), packet, nil)
ctx := suite.chainA.GetContext()
ack := cbs.OnRecvPacket(ctx, packet, nil)
suite.Require().Equal(tc.expPass, ack.Success())

expectedEvents := sdk.Events{
sdk.NewEvent(
icatypes.EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
sdk.NewAttribute(icatypes.AttributeKeyControllerChannelID, packet.GetDestChannel()),
sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", false)),
sdk.NewAttribute(icatypes.AttributeKeyAckError, "cannot receive packet on controller chain: invalid message sent to channel end"),
),
}.ToABCIEvents()

expectedEvents = sdk.MarkEventsToIndex(expectedEvents, map[string]struct{}{})
ibctesting.AssertEvents(&suite.Suite, expectedEvents, ctx.EventManager().Events().ToABCIEvents())
})
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (im IBCModule) OnRecvPacket(
logger := im.keeper.Logger(ctx)
if !im.keeper.GetParams(ctx).HostEnabled {
logger.Info("host submodule is disabled")
keeper.EmitHostDisabledEvent(ctx, packet)
return channeltypes.NewErrorAcknowledgement(types.ErrHostSubModuleDisabled)
}

Expand Down
38 changes: 36 additions & 2 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,16 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
name string
malleate func()
expAckSuccess bool
eventErrorMsg string
}{
{
"success", func() {}, true,
"success", func() {}, true, "",
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, false,
types.ErrHostSubModuleDisabled.Error(),
},
{
"success with ICA auth module callback failure", func() {
Expand All @@ -417,11 +419,13 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
return channeltypes.NewErrorAcknowledgement(fmt.Errorf("failed OnRecvPacket mock callback"))
}
}, true,
"failed OnRecvPacket mock callback",
},
{
"ICA OnRecvPacket fails - cannot unmarshal packet data", func() {
packetData = []byte("invalid data")
}, false,
"cannot unmarshal ICS-27 interchain account packet data: unknown data type",
},
}

Expand Down Expand Up @@ -487,12 +491,42 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
cbs, ok := suite.chainB.App.GetIBCKeeper().Router.GetRoute(module)
suite.Require().True(ok)

ack := cbs.OnRecvPacket(suite.chainB.GetContext(), packet, nil)
ctx := suite.chainB.GetContext()
ack := cbs.OnRecvPacket(ctx, packet, nil)

expectedAttributes := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()),
sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
}

if tc.expAckSuccess {
suite.Require().True(ack.Success())
suite.Require().Equal(expectedAck, ack)

expectedEvents := sdk.Events{
sdk.NewEvent(
icatypes.EventTypePacket,
expectedAttributes...,
),
}.ToABCIEvents()

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

} else {
suite.Require().False(ack.Success())

expectedAttributes = append(expectedAttributes, sdk.NewAttribute(icatypes.AttributeKeyAckError, tc.eventErrorMsg))
expectedEvents := sdk.Events{
sdk.NewEvent(
icatypes.EventTypePacket,
expectedAttributes...,
),
}.ToABCIEvents()

expectedEvents = sdk.MarkEventsToIndex(expectedEvents, map[string]struct{}{})
ibctesting.AssertEvents(&suite.Suite, expectedEvents, ctx.EventManager().Events().ToABCIEvents())
}
})
}
Expand Down
14 changes: 14 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand All @@ -30,3 +31,16 @@ func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack e
),
)
}

// EmitHostDisabledEvent emits an event signalling that the host submodule is disabled.
func EmitHostDisabledEvent(ctx sdk.Context, packet channeltypes.Packet) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
icatypes.EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()),
sdk.NewAttribute(icatypes.AttributeKeyAckError, types.ErrHostSubModuleDisabled.Error()),
sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, "false"),
),
)
}
Loading