-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ICA: Adding tests for relay.go (#337)
* test: adding test for TrySendTx * test: adding tests for data check * test: adding check for SendTx with []sdk.Message * chore: seperate imports * test: add helper function for creating ICA path * test: adding cases for incorrect outgoing data & channel does not exist
- Loading branch information
Showing
6 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
|
||
ibctesting "github.com/cosmos/ibc-go/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestTrySendTx() { | ||
var ( | ||
path *ibctesting.Path | ||
msg interface{} | ||
portID string | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"success", func() { | ||
amount, _ := sdk.ParseCoinsNormalized("100stake") | ||
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) | ||
msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} | ||
}, true, | ||
}, | ||
{ | ||
"success with []sdk.Message", func() { | ||
amount, _ := sdk.ParseCoinsNormalized("100stake") | ||
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) | ||
msg1 := &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} | ||
msg2 := &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} | ||
msg = []sdk.Msg{msg1, msg2} | ||
}, true, | ||
}, | ||
{ | ||
"incorrect outgoing data", func() { | ||
msg = []byte{} | ||
}, false, | ||
}, | ||
{ | ||
"active channel not found", func() { | ||
amount, _ := sdk.ParseCoinsNormalized("100stake") | ||
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) | ||
msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} | ||
portID = "incorrect portID" | ||
}, false, | ||
}, | ||
{ | ||
"channel does not exist", func() { | ||
amount, _ := sdk.ParseCoinsNormalized("100stake") | ||
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) | ||
msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount} | ||
suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), portID, "channel-100") | ||
}, false, | ||
}, | ||
{ | ||
"data is nil", func() { | ||
msg = nil | ||
}, false, | ||
}, | ||
{ | ||
"data is not an SDK message", func() { | ||
msg = "not an sdk message" | ||
}, false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
suite.Run(tc.name, func() { | ||
suite.SetupTest() // reset | ||
path = NewICAPath(suite.chainA, suite.chainB) | ||
owner := "owner" | ||
suite.coordinator.SetupConnections(path) | ||
|
||
err := suite.SetupICAPath(path, owner) | ||
suite.Require().NoError(err) | ||
portID = path.EndpointA.ChannelConfig.PortID | ||
tc.malleate() | ||
_, err = suite.chainA.GetSimApp().ICAKeeper.TrySendTx(suite.chainA.GetContext(), portID, msg) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters