From da858f1aae3ff5f906e041f025094d0a90ccc0c5 Mon Sep 17 00:00:00 2001
From: protolambda <proto@protolambda.com>
Date: Sat, 22 Jun 2019 21:49:42 +0200
Subject: [PATCH] fix int encoding, fix list randomization size limit.

---
 test_libs/pyspec/eth2spec/debug/encode.py       | 4 ++--
 test_libs/pyspec/eth2spec/debug/random_value.py | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/test_libs/pyspec/eth2spec/debug/encode.py b/test_libs/pyspec/eth2spec/debug/encode.py
index 9a819a256..0878a1f94 100644
--- a/test_libs/pyspec/eth2spec/debug/encode.py
+++ b/test_libs/pyspec/eth2spec/debug/encode.py
@@ -8,8 +8,8 @@ def encode(value: SSZValue, include_hash_tree_roots=False):
     if isinstance(value, uint):
         # Larger uints are boxed and the class declares their byte length
         if value.type().byte_len > 8:
-            return str(value)
-        return value
+            return str(int(value))
+        return int(value)
     elif isinstance(value, Bit):
         return value == 1
     elif isinstance(value, list):  # normal python lists, ssz-List, Vector
diff --git a/test_libs/pyspec/eth2spec/debug/random_value.py b/test_libs/pyspec/eth2spec/debug/random_value.py
index bd40cb832..8e13cd5e1 100644
--- a/test_libs/pyspec/eth2spec/debug/random_value.py
+++ b/test_libs/pyspec/eth2spec/debug/random_value.py
@@ -95,6 +95,9 @@ def get_random_ssz_object(rng: Random,
         elif mode == RandomizationMode.mode_max_count:
             length = max_list_length
 
+        if typ.length < length:  # SSZ imposes a hard limit on lists, we can't put in more than that
+            length = typ.length
+
         return typ(
             get_random_ssz_object(rng, typ.elem_type, max_bytes_length, max_list_length, mode, chaos)
             for _ in range(length)