Skip to content

Commit

Permalink
(chore) change tests in 27ica/controller to expect specific error (#7177
Browse files Browse the repository at this point in the history
)

* changed tests in 27ica/controller to expect specific error

* fix test

* fixed test

* PR feedback
  • Loading branch information
bznein authored Aug 20, 2024
1 parent b996035 commit 1448c59
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
"success", func() {}, nil,
},
{
"ICA auth module does not claim channel capability", func() {
Expand All @@ -139,7 +139,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {

return version, nil
}
}, true,
}, nil,
},
{
"ICA auth module modification of channel version is ignored", func() {
Expand All @@ -151,12 +151,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
) (string, error) {
return "invalid-version", nil
}
}, true,
}, nil,
},
{
"controller submodule disabled", func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false))
}, false,
}, types.ErrControllerSubModuleDisabled,
},
{
"ICA auth module callback fails", func() {
Expand All @@ -166,12 +166,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
) (string, error) {
return "", fmt.Errorf("mock ica auth fails")
}
}, false,
}, fmt.Errorf("mock ica auth fails"),
},
{
"nil underlying app", func() {
isNilApp = true
}, true,
}, nil,
},
{
"middleware disabled", func() {
Expand All @@ -183,7 +183,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
) (string, error) {
return "", fmt.Errorf("error should be unreachable")
}
}, true,
}, nil,
},
}

Expand Down Expand Up @@ -242,11 +242,11 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.Version,
)

if tc.expPass {
if tc.expErr == nil {
suite.Require().Equal(TestVersion, version)
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorContains(err, tc.expErr.Error())
}
})
}
Expand Down Expand Up @@ -315,20 +315,20 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
"success", func() {}, nil,
},
{
"controller submodule disabled", func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false))
}, false,
}, types.ErrControllerSubModuleDisabled,
},
{
"ICA OnChanOpenACK fails - invalid version", func() {
path.EndpointB.ChannelConfig.Version = invalidVersion
}, false,
}, ibcerrors.ErrInvalidType,
},
{
"ICA auth module callback fails", func() {
Expand All @@ -337,12 +337,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() {
) error {
return fmt.Errorf("mock ica auth fails")
}
}, false,
}, fmt.Errorf("mock ica auth fails"),
},
{
"nil underlying app", func() {
isNilApp = true
}, true,
}, nil,
},
{
"middleware disabled", func() {
Expand All @@ -353,7 +353,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() {
) error {
return fmt.Errorf("error should be unreachable")
}
}, true,
}, nil,
},
}

Expand Down Expand Up @@ -388,10 +388,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() {
cbs = controller.NewIBCMiddleware(suite.chainA.GetSimApp().ICAControllerKeeper)
}

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorContains(err, tc.expErr.Error())
}
})
}
Expand Down Expand Up @@ -484,15 +484,15 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
"success", func() {}, nil,
},
{
"nil underlying app", func() {
isNilApp = true
}, true,
}, nil,
},
}

Expand Down Expand Up @@ -524,10 +524,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
err = cbs.OnChanCloseConfirm(
suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -536,9 +536,9 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {

func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
testCases := []struct {
name string
malleate func()
expPass bool
name string
malleate func()
expSuccess bool
}{
{
"ICA OnRecvPacket fails with ErrInvalidChannelFlow", func() {}, false,
Expand Down Expand Up @@ -579,7 +579,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {

ctx := suite.chainA.GetContext()
ack := cbs.OnRecvPacket(ctx, path.EndpointA.GetChannel().Version, packet, nil)
suite.Require().Equal(tc.expPass, ack.Success())
suite.Require().Equal(tc.expSuccess, ack.Success())

expectedEvents := sdk.Events{
sdk.NewEvent(
Expand Down Expand Up @@ -607,17 +607,17 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"success",
func() {},
true,
nil,
},
{
"controller submodule disabled", func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false))
}, false,
}, types.ErrControllerSubModuleDisabled,
},
{
"ICA auth module callback fails", func() {
Expand All @@ -626,12 +626,12 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {
) error {
return fmt.Errorf("mock ica auth fails")
}
}, false,
}, fmt.Errorf("mock ica auth fails"),
},
{
"nil underlying app", func() {
isNilApp = true
}, true,
}, nil,
},
{
"middleware disabled", func() {
Expand All @@ -642,7 +642,7 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {
) error {
return fmt.Errorf("error should be unreachable")
}
}, true,
}, nil,
},
}

Expand Down Expand Up @@ -685,10 +685,10 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {

err = cbs.OnAcknowledgementPacket(suite.chainA.GetContext(), path.EndpointA.GetChannel().Version, packet, []byte("ack"), nil)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorContains(err, tc.expErr.Error())
}
})
}
Expand All @@ -704,17 +704,17 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"success",
func() {},
true,
nil,
},
{
"controller submodule disabled", func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false))
}, false,
}, types.ErrControllerSubModuleDisabled,
},
{
"ICA auth module callback fails", func() {
Expand All @@ -723,12 +723,12 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
) error {
return fmt.Errorf("mock ica auth fails")
}
}, false,
}, fmt.Errorf("mock ica auth fails"),
},
{
"nil underlying app", func() {
isNilApp = true
}, true,
}, nil,
},
{
"middleware disabled", func() {
Expand All @@ -739,7 +739,7 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
) error {
return fmt.Errorf("error should be unreachable")
}
}, true,
}, nil,
},
}

Expand Down Expand Up @@ -782,10 +782,10 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {

err = cbs.OnTimeoutPacket(suite.chainA.GetContext(), path.EndpointA.GetChannel().Version, packet, nil)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorContains(err, tc.expErr.Error())
}
})
}
Expand Down Expand Up @@ -1123,12 +1123,10 @@ func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() {
testCases := []struct {
msg string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
"success", func() {}, nil,
},
{
"port is already bound for owner but capability is claimed by another module",
Expand All @@ -30,14 +30,14 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID))
suite.Require().NoError(err)
},
false,
icatypes.ErrPortAlreadyBound,
},
{
"fails to generate port-id",
func() {
owner = ""
},
false,
icatypes.ErrInvalidAccountAddress,
},
{
"MsgChanOpenInit fails - channel is already active & in state OPEN",
Expand All @@ -57,7 +57,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
}
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel)
},
false,
icatypes.ErrActiveChannelAlreadySet,
},
}

Expand All @@ -76,10 +76,10 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {

err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), path.EndpointA.ConnectionID, owner, TestVersion, ordering)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down
Loading

0 comments on commit 1448c59

Please sign in to comment.