Skip to content

Commit 0ca91eb

Browse files
committed
Add tuple tests back
1 parent e9325ba commit 0ca91eb

File tree

5 files changed

+103
-133
lines changed

5 files changed

+103
-133
lines changed

tests/core/contracts/test_contract_deployment.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
from eth_utils import (
55
decode_hex,
66
)
7-
from web3.exceptions import (
8-
ValidationError,
9-
)
107

118

129
def test_contract_deployment_no_constructor(web3, MathContract,
@@ -67,8 +64,8 @@ def test_contract_deployment_with_constructor_with_arguments_strict(web3_strict_
6764
WITH_CONSTRUCTOR_ARGUMENTS_RUNTIME, # noqa: E501
6865
constructor_arg):
6966
deploy_txn = WithConstructorArgumentsContractStrict.constructor(
70-
1234, constructor_arg
71-
).transact()
67+
1234, constructor_arg
68+
).transact()
7269

7370
txn_receipt = web3_strict_types.eth.waitForTransactionReceipt(deploy_txn)
7471
assert txn_receipt is not None
@@ -89,6 +86,7 @@ def test_contract_deployment_with_constructor_with_arguments_strict_error(web3_s
8986
):
9087
WithConstructorArgumentsContractStrict.constructor(1234, 'abcd').transact()
9188

89+
9290
def test_contract_deployment_with_constructor_with_address_argument(web3,
9391
WithConstructorAddressArgumentsContract, # noqa: E501
9492
WITH_CONSTRUCTOR_ADDRESS_RUNTIME): # noqa: E501

tests/core/filtering/test_utils_functions.py

Lines changed: 91 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
)
44
import pytest
55

