github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/29-fee/keeper/relay_test.go (about) 1 package keeper_test 2 3 import ( 4 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/29-fee/types" 5 clienttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types" 6 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 7 ibctesting "github.com/fibonacci-chain/fbc/libs/ibc-go/testing" 8 ibcmock "github.com/fibonacci-chain/fbc/libs/ibc-go/testing/mock" 9 ) 10 11 func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { 12 testCases := []struct { 13 name string 14 malleate func() 15 expPass bool 16 }{ 17 { 18 "success", 19 func() { 20 suite.chainB.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 1), suite.chainA.SenderAccount().GetAddress().String()) 21 suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyPayeeAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount().GetAddress().String(), suite.chainB.SenderAccount().GetAddress().String(), suite.path.EndpointB.ChannelID) 22 }, 23 true, 24 }, 25 { 26 "relayer address not set for async WriteAcknowledgement", 27 func() {}, 28 false, 29 }, 30 } 31 32 for _, tc := range testCases { 33 tc := tc 34 suite.Run(tc.name, func() { 35 suite.SetupTest() 36 37 // open incentivized channels 38 // setup pathAToC (chainA -> chainC) first in order to have different channel IDs for chainA & chainB 39 suite.coordinator.Setup(suite.pathAToC) 40 // setup path for chainA -> chainB 41 suite.coordinator.Setup(suite.path) 42 43 // build packet 44 timeoutTimestamp := ^uint64(0) 45 packet := channeltypes.NewPacket( 46 []byte("packetData"), 47 1, 48 suite.path.EndpointA.ChannelConfig.PortID, 49 suite.path.EndpointA.ChannelID, 50 suite.path.EndpointB.ChannelConfig.PortID, 51 suite.path.EndpointB.ChannelID, 52 clienttypes.ZeroHeight(), 53 timeoutTimestamp, 54 ) 55 56 ack := channeltypes.NewResultAcknowledgement([]byte("success")) 57 chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID) 58 59 // malleate test case 60 tc.malleate() 61 62 err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), chanCap, packet, ack) 63 64 if tc.expPass { 65 suite.Require().NoError(err) 66 _, found := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 1)) 67 suite.Require().False(found) 68 69 expectedAck := types.NewIncentivizedAcknowledgement(suite.chainB.SenderAccount().GetAddress().String(), ack.Acknowledgement(), ack.Success()) 70 commitedAck, _ := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationPort, packet.DestinationChannel, 1) 71 suite.Require().Equal(commitedAck, channeltypes.CommitAcknowledgement(expectedAck.Acknowledgement())) 72 } else { 73 suite.Require().Error(err) 74 } 75 }) 76 } 77 } 78 79 func (suite *KeeperTestSuite) TestWriteAcknowledgementAsyncFeeDisabled() { 80 // open incentivized channel 81 suite.coordinator.Setup(suite.path) 82 suite.chainB.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainB.GetContext(), suite.path.EndpointB.ChannelConfig.PortID, "channel-0") 83 84 // build packet 85 timeoutTimestamp := ^uint64(0) 86 packet := channeltypes.NewPacket( 87 []byte("packetData"), 88 1, 89 suite.path.EndpointA.ChannelConfig.PortID, 90 suite.path.EndpointA.ChannelID, 91 suite.path.EndpointB.ChannelConfig.PortID, 92 suite.path.EndpointB.ChannelID, 93 clienttypes.ZeroHeight(), 94 timeoutTimestamp, 95 ) 96 97 ack := channeltypes.NewResultAcknowledgement([]byte("success")) 98 chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID) 99 100 err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), chanCap, packet, ack) 101 suite.Require().NoError(err) 102 103 packetAck, _ := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationPort, packet.DestinationChannel, 1) 104 suite.Require().Equal(packetAck, channeltypes.CommitAcknowledgement(ack.Acknowledgement())) 105 } 106 107 func (suite *KeeperTestSuite) TestGetAppVersion() { 108 var ( 109 portID string 110 channelID string 111 expAppVersion string 112 ) 113 testCases := []struct { 114 name string 115 malleate func() 116 expFound bool 117 }{ 118 { 119 "success for fee enabled channel", 120 func() { 121 expAppVersion = ibcmock.Version 122 }, 123 true, 124 }, 125 { 126 "success for non fee enabled channel", 127 func() { 128 path := ibctesting.NewPath(suite.chainA, suite.chainB) 129 path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort 130 path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort 131 // by default a new path uses a non fee channel 132 suite.coordinator.Setup(path) 133 portID = path.EndpointA.ChannelConfig.PortID 134 channelID = path.EndpointA.ChannelID 135 136 expAppVersion = ibcmock.Version 137 }, 138 true, 139 }, 140 { 141 "channel does not exist", 142 func() { 143 channelID = "does not exist" 144 }, 145 false, 146 }, 147 } 148 149 for _, tc := range testCases { 150 tc := tc 151 suite.Run(tc.name, func() { 152 suite.SetupTest() 153 suite.coordinator.Setup(suite.path) 154 155 portID = suite.path.EndpointA.ChannelConfig.PortID 156 channelID = suite.path.EndpointA.ChannelID 157 158 // malleate test case 159 tc.malleate() 160 161 appVersion, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetAppVersion(suite.chainA.GetContext(), portID, channelID) 162 163 if tc.expFound { 164 suite.Require().True(found) 165 suite.Require().Equal(expAppVersion, appVersion) 166 } else { 167 suite.Require().False(found) 168 suite.Require().Empty(appVersion) 169 } 170 }) 171 } 172 }