Skip to content

Commit

Permalink
test: upgrade packetSniffer to latest ABCIListener API (#1398)
Browse files Browse the repository at this point in the history
test: upgrade packetSniffer to latest ABCIListener API

Relates: #1349

Also remove unused func ABCIToSDKEvents.
  • Loading branch information
tbruyelle authored Nov 8, 2023
1 parent ca97abb commit 657c063
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion tests/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func checkRedelegationEntryCompletionTime(
func getStakingUnbondingDelegationEntry(ctx sdk.Context, k testutil.TestStakingKeeper, id uint64) (stakingUnbondingOp stakingtypes.UnbondingDelegationEntry, found bool) {
stakingUbd, err := k.GetUnbondingDelegationByUnbondingID(ctx, id)
if err != nil {
panic(fmt.Sprintf("could not get unbonding delegation", err))
panic(fmt.Sprintf("could not get unbonding delegation: %v", err))
}

found = false
Expand Down
31 changes: 4 additions & 27 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package integration
import (
"context"
"fmt"
"sync"
"testing"

transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand Down Expand Up @@ -167,7 +166,9 @@ func (s *CCVTestSuite) registerPacketSniffer(chain *ibctesting.TestChain) {
s.packetSniffers = make(map[*ibctesting.TestChain]*packetSniffer)
}
p := newPacketSniffer()
chain.App.GetBaseApp().SetStreamingManager(p)
chain.App.GetBaseApp().SetStreamingManager(store.StreamingManager{
ABCIListeners: []store.ABCIListener{p},
})
s.packetSniffers[chain] = p
}

Expand Down Expand Up @@ -380,8 +381,7 @@ type packetSniffer struct {
packets map[string]channeltypes.Packet
}

// TODO: @MSalopek this was deprecated, figure out how to use it or ask @tbruyelle
// var _ baseapp.StreamingService = &packetSniffer{}
var _ store.ABCIListener = &packetSniffer{}

func newPacketSniffer() *packetSniffer {
return &packetSniffer{
Expand All @@ -390,7 +390,6 @@ func newPacketSniffer() *packetSniffer {
}

func (ps *packetSniffer) ListenFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error {
// 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
Expand All @@ -408,29 +407,7 @@ func (*packetSniffer) ListenCommit(ctx context.Context, res abci.ResponseCommit,
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 {
Expand Down

0 comments on commit 657c063

Please sign in to comment.