6+
from eth_abi.exceptions import (
7+
ValueOutOfBounds,
8+
)
9+
610
from web3._utils.filters import (
711
match_fn,
812
)
@@ -31,54 +35,54 @@
3135
("ufixed256x4", None)
3236
)
3337
),
34-
# (
35-
# ("aye", "bee", "sea", b"\xde\xee"),
36-
# False,
37-
# (
38-
# ("string", ("eee",)),
39-
# ("string", ("aye",)),
40-
# ("string", ("sea",)),
41-
# ("bytes", (b"\x00",))
42-
# )
43-
# ),
44-
# (
45-
# ("aye", "bee", "sea", "0x1234"),
46-
# True,
47-
# (
48-
# ("string", ("aye",)),
49-
# ("string", ("bee",)),
50-
# ("string", ("sea",)),
51-
# ("bytes", ("0x1234"))
52-
# )
53-
# ),
54-
# (
55-
# ("aye", "bee", "sea", b"\xde\xee"),
56-
# True,
57-
# (
58-
# ("string", ("aye",)),
59-
# ("string", ("bee",)),
60-
# ("string", ("sea",)),
61-
# ("bytes", (b"\xde\xee",))
62-
# )
63-
# ),
64-
# (
65-
# ("aye", "bee", "sea", b"\xde\xee"),
66-
# True,
67-
# (
68-
# ("string", None),
69-
# ("string", None),
70-
# ("string", None),
71-
# ("bytes", None)
72-
# )
73-
# ),
74-
# (
75-
# ((b"aye", b"bee"), ("sea", "dee")),
76-
# True,
77-
# (
78-
# ("bytes3[]", ((b"aye", b"bee"),)),
79-
# ("string[]", (("sea", "dee"),)),
80-
# )
81-
# ),
38+
(
39+
("aye", "bee", "sea", b"\xde\xee"),
40+
False,
41+
(
42+
("string", ("eee",)),
43+
("string", ("aye",)),
44+
("string", ("sea",)),
45+
("bytes", (b"\x00",))
46+
)
47+
),
48+
(
49+
("aye", "bee", "sea", "0x1234"),
50+
True,
51+
(
52+
("string", ("aye",)),
53+
("string", ("bee",)),
54+
("string", ("sea",)),
55+
("bytes", (b'\x124',))
56+
)
57+
),
58+
(
59+
("aye", "bee", "sea", b"\xde\xee"),
60+
True,
61+
(
62+
("string", ("aye",)),
63+
("string", ("bee",)),
64+
("string", ("sea",)),
65+
("bytes", (b"\xde\xee",))
66+
)
67+
),
68+
(
69+
("aye", "bee", "sea", b"\xde\xee"),
70+
True,
71+
(
72+
("string", None),
73+
("string", None),
74+
("string", None),
75+
("bytes", None)
76+
)
77+
),
78+
(
79+
((b"aye", b"bee"), ("sea", "dee")),
80+
True,
81+
(
82+
("bytes3[]", ((b"aye", b"bee"),)),
83+
("string[]", (("sea", "dee"),)),
84+
)
85+
),
8286
(
8387
(("aye", "bee"), ("sea", "dee")),
8488
True,
@@ -111,57 +115,47 @@ def test_match_fn_with_various_data_types(web3, data, expected, match_data_and_a
111115
assert match_fn(web3, match_data_and_abi, encoded_data) == expected
112116

113117

114-
# @pytest.mark.parametrize(
115-
# "data,expected,match_data_and_abi",
116-
# (
117-
# (
118-
# ([b'1234']),
119-
# True,
120-
# (
121-
# ("bytes4", (b"1234",)),
122-
# )
123-
# ),
124-
# (
125-
# (['0x12343434']),
126-
# True,
127-
# (
128-
# ("bytes4", (b"1234",)),
129-
# )
130-
# ),
131-
# )
132-
# )
133-
# def test_match_fn_with_various_data_types_strict(web3_strict_types,
134-
# data,
135-
# expected,
136-
# match_data_and_abi):
137-
# abi_types, match_data = zip(*match_data_and_abi)
138-
# encoded_data = web3_strict_types.codec.encode_abi(abi_types, data)
139-
# assert match_fn(web3_strict_types, match_data_and_abi, encoded_data) == expected
118+
@pytest.mark.parametrize(
119+
"data,expected,match_data_and_abi",
120+
(
121+
(
122+
([b'1234']),
123+
True,
124+
(
125+
("bytes4", (b"1234",)),
126+
)
127+
),
128+
(
129+
(['0x12343434']),
130+
True,
131+
(
132+
("bytes4", (b"1234",)),
133+
)
134+
),
135+
)
136+
)
137+
def test_match_fn_with_various_data_types_strict(web3_strict_types,
138+
data,
139+
expected,
140+
match_data_and_abi):
141+
abi_types, match_data = zip(*match_data_and_abi)
142+
encoded_data = web3_strict_types.codec.encode_abi(abi_types, data)
143+
assert match_fn(web3_strict_types, match_data_and_abi, encoded_data) == expected
140144

141145

142-
# @pytest.mark.parametrize(
143-
# "data,match_data_and_abi",
144-
# ( # # (
145-
# # ([b'124']),
146-
# # (
147-
# # ("bytes4", (b"1234",)),
148-
# # )
149-
# # ),
150-
# (
151-
# (['0x12343434']),
152-
# (
153-
# ("bytes4", ("124",)),
154-
# )
155-
# ),
156-
# )
157-
# )
158-
# def test_match_fn_with_wrong_types_strict(web3_strict_types,
159-
# data,
160-
# match_data_and_abi):
161-
# abi_types, match_data = zip(*match_data_and_abi)
162-
# encoded_data = web3_strict_types.codec.encode_abi(abi_types, data)
163-
# with pytest.raises(ValueError):
164-
# match_fn(web3_strict_types, match_data_and_abi, encoded_data)
146+
@pytest.mark.parametrize(
147+
"data,abi_type",
148+
(
149+
((b'124',), ("bytes4",)),
150+
(('0x123434',), ("bytes4",)),
151+
(('0x1234343232',), ("bytes4",)),
152+
)
153+
)
154+
def test_encode_abi_with_wrong_types_strict(web3_strict_types,
155+
data,
156+
abi_type):
157+
with pytest.raises(ValueOutOfBounds):
158+
web3_strict_types.codec.encode_abi(abi_type, data)
165159

166160

167161
def test_wrong_type_match_data(web3):

web3/_utils/abi.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import binascii
2-
32
from collections import (
43
abc,
54
namedtuple,
@@ -32,8 +31,8 @@
3231
)
3332
from eth_abi.registry import (
3433
BaseEquals,
35-
registry as default_registry,
3634
is_base_tuple,
35+
registry as default_registry,
3736
)
3837
from eth_typing import (
3938
TypeStr,
@@ -54,9 +53,6 @@
5453
partial,
5554
pipe,
5655
)
57-
# from itertools import (
58-
# accumulate,
59-
# )
6056

6157
from web3._utils.decorators import (
6258
combomethod,
@@ -226,19 +222,6 @@ class StrictByteStringEncoder(AcceptsHexStrMixin):
226222
is_strict = True
227223

228224

229-
# class BytesDecoderStrict(AcceptsHexStrMixin, decoding.FixedByteSizeDecoder):
230-
231-
# is_strict = True
232-
233-
# @staticmethod
234-
# def decoder_fn(data):
235-
# return data
236-
237-
# @parse_type_str('bytes')
238-
# def from_type_str(cls, abi_type, registry):
239-
# return cls(value_bit_size=abi_type.sub * 8)
240-
241-
242225
class ExactLengthBytesEncoder(encoding.BaseEncoder):
243226
# TODO: move this to eth-abi once the api is stabilized
244227
is_big_endian = False
@@ -269,26 +252,26 @@ def validate(self):
269252
raise ValueError("Value byte size exceeds data size")
270253

271254
def encode(self, value):
272-
self.validate_value(value)
273-
return self.encode_fn(value)
255+
normalized_value = self.validate_value(value)
256+
return self.encode_fn(normalized_value)
274257

275258
def validate_value(self, value):
276259
if not is_bytes(value) and not is_text(value):
277260
self.invalidate_value(value)
278261

279-
original_value = value
262+
raw_value = value
280263
if is_text(value):
281264
try:
282265
value = decode_hex(value)
283266
except binascii.Error:
284267
self.invalidate_value(
285268
value,
286-
msg=f'{value} is an invalid hex string',
269+
msg=f'{value} is not a valid hex string',
287270
)
288271
else:
289-
if original_value[:2] != '0x':
272+
if raw_value[:2] != '0x':
290273
self.invalidate_value(
291-
original_value,
274+
raw_value,
292275
msg='hex string must be prefixed with 0x'
293276
)
294277

@@ -305,6 +288,7 @@ def validate_value(self, value):
305288
exc=ValueOutOfBounds,
306289
msg="less than total byte size for bytes{} encoding".format(byte_size),
307290
)
291+
return value
308292

309293
@staticmethod
310294
def encode_fn(value):

web3/_utils/filters.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,13 @@ def match_fn(w3, match_values_and_abi, data):
209209
compared to the abi decoded log data.
210210
"""
211211
abi_types, all_match_values = zip(*match_values_and_abi)
212-
# import pdb; pdb.set_trace()
213212

214213
decoded_values = w3.codec.decode_abi(abi_types, HexBytes(data))
215214
for data_value, match_values, abi_type in zip(decoded_values, all_match_values, abi_types):
216-
print(data_value, type(data_value))
217-
print(match_values, type(match_values))
218-
print(abi_type)
219215
if match_values is None:
220216
continue
221217
normalized_data = normalize_data_values(abi_type, data_value)
222218
for value in match_values:
223-
print(value)
224219
if not w3.is_encodable(abi_type, value):
225220
raise ValueError(
226221
f"Value {value} is of the wrong abi type. "

web3/contract.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from eth_abi.exceptions import (
99
DecodingError,
10-
InsufficientDataBytes,
1110
)
1211
from eth_utils import (
1312
add_0x_prefix,
@@ -1016,7 +1015,7 @@ def _parse_logs(self, txn_receipt, errors):
10161015
for log in txn_receipt['logs']:
10171016
try:
10181017
rich_log = get_event_data(self.web3.codec, self.abi, log)
1019-
except (MismatchedABI, LogTopicError, InvalidEventABI, TypeError, InsufficientDataBytes) as e:
1018+
except (MismatchedABI, LogTopicError, InvalidEventABI, TypeError) as e:
10201019
if errors == DISCARD:
10211020
continue
10221021
elif errors == IGNORE:

0 commit comments

Comments
 (0)