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): use expected errors in 29fee #7191

Merged
merged 10 commits into from
Aug 27, 2024
Merged

(chore): use expected errors in 29fee #7191

merged 10 commits into from
Aug 27, 2024

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Aug 20, 2024

Description

closes: #7190


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

false,
nil,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this up as it's a success case

@@ -135,7 +138,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {

suite.Require().NoError(err, "unexpected error from version: %s", tc.version)
} else {
suite.Require().Error(err, "error not returned for version: %s", tc.version)
suite.Require().True(errors.Is(err, tc.expErr) || strings.Contains(err.Error(), tc.expErr.Error()), "error no returned for version: %s or error %s is not %s", tc.version, err, tc.expErr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will come up several times in the PR. It's ugly, but the issue is that some of the errors that we get (especially from sdk) are not wrapped, so we can't check for a specific error but rather we have to rely on the error string. It's not ideal, but the other option would be to catch every usage of those errors and wrap them ourselves with something else

return fmt.Errorf("application callback fails")
}
}, false,
"fee module is not enabled", func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved stuff around here to have success cases before failures

@@ -24,7 +24,7 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
testCases := []struct {
name string
malleate func()
expPass bool
errMsg string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file relies entirely on error messages as all the errors we get from GRPC queries are not wrapped

}
})
}
}

func (suite *KeeperTestSuite) TestQueryFeeEnabledChannelsWithPagination() {
Copy link
Contributor Author

@bznein bznein Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was really interesting.

In this test, that was before a test case of another one, we create 10 extra channel, then get the first 5 from pagination and compare them. However, when building them, we loop over an integer and create them.

BUT, the logic that handles pagination paginates them based on their lexicographical order.
This means that if our channels are all after 10 (and before 100, so as to have 2 digits), the two orders are equal.

But in our case, depending on how many tests were ran before that, we could have the case in which our channels were 1,2,3,4,5,6,7,8,9,10, but the pagination would return 1, 10, 2,3,4,5,6,7,8,9, making the test fail!

Thanks @chatton for helping me debug this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting! And thank you both for debugging and fixing it!

},
}

for _, tc := range testCases {
tc := tc

suite.SetupTest()
suite.path.Setup()
suite.Run(tc.name, func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few instances in this PR where I introduced t.Run or suite.Run. It helped me debug things but I also think it's better to have it this way, even though it increases the diff. Happy to revert if people find it would be better suited for another PR

@bznein bznein marked this pull request as ready for review August 20, 2024 09:40
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for going through all these, it ended up being quite a bit 🥇

Only suggestion is maybe adding a helper for that error checking condition, otherwise looks great!

require.NoError(t, err, tc.name)
} else {
require.True(t, errors.Is(err, tc.expErr) || strings.Contains(err.Error(), tc.expErr.Error()), err.Error())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder would it be worth while turning this into some helper within the tests, seems like we need it in a good few places where errors aren't wrapped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense, done!

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we are missing the function RequireErrorIsOrContains. Other than that it looks good; thanks again for continuing with these refactors!

modules/apps/29-fee/ibc_middleware_test.go Outdated Show resolved Hide resolved
}
})
}
}

func (suite *KeeperTestSuite) TestQueryFeeEnabledChannelsWithPagination() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting! And thank you both for debugging and fixing it!

@chatton chatton enabled auto-merge August 26, 2024 11:20
Copy link

sonarcloud bot commented Aug 27, 2024

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@chatton chatton added this pull request to the merge queue Aug 27, 2024
Merged via the queue into main with commit 5db55dd Aug 27, 2024
70 checks passed
@chatton chatton deleted the bznein/expectErr/29fee branch August 27, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use expected errors instead of boolean values for 29fee
3 participants