-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: implement packet parsing from events in MsgSendPacketWithSender #8012
Open
crStiv
wants to merge
8
commits into
cosmos:main
Choose a base branch
from
crStiv:endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d7bdc74
Update endpoint_v2.go
crStiv 06d7bf3
Create endpoint_v2_test.go
crStiv d8397ca
Update endpoint_v2.go
crStiv 1f5fc28
Update endpoint_v2_test.go
crStiv 8c6bcc9
Delete testing/endpoint_v2.go
crStiv 9217ddc
Delete testing/endpoint_v2_test.go
crStiv f67a79c
Update events.go
crStiv 44b8155
Update events_test.go
crStiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,114 @@ | ||
package ibctesting | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/cosmos/gogoproto/proto" | ||
"github.com/stretchr/testify/require" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
channeltypesv2 "github.com/cosmos/ibc-go/v10/modules/core/04-channel/v2/types" | ||
) | ||
|
||
func TestParsePacketFromEventsV2(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check the tests we have for the previous version of this in |
||
testCases := []struct { | ||
name string | ||
events []abci.Event | ||
expectedError string | ||
}{ | ||
{ | ||
name: "successful packet parsing", | ||
events: []abci.Event{ | ||
{ | ||
Type: channeltypesv2.EventTypeSendPacket, | ||
Attributes: []abci.EventAttribute{ | ||
{ | ||
Key: channeltypesv2.AttributeKeyEncodedPacketHex, | ||
Value: hex.EncodeToString(func() []byte { | ||
packet := channeltypesv2.Packet{ | ||
SourceClient: "client-0", | ||
DestinationClient: "client-1", | ||
Sequence: 1, | ||
TimeoutTimestamp: 100, | ||
Payloads: []channeltypesv2.Payload{ | ||
{ | ||
SourcePort: "transfer", | ||
DestinationPort: "transfer", | ||
Version: "1.0", | ||
Encoding: "proto3", | ||
Value: []byte("test data"), | ||
}, | ||
}, | ||
} | ||
bz, err := proto.Marshal(&packet) | ||
require.NoError(t, err) | ||
return bz | ||
}()), | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedError: "", | ||
}, | ||
{ | ||
name: "empty events", | ||
events: []abci.Event{}, | ||
expectedError: "packet not found in events", | ||
}, | ||
{ | ||
name: "invalid hex encoding", | ||
events: []abci.Event{ | ||
{ | ||
Type: channeltypesv2.EventTypeSendPacket, | ||
Attributes: []abci.EventAttribute{ | ||
{ | ||
Key: channeltypesv2.AttributeKeyEncodedPacketHex, | ||
Value: "invalid hex", | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedError: "failed to decode packet bytes", | ||
}, | ||
{ | ||
name: "invalid proto encoding", | ||
events: []abci.Event{ | ||
{ | ||
Type: channeltypesv2.EventTypeSendPacket, | ||
Attributes: []abci.EventAttribute{ | ||
{ | ||
Key: channeltypesv2.AttributeKeyEncodedPacketHex, | ||
Value: hex.EncodeToString([]byte("invalid proto")), | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedError: "failed to unmarshal packet", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
packet, err := ParsePacketFromEventsV2(tc.events) | ||
if tc.expectedError == "" { | ||
require.NoError(t, err) | ||
require.NotEmpty(t, packet) | ||
require.Equal(t, "client-0", packet.SourceClient) | ||
require.Equal(t, "client-1", packet.DestinationClient) | ||
require.Equal(t, uint64(1), packet.Sequence) | ||
require.Equal(t, uint64(100), packet.TimeoutTimestamp) | ||
require.Len(t, packet.Payloads, 1) | ||
require.Equal(t, "transfer", packet.Payloads[0].SourcePort) | ||
require.Equal(t, "transfer", packet.Payloads[0].DestinationPort) | ||
} else { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), tc.expectedError) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMsgSendPacketWithSender(t *testing.T) { | ||
coordinator := NewCoordinator(t, 2) | ||
chainA := coordinator.GetChain(GetChainID(1)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at
testing/events.go
. There is a ParsePacketFromEvents there. This one should be moved there.