-
Notifications
You must be signed in to change notification settings - Fork 30
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
Stress tests #43
Merged
+275
−9
Merged
Stress tests #43
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0819d89
WIP: (stress) tests:
liamsi 79a534a
[WIP]: (stress) tests:
liamsi 803075a
[WIP]: (stress) tests:
liamsi 8525fba
[WIP]: (stress) tests:
liamsi 57effe9
[WIP]: (stress) tests:
liamsi c5683a7
minor changes
liamsi 4da5cb4
rebase and fixes
liamsi 22d7236
Use TB.Serialize instead of manually serializing
liamsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package crypto | ||
|
||
import ( | ||
"bytes" | ||
"crypto/rand" | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestDigest(t *testing.T) { | ||
msg := []byte("test message") | ||
d := Digest(msg) | ||
if len(d) != HashSizeByte { | ||
t.Fatal("Computation of Hash failed.") | ||
} | ||
if bytes.Equal(d, make([]byte, HashSizeByte)) { | ||
t.Fatal("Hash is all zeros.") | ||
} | ||
} | ||
|
||
type testErrorRandReader struct{} | ||
|
||
func (er testErrorRandReader) Read([]byte) (int, error) { | ||
return 0, errors.New("Not enough entropy!") | ||
} | ||
|
||
func TestMakeRand(t *testing.T) { | ||
r, err := MakeRand() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// check if hashed the random output: | ||
if len(r) != HashSizeByte { | ||
t.Fatal("Looks like Digest wasn't called correctly.") | ||
} | ||
orig := rand.Reader | ||
rand.Reader = testErrorRandReader{} | ||
r, err = MakeRand() | ||
if err == nil { | ||
t.Fatal("No error returned") | ||
} | ||
rand.Reader = orig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I don't expect the server will use signed ints. Do you think
IntToBytes()
should throw an error when it receives a negative value? Or should we change toUIntToBytes()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to let it
panic
or only useUIntToBytes
would make sense. As far as I can seenode.level
can only grow (or never is a value subtracted from level). Maybe we could even refactorlevel
to be unsigned?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring
level
to be unsigned makes a lot of sense to me. The only scenario in which level could decrease is when the tree is re-randomized after the VRF key is changed. But this should still work with an unsignedlevel
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW (unsigned) inters can overflow in golang without panic/error or something similar: https://golang.org/ref/spec#Integer_overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, should this go into another issue/PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks! Opened #53 for that.