mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-12 18:46:22 +00:00
Merge branch 'ethereum:dev' into update-readme-deps
This commit is contained in:
commit
33a8e197aa
@ -35,13 +35,13 @@ commands:
|
||||
description: "Restore the cache with pyspec keys"
|
||||
steps:
|
||||
- restore_cached_venv:
|
||||
venv_name: v24-pyspec
|
||||
venv_name: v25-pyspec
|
||||
reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}
|
||||
save_pyspec_cached_venv:
|
||||
description: Save a venv into a cache with pyspec keys"
|
||||
steps:
|
||||
- save_cached_venv:
|
||||
venv_name: v24-pyspec
|
||||
venv_name: v25-pyspec
|
||||
reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}
|
||||
venv_path: ./venv
|
||||
restore_deposit_contract_tester_cached_venv:
|
||||
@ -60,7 +60,7 @@ commands:
|
||||
jobs:
|
||||
checkout_specs:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
# Restore git repo at point close to target branch/revision, to speed up checkout
|
||||
@ -80,7 +80,7 @@ jobs:
|
||||
- ~/specs-repo
|
||||
install_pyspec_test:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -92,7 +92,7 @@ jobs:
|
||||
- save_pyspec_cached_venv
|
||||
test-phase0:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -105,7 +105,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-altair:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -118,7 +118,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-bellatrix:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -131,7 +131,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-capella:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -144,7 +144,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-deneb:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -157,7 +157,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-electra:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -170,7 +170,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-whisk:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -183,7 +183,7 @@ jobs:
|
||||
path: tests/core/pyspec/test-reports
|
||||
test-eip7594:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -205,7 +205,7 @@ jobs:
|
||||
command: sudo npm install -g doctoc@2.2.0 && make check_toc
|
||||
codespell:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- checkout
|
||||
@ -214,7 +214,7 @@ jobs:
|
||||
command: pip install 'codespell<3.0.0,>=2.0.0' --user && make codespell
|
||||
lint:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -270,7 +270,7 @@ jobs:
|
||||
- /nix
|
||||
install_deposit_contract_web3_tester:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@ -282,7 +282,7 @@ jobs:
|
||||
- save_deposit_contract_tester_cached_venv
|
||||
test_deposit_contract_web3_tests:
|
||||
docker:
|
||||
- image: circleci/python:3.9
|
||||
- image: cimg/python:3.12.4
|
||||
working_directory: ~/specs-repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
|
2
.github/workflows/generate_vectors.yml
vendored
2
.github/workflows/generate_vectors.yml
vendored
@ -32,7 +32,7 @@ jobs:
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
python-version: '3.12.4'
|
||||
cache: ''
|
||||
- name: Clean up Spec Repository
|
||||
run: |
|
||||
|
10
.github/workflows/run-tests.yml
vendored
10
.github/workflows/run-tests.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
python-version: '3.12.4'
|
||||
cache: ''
|
||||
- name: Check codespell
|
||||
run: make codespell
|
||||
@ -55,10 +55,12 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Rust for dependencies
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
python-version: '3.12.4'
|
||||
cache: ''
|
||||
- name: Install pyspec requirements
|
||||
run: make install_test
|
||||
@ -76,10 +78,12 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Rust for dependencies
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
python-version: '3.12.4'
|
||||
cache: ''
|
||||
- name: set TEST_PRESET_TYPE
|
||||
if: github.event.inputs.test_preset_type != ''
|
||||
|
@ -161,7 +161,6 @@ WHISK_PROPOSER_SELECTION_GAP: 2
|
||||
|
||||
# EIP7594
|
||||
NUMBER_OF_COLUMNS: 128
|
||||
MAX_CELLS_IN_EXTENDED_MATRIX: 768
|
||||
DATA_COLUMN_SIDECAR_SUBNET_COUNT: 128
|
||||
MAX_REQUEST_DATA_COLUMN_SIDECARS: 16384
|
||||
SAMPLES_PER_SLOT: 8
|
||||
|
@ -160,7 +160,6 @@ WHISK_PROPOSER_SELECTION_GAP: 1
|
||||
|
||||
# EIP7594
|
||||
NUMBER_OF_COLUMNS: 128
|
||||
MAX_CELLS_IN_EXTENDED_MATRIX: 768
|
||||
DATA_COLUMN_SIDECAR_SUBNET_COUNT: 128
|
||||
MAX_REQUEST_DATA_COLUMN_SIDECARS: 16384
|
||||
SAMPLES_PER_SLOT: 8
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Rename the build stage from 'base' to 'builder' for clarification and code readability
|
||||
FROM python:3.11.0-slim-bullseye as builder
|
||||
FROM python:3.12.4-slim-bullseye as builder
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
WORKDIR=/consensus-specs \
|
||||
|
@ -27,7 +27,6 @@ def retrieve_column_sidecars(beacon_block_root: Root) -> Sequence[DataColumnSide
|
||||
'FIELD_ELEMENTS_PER_CELL': spec_object.preset_vars['FIELD_ELEMENTS_PER_CELL'].value,
|
||||
'FIELD_ELEMENTS_PER_EXT_BLOB': spec_object.preset_vars['FIELD_ELEMENTS_PER_EXT_BLOB'].value,
|
||||
'NUMBER_OF_COLUMNS': spec_object.config_vars['NUMBER_OF_COLUMNS'].value,
|
||||
'MAX_CELLS_IN_EXTENDED_MATRIX': spec_object.config_vars['MAX_CELLS_IN_EXTENDED_MATRIX'].value,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -1,4 +1,4 @@
|
||||
pip>=23.1.2
|
||||
wheel>=0.40.0
|
||||
setuptools>=68.0.0
|
||||
pylint>=3.0.0
|
||||
pip>=24.0.0
|
||||
wheel>=0.44.0
|
||||
setuptools>=72.0.0
|
||||
pylint>=3.2.0
|
@ -20,7 +20,7 @@
|
||||
- [`MatrixEntry`](#matrixentry)
|
||||
- [Helper functions](#helper-functions)
|
||||
- [`get_custody_columns`](#get_custody_columns)
|
||||
- [`compute_extended_matrix`](#compute_extended_matrix)
|
||||
- [`compute_matrix`](#compute_matrix)
|
||||
- [`recover_matrix`](#recover_matrix)
|
||||
- [`get_data_column_sidecars`](#get_data_column_sidecars)
|
||||
- [Custody](#custody)
|
||||
@ -62,7 +62,6 @@ The following values are (non-configurable) constants used throughout the specif
|
||||
| Name | Value | Description |
|
||||
| - | - | - |
|
||||
| `NUMBER_OF_COLUMNS` | `uint64(CELLS_PER_EXT_BLOB)` (= 128) | Number of columns in the extended data matrix |
|
||||
| `MAX_CELLS_IN_EXTENDED_MATRIX` | `uint64(MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS)` (= 768) | The data size of `ExtendedMatrix` |
|
||||
|
||||
### Networking
|
||||
|
||||
@ -133,54 +132,52 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen
|
||||
])
|
||||
```
|
||||
|
||||
### `compute_extended_matrix`
|
||||
### `compute_matrix`
|
||||
|
||||
```python
|
||||
def compute_extended_matrix(blobs: Sequence[Blob]) -> List[MatrixEntry, MAX_CELLS_IN_EXTENDED_MATRIX]:
|
||||
def compute_matrix(blobs: Sequence[Blob]) -> Sequence[MatrixEntry]:
|
||||
"""
|
||||
Return the full ``ExtendedMatrix``.
|
||||
Return the full, flattened sequence of matrix entries.
|
||||
|
||||
This helper demonstrates the relationship between blobs and ``ExtendedMatrix``.
|
||||
The data structure for storing cells is implementation-dependent.
|
||||
This helper demonstrates the relationship between blobs and the matrix of cells/proofs.
|
||||
The data structure for storing cells/proofs is implementation-dependent.
|
||||
"""
|
||||
extended_matrix = []
|
||||
matrix = []
|
||||
for blob_index, blob in enumerate(blobs):
|
||||
cells, proofs = compute_cells_and_kzg_proofs(blob)
|
||||
for cell_index, (cell, proof) in enumerate(zip(cells, proofs)):
|
||||
extended_matrix.append(MatrixEntry(
|
||||
matrix.append(MatrixEntry(
|
||||
cell=cell,
|
||||
kzg_proof=proof,
|
||||
row_index=blob_index,
|
||||
column_index=cell_index,
|
||||
))
|
||||
return extended_matrix
|
||||
return matrix
|
||||
```
|
||||
|
||||
### `recover_matrix`
|
||||
|
||||
```python
|
||||
def recover_matrix(partial_matrix: Sequence[MatrixEntry],
|
||||
blob_count: uint64) -> List[MatrixEntry, MAX_CELLS_IN_EXTENDED_MATRIX]:
|
||||
def recover_matrix(partial_matrix: Sequence[MatrixEntry], blob_count: uint64) -> Sequence[MatrixEntry]:
|
||||
"""
|
||||
Return the recovered extended matrix.
|
||||
Recover the full, flattened sequence of matrix entries.
|
||||
|
||||
This helper demonstrates how to apply ``recover_cells_and_kzg_proofs``.
|
||||
The data structure for storing cells is implementation-dependent.
|
||||
The data structure for storing cells/proofs is implementation-dependent.
|
||||
"""
|
||||
extended_matrix = []
|
||||
matrix = []
|
||||
for blob_index in range(blob_count):
|
||||
cell_indices = [e.column_index for e in partial_matrix if e.row_index == blob_index]
|
||||
cells = [e.cell for e in partial_matrix if e.row_index == blob_index]
|
||||
|
||||
recovered_cells, recovered_proofs = recover_cells_and_kzg_proofs(cell_indices, cells)
|
||||
for cell_index, (cell, proof) in enumerate(zip(recovered_cells, recovered_proofs)):
|
||||
extended_matrix.append(MatrixEntry(
|
||||
matrix.append(MatrixEntry(
|
||||
cell=cell,
|
||||
kzg_proof=proof,
|
||||
row_index=blob_index,
|
||||
column_index=cell_index,
|
||||
))
|
||||
return extended_matrix
|
||||
return matrix
|
||||
```
|
||||
|
||||
### `get_data_column_sidecars`
|
||||
@ -241,7 +238,7 @@ At each slot, a node advertising `custody_subnet_count` downloads a minimum of `
|
||||
|
||||
## Extended data
|
||||
|
||||
In this construction, we extend the blobs using a one-dimensional erasure coding extension. The matrix comprises maximum `MAX_BLOBS_PER_BLOCK` rows and fixed `NUMBER_OF_COLUMNS` columns, with each row containing a `Blob` and its corresponding extension. `compute_extended_matrix` demonstrates the relationship between blobs and custom type `ExtendedMatrix`.
|
||||
In this construction, we extend the blobs using a one-dimensional erasure coding extension. The matrix comprises maximum `MAX_BLOBS_PER_BLOCK` rows and fixed `NUMBER_OF_COLUMNS` columns, with each row containing a `Blob` and its corresponding extension. `compute_matrix` demonstrates the relationship between blobs and the matrix, a potential method of storing cells/proofs.
|
||||
|
||||
## Column gossip
|
||||
|
||||
|
@ -1 +1 @@
|
||||
1.5.0-alpha.4
|
||||
1.5.0-alpha.5
|
||||
|
@ -132,7 +132,7 @@ def should_skip_case_dir(case_dir, is_force, diagnostics_obj):
|
||||
print(f'Skipping already existing test: {case_dir}')
|
||||
is_skip = True
|
||||
else:
|
||||
print(f'Warning, output directory {case_dir} already exist,'
|
||||
print(f'Warning, output directory {case_dir} already exist, '
|
||||
' old files will be deleted and it will generate test vector files with the latest version')
|
||||
# Clear the existing case_dir folder
|
||||
shutil.rmtree(case_dir)
|
||||
@ -356,7 +356,7 @@ def generate_test_vector(test_case, case_dir, log_file, file_mode):
|
||||
test_end = time.time()
|
||||
span = round(test_end - test_start, 2)
|
||||
if span > TIME_THRESHOLD_TO_PRINT:
|
||||
print(f' - generated in {span} seconds')
|
||||
print(f'- generated in {span} seconds')
|
||||
|
||||
return result
|
||||
|
||||
|
@ -429,6 +429,13 @@ def with_all_phases_from(earliest_phase, all_phases=ALL_PHASES):
|
||||
return decorator
|
||||
|
||||
|
||||
def with_all_phases_from_except(earliest_phase, except_phases=None):
|
||||
"""
|
||||
A decorator factory for running a tests with every phase except the ones listed
|
||||
"""
|
||||
return with_all_phases_from(earliest_phase, [phase for phase in ALL_PHASES if phase not in except_phases])
|
||||
|
||||
|
||||
def with_all_phases_except(exclusion_phases):
|
||||
"""
|
||||
A decorator factory for running a tests with every phase except the ones listed
|
||||
|
@ -2,10 +2,13 @@ from random import Random
|
||||
|
||||
from eth2spec.test.context import (
|
||||
spec_state_test,
|
||||
with_phases,
|
||||
with_all_phases_from_except,
|
||||
)
|
||||
|
||||
from eth2spec.test.helpers.constants import DENEB
|
||||
from eth2spec.test.helpers.constants import (
|
||||
DENEB,
|
||||
EIP7594,
|
||||
)
|
||||
|
||||
from eth2spec.test.helpers.block import (
|
||||
build_empty_block_for_next_slot,
|
||||
@ -36,7 +39,7 @@ def get_block_with_blob(spec, state, rng=None):
|
||||
return block, blobs, blob_kzg_proofs
|
||||
|
||||
|
||||
@with_phases([DENEB])
|
||||
@with_all_phases_from_except(DENEB, [EIP7594])
|
||||
@spec_state_test
|
||||
def test_simple_blob_data(spec, state):
|
||||
rng = Random(1234)
|
||||
@ -71,7 +74,7 @@ def test_simple_blob_data(spec, state):
|
||||
yield 'steps', test_steps
|
||||
|
||||
|
||||
@with_phases([DENEB])
|
||||
@with_all_phases_from_except(DENEB, [EIP7594])
|
||||
@spec_state_test
|
||||
def test_invalid_incorrect_proof(spec, state):
|
||||
rng = Random(1234)
|
||||
@ -99,7 +102,7 @@ def test_invalid_incorrect_proof(spec, state):
|
||||
yield 'steps', test_steps
|
||||
|
||||
|
||||
@with_phases([DENEB])
|
||||
@with_all_phases_from_except(DENEB, [EIP7594])
|
||||
@spec_state_test
|
||||
def test_invalid_data_unavailable(spec, state):
|
||||
rng = Random(1234)
|
||||
@ -127,7 +130,7 @@ def test_invalid_data_unavailable(spec, state):
|
||||
yield 'steps', test_steps
|
||||
|
||||
|
||||
@with_phases([DENEB])
|
||||
@with_all_phases_from_except(DENEB, [EIP7594])
|
||||
@spec_state_test
|
||||
def test_invalid_wrong_proofs_length(spec, state):
|
||||
rng = Random(1234)
|
||||
@ -155,7 +158,7 @@ def test_invalid_wrong_proofs_length(spec, state):
|
||||
yield 'steps', test_steps
|
||||
|
||||
|
||||
@with_phases([DENEB])
|
||||
@with_all_phases_from_except(DENEB, [EIP7594])
|
||||
@spec_state_test
|
||||
def test_invalid_wrong_blobs_length(spec, state):
|
||||
rng = Random(1234)
|
||||
|
@ -19,15 +19,15 @@ def chunks(lst, n):
|
||||
@with_eip7594_and_later
|
||||
@spec_test
|
||||
@single_phase
|
||||
def test_compute_extended_matrix(spec):
|
||||
def test_compute_matrix(spec):
|
||||
rng = random.Random(5566)
|
||||
|
||||
blob_count = 2
|
||||
input_blobs = [get_sample_blob(spec, rng=rng) for _ in range(blob_count)]
|
||||
extended_matrix = spec.compute_extended_matrix(input_blobs)
|
||||
assert len(extended_matrix) == spec.CELLS_PER_EXT_BLOB * blob_count
|
||||
matrix = spec.compute_matrix(input_blobs)
|
||||
assert len(matrix) == spec.CELLS_PER_EXT_BLOB * blob_count
|
||||
|
||||
rows = chunks(extended_matrix, spec.CELLS_PER_EXT_BLOB)
|
||||
rows = chunks(matrix, spec.CELLS_PER_EXT_BLOB)
|
||||
assert len(rows) == blob_count
|
||||
for row in rows:
|
||||
assert len(row) == spec.CELLS_PER_EXT_BLOB
|
||||
@ -53,11 +53,11 @@ def test_recover_matrix(spec):
|
||||
# Compute an extended matrix with two blobs
|
||||
blob_count = 2
|
||||
blobs = [get_sample_blob(spec, rng=rng) for _ in range(blob_count)]
|
||||
extended_matrix = spec.compute_extended_matrix(blobs)
|
||||
matrix = spec.compute_matrix(blobs)
|
||||
|
||||
# Construct a matrix with some entries missing
|
||||
partial_matrix = []
|
||||
for blob_entries in chunks(extended_matrix, spec.CELLS_PER_EXT_BLOB):
|
||||
for blob_entries in chunks(matrix, spec.CELLS_PER_EXT_BLOB):
|
||||
rng.shuffle(blob_entries)
|
||||
partial_matrix.extend(blob_entries[:N_SAMPLES])
|
||||
|
||||
@ -65,7 +65,7 @@ def test_recover_matrix(spec):
|
||||
recovered_matrix = spec.recover_matrix(partial_matrix, blob_count)
|
||||
|
||||
# Ensure that the recovered matrix matches the original matrix
|
||||
assert recovered_matrix == extended_matrix
|
||||
assert recovered_matrix == matrix
|
||||
|
||||
|
||||
@with_eip7594_and_later
|
||||
|
@ -18,7 +18,6 @@ def test_invariants(spec):
|
||||
assert spec.config.MAX_REQUEST_DATA_COLUMN_SIDECARS == (
|
||||
spec.config.MAX_REQUEST_BLOCKS_DENEB * spec.config.NUMBER_OF_COLUMNS
|
||||
)
|
||||
assert spec.config.MAX_CELLS_IN_EXTENDED_MATRIX == spec.config.MAX_BLOBS_PER_BLOCK * spec.config.NUMBER_OF_COLUMNS
|
||||
|
||||
|
||||
@with_eip7594_and_later
|
||||
|
@ -33,7 +33,7 @@ def valid_cases():
|
||||
for length in [1, 2, 3, 4, 5, 8, 16, 31, 512, 513]:
|
||||
for mode in random_modes:
|
||||
yield f'vec_{name}_{length}_{mode.to_name()}', \
|
||||
valid_test_case(lambda: basic_vector_case_fn(rng, mode, typ, length))
|
||||
valid_test_case(lambda: basic_vector_case_fn(rng, mode, typ, length))
|
||||
|
||||
|
||||
def invalid_cases():
|
||||
@ -52,14 +52,14 @@ def invalid_cases():
|
||||
if length == 1:
|
||||
# empty bytes, no elements. It may seem valid, but empty fixed-size elements are not valid SSZ.
|
||||
yield f'vec_{name}_{length}_{mode.to_name()}_one_less', \
|
||||
invalid_test_case(lambda: b"")
|
||||
invalid_test_case(lambda: b"")
|
||||
else:
|
||||
yield f'vec_{name}_{length}_{mode.to_name()}_one_less', \
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length - 1)))
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length - 1)))
|
||||
yield f'vec_{name}_{length}_{mode.to_name()}_one_more', \
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length + 1)))
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length + 1)))
|
||||
yield f'vec_{name}_{length}_{mode.to_name()}_one_byte_less', \
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length))[:-1])
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length))[:-1])
|
||||
yield f'vec_{name}_{length}_{mode.to_name()}_one_byte_more', \
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length))
|
||||
+ serialize(basic_vector_case_fn(rng, mode, uint8, 1)))
|
||||
invalid_test_case(lambda: serialize(basic_vector_case_fn(rng, mode, typ, length))
|
||||
+ serialize(basic_vector_case_fn(rng, mode, uint8, 1)))
|
||||
|
@ -22,7 +22,7 @@ def valid_cases():
|
||||
RandomizationMode.mode_zero,
|
||||
RandomizationMode.mode_max]:
|
||||
yield f'bitlist_{size}_{mode.to_name()}_{variation}', \
|
||||
valid_test_case(lambda: bitlist_case_fn(rng, mode, size))
|
||||
valid_test_case(lambda: bitlist_case_fn(rng, mode, size))
|
||||
|
||||
|
||||
def invalid_cases():
|
||||
@ -33,5 +33,5 @@ def invalid_cases():
|
||||
for (typ_limit, test_limit) in [(1, 2), (1, 8), (1, 9), (2, 3), (3, 4), (4, 5),
|
||||
(5, 6), (8, 9), (32, 64), (32, 33), (512, 513)]:
|
||||
yield f'bitlist_{typ_limit}_but_{test_limit}', \
|
||||
invalid_test_case(lambda: serialize(
|
||||
bitlist_case_fn(rng, RandomizationMode.mode_max_count, test_limit)))
|
||||
invalid_test_case(lambda: serialize(
|
||||
bitlist_case_fn(rng, RandomizationMode.mode_max_count, test_limit)))
|
||||
|
@ -38,5 +38,5 @@ def invalid_cases():
|
||||
(5, 6), (8, 9), (9, 8), (16, 8), (32, 33), (512, 513)]:
|
||||
for mode in [RandomizationMode.mode_random, RandomizationMode.mode_zero, RandomizationMode.mode_max]:
|
||||
yield f'bitvec_{typ_size}_{mode.to_name()}_{test_size}', \
|
||||
invalid_test_case(lambda: serialize(bitvector_case_fn(rng, mode, test_size,
|
||||
invalid_making_pos=typ_size)))
|
||||
invalid_test_case(lambda: serialize(bitvector_case_fn(rng, mode, test_size,
|
||||
invalid_making_pos=typ_size)))
|
||||
|
@ -46,7 +46,7 @@ class BitsStruct(Container):
|
||||
E: Bitvector[8]
|
||||
|
||||
|
||||
def container_case_fn(rng: Random, mode: RandomizationMode, typ: Type[View], chaos: bool=False):
|
||||
def container_case_fn(rng: Random, mode: RandomizationMode, typ: Type[View], chaos: bool = False):
|
||||
return get_random_ssz_object(rng, typ,
|
||||
max_bytes_length=2000,
|
||||
max_list_length=2000,
|
||||
@ -77,7 +77,7 @@ def valid_cases():
|
||||
for mode in modes:
|
||||
for variation in range(3):
|
||||
yield f'{name}_{mode.to_name()}_chaos_{variation}', \
|
||||
valid_test_case(lambda: container_case_fn(rng, mode, typ, chaos=True))
|
||||
valid_test_case(lambda: container_case_fn(rng, mode, typ, chaos=True))
|
||||
# Notes: Below is the second wave of iteration, and only the random mode is selected
|
||||
# for container without offset since ``RandomizationMode.mode_zero`` and ``RandomizationMode.mode_max``
|
||||
# are deterministic.
|
||||
@ -85,7 +85,7 @@ def valid_cases():
|
||||
for mode in modes:
|
||||
for variation in range(10):
|
||||
yield f'{name}_{mode.to_name()}_{variation}', \
|
||||
valid_test_case(lambda: container_case_fn(rng, mode, typ))
|
||||
valid_test_case(lambda: container_case_fn(rng, mode, typ))
|
||||
|
||||
|
||||
def mod_offset(b: bytes, offset_index: int, change: Callable[[int], int]):
|
||||
@ -100,8 +100,8 @@ def invalid_cases():
|
||||
for (name, (typ, offsets)) in PRESET_CONTAINERS.items():
|
||||
# using mode_max_count, so that the extra byte cannot be picked up as normal list content
|
||||
yield f'{name}_extra_byte', \
|
||||
invalid_test_case(lambda: serialize(
|
||||
container_case_fn(rng, RandomizationMode.mode_max_count, typ)) + b'\xff')
|
||||
invalid_test_case(lambda: serialize(
|
||||
container_case_fn(rng, RandomizationMode.mode_max_count, typ)) + b'\xff')
|
||||
|
||||
if len(offsets) != 0:
|
||||
# Note: there are many more ways to have invalid offsets,
|
||||
@ -112,23 +112,22 @@ def invalid_cases():
|
||||
RandomizationMode.mode_max_count]:
|
||||
for index, offset_index in enumerate(offsets):
|
||||
yield f'{name}_{mode.to_name()}_offset_{offset_index}_plus_one', \
|
||||
invalid_test_case(lambda: mod_offset(
|
||||
b=serialize(container_case_fn(rng, mode, typ)),
|
||||
offset_index=offset_index,
|
||||
change=lambda x: x + 1
|
||||
))
|
||||
invalid_test_case(lambda: mod_offset(
|
||||
b=serialize(container_case_fn(rng, mode, typ)),
|
||||
offset_index=offset_index,
|
||||
change=lambda x: x + 1))
|
||||
yield f'{name}_{mode.to_name()}_offset_{offset_index}_zeroed', \
|
||||
invalid_test_case(lambda: mod_offset(
|
||||
b=serialize(container_case_fn(rng, mode, typ)),
|
||||
offset_index=offset_index,
|
||||
change=lambda x: 0
|
||||
))
|
||||
invalid_test_case(lambda: mod_offset(
|
||||
b=serialize(container_case_fn(rng, mode, typ)),
|
||||
offset_index=offset_index,
|
||||
change=lambda x: 0
|
||||
))
|
||||
if index == 0:
|
||||
yield f'{name}_{mode.to_name()}_offset_{offset_index}_minus_one', \
|
||||
invalid_test_case(lambda: mod_offset(
|
||||
b=serialize(container_case_fn(rng, mode, typ)),
|
||||
offset_index=offset_index,
|
||||
change=lambda x: x - 1
|
||||
b=serialize(container_case_fn(rng, mode, typ)),
|
||||
offset_index=offset_index,
|
||||
change=lambda x: x - 1
|
||||
))
|
||||
if mode == RandomizationMode.mode_max_count:
|
||||
serialized = serialize(container_case_fn(rng, mode, typ))
|
||||
|
@ -21,7 +21,7 @@ def valid_cases():
|
||||
mode = RandomizationMode.mode_random
|
||||
byte_len = uint_type.type_byte_length()
|
||||
yield f'uint_{byte_len * 8}_last_byte_empty', \
|
||||
valid_test_case(lambda: uint_type((2 ** ((byte_len - 1) * 8)) - 1))
|
||||
valid_test_case(lambda: uint_type((2 ** ((byte_len - 1) * 8)) - 1))
|
||||
for variation in range(5):
|
||||
yield f'uint_{byte_len * 8}_{mode.to_name()}_{variation}', \
|
||||
valid_test_case(lambda: uint_case_fn(rng, mode, uint_type))
|
||||
@ -38,8 +38,8 @@ def invalid_cases():
|
||||
for uint_type in [uint8, uint16, uint32, uint64, uint128, uint256]:
|
||||
byte_len = uint_type.type_byte_length()
|
||||
yield f'uint_{byte_len * 8}_one_byte_longer', \
|
||||
invalid_test_case(lambda: (2 ** (byte_len * 8) - 1).to_bytes(byte_len + 1, 'little'))
|
||||
invalid_test_case(lambda: (2 ** (byte_len * 8) - 1).to_bytes(byte_len + 1, 'little'))
|
||||
for uint_type in [uint8, uint16, uint32, uint64, uint128, uint256]:
|
||||
byte_len = uint_type.type_byte_length()
|
||||
yield f'uint_{byte_len * 8}_one_byte_shorter', \
|
||||
invalid_test_case(lambda: (2 ** ((byte_len - 1) * 8) - 1).to_bytes(byte_len - 1, 'little'))
|
||||
invalid_test_case(lambda: (2 ** ((byte_len - 1) * 8) - 1).to_bytes(byte_len - 1, 'little'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user