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

test: add randomized tests for errByzantine #312

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

walldiss
Copy link
Member

@walldiss walldiss commented Apr 9, 2024

ErrByzantine encompasses numerous edge cases. To address this, I implemented randomized fuzzing tests, which identified instances where shares encoding was not properly verified.

While I am neutral about maintaining the pretty printing code (as it looks kinda off), I retained it because it proved extremely useful for understanding the reasons behind test failures during extensive debugging. Should these tests fail in the future for any reason, having a visual representation of the issues will expedite debugging for future developers.

Allowed to discover #313

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.03%. Comparing base (d6c118c) to head (893acb1).
Report is 14 commits behind head on main.

❗ Current head 893acb1 differs from pull request most recent head 61f82d1. Consider uploading reports for the commit 61f82d1 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #312      +/-   ##
==========================================
+ Coverage   80.89%   84.03%   +3.14%     
==========================================
  Files           8        7       -1     
  Lines         869      614     -255     
==========================================
- Hits          703      516     -187     
+ Misses        119       59      -60     
+ Partials       47       39       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@walldiss walldiss marked this pull request as ready for review April 9, 2024 18:59
@walldiss walldiss self-assigned this Apr 9, 2024
@rootulp rootulp changed the title Testing: add randomised tests for errByzantine test: add randomized tests for errByzantine Apr 9, 2024
rootulp
rootulp previously approved these changes Apr 9, 2024
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.

LGTM

@@ -2,6 +2,7 @@ package rsmt2d

import (
"bytes"
crand "crypto/rand"
"errors"
"fmt"
"math/rand"
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 a follow up PR we may consider replacing usage of math/rand with crypto/rand and then deleting the import alias for crypto/rand

Copy link
Member Author

@walldiss walldiss Apr 10, 2024

Choose a reason for hiding this comment

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

Unfortunately, crypto/rand lacks handy IntN funciton, only

func Int(rand io.Reader, max *big.Int) (n *big.Int, err error) 

While math/rand lacks ability to generate random []byte slice. I wish one day there will be single package with both

Copy link
Member

Choose a reason for hiding this comment

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

There is rand v2

func TestErrRandByzantine(t *testing.T) {
codec := NewLeoRSCodec()
original, corrupted, idx := randCorruptedEDS(t, codec, 8)
require.False(t, original.Equals(corrupted), "corrupted eds is equal to original eds")
Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] why .False instead of:

	require.NotEqual(t, original, corrupted)

Copy link
Member Author

Choose a reason for hiding this comment

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

NotEqual uses == slice compare under the hood, while Equals method does more precise comparison.

extendeddatacrossword_test.go Outdated Show resolved Hide resolved
extendeddatacrossword_test.go Show resolved Hide resolved
@walldiss walldiss merged commit 015e3f2 into celestiaorg:main Apr 15, 2024
3 checks passed
walldiss added a commit that referenced this pull request Apr 16, 2024
…ed from orthogonal (#313)

If axis is fully recomputed from orthogonal axises, we need to verify
correct encoding on top of verification of roots.
Test coverage should happen by
#312
0xchainlover pushed a commit to celestia-org/rsmt2d that referenced this pull request Aug 1, 2024
…ed from orthogonal (#313)

If axis is fully recomputed from orthogonal axises, we need to verify
correct encoding on top of verification of roots.
Test coverage should happen by
celestiaorg/rsmt2d#312
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.

4 participants