This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
get_permuted_index
and new swap or not shuffle
1. Add constants `MAX_EXIT_DEQUEUES_PER_EPOCH` and `SHUFFLE_ROUND_COUNT` 2. Add `get_permuted_index` and new swap or not `shuffle` 3. Use the results of two different approaches to test
- Loading branch information
Showing
10 changed files
with
132 additions
and
84 deletions.
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
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
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 |
---|---|---|
@@ -1,27 +1,31 @@ | ||
import pytest | ||
|
||
from eth2.beacon._utils.random import ( | ||
get_permuted_index, | ||
shuffle, | ||
) | ||
|
||
|
||
def slow_shuffle(items, seed): | ||
length = len(items) | ||
return tuple([items[get_permuted_index(i, length, seed)] for i in range(length)]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
( | ||
'values,seed,expect' | ||
'values,seed' | ||
), | ||
[ | ||
( | ||
tuple(range(12)), | ||
b'\x23' * 32, | ||
(8, 3, 9, 0, 1, 11, 2, 4, 6, 7, 10, 5), | ||
), | ||
( | ||
tuple(range(2**6))[10:], | ||
b'\x67' * 32, | ||
), | ||
], | ||
) | ||
def test_shuffle_consistent(values, seed, expect): | ||
def test_shuffle_consistent(values, seed): | ||
expect = slow_shuffle(values, seed) | ||
assert shuffle(values, seed) == expect | ||
|
||
|
||
def test_shuffle_out_of_bound(): | ||
values = [i for i in range(2**24 + 1)] | ||
with pytest.raises(ValueError): | ||
shuffle(values, b'hello') |
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
Oops, something went wrong.