-
Notifications
You must be signed in to change notification settings - Fork 996
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 #3715 from ethereum/das-test-vectors
Make `get_custody_columns` return sorted values and add `get_custody_columns` tests
- Loading branch information
Showing
9 changed files
with
148 additions
and
3 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
Empty file.
89 changes: 89 additions & 0 deletions
89
tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.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,89 @@ | ||
import random | ||
|
||
from eth2spec.test.context import ( | ||
single_phase, | ||
spec_test, | ||
with_eip7594_and_later, | ||
) | ||
|
||
|
||
def _run_get_custody_columns(spec, rng, node_id=None, custody_subnet_count=None): | ||
if node_id is None: | ||
node_id = rng.randint(0, 2**256 - 1) | ||
|
||
if custody_subnet_count is None: | ||
custody_subnet_count = rng.randint(0, spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) | ||
|
||
result = spec.get_custody_columns(node_id, custody_subnet_count) | ||
yield 'node_id', 'meta', node_id | ||
yield 'custody_subnet_count', 'meta', custody_subnet_count | ||
|
||
assert len(result) == len(set(result)) | ||
assert len(result) == ( | ||
custody_subnet_count * spec.config.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT | ||
) | ||
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_eip7594_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_columns__min_node_id_min_custody_subnet_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_columns(spec, rng, node_id=0, custody_subnet_count=0) | ||
|
||
|
||
@with_eip7594_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_columns__min_node_id_max_custody_subnet_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_columns( | ||
spec, rng, node_id=0, | ||
custody_subnet_count=spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) | ||
|
||
|
||
@with_eip7594_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_columns__max_node_id_min_custody_subnet_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_columns(spec, rng, node_id=2**256 - 1, custody_subnet_count=0) | ||
|
||
|
||
@with_eip7594_and_later | ||
@spec_test | ||
@single_phase | ||
def test_get_custody_columns__max_node_id_max_custody_subnet_count(spec): | ||
rng = random.Random(1111) | ||
yield from _run_get_custody_columns( | ||
spec, rng, node_id=2**256 - 1, | ||
custody_subnet_count=spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT, | ||
) | ||
|
||
|
||
@with_eip7594_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_eip7594_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_eip7594_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) |
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,6 @@ | ||
# Networking tests | ||
|
||
The aim of the networking tests is to set a base-line on what really needs to pass, i.e. the essentials. | ||
|
||
Handlers: | ||
- [`get_custody_columns`](./get_custody_columns.md): `get_custody_columns` helper tests |
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,14 @@ | ||
# `get_custody_columns` tests | ||
|
||
`get_custody_columns` tests provide sanity check of the correctness of `get_custody_columns` helper. | ||
|
||
## Test case format | ||
|
||
### `meta.yaml` | ||
|
||
```yaml | ||
description: string -- optional: description of test case, purely for debugging purposes. | ||
node_id: int -- argument: the NodeId input. | ||
custody_subnet_count: int -- argument: the count of custody subnets. | ||
result: list of int -- output: the list of resulting column indices. | ||
``` |
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,5 @@ | ||
# Networking tests | ||
|
||
The purpose of this test-generator is to provide test-vectors for validating the correct implementation of the networking protocol. | ||
|
||
Test-format documentation can be found [here](../../formats/networking/README.md). |
Empty file.
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,14 @@ | ||
|
||
from eth2spec.test.helpers.constants import EIP7594 | ||
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators | ||
|
||
|
||
if __name__ == "__main__": | ||
eip7594_mods = {key: 'eth2spec.test.eip7594.networking.test_' + key for key in [ | ||
'get_custody_columns', | ||
]} | ||
all_mods = { | ||
EIP7594: eip7594_mods | ||
} | ||
|
||
run_state_test_generators(runner_name="networking", all_mods=all_mods) |
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,2 @@ | ||
pytest>=4.4 | ||
../../../[generator] |