Skip to content

Commit

Permalink
refactor: OnRecvPacket to use mock module (#927)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean King <seantking@users.noreply.github.com>
  • Loading branch information
colin-axner and seantking authored Feb 18, 2022
1 parent d8b9821 commit adc66d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
13 changes: 13 additions & 0 deletions modules/apps/29-fee/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,16 @@ func (suite *FeeTestSuite) CreateICS20Packet(coin sdk.Coin) channeltypes.Packet
0,
)
}

func (suite *FeeTestSuite) CreateMockPacket() channeltypes.Packet {
return channeltypes.NewPacket(
ibcmock.MockPacketData,
suite.chainA.SenderAccount.GetSequence(),
suite.path.EndpointA.ChannelConfig.PortID,
suite.path.EndpointA.ChannelID,
suite.path.EndpointB.ChannelConfig.PortID,
suite.path.EndpointB.ChannelID,
clienttypes.NewHeight(0, 100),
0,
)
}
16 changes: 6 additions & 10 deletions modules/apps/29-fee/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,21 +462,18 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {
for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest()
suite.SetupMockTest()
suite.coordinator.Setup(suite.path)

// set up coin & ics20 packet
coin := ibctesting.TestCoin

// set up a different channel to make sure that the test will error if the destination channel of the packet is not fee enabled
suite.path.EndpointB.ChannelID = "channel-1"
suite.chainB.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainB.GetContext(), suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID)
suite.chainB.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainB.GetContext(), suite.path.EndpointB.ChannelConfig.PortID, "channel-0")

packet := suite.CreateICS20Packet(coin)
packet := suite.CreateMockPacket()

// set up module and callbacks
module, _, err := suite.chainB.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainB.GetContext(), ibctesting.TransferPort)
module, _, err := suite.chainB.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainB.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainB.App.GetIBCKeeper().Router.GetRoute(module)
Expand All @@ -491,19 +488,18 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {

switch {
case !tc.feeEnabled:
ack := channeltypes.NewResultAcknowledgement([]byte{1})
suite.Require().Equal(ack, result)
suite.Require().Equal(ibcmock.MockAcknowledgement, result)

case tc.forwardRelayer:
ack := types.IncentivizedAcknowledgement{
Result: channeltypes.NewResultAcknowledgement([]byte{1}).Acknowledgement(),
Result: ibcmock.MockAcknowledgement.Acknowledgement(),
ForwardRelayerAddress: suite.chainB.SenderAccount.GetAddress().String(),
}
suite.Require().Equal(ack, result)

case !tc.forwardRelayer:
ack := types.IncentivizedAcknowledgement{
Result: channeltypes.NewResultAcknowledgement([]byte{1}).Acknowledgement(),
Result: ibcmock.MockAcknowledgement.Acknowledgement(),
ForwardRelayerAddress: "",
}
suite.Require().Equal(ack, result)
Expand Down

0 comments on commit adc66d2

Please sign in to comment.