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: improve nmt wrapper tests #1423

Merged
merged 2 commits into from
Feb 24, 2023
Merged

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Feb 23, 2023

Closes #1422

Motivation: I was reading through nmt_wrapper.go to prepare an ADR and got confused by the usage of appconsts.ContinuationSparseShareContentSize+1. I made a few changes to the test file for clarity & maintainability.

@rootulp rootulp added the testing items that are strictly related to adding or extending test coverage label Feb 23, 2023
@rootulp rootulp self-assigned this Feb 23, 2023
@rootulp
Copy link
Collaborator Author

rootulp commented Feb 23, 2023

This change broke for unexpected reasons. The error I observed is

    nmt_wrapper_test.go:140: shard sizes do not match

The root cause was klauspost expects shards to have a length that are a multiple of 64 bytes.

Update: improved error message in klauspost/reedsolomon#243

@rootulp rootulp marked this pull request as ready for review February 23, 2023 20:14
@codecov-commenter
Copy link

Codecov Report

Merging #1423 (3d08bea) into main (e6bbc30) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1423   +/-   ##
=======================================
  Coverage   49.21%   49.21%           
=======================================
  Files          79       79           
  Lines        4482     4482           
=======================================
  Hits         2206     2206           
  Misses       2091     2091           
  Partials      185      185           

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

Comment on lines +145 to 147
// generateRandNamespacedRawData returns random data of length total. Each chunk
// of random data is of size nidSize + leafSize.
func generateRandNamespacedRawData(total int, nidSize int, leafSize int) [][]byte {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW this could be simplified to:

func generateRandNamespacedRawData(numShares int, shareSize int) (data [][]byte) {
	for i := 0; i < numShares; i++ {
		share := make([]byte, shareSize)
		_, err := rand.Read(share)
		if err != nil {
			panic(err)
		}
		data = append(data, share)
	}
	sortByteArrays(data)
	return data
}

Copy link
Contributor

Choose a reason for hiding this comment

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

There is just a slight difference and that is the final data is sorted both based on namespace ID and their data whereas in the original implementation it is not the case.

@rootulp rootulp merged commit b56c1bb into celestiaorg:main Feb 24, 2023
Comment on lines +145 to 147
// generateRandNamespacedRawData returns random data of length total. Each chunk
// of random data is of size nidSize + leafSize.
func generateRandNamespacedRawData(total int, nidSize int, leafSize int) [][]byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is just a slight difference and that is the final data is sorted both based on namespace ID and their data whereas in the original implementation it is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing items that are strictly related to adding or extending test coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nmt_wrapper_test.go depends on magic constant
4 participants