Skip to content

Commit

Permalink
refactor: change sdk.Events usage to []abci.Event in the testing pkg (#…
Browse files Browse the repository at this point in the history
…3980)

* refactor, change sdk.Events usage to []abci.Event

* fix, e2e build
  • Loading branch information
colin-axner authored Jul 3, 2023
1 parent 445187e commit dffc7b7
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 43 deletions.
15 changes: 5 additions & 10 deletions e2e/tests/interchain_accounts/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down
6 changes: 2 additions & 4 deletions e2e/tests/transfer/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/29-fee/keeper/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
14 changes: 7 additions & 7 deletions testing/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions testing/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions testing/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dffc7b7

Please sign in to comment.