-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4063 from ppopth/fix-custody-group-spec-tests
EIP-7594: Fix custody group spec tests
- Loading branch information
Showing
4 changed files
with
170 additions
and
114 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
tests/core/pyspec/eth2spec/test/fulu/networking/test_compute_columns_for_custody_group.py
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,62 @@ | ||
import random | ||
|
||
from eth2spec.test.context import ( | ||
single_phase, | ||
spec_test, | ||
with_fulu_and_later, | ||
) | ||
|
||
|
||
def _run_compute_columns_for_custody_group(spec, rng, custody_group=None): | ||
if custody_group is None: | ||
custody_group = rng.randint(0, spec.config.NUMBER_OF_CUSTODY_GROUPS - 1) | ||
|
||
result = spec.compute_columns_for_custody_group(custody_group) | ||
yield 'custody_group', 'meta', custody_group | ||
|
||
assert len(result) == len(set(result)) | ||
assert len(result) == spec.config.NUMBER_OF_COLUMNS // spec.config.NUMBER_OF_CUSTODY_GROUPS | ||
assert all(i < spec.config.NUMBER_OF_COLUMNS for i in result) | ||
python_list_result = [int(i) for i in result] | ||
|
||
yield 'result', 'meta', python_list_result | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_compute_columns_for_custody_group__min_custody_group(spec): | ||
rng = random.Random(1111) | ||
yield from _run_compute_columns_for_custody_group(spec, rng, custody_group=0) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_compute_columns_for_custody_group__max_custody_group(spec): | ||
rng = random.Random(1111) | ||
yield from _run_compute_columns_for_custody_group(spec, rng, custody_group=spec.config.NUMBER_OF_CUSTODY_GROUPS - 1) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_compute_columns_for_custody_group__1(spec): | ||
rng = random.Random(1111) | ||
yield from _run_compute_columns_for_custody_group(spec, rng) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_compute_columns_for_custody_group__2(spec): | ||
rng = random.Random(2222) | ||
yield from _run_compute_columns_for_custody_group(spec, rng) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_compute_columns_for_custody_group__3(spec): | ||
rng = random.Random(3333) | ||
yield from _run_compute_columns_for_custody_group(spec, rng) |
113 changes: 0 additions & 113 deletions
113
tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_columns.py
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_groups.py
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,106 @@ | ||
import random | ||
|
||
from eth2spec.test.context import ( | ||
single_phase, | ||
spec_test, | ||
with_fulu_and_later, | ||
) | ||
|
||
|
||
def _run_get_custody_groups(spec, rng, node_id=None, custody_group_count=None): | ||
if node_id is None: | ||
node_id = rng.randint(0, 2**256 - 1) | ||
|
||
if custody_group_count is None: | ||
custody_group_count = rng.randint(0, spec.config.NUMBER_OF_CUSTODY_GROUPS) | ||
|
||
result = spec.get_custody_groups(node_id, custody_group_count) | ||
yield 'node_id', 'meta', node_id | ||
yield 'custody_group_count', 'meta', int(custody_group_count) | ||
|
||
assert len(result) == len(set(result)) | ||
assert len(result) == custody_group_count | ||
assert all(i < spec.config.NUMBER_OF_CUSTODY_GROUPS for i in result) | ||
python_list_result = [int(i) for i in result] | ||
|
||
yield 'result', 'meta', python_list_result | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__min_node_id_min_custody_group_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups(spec, rng, node_id=0, custody_group_count=0) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__min_node_id_max_custody_group_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups( | ||
spec, rng, node_id=0, | ||
custody_group_count=spec.config.NUMBER_OF_CUSTODY_GROUPS) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__max_node_id_min_custody_group_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups(spec, rng, node_id=2**256 - 1, custody_group_count=0) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__max_node_id_max_custody_group_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups( | ||
spec, rng, node_id=2**256 - 1, | ||
custody_group_count=spec.config.NUMBER_OF_CUSTODY_GROUPS, | ||
) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__max_node_id_max_custody_group_count_minus_1(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups( | ||
spec, rng, node_id=2**256 - 2, | ||
custody_group_count=spec.config.NUMBER_OF_CUSTODY_GROUPS, | ||
) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__short_node_id(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups(spec, rng, node_id=1048576, custody_group_count=1) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__1(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_groups(spec, rng) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__2(spec): | ||
rng = random.Random(2222) | ||
yield from _run_get_custody_groups(spec, rng) | ||
|
||
|
||
@with_fulu_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_groups__3(spec): | ||
rng = random.Random(3333) | ||
yield from _run_get_custody_groups(spec, rng) |
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