-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EIP712 support for bytes and uint formatted as string #427
Conversation
Pull Request Test Coverage Report for Build 3882828086
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👏 🚀
{"name": "maxByte", "type": "bytes32"}, | ||
], | ||
} | ||
# test string uint (chainId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: this comment does not apply to this test right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, copy pasted from above, done fa4a21f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moisses89 I think these things should be addressed in a new PR
@@ -57,6 +57,14 @@ def _encode_field(name, typ, value): | |||
if value is None: | |||
raise Exception(f"Missing value for field {name} of type {type}") | |||
|
|||
# Accept string bytes | |||
if "bytes" in typ and isinstance(value, str): | |||
value = bytes.fromhex(value.replace("0x", "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value = HexBytes(value)
if "bytes" in typ and isinstance(value, str): | ||
value = bytes.fromhex(value.replace("0x", "")) | ||
|
||
# Accept string uint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should support any kind of integer, not only uint
. This is a very misleading behaviour:
if "int" in typ
@@ -4,6 +4,43 @@ | |||
|
|||
|
|||
class TestEIP712(TestCase): | |||
address = "0x8e12f01dae5fe7f1122dc42f2cb084f2f9e8aa03" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use checksummed addresses unless we are testing not checksummed addresses:
0x8e12f01DAE5FE7f1122Dc42f2cB084F2f9E8aA03
|
||
self.assertEqual( | ||
eip712_encode_hash(payload).hex(), | ||
"2950cf06416c6c20059f24a965e3baf51a24f4ef49a1e7b1a47ee13ee08cde1f", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use hex()
here? I think we should be consistent, either using hex()
everywhere (it looks better and more readable IMHO) or using binary representation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moisses89 I think these things should be addressed in a new PR
Your suggestions sounds good for me, then I add the following PR #437
Regarding if use hex() or binary representation for test, I'd prefer hex() because as you mention is more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks
Closes #424
Description
eip712_encode_hash
is usingeth-abi
that doesn't support the typebytes
anduint
formatted as string.Type
bytes
andbytesN
oneth-abi
only accept python bytes, this was fixed including a conversion for bytes formatted on string to python bytes.Type
uint
only accept Numbers, this was fixed converting from string to python Integer.Additional changes