3
3
)
4
4
import pytest
5
5
6
+ from eth_utils import (
7
+ ValidationError ,
8
+ )
6
9
from eth_utils .toolz import (
7
10
compose ,
8
11
)
@@ -69,7 +72,7 @@ def test_get_formatters_non_falsy_config_retrieval():
69
72
first_formatter = (method .request_formatters (method_name ).first ,)
70
73
all_other_formatters = method .request_formatters (method_name ).funcs
71
74
assert len (first_formatter + all_other_formatters ) == 2
72
- # assert method.request_formatters('eth_nonmatching') == 'nonmatch'
75
+ assert ( method .request_formatters ('eth_getBalance' ). first ,) == first_formatter
73
76
74
77
75
78
def test_input_munger_parameter_passthrough_matching_arity ():
@@ -89,24 +92,87 @@ def test_input_munger_parameter_passthrough_mismatch_arity():
89
92
method .input_munger (object (), ['first' , 'second' , 'third' ], {})
90
93
91
94
92
- def test_input_munger_falsy_config_result_in_default_munger ():
95
+ def test_default_input_munger_with_no_input_parameters ():
93
96
method = Method (
94
- mungers = [],
97
+ json_rpc_method = 'eth_method' ,
98
+ )
99
+ assert method .input_munger (object (), [], {}) == []
100
+
101
+
102
+ @pytest .mark .parametrize ('empty' , ([], (), None ), ids = ['empty-list' , 'empty-tuple' , 'None' ])
103
+ def test_empty_input_munger_with_no_input_parameters (empty ):
104
+ method = Method (
105
+ mungers = empty ,
95
106
json_rpc_method = 'eth_method' ,
96
107
)
97
108
assert method .input_munger (object (), [], {}) == []
98
109
99
110
100
111
def test_default_input_munger_with_input_parameters ():
101
112
method = Method (
102
- mungers = [],
103
113
json_rpc_method = 'eth_method' ,
104
114
)
105
115
assert method .input_munger (object (), [1 ], {}) == [1 ]
106
116
107
117
118
+ @pytest .mark .parametrize ('empty' , ([], (), None ), ids = ['empty-list' , 'empty-tuple' , 'None' ])
119
+ def test_empty_input_mungers_with_input_parameters (empty ):
120
+ method = Method (
121
+ mungers = empty ,
122
+ json_rpc_method = 'eth_method' ,
123
+ )
124
+ assert method .input_munger (object (), [1 ], {}) == [1 ]
125
+
126
+
127
+ def test_default_munger_for_property_with_no_input_parameters ():
128
+ method = Method (
129
+ is_property = True ,
130
+ json_rpc_method = 'eth_method' ,
131
+ )
132
+ assert method .input_munger (object (), [], {}) == ()
133
+
134
+
135
+ @pytest .mark .parametrize ('empty' , ([], (), None ), ids = ['empty-list' , 'empty-tuple' , 'None' ])
136
+ def test_empty_mungers_for_property_with_no_input_parameters (empty ):
137
+ method = Method (
138
+ is_property = True ,
139
+ mungers = empty ,
140
+ json_rpc_method = 'eth_method' ,
141
+ )
142
+ assert method .input_munger (object (), [], {}) == ()
143
+
144
+
145
+ def test_default_munger_for_property_with_input_parameters_raises_ValidationError ():
146
+ method = Method (
147
+ is_property = True ,
148
+ json_rpc_method = 'eth_method' ,
149
+ )
150
+ with pytest .raises (ValidationError , match = 'Parameters cannot be passed to a property' ):
151
+ method .input_munger (object (), [1 ], {})
152
+
153
+
154
+ @pytest .mark .parametrize ('empty' , ([], (), None ), ids = ['empty-list' , 'empty-tuple' , 'None' ])
155
+ def test_empty_mungers_for_property_with_input_parameters_raises_ValidationError (empty ):
156
+ method = Method (
157
+ is_property = True ,
158
+ mungers = empty ,
159
+ json_rpc_method = 'eth_method' ,
160
+ )
161
+ with pytest .raises (ValidationError , match = 'Parameters cannot be passed to a property' ):
162
+ method .input_munger (object (), [1 ], {})
163
+
164
+
165
+ def test_property_with_mungers_raises_ValidationError ():
166
+ with pytest .raises (ValidationError , match = 'Mungers cannot be used with a property' ):
167
+ Method (
168
+ is_property = True ,
169
+ mungers = [lambda m , z , y : 'success' ],
170
+ json_rpc_method = 'eth_method' ,
171
+ )
172
+
173
+
108
174
@pytest .mark .parametrize (
109
- "method_config,args,kwargs,expected_request_result,expected_result_formatters_len " ,
175
+ "method_config,args,kwargs,expected_request_result" ,
110
176
(
111
177
(
112
178
{
@@ -115,17 +181,15 @@ def test_default_input_munger_with_input_parameters():
115
181
[],
116
182
{},
117
183
ValueError ,
118
- 2
119
184
),
120
185
(
121
186
{
122
187
'mungers' : [],
123
188
'json_rpc_method' : 'eth_getBalance' ,
124
189
},
125
- ['unexpected_argument ' ],
190
+ ['only_the_first_argument_but_expects_two ' ],
126
191
{},
127
192
IndexError ,
128
- 2
129
193
),
130
194
(
131
195
{
@@ -135,7 +199,6 @@ def test_default_input_munger_with_input_parameters():
135
199
['0x0000000000000000000000000000000000000000' , 3 ],
136
200
{},
137
201
('eth_getBalance' , (('0x' + '00' * 20 ), "0x3" )),
138
- 2
139
202
),
140
203
(
141
204
{
@@ -145,7 +208,6 @@ def test_default_input_munger_with_input_parameters():
145
208
['0x0000000000000000000000000000000000000000' , 3 ],
146
209
{},
147
210
('eth_getBalance' , (('0x' + '00' * 20 ), "0x3" )),
148
- 2
149
211
),
150
212
(
151
213
{
@@ -158,7 +220,6 @@ def test_default_input_munger_with_input_parameters():
158
220
[1 , 2 , 3 , ('0x' + '00' * 20 )],
159
221
{},
160
222
('eth_getBalance' , (('0x' + '00' * 20 ), "1" )),
161
- 2 ,
162
223
),
163
224
(
164
225
{
@@ -171,7 +232,6 @@ def test_default_input_munger_with_input_parameters():
171
232
[1 , 2 , 3 , 4 ],
172
233
{},
173
234
TypeError ,
174
- 2 ,
175
235
),
176
236
(
177
237
{
@@ -181,7 +241,6 @@ def test_default_input_munger_with_input_parameters():
181
241
('0x0000000000000000000000000000000000000000' , 3 ),
182
242
{},
183
243
('eth_getBalance' , ('0x0000000000000000000000000000000000000000' , '0x3' )),
184
- 2 ,
185
244
),
186
245
(
187
246
{
@@ -190,7 +249,6 @@ def test_default_input_munger_with_input_parameters():
190
249
('0x0000000000000000000000000000000000000000' , 3 ),
191
250
{},
192
251
('eth_getBalance' , ('0x0000000000000000000000000000000000000000' , '0x3' )),
193
- 2 ,
194
252
),
195
253
(
196
254
{
@@ -203,7 +261,6 @@ def test_default_input_munger_with_input_parameters():
203
261
[('0x' + '00' * 20 ), 1 , 2 , 3 ],
204
262
{},
205
263
('eth_getBalance' , (('0x' + '00' * 20 ), '1' )),
206
- 2 ,
207
264
),
208
265
(
209
266
{
@@ -213,7 +270,6 @@ def test_default_input_munger_with_input_parameters():
213
270
[],
214
271
{},
215
272
('eth_chainId' , ()),
216
- 2 ,
217
273
),
218
274
(
219
275
{
@@ -223,16 +279,15 @@ def test_default_input_munger_with_input_parameters():
223
279
[],
224
280
{},
225
281
('eth_chainId' , ()),
226
- 2 ,
227
282
),
228
283
),
229
284
ids = [
230
285
'raises-error-no-rpc-method' ,
231
- 'test-unexpected-arg ' ,
286
+ 'test-missing-argument ' ,
232
287
'test-rpc-method-as-string' ,
233
288
'test-rpc-method-as-callable' ,
234
289
'test-arg-munger' ,
235
- 'test-munger-wrong-length-arg ' ,
290
+ 'test-munger-too-many-args ' ,
236
291
'test-request-formatters-default-root-munger-explicit' ,
237
292
'test-request-formatters-default-root-munger-implicit' ,
238
293
'test-mungers-and-request-formatters' ,
@@ -245,7 +300,7 @@ def test_process_params(
245
300
args ,
246
301
kwargs ,
247
302
expected_request_result ,
248
- expected_result_formatters_len ):
303
+ ):
249
304
250
305
if isclass (expected_request_result ) and issubclass (expected_request_result , Exception ):
251
306
with pytest .raises (expected_request_result ):
@@ -257,7 +312,9 @@ def test_process_params(
257
312
assert request_params == expected_request_result
258
313
first_formatter = (output_formatter [0 ].first ,)
259
314
all_other_formatters = output_formatter [0 ].funcs
260
- assert len (first_formatter + all_other_formatters ) == expected_result_formatters_len
315
+
316
+ # the expected result formatters length is 2
317
+ assert len (first_formatter + all_other_formatters ) == 2
261
318
262
319
263
320
def keywords (module , keyword_one , keyword_two ):
0 commit comments