Skip to content

Commit 36e4b05

Browse files
author
bznein
committed
new tests
1 parent 3dd7deb commit 36e4b05

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

modules/apps/transfer/ibc_module_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,3 +894,87 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
894894
})
895895
}
896896
}
897+
898+
func (suite *TransferTestSuite) TestOnSendPacket() {
899+
var (
900+
packetData types.FungibleTokenPacketDataV2
901+
path *ibctesting.Path
902+
)
903+
904+
testCases := []struct {
905+
name string
906+
malleate func()
907+
expError error
908+
}{
909+
{
910+
"success",
911+
func() {},
912+
nil,
913+
},
914+
{
915+
"failure: send disabled",
916+
func() {
917+
suite.chainA.GetSimApp().TransferKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false, true))
918+
},
919+
types.ErrSendDisabled,
920+
},
921+
{
922+
"failure: blocked address",
923+
func() {
924+
packetData.Sender = string(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(types.ModuleName))
925+
},
926+
ibcerrors.ErrUnauthorized,
927+
},
928+
{
929+
"failure: sender is not signer",
930+
func() {
931+
packetData.Sender = suite.chainB.SenderAccount.GetAddress().String()
932+
},
933+
ibcerrors.ErrInvalidAddress,
934+
},
935+
{
936+
"failure: can't have forwarding info with V1",
937+
func() {
938+
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) {
939+
channel.Version = types.V1
940+
})
941+
packetData.Forwarding = types.NewForwardingPacketData("", types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
942+
},
943+
ibcerrors.ErrInvalidRequest,
944+
},
945+
}
946+
for _, tc := range testCases {
947+
suite.Run(tc.name, func() {
948+
suite.SetupTest()
949+
950+
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
951+
path.Setup()
952+
953+
packetData = types.NewFungibleTokenPacketDataV2(
954+
[]types.Token{{Denom: types.NewDenom(sdk.DefaultBondDenom), Amount: ibctesting.TestCoin.Amount.String()}},
955+
suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.String(), "", types.ForwardingPacketData{},
956+
)
957+
958+
tc.malleate()
959+
960+
dataBytes := packetData.GetBytes()
961+
962+
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.AppRoute(path.EndpointA.ChannelConfig.PortID)
963+
suite.Require().True(ok)
964+
965+
err := cbs[0].OnSendPacket(
966+
suite.chainA.GetContext(),
967+
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID,
968+
0, clienttypes.ZeroHeight(), 0,
969+
dataBytes,
970+
sdk.MustAccAddressFromBech32(suite.chainA.SenderAccount.GetAddress().String()),
971+
)
972+
973+
if tc.expError == nil {
974+
suite.Require().NoError(err)
975+
} else {
976+
suite.Require().ErrorIs(err, tc.expError)
977+
}
978+
})
979+
}
980+
}

0 commit comments

Comments
 (0)