forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45c6b6a
commit 5a70826
Showing
9 changed files
with
582 additions
and
0 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
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
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 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def get_contract(get_revm_contract): | ||
return get_revm_contract |
File renamed without changes.
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,47 @@ | ||
# wrapper module around whatever encoder we are using | ||
from typing import Any | ||
|
||
from eth.codecs.abi.decoder import Decoder | ||
from eth.codecs.abi.encoder import Encoder | ||
from eth.codecs.abi.exceptions import ABIError | ||
from eth.codecs.abi.nodes import ABITypeNode, BytesNode | ||
from eth.codecs.abi.parser import Parser | ||
|
||
_parsers: dict[str, ABITypeNode] = {} | ||
|
||
|
||
class _Encoder(Encoder): | ||
""" | ||
Custom encoder that parses bytes from hex to bytes | ||
""" | ||
|
||
@classmethod | ||
def visit_BytesNode(cls, node: BytesNode, value: bytes | str) -> bytes: | ||
if isinstance(value, str): | ||
assert value.startswith("0x"), "Sanity check failed: expected hex string" | ||
value = bytes.fromhex(value[2:]) | ||
return super().visit_BytesNode(node, value) | ||
|
||
|
||
def _get_parser(schema: str): | ||
try: | ||
return _parsers[schema] | ||
except KeyError: | ||
_parsers[schema] = (ret := Parser.parse(schema)) | ||
return ret | ||
|
||
|
||
def abi_encode(schema: str, data: Any) -> bytes: | ||
return _Encoder.encode(_get_parser(schema), data) | ||
|
||
|
||
def abi_decode(schema: str, data: bytes) -> Any: | ||
return Decoder.decode(_get_parser(schema), data) | ||
|
||
|
||
def is_abi_encodable(abi_type: str, data: Any) -> bool: | ||
try: | ||
abi_encode(abi_type, data) | ||
return True | ||
except ABIError: | ||
return False |
Oops, something went wrong.