Skip to content

Commit

Permalink
Merge pull request #4063 from ppopth/fix-custody-group-spec-tests
Browse files Browse the repository at this point in the history
EIP-7594: Fix custody group spec tests
  • Loading branch information
jtraglia authored Dec 18, 2024
2 parents 8d5c874 + dde8119 commit 6f9d029
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 114 deletions.
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)

This file was deleted.

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)
3 changes: 2 additions & 1 deletion tests/generators/networking/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

if __name__ == "__main__":
fulu_mods = {key: 'eth2spec.test.fulu.networking.test_' + key for key in [
'get_custody_columns',
'compute_columns_for_custody_group',
'get_custody_groups',
]}
all_mods = {
FULU: fulu_mods
Expand Down

0 comments on commit 6f9d029

Please sign in to comment.