Skip to content
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

chore: no need to declare new variables #7751

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel.Counterparty, channel.Version,
)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(expectedVersion, version)
} else {
Expand Down Expand Up @@ -686,9 +685,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeInit() {
version,
)

expPass := tc.expError == nil

if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(upgradeVersion, version)
} else {
Expand Down Expand Up @@ -857,8 +854,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeAck() {
counterpartyVersion,
)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(path.EndpointA.GetChannel().Version, counterpartyVersion)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeTry() {
counterpartyVersion,
)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(path.EndpointB.GetChannel().Version, version)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {

txResponse, err := suite.chainB.GetSimApp().ICAHostKeeper.OnRecvPacket(suite.chainB.GetContext(), packet)

expPass := tc.expErr == nil
if expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(txResponse)
} else {
Expand Down Expand Up @@ -874,8 +873,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {

txResponse, err := suite.chainB.GetSimApp().ICAHostKeeper.OnRecvPacket(suite.chainB.GetContext(), packet)

expPass := tc.expErr == nil
if expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(txResponse)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ func TestMsgModuleQuerySafeValidateBasic(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
err := tc.msg.ValidateBasic()

expPass := tc.expErr == nil
if expPass {
if tc.expErr == nil {
require.NoError(t, err)
} else {
require.Error(t, err)
Expand Down
9 changes: 3 additions & 6 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeInit() {

err := path.EndpointA.ChanUpgradeInit()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
Expand Down Expand Up @@ -1231,8 +1230,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeTry() {

err = path.EndpointB.ChanUpgradeTry()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
Expand Down Expand Up @@ -1338,8 +1336,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeAck() {

err = cbs.OnChanUpgradeAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterpartyUpgrade.Fields.Version)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/29-fee/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func (suite *FeeTestSuite) TestTransferFeeUpgrade() {
err = path.EndpointA.ChanUpgradeOpen()
suite.Require().NoError(err)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
channelA := path.EndpointA.GetChannel()
suite.Require().Equal(upgradeVersion, channelA.Version)

Expand Down
3 changes: 1 addition & 2 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func (s *CallbacksTestSuite) TestNewIBCMiddleware() {
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
s.Require().NotPanics(tc.instantiateFn, "unexpected panic: NewIBCMiddleware")
} else {
s.Require().PanicsWithError(tc.expError.Error(), tc.instantiateFn, "expected panic with error: ", tc.expError.Error())
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/callbacks/types/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,7 @@ func (s *CallbacksTypesTestSuite) TestGetCallbackData() {

callbackData, err := types.GetCallbackData(packetData, version, transfertypes.PortID, remainingGas, uint64(1_000_000), callbackKey)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
s.Require().NoError(err, tc.name)
s.Require().Equal(tc.expCallbackData, callbackData, tc.name)

Expand Down
24 changes: 8 additions & 16 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() {
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterparty, channel.Version,
)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(tc.expVersion, version)
} else {
Expand Down Expand Up @@ -186,8 +185,7 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() {
version, err := cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops,
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel.Counterparty, counterpartyVersion,
)
expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(tc.expVersion, version)
} else {
Expand Down Expand Up @@ -236,8 +234,7 @@ func (suite *TransferTestSuite) TestOnChanOpenAck() {

err := cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointA.Counterparty.ChannelID, counterpartyVersion)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
Expand Down Expand Up @@ -472,8 +469,7 @@ func (suite *TransferTestSuite) TestOnTimeoutPacket() {

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

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)

escrowAddress := types.GetEscrowAddress(packet.GetSourcePort(), packet.GetSourceChannel())
Expand Down Expand Up @@ -545,8 +541,7 @@ func (suite *TransferTestSuite) TestOnChanUpgradeInit() {

err := path.EndpointA.ChanUpgradeInit()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
upgrade := path.EndpointA.GetChannelUpgrade()
suite.Require().Equal(upgradePath.EndpointA.ConnectionID, upgrade.Fields.ConnectionHops[0])
Expand Down Expand Up @@ -623,8 +618,7 @@ func (suite *TransferTestSuite) TestOnChanUpgradeTry() {
counterpartyUpgrade.Fields.Ordering, counterpartyUpgrade.Fields.ConnectionHops, counterpartyUpgrade.Fields.Version,
)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().Equal(types.V2, version)
} else {
Expand Down Expand Up @@ -688,8 +682,7 @@ func (suite *TransferTestSuite) TestOnChanUpgradeAck() {

err = cbs.OnChanUpgradeAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.Version)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
Expand Down Expand Up @@ -847,8 +840,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {

packetData, version, err := unmarshalerStack.UnmarshalPacketData(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, data)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)

v2PacketData, ok := packetData.(types.FungibleTokenPacketDataV2)
Expand Down
3 changes: 1 addition & 2 deletions modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
),
}.ToABCIEvents()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().NotEqual(res.Sequence, uint64(0))
Expand Down
18 changes: 6 additions & 12 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {

res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(suite.chainA.GetContext(), msg)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
} else {
Expand Down Expand Up @@ -466,8 +465,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() {

err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, packetData)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)

// Check denom metadata for of tokens received on chain B.
Expand Down Expand Up @@ -593,8 +591,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() {
packet := channeltypes.NewPacket(packetData.GetBytes(), uint64(1), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, clienttypes.NewHeight(1, 100), 0)
err = suite.chainA.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainA.GetContext(), packet, packetData)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)

_, found := suite.chainA.GetSimApp().BankKeeper.GetDenomMetaData(suite.chainA.GetContext(), sdk.DefaultBondDenom)
Expand Down Expand Up @@ -809,8 +806,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() {
totalEscrow := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainA.GetContext(), denom.IBCDenom())
suite.Require().Equal(expEscrowAmount, totalEscrow.Amount)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
postAcknowledgementBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), denom.IBCDenom())
deltaAmount := postAcknowledgementBalance.Amount.Sub(preAcknowledgementBalance.Amount)
Expand Down Expand Up @@ -1047,8 +1043,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() {
totalEscrow := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainA.GetContext(), denom.IBCDenom())
suite.Require().Equal(expEscrowAmount, totalEscrow.Amount)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
amountParsed, ok := sdkmath.NewIntFromString(amount)
suite.Require().True(ok)
Expand Down Expand Up @@ -1230,8 +1225,7 @@ func (suite *KeeperTestSuite) TestPacketForwardsCompatibility() {
// receive packet on chainA
err = path.RelayPacket(packet)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
suite.Require().NoError(err)
} else {
suite.Require().ErrorContains(err, tc.expError.Error())
Expand Down
9 changes: 3 additions & 6 deletions modules/apps/transfer/types/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ func TestForwarding_Validate(t *testing.T) {

err := tc.forwarding.Validate()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tc.expError)
Expand Down Expand Up @@ -209,8 +208,7 @@ func TestForwardingPacketData_Validate(t *testing.T) {

err := tc.forwarding.Validate()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tc.expError)
Expand Down Expand Up @@ -267,8 +265,7 @@ func TestValidateHop(t *testing.T) {

err := tc.hop.Validate()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tc.expError)
Expand Down
6 changes: 2 additions & 4 deletions modules/apps/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func TestMsgTransferValidation(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
err := tc.msg.ValidateBasic()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tc.expError)
Expand Down Expand Up @@ -134,8 +133,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
err := tc.msg.ValidateBasic()

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tc.expError)
Expand Down
12 changes: 4 additions & 8 deletions modules/apps/transfer/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
err := tc.packetData.ValidateBasic()

expPass := tc.expErr == nil
if expPass {
if tc.expErr == nil {
require.NoError(t, err, tc.name)
} else {
require.ErrorContains(t, err, tc.expErr.Error(), tc.name)
Expand Down Expand Up @@ -767,8 +766,7 @@ func TestUnmarshalPacketData(t *testing.T) {

packetData, err := types.UnmarshalPacketData(packetDataBz, version)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.IsType(t, types.FungibleTokenPacketDataV2{}, packetData)
} else {
require.ErrorIs(t, err, tc.expError)
Expand Down Expand Up @@ -821,8 +819,7 @@ func TestV2ForwardsCompatibilityFails(t *testing.T) {

packetData, err := types.UnmarshalPacketData(packetDataBz, types.V2)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err)
require.NotEqual(t, types.FungibleTokenPacketDataV2{}, packetData)
} else {
Expand Down Expand Up @@ -938,8 +935,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
for _, tc := range testCases {
actualV2Data, err := types.PacketDataV1ToV2(tc.v1Data)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err, "test case: %s", tc.name)
require.Equal(t, tc.v2Data, actualV2Data, "test case: %s", tc.name)
} else {
Expand Down
6 changes: 2 additions & 4 deletions modules/apps/transfer/types/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ func TestValidate(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.token.Validate()
expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err, tc.name)
} else {
require.ErrorContains(t, err, tc.expError.Error(), tc.name)
Expand Down Expand Up @@ -193,8 +192,7 @@ func TestToCoin(t *testing.T) {

require.Equal(t, tc.expCoin, coin, tc.name)

expPass := tc.expError == nil
if expPass {
if tc.expError == nil {
require.NoError(t, err, tc.name)
} else {
require.ErrorContains(t, err, tc.expError.Error(), tc.name)
Expand Down
Loading
Loading