From c424ec6f421f1db83358ecc949398abca3504c47 Mon Sep 17 00:00:00 2001 From: akaladarshi Date: Mon, 25 Mar 2024 23:45:00 +0530 Subject: [PATCH 1/8] refactor(modules/core): use asset events instead of assert event legacy --- modules/core/04-channel/keeper/packet_test.go | 33 +- .../core/04-channel/keeper/timeout_test.go | 33 +- modules/core/keeper/msg_server_test.go | 740 +++++++++--------- 3 files changed, 420 insertions(+), 386 deletions(-) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 0791dfdd39c..097359f0f85 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "fmt" + abci "github.com/cometbft/cometbft/abci/types" "cosmossdk.io/errors" @@ -847,7 +848,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { name string malleate func() expResult func(commitment []byte, err error) - expEvents func(path *ibctesting.Path) map[string]map[string]string + expEvents func(path *ibctesting.Path) []abci.Event }{ { name: "success on ordered channel", @@ -954,19 +955,21 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { suite.Require().True(found) suite.Require().Equal(uint64(1), nextSequenceAck, "sequence incremented for UNORDERED channel") }, - expEvents: func(path *ibctesting.Path) map[string]map[string]string { - return ibctesting.EventsMap{ - types.EventTypeChannelFlushComplete: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyChannelState: path.EndpointA.GetChannel().State.String(), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } + expEvents: func(path *ibctesting.Path) []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelFlushComplete, + sdk.NewAttribute(types.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(types.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(types.AttributeKeyChannelState, path.EndpointA.GetChannel().State.String()), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }.ToABCIEvents() }, }, { @@ -1320,7 +1323,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { expEvents := tc.expEvents(path) - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + ibctesting.AssertEvents(&suite.Suite, expEvents, events) } }) } diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index b86d1b905c5..4952d4a2988 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "errors" "fmt" + abci "github.com/cometbft/cometbft/abci/types" errorsmod "cosmossdk.io/errors" @@ -247,7 +248,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { msg string malleate func() expResult func(packetCommitment []byte, err error) - expEvents func(path *ibctesting.Path) map[string]map[string]string + expEvents func(path *ibctesting.Path) []abci.Event }{ { "success ORDERED", @@ -333,19 +334,21 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { channel := path.EndpointA.GetChannel() suite.Require().Equal(types.FLUSHCOMPLETE, channel.State, "channel state should still be set to FLUSHCOMPLETE") }, - func(path *ibctesting.Path) map[string]map[string]string { - return ibctesting.EventsMap{ - types.EventTypeChannelFlushComplete: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyChannelState: path.EndpointA.GetChannel().State.String(), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } + func(path *ibctesting.Path) []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelFlushComplete, + sdk.NewAttribute(types.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(types.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(types.AttributeKeyChannelState, path.EndpointA.GetChannel().State.String()), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }.ToABCIEvents() }, }, { @@ -523,7 +526,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { expEvents := tc.expEvents(path) - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + ibctesting.AssertEvents(&suite.Suite, expEvents, events) } }) } diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 1f7de0c2fe1..5a06503ceaf 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -936,22 +936,24 @@ func (suite *KeeperTestSuite) TestChannelUpgradeInit() { upgrade := path.EndpointA.GetChannelUpgrade() channel := path.EndpointA.GetChannel() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeInit: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: upgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: upgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: upgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeInit, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, upgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, upgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, upgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1080,22 +1082,24 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() { upgrade := path.EndpointB.GetChannelUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeTry: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyConnectionHops: upgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: upgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: upgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeTry, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, upgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, upgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, upgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1128,22 +1132,23 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() { suite.Require().Equal(uint64(99), errorReceipt.Sequence) channel := path.EndpointB.GetChannel() - - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "counterparty upgrade sequence < current upgrade sequence (1 < 99): invalid upgrade sequence", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "counterparty upgrade sequence < current upgrade sequence (1 < 99): invalid upgrade sequence"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1266,23 +1271,24 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { suite.Require().Equal(uint64(1), channel.UpgradeSequence) upgrade := path.EndpointA.GetChannelUpgrade() - - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeAck: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: upgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: upgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: upgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeAck, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, upgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, upgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, upgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1304,22 +1310,20 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { upgrade := path.EndpointA.GetChannelUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeAck: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: upgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: upgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: upgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeAck, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, upgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, upgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, upgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1374,22 +1378,23 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { suite.Require().Equal(uint64(1), errorReceipt.Sequence) channel := path.EndpointB.GetChannel() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "expected upgrade ordering (ORDER_NONE_UNSPECIFIED) to match counterparty upgrade ordering (ORDER_UNORDERED): incompatible counterparty upgrade", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "expected upgrade ordering (ORDER_NONE_UNSPECIFIED) to match counterparty upgrade ordering (ORDER_UNORDERED): incompatible counterparty upgrade"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1419,22 +1424,23 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { suite.Require().False(store.Has([]byte("foo"))) channel := path.EndpointB.GetChannel() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "mock app callback failed", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "mock app callback failed"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1565,32 +1571,34 @@ func (suite *KeeperTestSuite) TestChannelUpgradeConfirm() { suite.Require().Equal(channeltypes.OPEN, channel.State) suite.Require().Equal(uint64(1), channel.UpgradeSequence) - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeConfirm: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyChannelState: channeltypes.FLUSHCOMPLETE.String(), - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeOpen: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyChannelState: channeltypes.OPEN.String(), - channeltypes.AttributeKeyConnectionHops: channel.ConnectionHops[0], - channeltypes.AttributeKeyVersion: channel.Version, - channeltypes.AttributeKeyOrdering: channel.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeConfirm, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelState, channeltypes.FLUSHCOMPLETE.String()), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeOpen, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelState, channeltypes.OPEN.String()), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, channel.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, channel.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, channel.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1647,18 +1655,18 @@ func (suite *KeeperTestSuite) TestChannelUpgradeConfirm() { suite.Require().Equal(channeltypes.FLUSHCOMPLETE, channel.State) suite.Require().Equal(uint64(1), channel.UpgradeSequence) - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeConfirm: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyChannelState: channeltypes.FLUSHCOMPLETE.String(), - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeConfirm, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelState, channeltypes.FLUSHCOMPLETE.String()), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1676,18 +1684,18 @@ func (suite *KeeperTestSuite) TestChannelUpgradeConfirm() { suite.Require().Equal(channeltypes.FLUSHING, channel.State) suite.Require().Equal(uint64(1), channel.UpgradeSequence) - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeConfirm: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyChannelState: channeltypes.FLUSHING.String(), - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeConfirm, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelState, channeltypes.FLUSHING.String()), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1755,22 +1763,23 @@ func (suite *KeeperTestSuite) TestChannelUpgradeConfirm() { channel := path.EndpointB.GetChannel() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "counterparty upgrade timeout elapsed: current timestamp: 1578269010000000000, timeout timestamp 1578268995000000000: timeout elapsed", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "counterparty upgrade timeout elapsed: current timestamp: 1578269010000000000, timeout timestamp 1578268995000000000: timeout elapsed"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1866,23 +1875,25 @@ func (suite *KeeperTestSuite) TestChannelUpgradeOpen() { channel := path.EndpointA.GetChannel() suite.Require().Equal(channeltypes.OPEN, channel.State) - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeOpen: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyChannelState: channeltypes.OPEN.String(), - channeltypes.AttributeKeyConnectionHops: channel.ConnectionHops[0], - channeltypes.AttributeKeyVersion: channel.Version, - channeltypes.AttributeKeyOrdering: channel.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeOpen, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelState, channeltypes.OPEN.String()), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, channel.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, channel.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, channel.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -1912,23 +1923,25 @@ func (suite *KeeperTestSuite) TestChannelUpgradeOpen() { channel := path.EndpointA.GetChannel() suite.Require().Equal(channeltypes.OPEN, channel.State) - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeOpen: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyChannelState: channeltypes.OPEN.String(), - channeltypes.AttributeKeyConnectionHops: channel.ConnectionHops[0], - channeltypes.AttributeKeyVersion: channel.Version, - channeltypes.AttributeKeyOrdering: channel.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeOpen, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelState, channeltypes.OPEN.String()), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, channel.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, channel.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, channel.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -2057,31 +2070,33 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. proposedUpgrade := path.EndpointA.GetProposedUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeCancel: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: proposedUpgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: proposedUpgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "invalid upgrade", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeCancel, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, proposedUpgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, proposedUpgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, proposedUpgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "invalid upgrade"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -2106,31 +2121,30 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. proposedUpgrade := path.EndpointA.GetProposedUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeCancel: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: proposedUpgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: proposedUpgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeCancel, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, proposedUpgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, proposedUpgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, proposedUpgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "invalid upgrade", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "invalid upgrade"), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -2156,31 +2170,34 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. proposedUpgrade := path.EndpointA.GetProposedUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeCancel: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: proposedUpgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: proposedUpgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeCancel, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, proposedUpgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, proposedUpgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, proposedUpgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "invalid upgrade", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "invalid upgrade"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -2206,31 +2223,34 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. proposedUpgrade := path.EndpointA.GetProposedUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeCancel: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: proposedUpgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: proposedUpgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeCancel, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, proposedUpgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, proposedUpgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, proposedUpgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "invalid upgrade", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "invalid upgrade"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -2255,31 +2275,35 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. proposedUpgrade := path.EndpointA.GetProposedUpgrade() - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeCancel: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: proposedUpgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: proposedUpgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeCancel, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, proposedUpgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, proposedUpgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, proposedUpgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "invalid upgrade", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "invalid upgrade"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute( + sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { @@ -2432,33 +2456,37 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTimeout() { proposedUpgrade := path.EndpointA.GetProposedUpgrade() // use the timeout we set in the malleate function timeout := channeltypes.NewTimeout(clienttypes.ZeroHeight(), 1) - expEvents := ibctesting.EventsMap{ - channeltypes.EventTypeChannelUpgradeTimeout: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - channeltypes.AttributeKeyVersion: proposedUpgrade.Fields.Version, - channeltypes.AttributeKeyOrdering: proposedUpgrade.Fields.Ordering.String(), - channeltypes.AttributeKeyUpgradeTimeoutHeight: timeout.Height.String(), - channeltypes.AttributeKeyUpgradeTimeoutTimestamp: fmt.Sprintf("%d", timeout.Timestamp), - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - channeltypes.EventTypeChannelUpgradeError: { - channeltypes.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - channeltypes.AttributeKeyChannelID: path.EndpointA.ChannelID, - channeltypes.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - channeltypes.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - channeltypes.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + + expEvents := sdk.Events{ + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeTimeout, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyConnectionHops, proposedUpgrade.Fields.ConnectionHops[0]), + sdk.NewAttribute(channeltypes.AttributeKeyVersion, proposedUpgrade.Fields.Version), + sdk.NewAttribute(channeltypes.AttributeKeyOrdering, proposedUpgrade.Fields.Ordering.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeTimeoutHeight, timeout.Height.String()), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeTimeoutTimestamp, fmt.Sprintf("%d", timeout.Timestamp)), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), + ), + sdk.NewEvent( + channeltypes.EventTypeChannelUpgradeError, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, path.EndpointA.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, path.EndpointA.ChannelID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyPortID, path.EndpointB.ChannelConfig.PortID), + sdk.NewAttribute(channeltypes.AttributeCounterpartyChannelID, path.EndpointB.ChannelID), + sdk.NewAttribute(channeltypes.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", channel.UpgradeSequence)), // need to manually insert this because the errorReceipt is a string constant as it is written into state - channeltypes.AttributeKeyErrorReceipt: "upgrade timed-out", - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: channeltypes.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + sdk.NewAttribute(channeltypes.AttributeKeyErrorReceipt, "upgrade timed-out"), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), + ), + }.ToABCIEvents() + ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, { From d48703856b0ee5bd4233faa84cfc449b426beb76 Mon Sep 17 00:00:00 2001 From: akaladarshi Date: Wed, 27 Mar 2024 12:00:00 +0530 Subject: [PATCH 2/8] refactor(modules/apps): use asset events instead of assert event legacy --- modules/apps/callbacks/types/events_test.go | 157 ++++++++++++------ .../apps/transfer/keeper/msg_server_test.go | 25 +-- 2 files changed, 118 insertions(+), 64 deletions(-) diff --git a/modules/apps/callbacks/types/events_test.go b/modules/apps/callbacks/types/events_test.go index 17cd920e211..c744e862df9 100644 --- a/modules/apps/callbacks/types/events_test.go +++ b/modules/apps/callbacks/types/events_test.go @@ -1,6 +1,7 @@ package types_test import ( + abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/callbacks/types" @@ -10,41 +11,13 @@ import ( ) func (s *CallbacksTypesTestSuite) TestEvents() { - constEvents := func() ibctesting.EventsMap { - return ibctesting.EventsMap{ - types.EventTypeSourceCallback: { - sdk.AttributeKeyModule: types.ModuleName, - types.AttributeKeyCallbackType: string(types.CallbackTypeAcknowledgementPacket), - types.AttributeKeyCallbackAddress: ibctesting.TestAccAddress, - types.AttributeKeyCallbackGasLimit: "100000", - types.AttributeKeyCallbackCommitGasLimit: "200000", - types.AttributeKeyCallbackSourcePortID: ibctesting.MockPort, - types.AttributeKeyCallbackSourceChannelID: ibctesting.FirstChannelID, - types.AttributeKeyCallbackSequence: "1", - types.AttributeKeyCallbackResult: types.AttributeValueCallbackSuccess, - }, - types.EventTypeDestinationCallback: { - sdk.AttributeKeyModule: types.ModuleName, - types.AttributeKeyCallbackType: string(types.CallbackTypeReceivePacket), - types.AttributeKeyCallbackAddress: ibctesting.TestAccAddress, - types.AttributeKeyCallbackGasLimit: "100000", - types.AttributeKeyCallbackCommitGasLimit: "200000", - types.AttributeKeyCallbackDestPortID: ibctesting.MockFeePort, - types.AttributeKeyCallbackDestChannelID: ibctesting.InvalidID, - types.AttributeKeyCallbackSequence: "1", - types.AttributeKeyCallbackResult: types.AttributeValueCallbackSuccess, - }, - } - } - - var expEvents ibctesting.EventsMap testCases := []struct { - name string - packet channeltypes.Packet - callbackType types.CallbackType - callbackData types.CallbackData - callbackError error - malleate func() + name string + packet channeltypes.Packet + callbackType types.CallbackType + callbackData types.CallbackData + callbackError error + expectedEvents func() []abci.Event }{ { "success: ack callback", @@ -59,7 +32,22 @@ func (s *CallbacksTypesTestSuite) TestEvents() { CommitGasLimit: 200_000, }, nil, - func() {}, + func() []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeSourceCallback, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyCallbackType, string(types.CallbackTypeAcknowledgementPacket)), + sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), + sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), + sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), + sdk.NewAttribute(types.AttributeKeyCallbackSourcePortID, ibctesting.MockPort), + sdk.NewAttribute(types.AttributeKeyCallbackSourceChannelID, ibctesting.FirstChannelID), + sdk.NewAttribute(types.AttributeKeyCallbackSequence, "1"), + sdk.NewAttribute(types.AttributeKeyCallbackResult, types.AttributeValueCallbackSuccess), + ), + }.ToABCIEvents() + }, }, { "success: send packet callback", @@ -74,8 +62,21 @@ func (s *CallbacksTypesTestSuite) TestEvents() { CommitGasLimit: 200_000, }, nil, - func() { - expEvents[types.EventTypeSourceCallback][types.AttributeKeyCallbackType] = string(types.CallbackTypeSendPacket) + func() []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeSourceCallback, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyCallbackType, string(types.CallbackTypeSendPacket)), + sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), + sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), + sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), + sdk.NewAttribute(types.AttributeKeyCallbackSourcePortID, ibctesting.MockPort), + sdk.NewAttribute(types.AttributeKeyCallbackSourceChannelID, ibctesting.FirstChannelID), + sdk.NewAttribute(types.AttributeKeyCallbackSequence, "1"), + sdk.NewAttribute(types.AttributeKeyCallbackResult, types.AttributeValueCallbackSuccess), + ), + }.ToABCIEvents() }, }, { @@ -91,8 +92,21 @@ func (s *CallbacksTypesTestSuite) TestEvents() { CommitGasLimit: 200_000, }, nil, - func() { - expEvents[types.EventTypeSourceCallback][types.AttributeKeyCallbackType] = string(types.CallbackTypeTimeoutPacket) + func() []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeSourceCallback, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyCallbackType, string(types.CallbackTypeTimeoutPacket)), + sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), + sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), + sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), + sdk.NewAttribute(types.AttributeKeyCallbackSourcePortID, ibctesting.MockPort), + sdk.NewAttribute(types.AttributeKeyCallbackSourceChannelID, ibctesting.FirstChannelID), + sdk.NewAttribute(types.AttributeKeyCallbackSequence, "1"), + sdk.NewAttribute(types.AttributeKeyCallbackResult, types.AttributeValueCallbackSuccess), + ), + }.ToABCIEvents() }, }, { @@ -108,7 +122,22 @@ func (s *CallbacksTypesTestSuite) TestEvents() { CommitGasLimit: 200_000, }, nil, - func() {}, + func() []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeDestinationCallback, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyCallbackType, string(types.CallbackTypeReceivePacket)), + sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), + sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), + sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), + sdk.NewAttribute(types.AttributeKeyCallbackDestPortID, ibctesting.MockFeePort), + sdk.NewAttribute(types.AttributeKeyCallbackDestChannelID, ibctesting.InvalidID), + sdk.NewAttribute(types.AttributeKeyCallbackSequence, "1"), + sdk.NewAttribute(types.AttributeKeyCallbackResult, types.AttributeValueCallbackSuccess), + ), + }.ToABCIEvents() + }, }, { "success: unknown callback", @@ -123,8 +152,21 @@ func (s *CallbacksTypesTestSuite) TestEvents() { CommitGasLimit: 200_000, }, nil, - func() { - expEvents[types.EventTypeSourceCallback][types.AttributeKeyCallbackType] = "something" + func() []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeSourceCallback, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyCallbackType, "something"), + sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), + sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), + sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), + sdk.NewAttribute(types.AttributeKeyCallbackSourcePortID, ibctesting.MockPort), + sdk.NewAttribute(types.AttributeKeyCallbackSourceChannelID, ibctesting.FirstChannelID), + sdk.NewAttribute(types.AttributeKeyCallbackSequence, "1"), + sdk.NewAttribute(types.AttributeKeyCallbackResult, types.AttributeValueCallbackSuccess), + ), + }.ToABCIEvents() }, }, { @@ -140,9 +182,22 @@ func (s *CallbacksTypesTestSuite) TestEvents() { CommitGasLimit: 200_000, }, types.ErrNotPacketDataProvider, - func() { - expEvents[types.EventTypeSourceCallback][types.AttributeKeyCallbackResult] = types.AttributeValueCallbackFailure - expEvents[types.EventTypeSourceCallback][types.AttributeKeyCallbackError] = types.ErrNotPacketDataProvider.Error() + func() []abci.Event { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeSourceCallback, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyCallbackType, "something"), + sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), + sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), + sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), + sdk.NewAttribute(types.AttributeKeyCallbackSourcePortID, ibctesting.MockPort), + sdk.NewAttribute(types.AttributeKeyCallbackSourceChannelID, ibctesting.FirstChannelID), + sdk.NewAttribute(types.AttributeKeyCallbackSequence, "1"), + sdk.NewAttribute(types.AttributeKeyCallbackResult, types.AttributeValueCallbackFailure), + sdk.NewAttribute(types.AttributeKeyCallbackError, types.ErrNotPacketDataProvider.Error()), + ), + }.ToABCIEvents() }, }, } @@ -150,28 +205,26 @@ func (s *CallbacksTypesTestSuite) TestEvents() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - expEvents = constEvents() - tc.malleate() + //expEvents = constEvents() newCtx := sdk.Context{}.WithEventManager(sdk.NewEventManager()) - switch tc.callbackType { case types.CallbackTypeReceivePacket: - delete(expEvents, types.EventTypeSourceCallback) types.EmitCallbackEvent( newCtx, tc.packet.GetDestPort(), tc.packet.GetDestChannel(), tc.packet.GetSequence(), tc.callbackType, tc.callbackData, tc.callbackError, ) default: - delete(expEvents, types.EventTypeDestinationCallback) types.EmitCallbackEvent( newCtx, tc.packet.GetSourcePort(), tc.packet.GetSourceChannel(), tc.packet.GetSequence(), tc.callbackType, tc.callbackData, tc.callbackError, ) } - events := newCtx.EventManager().Events().ToABCIEvents() - ibctesting.AssertEventsLegacy(&s.Suite, expEvents, events) + actualEvents := newCtx.EventManager().Events().ToABCIEvents() + expectedEvents := tc.expectedEvents() + + ibctesting.AssertEvents(&s.Suite, expectedEvents, actualEvents) }) } } diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 55bc27a8a89..027d1084d96 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -106,26 +106,27 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(ctx, msg) // Verify events - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - "ibc_transfer": { - "sender": suite.chainA.SenderAccount.GetAddress().String(), - "receiver": suite.chainB.SenderAccount.GetAddress().String(), - "amount": coin.Amount.String(), - "denom": coin.Denom, - "memo": "memo", - }, - } + actualEvents := ctx.EventManager().Events().ToABCIEvents() + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.EventTypeTransfer, + sdk.NewAttribute(sdk.AttributeKeySender, suite.chainA.SenderAccount.GetAddress().String()), + sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainB.SenderAccount.GetAddress().String()), + sdk.NewAttribute(types.AttributeKeyAmount, coin.Amount.String()), + sdk.NewAttribute(types.AttributeKeyDenom, coin.Denom), + sdk.NewAttribute(types.AttributeKeyMemo, "memo"), + ), + }.ToABCIEvents() if tc.expPass { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().NotEqual(res.Sequence, uint64(0)) - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + ibctesting.AssertEvents(&suite.Suite, expectedEvents, actualEvents) } else { suite.Require().Error(err) suite.Require().Nil(res) - suite.Require().Len(events, 0) + suite.Require().Len(expectedEvents, 0) } }) } From f29b72fdeb040057d0da4ffd8ae426c7dcee4ded Mon Sep 17 00:00:00 2001 From: akaladarshi Date: Wed, 27 Mar 2024 12:00:00 +0530 Subject: [PATCH 3/8] refactor: remove asset events legacy and events map --- testing/events.go | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/testing/events.go b/testing/events.go index 9ebe7af9c90..96b9063759a 100644 --- a/testing/events.go +++ b/testing/events.go @@ -14,8 +14,6 @@ import ( channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ) -type EventsMap map[string]map[string]string - // ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the // client identifier. func ParseClientIDFromEvents(events []abci.Event) (string, error) { @@ -167,36 +165,6 @@ func ParseProposalIDFromEvents(events []abci.Event) (uint64, error) { return 0, fmt.Errorf("proposalID event attribute not found") } -// AssertEventsLegacy asserts that expected events are present in the actual events. -// Expected map needs to be a subset of actual events to pass. -func AssertEventsLegacy( - suite *testifysuite.Suite, - expected EventsMap, - actual []abci.Event, -) { - hasEvents := make(map[string]bool) - for eventType := range expected { - hasEvents[eventType] = false - } - - for _, event := range actual { - expEvent, eventFound := expected[event.Type] - if eventFound { - hasEvents[event.Type] = true - suite.Require().Len(event.Attributes, len(expEvent)) - for _, attr := range event.Attributes { - expValue, found := expEvent[attr.Key] - suite.Require().True(found) - suite.Require().Equal(expValue, attr.Value) - } - } - } - - for eventName, hasEvent := range hasEvents { - suite.Require().True(hasEvent, "event: %s was not found in events", eventName) - } -} - // AssertEvents asserts that expected events are present in the actual events. func AssertEvents( suite *testifysuite.Suite, From dd04e90f9ce4f4c22c2feef5e80dfff2047e31f9 Mon Sep 17 00:00:00 2001 From: akaladarshi Date: Sun, 31 Mar 2024 11:35:05 +0530 Subject: [PATCH 4/8] fix: linter errors --- modules/apps/callbacks/types/events_test.go | 6 +++--- modules/apps/transfer/keeper/msg_server_test.go | 2 +- modules/core/02-client/keeper/events_test.go | 10 ++++++++-- modules/core/04-channel/keeper/packet_test.go | 4 ++-- modules/core/04-channel/keeper/timeout_test.go | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/apps/callbacks/types/events_test.go b/modules/apps/callbacks/types/events_test.go index c744e862df9..99b5a530f8e 100644 --- a/modules/apps/callbacks/types/events_test.go +++ b/modules/apps/callbacks/types/events_test.go @@ -1,9 +1,10 @@ package types_test import ( - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/ibc-go/modules/apps/callbacks/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" @@ -187,7 +188,7 @@ func (s *CallbacksTypesTestSuite) TestEvents() { sdk.NewEvent( types.EventTypeSourceCallback, sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(types.AttributeKeyCallbackType, "something"), + sdk.NewAttribute(types.AttributeKeyCallbackType, string(types.CallbackTypeAcknowledgementPacket)), sdk.NewAttribute(types.AttributeKeyCallbackAddress, ibctesting.TestAccAddress), sdk.NewAttribute(types.AttributeKeyCallbackGasLimit, "100000"), sdk.NewAttribute(types.AttributeKeyCallbackCommitGasLimit, "200000"), @@ -205,7 +206,6 @@ func (s *CallbacksTypesTestSuite) TestEvents() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - //expEvents = constEvents() newCtx := sdk.Context{}.WithEventManager(sdk.NewEventManager()) switch tc.callbackType { case types.CallbackTypeReceivePacket: diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 027d1084d96..dfca09ceabb 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -126,7 +126,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { } else { suite.Require().Error(err) suite.Require().Nil(res) - suite.Require().Len(expectedEvents, 0) + suite.Require().Len(actualEvents, 0) } }) } diff --git a/modules/core/02-client/keeper/events_test.go b/modules/core/02-client/keeper/events_test.go index 45423239e98..01d02328ef7 100644 --- a/modules/core/02-client/keeper/events_test.go +++ b/modules/core/02-client/keeper/events_test.go @@ -1,6 +1,8 @@ package keeper_test import ( + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" @@ -18,7 +20,9 @@ func (suite *KeeperTestSuite) TestMsgCreateClientEvents() { tmConfig, ok := path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig) suite.Require().True(ok) - height := path.EndpointA.Counterparty.Chain.LatestCommittedHeader.GetHeight().(clienttypes.Height) + height, ok := path.EndpointA.Counterparty.Chain.LatestCommittedHeader.GetHeight().(clienttypes.Height) + require.True(suite.T(), ok) + clientState := ibctm.NewClientState( path.EndpointA.Counterparty.Chain.ChainID, tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, height, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) @@ -56,7 +60,9 @@ func (suite *KeeperTestSuite) TestMsgUpdateClientEvents() { suite.chainB.Coordinator.CommitBlock(suite.chainB) - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + require.True(suite.T(), ok) + trustedHeight := clientState.LatestHeight header, err := suite.chainB.IBCClientHeader(suite.chainB.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 097359f0f85..e96e5e4a18a 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -2,12 +2,12 @@ package keeper_test import ( "fmt" - abci "github.com/cometbft/cometbft/abci/types" - "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/cometbft/cometbft/abci/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 4952d4a2988..4bc276b00f1 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -3,12 +3,12 @@ package keeper_test import ( "errors" "fmt" - abci "github.com/cometbft/cometbft/abci/types" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/cometbft/cometbft/abci/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" From 5181f1ba7e403c26afb0316f8ce10cc35fc14f78 Mon Sep 17 00:00:00 2001 From: akaladarshi Date: Wed, 3 Apr 2024 21:17:54 +0530 Subject: [PATCH 5/8] fix: linter errors --- modules/core/04-channel/keeper/packet_test.go | 1 + modules/core/04-channel/keeper/timeout_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index e96e5e4a18a..72335b55249 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "fmt" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 4bc276b00f1..44aca2f33ce 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "errors" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" From f4744425b2010bacb9488a5a373d3756b162cce9 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 10 Apr 2024 23:53:06 +0200 Subject: [PATCH 6/8] fix linter errors --- modules/core/02-client/keeper/events_test.go | 4 +--- modules/core/keeper/msg_server_test.go | 15 --------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/modules/core/02-client/keeper/events_test.go b/modules/core/02-client/keeper/events_test.go index 8d59e5b7723..a07cd9c3dc0 100644 --- a/modules/core/02-client/keeper/events_test.go +++ b/modules/core/02-client/keeper/events_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" @@ -62,7 +60,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateClientEvents() { clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) - + trustedHeight := clientState.LatestHeight header, err := suite.chainB.IBCClientHeader(suite.chainB.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 3ece3c53810..4ff6133b631 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -1077,8 +1077,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() { suite.Require().Equal(channeltypes.FLUSHING, channel.State) suite.Require().Equal(uint64(1), channel.UpgradeSequence) - upgrade := path.EndpointB.GetChannelUpgrade() - expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeTry, @@ -1264,7 +1262,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { suite.Require().Equal(channeltypes.FLUSHCOMPLETE, channel.State) suite.Require().Equal(uint64(1), channel.UpgradeSequence) - upgrade := path.EndpointA.GetChannelUpgrade() expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeAck, @@ -1299,8 +1296,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { suite.Require().Equal(channeltypes.FLUSHING, channel.State) suite.Require().Equal(uint64(1), channel.UpgradeSequence) - upgrade := path.EndpointA.GetChannelUpgrade() - expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeAck, @@ -2047,8 +2042,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // Upgrade sequence should be changed to match sequence on error receipt. suite.Require().Equal(uint64(2), channel.UpgradeSequence) - // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. - proposedUpgrade := path.EndpointA.GetProposedUpgrade() expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeCancel, @@ -2095,8 +2088,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // Upgrade sequence should be changed to match initial upgrade sequence. suite.Require().Equal(uint64(3), channel.UpgradeSequence) - // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. - proposedUpgrade := path.EndpointA.GetProposedUpgrade() expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeCancel, @@ -2141,8 +2132,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // Upgrade sequence should be changed to match initial upgrade sequence. suite.Require().Equal(uint64(1), channel.UpgradeSequence) - // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. - proposedUpgrade := path.EndpointA.GetProposedUpgrade() expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeCancel, @@ -2191,8 +2180,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // Upgrade sequence should be changed to match initial upgrade sequence. suite.Require().Equal(uint64(1), channel.UpgradeSequence) - // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. - proposedUpgrade := path.EndpointA.GetProposedUpgrade() expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeCancel, @@ -2240,8 +2227,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() { // Upgrade sequence should not be changed. suite.Require().Equal(uint64(2), channel.UpgradeSequence) - // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. - proposedUpgrade := path.EndpointA.GetProposedUpgrade() expEvents := sdk.Events{ sdk.NewEvent( channeltypes.EventTypeChannelUpgradeCancel, From 36d35995b0b1ac5f8a89933ec7d9ec7f5560e511 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 11 Apr 2024 09:07:30 +0200 Subject: [PATCH 7/8] add migration docs --- docs/docs/05-migrations/13-v8-to-v9.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 98425383303..aca3b3e9b75 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -46,6 +46,22 @@ Please use the new functions `path.Setup`, `path.SetupClients`, `path.SetupConne - The `mock.PV` type has been removed in favour of [`cmttypes.MockPV`](https://github.com/cometbft/cometbft/blob/v0.38.5/types/priv_validator.go#L50) ([#5709](https://github.com/cosmos/ibc-go/pull/5709)). - Functions `ConstructUpdateTMClientHeader` and `ConstructUpdateTMClientHeaderWithTrustedHeight` of `TestChain` type have been replaced with `IBCClientHeader`. This function will construct a `07-tendermint` header to update the light client on the counterparty chain. The trusted height must be passed in as a non-zero height. - `GetValsAtHeight` has been renamed to `GetTrustedValidators` +- `AssertEventsLegacy` function of `ibctesting` package (alias for `"github.com/cosmos/ibc-go/v9/testing"`) has been removed and `AssertEvents` function should be used instead (ref: [#6070](https://github.com/cosmos/ibc-go/pull/6070)). + +```diff +// testing/events.go +- func AssertEventsLegacy( +- suite *testifysuite.Suite, +- expected EventsMap, +- actual []abci.Event, +- ) + +func AssertEvents( + suite *testifysuite.Suite, + expected []abci.Event, + actual []abci.Event, +) +``` ### ICS27 - Interchain Accounts From 7facb477f12fcbf4842f60beba39323330b19aa7 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 11 Apr 2024 09:10:37 +0200 Subject: [PATCH 8/8] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ef1bf6ff1a..7532ba3bc99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (core/04-channel) [\#5991](https://github.com/cosmos/ibc-go/pull/5991) The client CLI `QueryLatestConsensusState` has been removed. * (light-clients/06-solomachine) [\#6037](https://github.com/cosmos/ibc-go/pull/6037) Remove `Initialize` function from `ClientState` and move logic to `Initialize` function of `LightClientModule`. * (core/02-client) [\#6084](https://github.com/cosmos/ibc-go/pull/6084) Removed `stakingKeeper` as an argument to `NewKeeper` and replaced with a `ConsensusHost` implementation. +* (testing) [\#6070](https://github.com/cosmos/ibc-go/pull/6070) Remove `AssertEventsLegacy` function. ### State Machine Breaking