diff --git a/tests/core/pyspec/eth2spec/test/fulu/networking/test_compute_columns_for_custody_group.py b/tests/core/pyspec/eth2spec/test/fulu/networking/test_compute_columns_for_custody_group.py new file mode 100644 index 0000000000..61752e919a --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/fulu/networking/test_compute_columns_for_custody_group.py @@ -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) diff --git a/tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_columns.py b/tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_columns.py deleted file mode 100644 index d3be42ce16..0000000000 --- a/tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_columns.py +++ /dev/null @@ -1,113 +0,0 @@ -import random - -from eth2spec.test.context import ( - single_phase, - spec_test, - with_fulu_and_later, -) - - -def _run_get_custody_columns(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) - - columns_per_group = spec.config.NUMBER_OF_COLUMNS // spec.config.NUMBER_OF_CUSTODY_GROUPS - groups = spec.get_custody_groups(node_id, custody_group_count) - yield 'node_id', 'meta', node_id - yield 'custody_group_count', 'meta', int(custody_group_count) - - result = [] - for group in groups: - group_columns = spec.compute_columns_for_custody_group(group) - assert len(group_columns) == columns_per_group - result.extend(group_columns) - - assert len(result) == len(set(result)) - assert len(result) == custody_group_count * columns_per_group - 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_get_custody_columns__min_node_id_min_custody_group_count(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns(spec, rng, node_id=0, custody_group_count=0) - - -@with_fulu_and_later -@spec_test -@single_phase -def test_get_custody_columns__min_node_id_max_custody_group_count(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns( - 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_columns__max_node_id_min_custody_group_count(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns(spec, rng, node_id=2**256 - 1, custody_group_count=0) - - -@with_fulu_and_later -@spec_test -@single_phase -def test_get_custody_columns__max_node_id_max_custody_group_count(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns( - 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_columns__max_node_id_max_custody_group_count_minus_1(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns( - 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_columns__short_node_id(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns(spec, rng, node_id=1048576, custody_group_count=1) - - -@with_fulu_and_later -@spec_test -@single_phase -def test_get_custody_columns__1(spec): - rng = random.Random(1111) - yield from _run_get_custody_columns(spec, rng) - - -@with_fulu_and_later -@spec_test -@single_phase -def test_get_custody_columns__2(spec): - rng = random.Random(2222) - yield from _run_get_custody_columns(spec, rng) - - -@with_fulu_and_later -@spec_test -@single_phase -def test_get_custody_columns__3(spec): - rng = random.Random(3333) - yield from _run_get_custody_columns(spec, rng) diff --git a/tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_groups.py b/tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_groups.py new file mode 100644 index 0000000000..8d33a2b920 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/fulu/networking/test_get_custody_groups.py @@ -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) diff --git a/tests/generators/networking/main.py b/tests/generators/networking/main.py index 3217c2cce2..a670f7bd4d 100644 --- a/tests/generators/networking/main.py +++ b/tests/generators/networking/main.py @@ -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