Skip to content

Commit 82408b4

Browse files
authored
fix(cli_types): Fix parsing undefined opcodes (#2289)
1 parent 15bafa9 commit 82408b4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/ethereum_clis/cli_types.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,19 @@ def print(self):
181181
}
182182

183183

184-
def validate_opcode(obj: Any) -> Opcodes | Opcode:
184+
class UndefinedOpcode(HexNumber):
185+
"""Undefined opcode."""
186+
187+
pass
188+
189+
190+
def validate_opcode(obj: Any) -> Opcodes | Opcode | UndefinedOpcode:
185191
"""Validate an opcode from a string."""
186-
if isinstance(obj, Opcode) or isinstance(obj, Opcodes):
192+
if isinstance(obj, (Opcode, Opcodes, UndefinedOpcode)):
187193
return obj
188194
if isinstance(obj, str):
195+
if obj.startswith("0x"):
196+
return UndefinedOpcode(obj)
189197
if obj in _opcode_synonyms:
190198
obj = _opcode_synonyms[obj]
191199
for op in Opcodes:
@@ -198,7 +206,12 @@ class OpcodeCount(EthereumTestRootModel):
198206
"""Opcode count returned from the evm tool."""
199207

200208
root: Dict[
201-
Annotated[Opcodes, PlainValidator(validate_opcode), PlainSerializer(lambda o: str(o))], int
209+
Annotated[
210+
Opcodes | UndefinedOpcode,
211+
PlainValidator(validate_opcode),
212+
PlainSerializer(lambda o: str(o)),
213+
],
214+
int,
202215
]
203216

204217
def __add__(self, other: Self) -> Self:

0 commit comments

Comments
 (0)