diff --git a/tests/integration/setup.go b/tests/integration/setup.go index a021c38bab..351fd7148a 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/suite" store "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/cometbft/cometbft/abci/types" @@ -21,7 +22,6 @@ import ( icstestingutils "github.com/cosmos/interchain-security/v3/testutil/ibc_testing" testutil "github.com/cosmos/interchain-security/v3/testutil/integration" - "github.com/cosmos/interchain-security/v3/testutil/simibc" ccv "github.com/cosmos/interchain-security/v3/x/ccv/types" ) @@ -389,7 +389,8 @@ func newPacketSniffer() *packetSniffer { } func (ps *packetSniffer) ListenFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error { - packets := simibc.ParsePacketsFromEvents(simibc.ABCIToSDKEvents(res.GetEvents())) + // TODO: @MSalopek this was deprecated, figure out how to use it + packets := ParsePacketsFromEvents(res.GetEvents()) for _, packet := range packets { ps.packets[getSentPacketKey(packet.Sequence, packet.SourceChannel)] = packet } @@ -402,10 +403,42 @@ func getSentPacketKey(sequence uint64, channelID string) string { return fmt.Sprintf("%s-%d", channelID, sequence) } -func (*packetSniffer) ListenCommit(ctx context.Context, res abci.ResponseCommit) error { +func (*packetSniffer) ListenCommit(ctx context.Context, res abci.ResponseCommit, cs []*store.StoreKVPair) error { return nil } func (*packetSniffer) Close() error { return nil } func (*packetSniffer) Listeners() map[store.StoreKey][]store.ABCIListener { return nil } func (*packetSniffer) Stream(wg *sync.WaitGroup) error { return nil } + +// [legacy simibc method] +// ABCIToSDKEvents converts a list of ABCI events to Cosmos SDK events. +func ABCIToSDKEvents(abciEvents []abci.Event) sdk.Events { + var events sdk.Events + for _, evt := range abciEvents { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + return events +} + +// [legacy simibc method] +// ParsePacketsFromEvents returns all packets found in events. +// func ParsePacketsFromEvents(events []sdk.Event) (packets []channeltypes.Packet) { +func ParsePacketsFromEvents(events []abci.Event) (packets []channeltypes.Packet) { + for i, ev := range events { + if ev.Type == channeltypes.EventTypeSendPacket { + packet, err := ibctesting.ParsePacketFromEvents(events[i:]) + if err != nil { + panic(err) + } + packets = append(packets, packet) + } + } + return +} diff --git a/tests/integration/throttle.go b/tests/integration/throttle.go index 2979c0b9e8..089049cc34 100644 --- a/tests/integration/throttle.go +++ b/tests/integration/throttle.go @@ -75,7 +75,10 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() { vals = providerStakingKeeper.GetAllValidators(s.providerCtx()) slashedVal := vals[0] s.Require().True(slashedVal.IsJailed()) - lastValPower := providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), slashedVal.GetOperator()) + + slashedValOperator, err := sdk.ValAddressFromHex(slashedVal.GetOperator()) + s.Require().NoError(err) + lastValPower := providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), slashedValOperator) s.Require().Equal(int64(0), lastValPower) // Assert expected slash meter and allowance value @@ -149,7 +152,10 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() { // Assert validator 2 has no power, this should be apparent next block, // since the staking endblocker runs before the ccv endblocker. s.providerChain.NextBlock() - lastValPower = providerStakingKeeper.GetLastValidatorPower(cacheCtx, slashedVal.GetOperator()) + + slashedValOperator, err = sdk.ValAddressFromHex(slashedVal.GetOperator()) + s.Require().NoError(err) + lastValPower = providerStakingKeeper.GetLastValidatorPower(cacheCtx, slashedValOperator) s.Require().Equal(int64(0), lastValPower) } } @@ -638,18 +644,30 @@ func (s *CCVTestSuite) TestSlashingSmallValidators() { // Default slash meter replenish fraction is 0.05, so all sent packets should be handled immediately. vals = providerStakingKeeper.GetAllValidators(s.providerCtx()) + + val0Operator, err := sdk.ValAddressFromHex(vals[0].GetOperator()) + s.Require().NoError(err) s.Require().False(vals[0].IsJailed()) s.Require().Equal(int64(1000), - providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[0].GetOperator())) + providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), val0Operator)) + + val1Operator, err := sdk.ValAddressFromHex(vals[1].GetOperator()) + s.Require().NoError(err) s.Require().True(vals[1].IsJailed()) s.Require().Equal(int64(0), - providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[1].GetOperator())) + providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), val1Operator)) + + val2Operator, err := sdk.ValAddressFromHex(vals[2].GetOperator()) + s.Require().NoError(err) s.Require().True(vals[2].IsJailed()) s.Require().Equal(int64(0), - providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[2].GetOperator())) + providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), val2Operator)) + + val3Operator, err := sdk.ValAddressFromHex(vals[3].GetOperator()) + s.Require().NoError(err) s.Require().True(vals[3].IsJailed()) s.Require().Equal(int64(0), - providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[3].GetOperator())) + providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), val3Operator)) } // TestSlashMeterAllowanceChanges tests scenarios where the slash meter allowance is expected to change. @@ -969,8 +987,10 @@ func (s *CCVTestSuite) confirmValidatorJailed(tmVal tmtypes.Validator, checkPowe s.Require().True(sdkVal.IsJailed()) if checkPower { + valOperator, err := sdk.ValAddressFromHex(sdkVal.GetOperator()) + s.Require().NoError(err) valPower := s.providerApp.GetTestStakingKeeper().GetLastValidatorPower( - s.providerCtx(), sdkVal.GetOperator()) + s.providerCtx(), valOperator) s.Require().Equal(int64(0), valPower) } } @@ -979,8 +999,11 @@ func (s *CCVTestSuite) confirmValidatorNotJailed(tmVal tmtypes.Validator, expect sdkVal, found := s.providerApp.GetTestStakingKeeper().GetValidator( s.providerCtx(), sdk.ValAddress(tmVal.Address)) s.Require().True(found) + + valOperator, err := sdk.ValAddressFromHex(sdkVal.GetOperator()) + s.Require().NoError(err) valPower := s.providerApp.GetTestStakingKeeper().GetLastValidatorPower( - s.providerCtx(), sdkVal.GetOperator()) + s.providerCtx(), valOperator) s.Require().Equal(expectedPower, valPower) s.Require().False(sdkVal.IsJailed()) } diff --git a/tests/integration/throttle_retry.go b/tests/integration/throttle_retry.go index 5c81318d54..a02bdca4dc 100644 --- a/tests/integration/throttle_retry.go +++ b/tests/integration/throttle_retry.go @@ -4,6 +4,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" provider "github.com/cosmos/interchain-security/v3/x/ccv/provider" @@ -83,8 +84,12 @@ func (s *CCVTestSuite) TestSlashRetries() { // Default slash meter replenish fraction is 0.05, so packet should be handled on provider. vals = s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx()) s.Require().True(vals[1].IsJailed()) + + val1Operator, err := sdk.ValAddressFromHex(vals[1].GetOperator()) + s.Require().NoError(err) + s.Require().Equal(int64(0), - s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), vals[1].GetOperator())) + s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), val1Operator)) s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), s.getFirstBundle().Chain.ChainID)) @@ -93,7 +98,7 @@ func (s *CCVTestSuite) TestSlashRetries() { // Apply ack back on consumer ackForConsumer := expectedv1Ack - err := consumerKeeper.OnAcknowledgementPacket(s.consumerCtx(), packet1, ackForConsumer) + err = consumerKeeper.OnAcknowledgementPacket(s.consumerCtx(), packet1, ackForConsumer) s.Require().NoError(err) // Slash record should have been deleted, head of pending packets should have been popped @@ -136,8 +141,11 @@ func (s *CCVTestSuite) TestSlashRetries() { // Val shouldn't be jailed on provider. Slash packet was queued s.Require().False(vals[2].IsJailed()) + val2Operator, err := sdk.ValAddressFromHex(vals[2].GetOperator()) + s.Require().NoError(err) + s.Require().Equal(int64(1000), - providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[2].GetOperator())) + providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), val2Operator)) s.Require().Equal(uint64(1), providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), s.getFirstBundle().Chain.ChainID))