Skip to content
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

chore[test]: update hexbytes version and tests #3904

Merged
merged 11 commits into from
Apr 4, 2024
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"eth-tester[py-evm]>=0.10.0b4,<0.11",
"eth_abi>=4.0.0,<5.0.0",
"py-evm>=0.10.0b4,<0.11",
"hexbytes>1.0,<2.0",
"web3==6.0.0",
"lark==1.1.9",
"hypothesis[lark]>=6.0,<7.0",
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/builtins/codegen/test_keccak256.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def bar() -> bytes32:

c = get_contract_with_gas_estimation(hash_code)
for inp in (b"", b"cow", b"s" * 31, b"\xff" * 32, b"\n" * 33, b"g" * 64, b"h" * 65):
assert "0x" + c.foo(inp).hex() == keccak(inp).hex()
assert c.foo(inp).hex() == keccak(inp).hex()

assert "0x" + c.bar().hex() == keccak(b"inp").hex()
assert "0x" + c.foob().hex() == keccak(b"inp").hex()
assert c.bar().hex() == keccak(b"inp").hex()
assert c.foob().hex() == keccak(b"inp").hex()


def test_hash_code2(get_contract_with_gas_estimation):
Expand Down Expand Up @@ -96,7 +96,7 @@ def foo() -> bytes32:
return x
"""
c = get_contract_with_gas_estimation(code)
assert "0x" + c.foo().hex() == keccak(hex_to_int(hex_val).to_bytes(32, "big")).hex()
assert c.foo().hex() == keccak(hex_to_int(hex_val).to_bytes(32, "big")).hex()


def test_hash_constant_string(get_contract_with_gas_estimation, keccak):
Expand All @@ -110,4 +110,4 @@ def foo() -> bytes32:
return x
"""
c = get_contract_with_gas_estimation(code)
assert "0x" + c.foo().hex() == keccak(str_val.encode()).hex()
assert c.foo().hex() == keccak(str_val.encode()).hex()
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ def foo(a: {typ}):
pass
"""
c1 = get_contract(code)
sig = keccak(f"foo({typ})".encode()).hex()[:10]
sig = keccak(f"foo({typ})".encode()).to_0x_hex()[:10]
encoded = abi.encode(f"({typ})", (val,)).hex()
data = f"{sig}{encoded}"

Expand All @@ -2528,7 +2528,7 @@ def foo(a: DynArray[{typ}, 3], b: String[5]):
"""

c1 = get_contract(code)
sig = keccak(f"foo({typ}[],string)".encode()).hex()[:10]
sig = keccak(f"foo({typ}[],string)".encode()).to_0x_hex()[:10]
encoded = abi.encode(f"({typ}[],string)", val).hex()
data = f"{sig}{encoded}"

Expand Down
36 changes: 18 additions & 18 deletions tests/functional/codegen/features/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def foo():
event_id = keccak(bytes("MyLog()", "utf-8"))

# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -66,7 +66,7 @@ def foo():
event_id = keccak(bytes("MyLog(bytes)", "utf-8"))

# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -96,7 +96,7 @@ def foo():

event_id = keccak(bytes("MyLog(int128,bool,address)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -172,8 +172,8 @@ def bar():

event_id = keccak(bytes("MyLog(int128,address)", "utf-8"))
# Event id is always the first topic
assert receipt1["logs"][0]["topics"][0] == event_id.hex()
assert receipt2["logs"][0]["topics"][0] == event_id.hex()
assert receipt1["logs"][0]["topics"][0] == event_id.to_0x_hex()
assert receipt2["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -224,7 +224,7 @@ def foo():

event_id = keccak(bytes("MyLog(int128)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -260,7 +260,7 @@ def foo():

event_id = keccak(bytes("MyLog(int128[2],uint256[3],int128[2][2])", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly

assert c._classic_contract.abi[0] == {
Expand Down Expand Up @@ -303,7 +303,7 @@ def foo(arg1: Bytes[29], arg2: Bytes[31]):

event_id = keccak(bytes("MyLog(bytes,bytes,bytes)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -341,7 +341,7 @@ def foo(_arg1: Bytes[20]):

event_id = keccak(bytes("MyLog(bytes)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"anonymous": False,
Expand Down Expand Up @@ -370,7 +370,7 @@ def foo(_arg1: Bytes[5]):

event_id = keccak(bytes("MyLog(bytes)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"anonymous": False,
Expand Down Expand Up @@ -406,7 +406,7 @@ def foo():

event_id = keccak(bytes("MyLog(int128,bytes,bytes,address,address,uint256)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -453,7 +453,7 @@ def foo():

event_id = keccak(bytes("MyLog(int128,bytes)", "utf-8"))
# Event id is always the first topic
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"anonymous": False,
Expand Down Expand Up @@ -506,8 +506,8 @@ def foo():
event_id2 = keccak(bytes("YourLog(address,(uint256,bytes,(string,fixed168x10)))", "utf-8"))

# Event id is always the first topic
assert logs1["topics"][0] == event_id1.hex()
assert logs2["topics"][0] == event_id2.hex()
assert logs1["topics"][0] == event_id1.to_0x_hex()
assert logs2["topics"][0] == event_id2.to_0x_hex()
# Event abi is created correctly
assert c._classic_contract.abi[0] == {
"name": "MyLog",
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def foo(a: Bytes[36], b: int128, c: String[7]):

# Event id is always the first topic
event_id = keccak(b"MyLog(bytes,int128,string)")
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()

topic1 = f"0x{keccak256(b'bar').hex()}"
assert receipt["logs"][0]["topics"][1] == topic1
Expand Down Expand Up @@ -1126,7 +1126,7 @@ def foo():

# Event id is always the first topic
event_id = keccak(b"MyLog(bytes,int128,string)")
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()

topic1 = f"0x{keccak256(b'potato').hex()}"
assert receipt["logs"][0]["topics"][1] == topic1
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def foo():

# Event id is always the first topic
event_id = keccak(b"MyLog(bytes,int128,string)")
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()

topic1 = f"0x{keccak256(b'zonk').hex()}"
assert receipt["logs"][0]["topics"][1] == topic1
Expand Down Expand Up @@ -1222,7 +1222,7 @@ def foo():

# Event id is always the first topic
event_id = keccak(b"MyLog(bytes,int128,string)")
assert receipt["logs"][0]["topics"][0] == event_id.hex()
assert receipt["logs"][0]["topics"][0] == event_id.to_0x_hex()

topic1 = f"0x{keccak256(b'wow').hex()}"
assert receipt["logs"][0]["topics"][1] == topic1
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_msg_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def foo(bar: uint256) -> Bytes[36]:
contract = get_contract(code)

# 2fbebd38000000000000000000000000000000000000000000000000000000000000002a
method_id = keccak(text="foo(uint256)").hex()[2:10] # 2fbebd38
method_id = keccak(text="foo(uint256)").hex()[:8] # 2fbebd38
encoded_42 = w3.to_bytes(42).hex() # 2a
expected_result = method_id + "00" * 31 + encoded_42

Expand Down
Loading