From 01f62b6923a2c7bc2ac91ced82ee13b6dabc656d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:02:43 +0200 Subject: [PATCH 1/2] refactor: change sdk.Events usage to []abci.Event --- modules/apps/29-fee/keeper/events_test.go | 8 ++++---- modules/apps/29-fee/transfer_test.go | 2 +- modules/apps/transfer/keeper/msg_server_test.go | 2 +- modules/apps/transfer/keeper/relay_test.go | 6 +++--- modules/apps/transfer/transfer_test.go | 6 +++--- testing/endpoint.go | 10 +++++----- testing/events.go | 14 +++++++------- testing/path.go | 4 ++-- testing/solomachine.go | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/apps/29-fee/keeper/events_test.go b/modules/apps/29-fee/keeper/events_test.go index 2cd5b265b6d..f2d5c34d9ae 100644 --- a/modules/apps/29-fee/keeper/events_test.go +++ b/modules/apps/29-fee/keeper/events_test.go @@ -122,7 +122,7 @@ func (suite *KeeperTestSuite) TestDistributeFeeEvent() { suite.Require().NotNil(res) // parse the packet from result events and recv packet on chainB - packet, err := ibctesting.ParsePacketFromEvents(res.GetEvents()) + packet, err := ibctesting.ParsePacketFromEvents(res.Events) suite.Require().NoError(err) suite.Require().NotNil(packet) @@ -134,7 +134,7 @@ func (suite *KeeperTestSuite) TestDistributeFeeEvent() { suite.Require().NotNil(res) // parse the acknowledgement from result events and acknowledge packet on chainA - ack, err := ibctesting.ParseAckFromEvents(res.GetEvents()) + ack, err := ibctesting.ParseAckFromEvents(res.Events) suite.Require().NoError(err) suite.Require().NotNil(ack) @@ -146,7 +146,7 @@ func (suite *KeeperTestSuite) TestDistributeFeeEvent() { suite.Require().NoError(err) suite.Require().NotNil(res) - events := res.GetEvents() + events := res.Events expectedEvents := sdk.Events{ sdk.NewEvent( types.EventTypeDistributeFee, @@ -163,7 +163,7 @@ func (suite *KeeperTestSuite) TestDistributeFeeEvent() { sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()), sdk.NewAttribute(types.AttributeKeyFee, defaultTimeoutFee.String()), ), - } + }.ToABCIEvents() for _, evt := range expectedEvents { suite.Require().Contains(events, evt) diff --git a/modules/apps/29-fee/transfer_test.go b/modules/apps/29-fee/transfer_test.go index 7cf070113ec..0cdc934daf7 100644 --- a/modules/apps/29-fee/transfer_test.go +++ b/modules/apps/29-fee/transfer_test.go @@ -38,7 +38,7 @@ func (suite *FeeTestSuite) TestFeeTransfer() { // after incentivizing the packets originalChainASenderAccountBalance := sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom)) - packet, err := ibctesting.ParsePacketFromEvents(res.GetEvents()) + packet, err := ibctesting.ParsePacketFromEvents(res.Events) suite.Require().NoError(err) // register counterparty address on chainB diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 552d43be0d4..e8c3a0a099b 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -104,7 +104,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(ctx), msg) // Verify events - events := ctx.EventManager().Events() + events := ctx.EventManager().Events().ToABCIEvents() expEvents := ibctesting.EventsMap{ "ibc_transfer": { "sender": suite.chainA.SenderAccount.GetAddress().String(), diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 6d723cd107c..d591402e020 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -126,7 +126,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { result, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed - packet, err := ibctesting.ParsePacketFromEvents(result.GetEvents()) + packet, err := ibctesting.ParsePacketFromEvents(result.Events) suite.Require().NoError(err) err = path.RelayPacket(packet) @@ -210,7 +210,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT result, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed - packet, err := ibctesting.ParsePacketFromEvents(result.GetEvents()) + packet, err := ibctesting.ParsePacketFromEvents(result.Events) suite.Require().NoError(err) err = path1.RelayPacket(packet) @@ -357,7 +357,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { res, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed - packet, err := ibctesting.ParsePacketFromEvents(res.GetEvents()) + packet, err := ibctesting.ParsePacketFromEvents(res.Events) suite.Require().NoError(err) err = path.RelayPacket(packet) diff --git a/modules/apps/transfer/transfer_test.go b/modules/apps/transfer/transfer_test.go index 74315f35fd6..a213147baa9 100644 --- a/modules/apps/transfer/transfer_test.go +++ b/modules/apps/transfer/transfer_test.go @@ -66,7 +66,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { res, err := suite.chainA.SendMsgs(msg) suite.Require().NoError(err) // message committed - packet, err := ibctesting.ParsePacketFromEvents(res.GetEvents()) + packet, err := ibctesting.ParsePacketFromEvents(res.Events) suite.Require().NoError(err) // relay send @@ -96,7 +96,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { res, err = suite.chainB.SendMsgs(msg) suite.Require().NoError(err) // message committed - packet, err = ibctesting.ParsePacketFromEvents(res.GetEvents()) + packet, err = ibctesting.ParsePacketFromEvents(res.Events) suite.Require().NoError(err) err = pathBtoC.RelayPacket(packet) @@ -119,7 +119,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { res, err = suite.chainC.SendMsgs(msg) suite.Require().NoError(err) // message committed - packet, err = ibctesting.ParsePacketFromEvents(res.GetEvents()) + packet, err = ibctesting.ParsePacketFromEvents(res.Events) suite.Require().NoError(err) err = pathBtoC.RelayPacket(packet) diff --git a/testing/endpoint.go b/testing/endpoint.go index c938f99d5e6..78c725c8cb8 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -122,7 +122,7 @@ func (endpoint *Endpoint) CreateClient() (err error) { return err } - endpoint.ClientID, err = ParseClientIDFromEvents(res.GetEvents()) + endpoint.ClientID, err = ParseClientIDFromEvents(res.Events) require.NoError(endpoint.Chain.TB, err) return nil @@ -219,7 +219,7 @@ func (endpoint *Endpoint) ConnOpenInit() error { return err } - endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.GetEvents()) + endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.Events) require.NoError(endpoint.Chain.TB, err) return nil @@ -245,7 +245,7 @@ func (endpoint *Endpoint) ConnOpenTry() error { } if endpoint.ConnectionID == "" { - endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.GetEvents()) + endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.Events) require.NoError(endpoint.Chain.TB, err) } @@ -327,7 +327,7 @@ func (endpoint *Endpoint) ChanOpenInit() error { return err } - endpoint.ChannelID, err = ParseChannelIDFromEvents(res.GetEvents()) + endpoint.ChannelID, err = ParseChannelIDFromEvents(res.Events) require.NoError(endpoint.Chain.TB, err) // update version to selected app version @@ -358,7 +358,7 @@ func (endpoint *Endpoint) ChanOpenTry() error { } if endpoint.ChannelID == "" { - endpoint.ChannelID, err = ParseChannelIDFromEvents(res.GetEvents()) + endpoint.ChannelID, err = ParseChannelIDFromEvents(res.Events) require.NoError(endpoint.Chain.TB, err) } diff --git a/testing/events.go b/testing/events.go index 69fef9d1f8c..34f7a147d40 100644 --- a/testing/events.go +++ b/testing/events.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/suite" - sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/cometbft/cometbft/abci/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -17,7 +17,7 @@ type EventsMap map[string]map[string]string // ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the // client identifier. -func ParseClientIDFromEvents(events sdk.Events) (string, error) { +func ParseClientIDFromEvents(events []abci.Event) (string, error) { for _, ev := range events { if ev.Type == clienttypes.EventTypeCreateClient { for _, attr := range ev.Attributes { @@ -32,7 +32,7 @@ func ParseClientIDFromEvents(events sdk.Events) (string, error) { // ParseConnectionIDFromEvents parses events emitted from a MsgConnectionOpenInit or // MsgConnectionOpenTry and returns the connection identifier. -func ParseConnectionIDFromEvents(events sdk.Events) (string, error) { +func ParseConnectionIDFromEvents(events []abci.Event) (string, error) { for _, ev := range events { if ev.Type == connectiontypes.EventTypeConnectionOpenInit || ev.Type == connectiontypes.EventTypeConnectionOpenTry { @@ -48,7 +48,7 @@ func ParseConnectionIDFromEvents(events sdk.Events) (string, error) { // ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or // MsgChannelOpenTry and returns the channel identifier. -func ParseChannelIDFromEvents(events sdk.Events) (string, error) { +func ParseChannelIDFromEvents(events []abci.Event) (string, error) { for _, ev := range events { if ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { for _, attr := range ev.Attributes { @@ -63,7 +63,7 @@ func ParseChannelIDFromEvents(events sdk.Events) (string, error) { // ParsePacketFromEvents parses events emitted from a MsgRecvPacket and returns the // acknowledgement. -func ParsePacketFromEvents(events sdk.Events) (channeltypes.Packet, error) { +func ParsePacketFromEvents(events []abci.Event) (channeltypes.Packet, error) { for _, ev := range events { if ev.Type == channeltypes.EventTypeSendPacket { packet := channeltypes.Packet{} @@ -121,7 +121,7 @@ func ParsePacketFromEvents(events sdk.Events) (channeltypes.Packet, error) { // ParseAckFromEvents parses events emitted from a MsgRecvPacket and returns the // acknowledgement. -func ParseAckFromEvents(events sdk.Events) ([]byte, error) { +func ParseAckFromEvents(events []abci.Event) ([]byte, error) { for _, ev := range events { if ev.Type == channeltypes.EventTypeWriteAck { for _, attr := range ev.Attributes { @@ -139,7 +139,7 @@ func ParseAckFromEvents(events sdk.Events) ([]byte, error) { func AssertEvents( suite *suite.Suite, expected EventsMap, - actual sdk.Events, + actual []abci.Event, ) { hasEvents := make(map[string]bool) for eventType := range expected { diff --git a/testing/path.go b/testing/path.go index 4fb605ecbe8..9a97c8fe18d 100644 --- a/testing/path.go +++ b/testing/path.go @@ -52,7 +52,7 @@ func (path *Path) RelayPacket(packet channeltypes.Packet) error { return err } - ack, err := ParseAckFromEvents(res.GetEvents()) + ack, err := ParseAckFromEvents(res.Events) if err != nil { return err } @@ -73,7 +73,7 @@ func (path *Path) RelayPacket(packet channeltypes.Packet) error { return err } - ack, err := ParseAckFromEvents(res.GetEvents()) + ack, err := ParseAckFromEvents(res.Events) if err != nil { return err } diff --git a/testing/solomachine.go b/testing/solomachine.go index df683d3ea0c..13185d40d87 100644 --- a/testing/solomachine.go +++ b/testing/solomachine.go @@ -133,7 +133,7 @@ func (solo *Solomachine) CreateClient(chain *TestChain) string { require.NoError(solo.t, err) require.NotNil(solo.t, res) - clientID, err := ParseClientIDFromEvents(res.GetEvents()) + clientID, err := ParseClientIDFromEvents(res.Events) require.NoError(solo.t, err) return clientID @@ -277,7 +277,7 @@ func (solo *Solomachine) ConnOpenInit(chain *TestChain, clientID string) string require.NoError(solo.t, err) require.NotNil(solo.t, res) - connectionID, err := ParseConnectionIDFromEvents(res.GetEvents()) + connectionID, err := ParseConnectionIDFromEvents(res.Events) require.NoError(solo.t, err) return connectionID @@ -386,7 +386,7 @@ func (solo *Solomachine) SendTransfer(chain *TestChain, portID, channelID string res, err := chain.SendMsgs(&msgTransfer) require.NoError(solo.t, err) - packet, err := ParsePacketFromEvents(res.GetEvents()) + packet, err := ParsePacketFromEvents(res.Events) require.NoError(solo.t, err) return packet From aa0dbbdfccf439e55b0dc29d5e3ad1483c207387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 29 Jun 2023 17:22:56 +0200 Subject: [PATCH 2/2] fix: e2e build --- e2e/tests/interchain_accounts/localhost_test.go | 15 +++++---------- e2e/tests/transfer/localhost_test.go | 6 ++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index 7008c7ab8c4..7a0b1181893 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -154,8 +154,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - packet, err = ibctesting.ParsePacketFromEvents(events) + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(packet) }) @@ -166,8 +165,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - ack, err = ibctesting.ParseAckFromEvents(events) + ack, err = ibctesting.ParseAckFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(ack) }) @@ -311,8 +309,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - packet, err = ibctesting.ParsePacketFromEvents(events) + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(packet) }) @@ -439,8 +436,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - packet, err = ibctesting.ParsePacketFromEvents(events) + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(packet) }) @@ -451,8 +447,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - ack, err = ibctesting.ParseAckFromEvents(events) + ack, err = ibctesting.ParseAckFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(ack) }) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index e09331fc98c..efca34f1fd4 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -118,8 +118,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { txResp := s.Transfer(ctx, chainA, userAWallet, transfertypes.PortID, msgChanOpenInitRes.ChannelId, testvalues.DefaultTransferAmount(chainADenom), userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), clienttypes.NewHeight(1, 100), 0, "") s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - packet, err = ibctesting.ParsePacketFromEvents(events) + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(packet) }) @@ -139,8 +138,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.AssertTxSuccess(txResp) - events := testsuite.ABCIToSDKEvents(txResp.Events) - ack, err = ibctesting.ParseAckFromEvents(events) + ack, err = ibctesting.ParseAckFromEvents(txResp.Events) s.Require().NoError(err) s.Require().NotNil(ack) })