From f229d21faae0e59e9769ed361ffc39d30be84a3e Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 11 Jul 2019 20:51:34 +0800 Subject: [PATCH 1/6] Bump `py-ssz` to `0.1.0a11` and update the fuzzing tests --- test_libs/pyspec/eth2spec/fuzzing/decoder.py | 6 +++--- test_libs/pyspec/eth2spec/fuzzing/test_decoder.py | 4 +--- test_libs/pyspec/requirements.txt | 2 +- test_libs/pyspec/setup.py | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/test_libs/pyspec/eth2spec/fuzzing/decoder.py b/test_libs/pyspec/eth2spec/fuzzing/decoder.py index ccca17385..e3b4de318 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/decoder.py @@ -19,13 +19,13 @@ def translate_typ(typ) -> ssz.BaseSedes: return ssz.Vector(translate_typ(typ.elem_type), typ.length) elif issubclass(typ, spec_ssz.List): # TODO: Make py-ssz List support the new fixed length list - return ssz.List(translate_typ(typ.elem_type)) + return ssz.List(translate_typ(typ.elem_type), typ.length) elif issubclass(typ, spec_ssz.Bitlist): # TODO: Once Bitlist implemented in py-ssz, use appropriate type - return ssz.List(translate_typ(typ.elem_type)) + return ssz.Bitlist(typ.length) elif issubclass(typ, spec_ssz.Bitvector): # TODO: Once Bitvector implemented in py-ssz, use appropriate type - return ssz.Vector(translate_typ(typ.elem_type), typ.length) + return ssz.Bitvector(typ.length) elif issubclass(typ, spec_ssz.boolean): return ssz.boolean elif issubclass(typ, spec_ssz.uint): diff --git a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py index ea1f1d47f..e68133bd6 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py @@ -9,9 +9,7 @@ def test_decoder(): rng = Random(123) # check these types only, Block covers a lot of operation types already. - # TODO: Once has Bitlists and Bitvectors, add back - # spec.BeaconState and spec.BeaconBlock - for typ in [spec.IndexedAttestation, spec.AttestationDataAndCustodyBit]: + for typ in [spec.BeaconState, spec.BeaconBlock]: # create a random pyspec value original = random_value.get_random_ssz_object(rng, typ, 100, 10, mode=random_value.RandomizationMode.mode_random, diff --git a/test_libs/pyspec/requirements.txt b/test_libs/pyspec/requirements.txt index 713b4331a..5aeea4cab 100644 --- a/test_libs/pyspec/requirements.txt +++ b/test_libs/pyspec/requirements.txt @@ -3,4 +3,4 @@ eth-typing>=2.1.0,<3.0.0 pycryptodome==3.7.3 py_ecc==1.7.1 dataclasses==0.6 -ssz==0.1.0a10 +ssz==0.1.0a11 diff --git a/test_libs/pyspec/setup.py b/test_libs/pyspec/setup.py index 07e538e80..9bdbdb2e9 100644 --- a/test_libs/pyspec/setup.py +++ b/test_libs/pyspec/setup.py @@ -9,7 +9,7 @@ setup( "eth-typing>=2.1.0,<3.0.0", "pycryptodome==3.7.3", "py_ecc==1.7.1", - "ssz==0.1.0a10", + "ssz==0.1.0a11", "dataclasses==0.6", ] ) From b08ecb018a97a5a50581e4fcac218f7c65f46360 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 13 Jul 2019 12:29:08 +0800 Subject: [PATCH 2/6] Apply suggestions from code review Co-Authored-By: Diederik Loerakker --- test_libs/pyspec/eth2spec/fuzzing/decoder.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test_libs/pyspec/eth2spec/fuzzing/decoder.py b/test_libs/pyspec/eth2spec/fuzzing/decoder.py index e3b4de318..272ed0c44 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/decoder.py @@ -18,13 +18,10 @@ def translate_typ(typ) -> ssz.BaseSedes: elif issubclass(typ, spec_ssz.Vector): return ssz.Vector(translate_typ(typ.elem_type), typ.length) elif issubclass(typ, spec_ssz.List): - # TODO: Make py-ssz List support the new fixed length list return ssz.List(translate_typ(typ.elem_type), typ.length) elif issubclass(typ, spec_ssz.Bitlist): - # TODO: Once Bitlist implemented in py-ssz, use appropriate type return ssz.Bitlist(typ.length) elif issubclass(typ, spec_ssz.Bitvector): - # TODO: Once Bitvector implemented in py-ssz, use appropriate type return ssz.Bitvector(typ.length) elif issubclass(typ, spec_ssz.boolean): return ssz.boolean From db9091f507a8a83a37b0c3ae4c3ecde4e9c68c8c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 13 Jul 2019 12:31:41 +0800 Subject: [PATCH 3/6] Add `AttestationDataAndCustodyBit` back --- test_libs/pyspec/eth2spec/fuzzing/test_decoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py index e68133bd6..c38fd69af 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py @@ -9,7 +9,7 @@ def test_decoder(): rng = Random(123) # check these types only, Block covers a lot of operation types already. - for typ in [spec.BeaconState, spec.BeaconBlock]: + for typ in [spec.AttestationDataAndCustodyBit, spec.BeaconState, spec.BeaconBlock]: # create a random pyspec value original = random_value.get_random_ssz_object(rng, typ, 100, 10, mode=random_value.RandomizationMode.mode_random, From 82e2c559ca0d382c734b2abcf9f9196c6a491794 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 15 Jul 2019 11:33:09 +0800 Subject: [PATCH 4/6] ssz==0.1.3 --- test_generators/ssz_generic/requirements.txt | 2 +- test_libs/pyspec/requirements.txt | 2 +- test_libs/pyspec/setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test_generators/ssz_generic/requirements.txt b/test_generators/ssz_generic/requirements.txt index dcdb0824f..94c019c4e 100644 --- a/test_generators/ssz_generic/requirements.txt +++ b/test_generators/ssz_generic/requirements.txt @@ -1,4 +1,4 @@ eth-utils==1.6.0 ../../test_libs/gen_helpers ../../test_libs/config_helpers -ssz==0.1.0a2 +ssz==0.1.3 diff --git a/test_libs/pyspec/requirements.txt b/test_libs/pyspec/requirements.txt index 5aeea4cab..480602779 100644 --- a/test_libs/pyspec/requirements.txt +++ b/test_libs/pyspec/requirements.txt @@ -3,4 +3,4 @@ eth-typing>=2.1.0,<3.0.0 pycryptodome==3.7.3 py_ecc==1.7.1 dataclasses==0.6 -ssz==0.1.0a11 +ssz==0.1.3 diff --git a/test_libs/pyspec/setup.py b/test_libs/pyspec/setup.py index 9bdbdb2e9..94575f2a1 100644 --- a/test_libs/pyspec/setup.py +++ b/test_libs/pyspec/setup.py @@ -9,7 +9,7 @@ setup( "eth-typing>=2.1.0,<3.0.0", "pycryptodome==3.7.3", "py_ecc==1.7.1", - "ssz==0.1.0a11", + "ssz==0.1.3", "dataclasses==0.6", ] ) From 47714cbf64026ecf74dee52601e9a8c5d7923cc5 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 25 Jul 2019 00:17:43 +0800 Subject: [PATCH 5/6] Add hash_tree_root tests against py-ssz --- test_libs/pyspec/eth2spec/fuzzing/test_decoder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py index c38fd69af..3c3afa975 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py @@ -31,3 +31,4 @@ def test_decoder(): # and see if the hash-tree-root of the original matches the hash-tree-root of the decoded & translated value. assert spec_ssz_impl.hash_tree_root(original) == spec_ssz_impl.hash_tree_root(block) + assert spec_ssz_impl.hash_tree_root(original) == block_sedes.get_hash_tree_root(raw_value) From 62772c9e79cea51278ecb16bd931c6e1d3b26498 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 25 Jul 2019 19:41:12 +0800 Subject: [PATCH 6/6] Refactor --- test_libs/pyspec/eth2spec/fuzzing/test_decoder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py index 3c3afa975..77b52e7a2 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py @@ -30,5 +30,6 @@ def test_decoder(): block = translate_value(raw_value, typ) # and see if the hash-tree-root of the original matches the hash-tree-root of the decoded & translated value. - assert spec_ssz_impl.hash_tree_root(original) == spec_ssz_impl.hash_tree_root(block) - assert spec_ssz_impl.hash_tree_root(original) == block_sedes.get_hash_tree_root(raw_value) + original_hash_tree_root = spec_ssz_impl.hash_tree_root(original) + assert original_hash_tree_root == spec_ssz_impl.hash_tree_root(block) + assert original_hash_tree_root == block_sedes.get_hash_tree_root(raw_value)