-
Notifications
You must be signed in to change notification settings - Fork 751
feat: Packet forward middleware #8285
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
58e0268
chore: update minor dependencies
DeshErBojhaa 863799f
feat: move packet_forward_middleware from ibc-app to ibc-go repo.
DeshErBojhaa 2f0b0b0
fix: run go mod tidy
DeshErBojhaa 048215d
Merge branch 'main' into tamjid/pfm-homecoming
DeshErBojhaa 7b7a159
feat: Unit tests for Packet Forward Middleware (#8313)
DeshErBojhaa ae228c4
e2e: Port tests for packet forward middleware module (#8292)
DeshErBojhaa 695ee1d
chore: bump sdk math to 1.5.3 (#8293)
gjermundgaraba fadf346
test(07-tendermint): remove unused expPass in TestSetAndGetParams (#8…
hungdinh82 e665141
test(08-wasm): replace expPass with expError in TestNewKeeper (#8280)
hungdinh82 554de1c
chore: bump go-ethereum to v1.15.8 (#8295)
gjermundgaraba 76e2ef2
docs: add versioned docs for v10 (#8279)
gjermundgaraba ca1cbdb
rename total_escrow query path (#8287)
vladjdk 4f48209
docs: set v10 as default (#8301)
gjermundgaraba 209f0cd
feat: allow scaling of trusting period for client upgrades (#8185)
damiannolan 187fdf3
chore: prep v10.2.x mergify (#8305)
gjermundgaraba e48f6df
chore: fix test TestSetGetTotalEscrowForDenom, use expected errors (#…
hungdinh82 580420c
chore: bump deps (#8304)
gjermundgaraba 11f5a79
chore: remove datahash from ica account creation (#8307)
gjermundgaraba 093b44f
feat: sdk v53 upgrade (#8254)
7234ec5
chore: bump cosmossdk.io/api from v0.9.0 to v0.9.2 (#8326)
gjermundgaraba 6652880
chore(deps): bump github.com/ethereum/go-ethereum from 1.15.8 to 1.15…
dependabot[bot] 6e9ba42
chore: update to official sdk v0.53 release (#8329)
17724ed
chore: add changelog for v10.2.0 (#8331)
gjermundgaraba 4ead143
chore: fixed proto-lint errors (#8336)
srdtrk d9f49a2
chore: bumped go version used by wasm dockerfile (#8354)
srdtrk f883b96
chore: remove modules/core/specs (#8350)
gjermundgaraba 64ca973
feat: Prefix-based routing in IBCv2 Router (#8303)
kulikthebird 6c785a8
chore: remove e2e fork and draft restrictions (#8359)
gjermundgaraba 3cfc3f6
bump wasmvm to v2.2.4, go-etheruem to v1.15.11, spf13/cast to v1.8.0 …
gjermundgaraba 618a409
e2e: Create only required number of chains. (#8371)
DeshErBojhaa 4bf9be1
chore: update minor dependencies
DeshErBojhaa 7dda020
feat: move packet_forward_middleware from ibc-app to ibc-go repo.
DeshErBojhaa 7317ae2
fix: run go mod tidy
DeshErBojhaa 0b6af28
feat: Unit tests for Packet Forward Middleware (#8313)
DeshErBojhaa 9b399c7
e2e: Port tests for packet forward middleware module (#8292)
DeshErBojhaa f5de71c
sync dep
DeshErBojhaa 36fa262
fix: lint - Shutup Meg!
DeshErBojhaa 6bbbd0b
feat: sdk v53 upgrade (#8254)
67abf32
chore: update to official sdk v0.53 release (#8329)
575f650
e2e: Create only required number of chains. (#8371)
DeshErBojhaa 1f5a087
feat: move packet_forward_middleware from ibc-app to ibc-go repo.
DeshErBojhaa 2749602
feat: Unit tests for Packet Forward Middleware (#8313)
DeshErBojhaa 983a045
e2e: Port tests for packet forward middleware module (#8292)
DeshErBojhaa 05fd50e
feat: sdk v53 upgrade (#8254)
eb227b6
chore: update to official sdk v0.53 release (#8329)
18b514b
e2e: Create only required number of chains. (#8371)
DeshErBojhaa c8b8ac2
Merge branch 'main' of github.com:cosmos/ibc-go into tamjid/pfm-homec…
DeshErBojhaa 735636d
sync dep: WTF!!
DeshErBojhaa 8819f59
fix lint: Shutup Meg!
DeshErBojhaa 0aa1e9f
fix e2e
DeshErBojhaa 2fcf66c
changelog
DeshErBojhaa bc5df6a
fix markdown lint
DeshErBojhaa b2433d0
Merge remote-tracking branch 'origin/main' into tamjid/pfm-homecoming
gjermundgaraba deab81c
Merge branch 'main' into tamjid/pfm-homecoming
gjermundgaraba 0fe788e
address pr comment
DeshErBojhaa 0adb957
add comment
DeshErBojhaa d4f5dbf
fix: removed unused key
DeshErBojhaa a1ac2e0
refactor: removed unused func from expected keepers
DeshErBojhaa 38ca1d9
fix: Removed duplicated makefile
DeshErBojhaa 665fed0
Removed unused tar files
DeshErBojhaa 9dec322
refactor: remove unused param subspace
DeshErBojhaa b6ec134
refactor: simplify logic for getting inflight packets from KV store
DeshErBojhaa 1143ceb
refactor: remove unclear function
DeshErBojhaa 0018d29
refactor: remove dup interface
DeshErBojhaa b225209
chore: bump deps + lint (#8383)
gjermundgaraba affe099
fix dep
DeshErBojhaa 596d4ee
fix dep
DeshErBojhaa 4d63041
sync dep
DeshErBojhaa e8306cd
Merge branch 'main' of github.com:cosmos/ibc-go into tamjid/pfm-homec…
DeshErBojhaa 94ed241
refactor: rename function param
DeshErBojhaa f6ab855
Merge branch 'main' of github.com:cosmos/ibc-go into tamjid/pfm-homec…
DeshErBojhaa d31125d
move CallbacksCompatibleModuleV2 to api
gjermundgaraba f24e6a9
rename CallbacksCompatibleModuleV2 to PacketUnmarshalarModuleV2
gjermundgaraba 1947674
Merge branch 'main' into tamjid/pfm-homecoming
gjermundgaraba 16134a6
add note on module name spelling mistake
gjermundgaraba f2a204a
remove commented out import in genesis.proto
gjermundgaraba 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
feat: Unit tests for Packet Forward Middleware (#8313)
Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
- Loading branch information
commit 7b7a15970815247d6e5bdf4c9a86c65790fa8999
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
245 changes: 245 additions & 0 deletions
245
modules/apps/packet-forward-middleware/ibc_middleware_test.go
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,245 @@ | ||
| package packetforward_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/suite" | ||
|
|
||
| packetforward "github.com/cosmos/ibc-go/v10/modules/apps/packet-forward-middleware" | ||
| packetforwardkeeper "github.com/cosmos/ibc-go/v10/modules/apps/packet-forward-middleware/keeper" | ||
| packetforwardtypes "github.com/cosmos/ibc-go/v10/modules/apps/packet-forward-middleware/types" | ||
| transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types" | ||
| channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types" | ||
| ibctesting "github.com/cosmos/ibc-go/v10/testing" | ||
| ) | ||
|
|
||
| type PFMTestSuite struct { | ||
| suite.Suite | ||
|
|
||
| coordinator *ibctesting.Coordinator | ||
|
|
||
| chainA *ibctesting.TestChain | ||
| chainB *ibctesting.TestChain | ||
| chainC *ibctesting.TestChain | ||
|
|
||
| pathAB *ibctesting.Path | ||
| pathBC *ibctesting.Path | ||
| } | ||
|
|
||
| func TestPFMTestSuite(t *testing.T) { | ||
| suite.Run(t, new(PFMTestSuite)) | ||
| } | ||
|
|
||
| // setupChains sets up a coordinator with 3 test chains. | ||
| func (s *PFMTestSuite) setupChains() { | ||
| s.coordinator = ibctesting.NewCoordinator(s.T(), 3) | ||
| s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) | ||
| s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) | ||
| s.chainC = s.coordinator.GetChain(ibctesting.GetChainID(3)) | ||
|
|
||
| s.pathAB = ibctesting.NewTransferPath(s.chainA, s.chainB) | ||
| s.pathAB.Setup() | ||
|
|
||
| s.pathBC = ibctesting.NewTransferPath(s.chainB, s.chainC) | ||
| s.pathBC.Setup() | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) TestOnRecvPacket_NonfungibleToken() { | ||
| s.setupChains() | ||
|
|
||
| ctx := s.chainA.GetContext() | ||
| version := s.pathAB.EndpointA.GetChannel().Version | ||
| relayerAddr := s.chainA.SenderAccount.GetAddress() | ||
|
|
||
| pfm := s.pktForwardMiddleware(s.chainA) | ||
| ack := pfm.OnRecvPacket(ctx, version, channeltypes.Packet{}, relayerAddr) | ||
| s.Require().False(ack.Success()) | ||
|
|
||
| expectedAck := &channeltypes.Acknowledgement{} | ||
| err := s.chainA.Codec.UnmarshalJSON(ack.Acknowledgement(), expectedAck) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Transfer keeper returns this error if the packet received is not a fungible token. | ||
| s.Require().Equal("ABCI code: 12: error handling packet: see events for details", expectedAck.GetError()) | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) TestOnRecvPacket_NoMemo() { | ||
| s.setupChains() | ||
|
|
||
| ctx := s.chainA.GetContext() | ||
| version := s.pathAB.EndpointA.GetChannel().Version | ||
| relayerAddr := s.chainA.SenderAccount.GetAddress() | ||
| receiverAddr := s.chainB.SenderAccount.GetAddress() | ||
|
|
||
| packet := s.transferPacket(relayerAddr.String(), receiverAddr.String(), s.pathAB, 0, "{}") | ||
|
|
||
| pfm := s.pktForwardMiddleware(s.chainA) | ||
| ack := pfm.OnRecvPacket(ctx, version, packet, relayerAddr) | ||
| s.Require().True(ack.Success()) | ||
|
|
||
| expectedAck := &channeltypes.Acknowledgement{} | ||
| err := s.chainA.Codec.UnmarshalJSON(ack.Acknowledgement(), expectedAck) | ||
| s.Require().NoError(err) | ||
|
|
||
| s.Require().Equal("", expectedAck.GetError()) | ||
| s.Require().ElementsMatch([]byte{1}, expectedAck.GetResult()) | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) TestOnRecvPacket_InvalidReceiver() { | ||
| s.setupChains() | ||
|
|
||
| ctx := s.chainA.GetContext() | ||
| version := s.pathAB.EndpointA.GetChannel().Version | ||
| relayerAddr := s.chainA.SenderAccount.GetAddress() | ||
|
|
||
| packet := s.transferPacket(relayerAddr.String(), "", s.pathAB, 0, nil) | ||
|
|
||
| pfm := s.pktForwardMiddleware(s.chainA) | ||
| ack := pfm.OnRecvPacket(ctx, version, packet, relayerAddr) | ||
| s.Require().False(ack.Success()) | ||
|
|
||
| expectedAck := &channeltypes.Acknowledgement{} | ||
| err := s.chainA.Codec.UnmarshalJSON(ack.Acknowledgement(), expectedAck) | ||
| s.Require().NoError(err) | ||
|
|
||
| s.Require().Equal("ABCI code: 5: error handling packet: see events for details", expectedAck.GetError()) | ||
| s.Require().Empty(expectedAck.GetResult()) | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) TestOnRecvPacket_NoForward() { | ||
| s.setupChains() | ||
|
|
||
| ctx := s.chainA.GetContext() | ||
| version := s.pathAB.EndpointA.GetChannel().Version | ||
|
|
||
| senderAddr := s.chainA.SenderAccount.GetAddress() | ||
| receiverAddr := s.chainB.SenderAccount.GetAddress() | ||
|
|
||
| packet := s.transferPacket(senderAddr.String(), receiverAddr.String(), s.pathAB, 0, nil) | ||
|
|
||
| pfm := s.pktForwardMiddleware(s.chainA) | ||
| ack := pfm.OnRecvPacket(ctx, version, packet, senderAddr) | ||
| s.Require().True(ack.Success()) | ||
|
|
||
| expectedAck := &channeltypes.Acknowledgement{} | ||
| err := s.chainA.Codec.UnmarshalJSON(ack.Acknowledgement(), expectedAck) | ||
| s.Require().NoError(err) | ||
| s.Require().Equal("", expectedAck.GetError()) | ||
|
|
||
| s.Require().Equal([]byte{1}, expectedAck.GetResult()) | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) TestOnRecvPacket_RecvPacketFailed() { | ||
| s.setupChains() | ||
|
|
||
| transferKeeper := s.chainA.GetSimApp().TransferKeeper | ||
| ctx := s.chainA.GetContext() | ||
| transferKeeper.SetParams(ctx, transfertypes.Params{ReceiveEnabled: false}) | ||
|
|
||
| version := s.pathAB.EndpointA.GetChannel().Version | ||
|
|
||
| senderAddr := s.chainA.SenderAccount.GetAddress() | ||
| receiverAddr := s.chainB.SenderAccount.GetAddress() | ||
| metadata := &packetforwardtypes.PacketMetadata{ | ||
| Forward: &packetforwardtypes.ForwardMetadata{ | ||
| Receiver: receiverAddr.String(), | ||
| Port: s.pathAB.EndpointA.ChannelConfig.PortID, | ||
| Channel: s.pathAB.EndpointA.ChannelID, | ||
| }, | ||
| } | ||
| packet := s.transferPacket(senderAddr.String(), receiverAddr.String(), s.pathAB, 0, metadata) | ||
|
|
||
| pfm := s.pktForwardMiddleware(s.chainA) | ||
| ack := pfm.OnRecvPacket(ctx, version, packet, senderAddr) | ||
| s.Require().False(ack.Success()) | ||
|
|
||
| expectedAck := &channeltypes.Acknowledgement{} | ||
|
|
||
| err := s.chainA.Codec.UnmarshalJSON(ack.Acknowledgement(), expectedAck) | ||
| s.Require().NoError(err) | ||
| s.Require().Equal("packet-forward-middleware error: error receiving packet: ack error: {\"error\":\"ABCI code: 8: error handling packet: see events for details\"}", expectedAck.GetError()) | ||
|
|
||
| s.Require().Equal([]byte(nil), expectedAck.GetResult()) | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) TestOnRecvPacket_ForwardNoFee() { | ||
| s.setupChains() | ||
|
|
||
| senderAddr := s.chainA.SenderAccount.GetAddress() | ||
| receiverAddr := s.chainC.SenderAccount.GetAddress() | ||
| metadata := &packetforwardtypes.PacketMetadata{ | ||
| Forward: &packetforwardtypes.ForwardMetadata{ | ||
| Receiver: receiverAddr.String(), | ||
| Port: s.pathBC.EndpointA.ChannelConfig.PortID, | ||
| Channel: s.pathBC.EndpointA.ChannelID, | ||
| }, | ||
| } | ||
| packet := s.transferPacket(senderAddr.String(), receiverAddr.String(), s.pathAB, 0, metadata) | ||
| version := s.pathAB.EndpointA.GetChannel().Version | ||
| ctxB := s.chainB.GetContext() | ||
|
|
||
| pfmB := s.pktForwardMiddleware(s.chainB) | ||
| ack := pfmB.OnRecvPacket(ctxB, version, packet, senderAddr) | ||
| s.Require().Nil(ack) | ||
|
|
||
| // Check that chain C has received the packet | ||
| ctxC := s.chainC.GetContext() | ||
| packet = s.transferPacket(senderAddr.String(), receiverAddr.String(), s.pathBC, 0, nil) | ||
| version = s.pathBC.EndpointA.GetChannel().Version | ||
|
|
||
| pfmC := s.pktForwardMiddleware(s.chainC) | ||
| ack = pfmC.OnRecvPacket(ctxC, version, packet, senderAddr) | ||
| s.Require().NotNil(ack) | ||
|
|
||
| // Ack on chainC | ||
| packet = s.transferPacket(senderAddr.String(), receiverAddr.String(), s.pathBC, 1, nil) | ||
| err := pfmC.OnAcknowledgementPacket(ctxC, version, packet, ack.Acknowledgement(), senderAddr) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Ack on ChainB | ||
| err = pfmB.OnAcknowledgementPacket(ctxB, version, packet, ack.Acknowledgement(), senderAddr) | ||
| s.Require().NoError(err) | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) pktForwardMiddleware(chain *ibctesting.TestChain) packetforward.IBCMiddleware { | ||
| pfmKeeper := chain.GetSimApp().PFMKeeper | ||
|
|
||
| ibcModule, ok := chain.App.GetIBCKeeper().PortKeeper.Route(transfertypes.ModuleName) | ||
| s.Require().True(ok) | ||
|
|
||
| ibcMiddleware := packetforward.NewIBCMiddleware(ibcModule, &pfmKeeper, 0, packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp) | ||
| return ibcMiddleware | ||
| } | ||
|
|
||
| func (s *PFMTestSuite) transferPacket(sender string, receiver string, path *ibctesting.Path, seq uint64, metadata any) channeltypes.Packet { | ||
| s.T().Helper() | ||
| tokenPacket := transfertypes.FungibleTokenPacketData{ | ||
| Denom: "uatom", | ||
| Amount: "100", | ||
| Sender: sender, | ||
| Receiver: receiver, | ||
| } | ||
|
|
||
| if metadata != nil { | ||
| if mStr, ok := metadata.(string); ok { | ||
| tokenPacket.Memo = mStr | ||
| } else { | ||
| memo, err := json.Marshal(metadata) | ||
| s.Require().NoError(err) | ||
| tokenPacket.Memo = string(memo) | ||
| } | ||
| } | ||
|
|
||
| tokenData, err := transfertypes.ModuleCdc.MarshalJSON(&tokenPacket) | ||
| s.Require().NoError(err) | ||
|
|
||
| return channeltypes.Packet{ | ||
| SourcePort: path.EndpointA.ChannelConfig.PortID, | ||
| SourceChannel: path.EndpointA.ChannelID, | ||
| DestinationPort: path.EndpointB.ChannelConfig.PortID, | ||
| DestinationChannel: path.EndpointB.ChannelID, | ||
| Data: tokenData, | ||
| Sequence: seq, | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.