|
| 1 | +package keeper_test |
| 2 | + |
| 3 | +import ( |
| 4 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 5 | + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" |
| 6 | + |
| 7 | + ibctesting "github.com/cosmos/ibc-go/testing" |
| 8 | +) |
| 9 | + |
| 10 | +func (suite *KeeperTestSuite) TestTrySendTx() { |
| 11 | + var ( |
| 12 | + path *ibctesting.Path |
| 13 | + msg interface{} |
| 14 | + portID string |
| 15 | + ) |
| 16 | + |
| 17 | + testCases := []struct { |
| 18 | + name string |
| 19 | + malleate func() |
| 20 | + expPass bool |
| 21 | + }{ |
| 22 | + { |
| 23 | + "success", func() { |
| 24 | + amount, _ := sdk.ParseCoinsNormalized("100stake") |
| 25 | + interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) |
| 26 | + msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} |
| 27 | + }, true, |
| 28 | + }, |
| 29 | + { |
| 30 | + "success with []sdk.Message", func() { |
| 31 | + amount, _ := sdk.ParseCoinsNormalized("100stake") |
| 32 | + interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) |
| 33 | + msg1 := &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} |
| 34 | + msg2 := &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} |
| 35 | + msg = []sdk.Msg{msg1, msg2} |
| 36 | + }, true, |
| 37 | + }, |
| 38 | + { |
| 39 | + "incorrect outgoing data", func() { |
| 40 | + msg = []byte{} |
| 41 | + }, false, |
| 42 | + }, |
| 43 | + { |
| 44 | + "active channel not found", func() { |
| 45 | + amount, _ := sdk.ParseCoinsNormalized("100stake") |
| 46 | + interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) |
| 47 | + msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} |
| 48 | + portID = "incorrect portID" |
| 49 | + }, false, |
| 50 | + }, |
| 51 | + { |
| 52 | + "channel does not exist", func() { |
| 53 | + amount, _ := sdk.ParseCoinsNormalized("100stake") |
| 54 | + interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) |
| 55 | + msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} |
| 56 | + suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), portID, "channel-100") |
| 57 | + }, false, |
| 58 | + }, |
| 59 | + { |
| 60 | + "data is nil", func() { |
| 61 | + msg = nil |
| 62 | + }, false, |
| 63 | + }, |
| 64 | + { |
| 65 | + "data is not an SDK message", func() { |
| 66 | + msg = "not an sdk message" |
| 67 | + }, false, |
| 68 | + }, |
| 69 | + } |
| 70 | + |
| 71 | + for _, tc := range testCases { |
| 72 | + tc := tc |
| 73 | + |
| 74 | + suite.Run(tc.name, func() { |
| 75 | + suite.SetupTest() // reset |
| 76 | + path = NewICAPath(suite.chainA, suite.chainB) |
| 77 | + owner := "owner" |
| 78 | + suite.coordinator.SetupConnections(path) |
| 79 | + |
| 80 | + err := suite.SetupICAPath(path, owner) |
| 81 | + suite.Require().NoError(err) |
| 82 | + portID = path.EndpointA.ChannelConfig.PortID |
| 83 | + tc.malleate() |
| 84 | + _, err = suite.chainA.GetSimApp().ICAKeeper.TrySendTx(suite.chainA.GetContext(), portID, msg) |
| 85 | + |
| 86 | + if tc.expPass { |
| 87 | + suite.Require().NoError(err) |
| 88 | + } else { |
| 89 | + suite.Require().Error(err) |
| 90 | + } |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments