-
Notifications
You must be signed in to change notification settings - Fork 694
ICA: Adding tests for relay.go #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
47deece
3f3ae8b
b5c9ed9
931ecb7
862ec08
1fccda1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,24 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { | |
suite.Require().True(found) | ||
suite.Require().Equal(expectedAddr, retrievedAddr) | ||
} | ||
|
||
func (suite *KeeperTestSuite) SetupICAPath(path *ibctesting.Path, owner string) error { | ||
if err := InitInterchainAccount(path.EndpointA, owner); err != nil { | ||
return err | ||
} | ||
|
||
if err := path.EndpointB.ChanOpenTry(); err != nil { | ||
return err | ||
} | ||
|
||
if err := path.EndpointA.ChanOpenAck(); err != nil { | ||
return err | ||
} | ||
|
||
if err := suite.chainB.GetSimApp().ICAKeeper.OnChanOpenConfirm(suite.chainA.GetContext(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It was a bug on my part (and a good sign it didn't work). It should be:
not
A -> B Would be good to switch back since you are using the Keeper on chainB and the context on chainA |
||
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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() { | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var ( | ||
path *ibctesting.Path | ||
msg interface{} | ||
portID string | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"success", func() { | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could probably be a var defined at the top of the test? (reduce code) |
||
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) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random fix