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

Refactoring of contracts/evoting/types/ballots_test.go : #184

Merged
merged 5 commits into from
Oct 17, 2022
Merged

Refactoring of contracts/evoting/types/ballots_test.go : #184

merged 5 commits into from
Oct 17, 2022

Conversation

mamine2207
Copy link
Contributor

Defined constants for the most duplicated strings (select, rank, text and the string used when an answer could not be marshaled) to reduce code smells.

defined constants for the most duplicated strings (select, rank, text and
the string used when an answer could not be marshaled) to reduce code smells.
@coveralls
Copy link

coveralls commented Oct 8, 2022

Pull Request Test Coverage Report for Build 3260389972

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 15 of 15 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.09%) to 58.593%

Totals Coverage Status
Change from base Build 3189819177: 0.09%
Covered Lines: 2373
Relevant Lines: 4050

💛 - Coveralls

@nkcr nkcr added the node backend About the blockchain node label Oct 10, 2022
@mamine2207 mamine2207 requested review from nkcr and emduc October 11, 2022 08:35
emduc
emduc previously requested changes Oct 11, 2022
Copy link
Contributor

@emduc emduc left a comment

Choose a reason for hiding this comment

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

Nice ! Just need a small change on the naming convention :)

Food for thoughts: would it make sense to have those strings linked to the questions and accessible with a getter?

Comment on lines 11 to 15
const SELECT_STR = "select:"
const RANK_STR = "rank:"
const TEXT_STR = "text:"
const UNMARSHALING_RANK_STR = "could not unmarshal rank answers: "
const UNMARSHALING_TEXT_STR = "could not unmarshal text answers: "
Copy link
Contributor

Choose a reason for hiding this comment

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

We use camel case for constants as well. You can also declare them altogether since they're related, see PR #183 or contract/evoting.go for examples

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I think it would make sense and we will be able to use them in some functions in ballots.go such as unmarshal(...) or MaxEncodedSize(...). The only problem I can see is that the format is slightly different between the strings in the tests and the ones in ballots.go and that they are mostly recurrent in the tests.
Thanks for the note on the camel case convention, I have to get rid of my Java habits :)

Copy link
Contributor

@emduc emduc Oct 11, 2022

Choose a reason for hiding this comment

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

Do you mean because of the : ? Since this is just formatting it does not have to be part of the string. It could be written as a join in the tests.
This might be overthinking it (although quite clean), but we could use the Question interface to force the Text/Rank/Select questions to re-define the "String()" function which would simply return "select"/"rank"/"text" and could be called everywhere. It would avoid redefining or hardcoding those strings everywhere. It's just an idea though ;).

@mamine2207 mamine2207 requested a review from pierluca October 11, 2022 14:28
@mamine2207 mamine2207 marked this pull request as draft October 11, 2022 14:45
Added a specific string related to each kind of question to avoid hardcoding them and a getter for these strings in the Interface Question + corrected constants in the tests
@mamine2207 mamine2207 marked this pull request as ready for review October 12, 2022 17:24
@mamine2207 mamine2207 requested a review from emduc October 12, 2022 17:24
@@ -401,6 +407,7 @@ type Question interface {
GetMaxN() uint
GetMinN() uint
GetChoicesLength() int
GetString() string
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case GetID() string feels more appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, you can rename selectStr to selectID, same for rank and text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, same thing for the constants in the test file, right ?

@mamine2207 mamine2207 requested a review from a team as a code owner October 16, 2022 18:02
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

25.0% 25.0% Coverage
0.0% 0.0% Duplication

@mamine2207 mamine2207 requested a review from nkcr October 16, 2022 18:06
Copy link
Contributor

@nkcr nkcr left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@nkcr nkcr dismissed emduc’s stale review October 17, 2022 07:54

Changes applied

@nkcr nkcr merged commit 8477859 into main Oct 17, 2022
@nkcr nkcr deleted the amine branch October 17, 2022 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node backend About the blockchain node
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants