Skip to content

Commit

Permalink
test: moving check to WriteAcknowledgement
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed Feb 24, 2022
1 parent 53decd4 commit f67f139
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
11 changes: 2 additions & 9 deletions modules/apps/29-fee/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest()
// setup path2 (chainA -> chainC) first in order to have different channel IDs for chainA & chainB
suite.coordinator.Setup(suite.path2)
// setup path for chainA -> chainB
suite.coordinator.Setup(suite.path)

suite.chainB.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainB.GetContext(), suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID)
Expand Down Expand Up @@ -531,15 +533,6 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {
relayer, _ := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), packetId)
suite.Require().Equal(relayer, suite.chainA.SenderAccount.GetAddress().String())

chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID)
ack := channeltypes.NewResultAcknowledgement([]byte("success"))

err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), chanCap, packet, ack)
suite.Require().NoError(err)

packetAck, _ := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
suite.Require().Equal(packetAck, channeltypes.CommitAcknowledgement(ack.Acknowledgement()))

case !tc.forwardRelayer:
forwardAddr, _ := suite.chainB.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.path.EndpointA.ChannelID)

Expand Down
15 changes: 13 additions & 2 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ type KeeperTestSuite struct {
// testing chains used for convenience and readability
chainA *ibctesting.TestChain
chainB *ibctesting.TestChain
chainC *ibctesting.TestChain

path *ibctesting.Path
path2 *ibctesting.Path

path *ibctesting.Path
queryClient types.QueryClient
}

func (suite *KeeperTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3))

path := ibctesting.NewPath(suite.chainA, suite.chainB)
mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version}))
Expand All @@ -46,6 +50,13 @@ func (suite *KeeperTestSuite) SetupTest() {
path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort
suite.path = path

path = ibctesting.NewPath(suite.chainA, suite.chainC)
path.EndpointA.ChannelConfig.Version = mockFeeVersion
path.EndpointB.ChannelConfig.Version = mockFeeVersion
path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort
path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort
suite.path2 = path

queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry())
types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().IBCFeeKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)
Expand Down
12 changes: 10 additions & 2 deletions modules/apps/29-fee/keeper/relay_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
)
Expand All @@ -14,7 +15,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() {
{
"success",
func() {
suite.chainB.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String())
suite.chainB.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointB.ChannelID, suite.path.EndpointB.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String())
suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.path.EndpointA.ChannelID)
},
true,
Expand All @@ -31,7 +32,10 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() {
suite.Run(tc.name, func() {
suite.SetupTest()

// open incentivized channel
// open incentivized channels
// setup path2 (chainA -> chainC) first in order to have different channel IDs for chainA & chainB
suite.coordinator.Setup(suite.path2)
// setup path for chainA -> chainB
suite.coordinator.Setup(suite.path)

// build packet
Expand Down Expand Up @@ -59,6 +63,10 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() {
suite.Require().NoError(err)
_, found := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1))
suite.Require().False(found)

expectedAck := types.NewIncentivizedAcknowledgement(suite.chainB.SenderAccount.GetAddress().String(), ack.Acknowledgement(), ack.Success())
commitedAck, _ := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationPort, packet.DestinationChannel, 1)
suite.Require().Equal(commitedAck, channeltypes.CommitAcknowledgement(expectedAck.Acknowledgement()))
} else {
suite.Require().Error(err)
}
Expand Down

0 comments on commit f67f139

Please sign in to comment.