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

refactor: consolidate duplicate test methods #1074

Merged
merged 12 commits into from
Nov 29, 2022

Conversation

vidhanarya
Copy link
Contributor

@vidhanarya vidhanarya commented Nov 26, 2022

Overview

Closes #1073

Affected packages

  1. pkg -> shares & prove
    • Remove duplicated generateRandomTransaction, generateRandomlySizedTransactions, generateRandomBlob, and generateRandomlySizedBlobs
  2. testutil
    • Add factory package with generator method for the random transaction(s) and random blob(s)
    • Deprecate blobtestutil
    • Remove duplicated GenerateKeyringSigner and generateKeyring methods
  3. x/blob/types
    • Refactor keyring generator method in separate file test_util.go
    • Reuse keyring generators from x/blob/types in app package
    • Use constants instead of hardcoded strings for the test account and chain id
  4. app/app_test
    • Refactor all helper generate methods in app package's test_util.go
    • Reuse keyring generators from blobtypes
    • Simplify some of the helper generateTxs methods

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2022

Codecov Report

Merging #1074 (fbca36f) into main (2f89956) will decrease coverage by 0.07%.
The diff coverage is 45.16%.

@@            Coverage Diff             @@
##             main    #1074      +/-   ##
==========================================
- Coverage   50.50%   50.42%   -0.08%     
==========================================
  Files          71       72       +1     
  Lines        4390     4387       -3     
==========================================
- Hits         2217     2212       -5     
- Misses       1946     1947       +1     
- Partials      227      228       +1     
Impacted Files Coverage Δ
app/test_util.go 71.84% <35.55%> (-2.14%) ⬇️
x/blob/types/test_util.go 70.58% <70.58%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

rootulp
rootulp previously approved these changes Nov 28, 2022
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Thanks @vidhanarya for this stellar PR! I'm really happy to see this net negative lines of code diff

Screenshot 2022-11-28 at 11 45 58 AM

None of my feedback is blocking this PR from being merged. Let's wait for @evan-forbes to review before merging 🚀

@@ -0,0 +1,62 @@
package testfactory
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] since this file doesn't define any new types, proposal to rename it from types.go to something else?

Proposals:

  1. generate.go
  2. generate_tx.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, the idea here was that any file inside factory testfactory/[package_for_which_factory_is_needed].go represents the package from where definitions are being used (in this case Blob and Txs from tendermint's types package.
But if convention is different here then generate_tx.go or just tx.go (in this case, apt thing to do would be to move blob generator methods to another file blob.go) also work. Changing to generate_tx.go for now, can update if any better suggestion comes up.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining the rationale. Given that rationale, I'm comfortable with the name: testutil/testfactory/types.go. I'm also comfortable with splitting the generation into generate_tx.go and generate_blob.go so defer to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, changing to generate_txs.go and generate_blob.go for now, will also wait for @evan-forbes if he have any input here since I saw a similar structure being used in celestia-core (https://github.com/celestiaorg/celestia-core/blob/v0.34.x-celestia/test/factory/tx.go#L1)

EDIT: Changing to txs.go and blob.go


func GenerateRandomBlob(size int) types.Blob {
blob := types.Blob{
NamespaceID: tmrand.Bytes(appconsts.NamespaceSize),
Copy link
Collaborator

Choose a reason for hiding this comment

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

[no change needed] in the future, we may want this to generate a valid blob namespace. In other words, something like https://github.com/celestiaorg/celestia-app/blob/5bbdac2d3f46662a34b2111602b8f964d6e6fba5/testutil/namespace/random_ns_generator.go#L11-L23

testutil/testfactory/types.go Outdated Show resolved Hide resolved
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

really great work @vidhanarya !! sincerely, thank you for getting rid of all that crap!!

we just merged a rather large naming PR, which caused a bunch of conflicts, so unfortunately we have to fix those, but then we can merge this!

thanks again 💯 🙂

@vidhanarya vidhanarya marked this pull request as draft November 29, 2022 05:33
@vidhanarya
Copy link
Contributor Author

vidhanarya commented Nov 29, 2022

Marking as draft for now, will push an updated commit (with rename changes) and resolved merge conflicts by 6:30 PM UTC today.

This is done. @evan-forbes @rootulp Please have a final look to confirm message -> blob changes are accordingly migrated in testfactory/test_util changes. Also added one more commit to remove GenerateValidBlockData.

@vidhanarya vidhanarya marked this pull request as ready for review November 29, 2022 14:27
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

:shipit: 👍 💯 🤸

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Really great work @vidhanarya 💯

}

// SetupWithGenesisValSet initializes GenesisState with a single validator and genesis accounts
// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

[no change needed] it would be awesome if we enabled a lint rule that flagged when the godoc for a function doesn't start with the name of the function. In the meantime, this type of correction is def appreciated!

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, this would be a nice addition 💯

@evan-forbes evan-forbes merged commit 3941003 into celestiaorg:main Nov 29, 2022
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.

Merge duplicate definitions with testutil
4 participants