Skip to content
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

refactor: use mock module for OnAcknowledgePacket ics29 testing #929

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
}
20 changes: 8 additions & 12 deletions modules/apps/29-fee/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeesInEscrow(suite.chainA.GetContext(), packetId)

ack = types.IncentivizedAcknowledgement{
Result: channeltypes.NewResultAcknowledgement([]byte{1}).Acknowledgement(),
Result: ibcmock.MockAcknowledgement.Acknowledgement(),
ForwardRelayerAddress: suite.chainA.SenderAccount.GetAddress().String(),
}.Acknowledgement()

Expand All @@ -566,7 +566,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
"channel is not fee not enabled, success",
func() {
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
ack = channeltypes.NewResultAcknowledgement([]byte{1}).Acknowledgement()
ack = ibcmock.MockAcknowledgement.Acknowledgement()

expectedBalance = originalBalance
},
Expand All @@ -578,7 +578,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
blockedAddr := suite.chainA.GetSimApp().AccountKeeper.GetModuleAccount(suite.chainA.GetContext(), transfertypes.ModuleName).GetAddress()

ack = types.IncentivizedAcknowledgement{
Result: channeltypes.NewResultAcknowledgement([]byte{1}).Acknowledgement(),
Result: ibcmock.MockAcknowledgement.Acknowledgement(),
ForwardRelayerAddress: blockedAddr.String(),
}.Acknowledgement()

Expand All @@ -592,24 +592,20 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest()
expectedRelayerBalance = sdk.Coins{} // reset

// open incentivized channel
suite.coordinator.Setup(suite.path)
packet := suite.CreateMockPacket()

// set up coin & ics20 packet
coin := ibctesting.TestCoin
packet := suite.CreateICS20Packet(coin)
expectedRelayerBalance = sdk.Coins{} // reset

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

cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module)
suite.Require().True(ok)

// escrow the packet fee
packetId := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, suite.chainA.SenderAccount.GetSequence())
packetId := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence())
identifiedFee = types.NewIdentifiedPacketFee(
packetId,
types.Fee{
Expand All @@ -627,7 +623,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {

// must be changed explicitly
ack = types.IncentivizedAcknowledgement{
Result: channeltypes.NewResultAcknowledgement([]byte{1}).Acknowledgement(),
Result: ibcmock.MockAcknowledgement.Acknowledgement(),
ForwardRelayerAddress: relayerAddr.String(),
}.Acknowledgement()

Expand Down