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,68 @@ 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
+ @pytest .mark .parametrize ('empty' , ([], (), None ), ids = ['empty-list' , 'empty-tuple' , 'None' ])
128
+ def test_empty_mungers_for_property_with_no_input_parameters (empty ):
129
+ method = Method (
130
+ is_property = True ,
131
+ mungers = empty ,
132
+ json_rpc_method = 'eth_method' ,
133
+ )
134
+ assert method .input_munger (object (), [], {}) == ()
135
+
136
+
137
+ def test_property_with_input_parameters_raises_ValidationError ():
138
+ method = Method (
139
+ is_property = True ,
140
+ json_rpc_method = 'eth_method' ,
141
+ )
142
+ with pytest .raises (ValidationError , match = 'Parameters cannot be passed to a property' ):
143
+ method .input_munger (object (), [1 ], {})
144
+
145
+
146
+ def test_property_with_mungers_raises_ValidationError ():
147
+ with pytest .raises (ValidationError , match = 'Mungers cannot be used with a property' ):
148
+ Method (
149
+ is_property = True ,
150
+ mungers = [lambda m , z , y : 'success' ],
151
+ json_rpc_method = 'eth_method' ,
152
+ )
153
+
154
+
108
155
@pytest .mark .parametrize (
109
- "method_config,args,kwargs,expected_request_result,expected_result_formatters_len " ,
156
+ "method_config,args,kwargs,expected_request_result" ,
110
157
(
111
158
(
112
159
{
@@ -115,17 +162,15 @@ def test_default_input_munger_with_input_parameters():
115
162
[],
116
163
{},
117
164
ValueError ,
118
- 2
119
165
),
120
166
(
121
167
{
122
168
'mungers' : [],
123
169
'json_rpc_method' : 'eth_getBalance' ,
124
170
},
125
- ['unexpected_argument ' ],
171
+ ['only_the_first_argument_but_expects_two ' ],
126
172
{},
127
173
IndexError ,
128
- 2
129
174
),
130
175
(
131
176
{
@@ -135,7 +180,6 @@ def test_default_input_munger_with_input_parameters():
135
180
['0x0000000000000000000000000000000000000000' , 3 ],
136
181
{},
137
182
('eth_getBalance' , (('0x' + '00' * 20 ), "0x3" )),
138
- 2
139
183
),
140
184
(
141
185
{
@@ -145,7 +189,6 @@ def test_default_input_munger_with_input_parameters():
145
189
['0x0000000000000000000000000000000000000000' , 3 ],
146
190
{},
147
191
('eth_getBalance' , (('0x' + '00' * 20 ), "0x3" )),
148
- 2
149
192
),
150
193
(
151
194
{
@@ -158,7 +201,6 @@ def test_default_input_munger_with_input_parameters():
158
201
[1 , 2 , 3 , ('0x' + '00' * 20 )],
159
202
{},
160
203
('eth_getBalance' , (('0x' + '00' * 20 ), "1" )),
161
- 2 ,
162
204
),
163
205
(
164
206
{
@@ -171,7 +213,6 @@ def test_default_input_munger_with_input_parameters():
171
213
[1 , 2 , 3 , 4 ],
172
214
{},
173
215
TypeError ,
174
- 2 ,
175
216
),
176
217
(
177
218
{
@@ -181,7 +222,6 @@ def test_default_input_munger_with_input_parameters():
181
222
('0x0000000000000000000000000000000000000000' , 3 ),
182
223
{},
183
224
('eth_getBalance' , ('0x0000000000000000000000000000000000000000' , '0x3' )),
184
- 2 ,
185
225
),
186
226
(
187
227
{
@@ -190,7 +230,6 @@ def test_default_input_munger_with_input_parameters():
190
230
('0x0000000000000000000000000000000000000000' , 3 ),
191
231
{},
192
232
('eth_getBalance' , ('0x0000000000000000000000000000000000000000' , '0x3' )),
193
- 2 ,
194
233
),
195
234
(
196
235
{
@@ -203,7 +242,6 @@ def test_default_input_munger_with_input_parameters():
203
242
[('0x' + '00' * 20 ), 1 , 2 , 3 ],
204
243
{},
205
244
('eth_getBalance' , (('0x' + '00' * 20 ), '1' )),
206
- 2 ,
207
245
),
208
246
(
209
247
{
@@ -213,7 +251,6 @@ def test_default_input_munger_with_input_parameters():
213
251
[],
214
252
{},
215
253
('eth_chainId' , ()),
216
- 2 ,
217
254
),
218
255
(
219
256
{
@@ -223,16 +260,15 @@ def test_default_input_munger_with_input_parameters():
223
260
[],
224
261
{},
225
262
('eth_chainId' , ()),
226
- 2 ,
227
263
),
228
264
),
229
265
ids = [
230
266
'raises-error-no-rpc-method' ,
231
- 'test-unexpected-arg ' ,
267
+ 'test-missing-argument ' ,
232
268
'test-rpc-method-as-string' ,
233
269
'test-rpc-method-as-callable' ,
234
270
'test-arg-munger' ,
235
- 'test-munger-wrong-length-arg ' ,
271
+ 'test-munger-too-many-args ' ,
236
272
'test-request-formatters-default-root-munger-explicit' ,
237
273
'test-request-formatters-default-root-munger-implicit' ,
238
274
'test-mungers-and-request-formatters' ,
@@ -245,7 +281,7 @@ def test_process_params(
245
281
args ,
246
282
kwargs ,
247
283
expected_request_result ,
248
- expected_result_formatters_len ):
284
+ ):
249
285
250
286
if isclass (expected_request_result ) and issubclass (expected_request_result , Exception ):
251
287
with pytest .raises (expected_request_result ):
@@ -257,7 +293,9 @@ def test_process_params(
257
293
assert request_params == expected_request_result
258
294
first_formatter = (output_formatter [0 ].first ,)
259
295
all_other_formatters = output_formatter [0 ].funcs
260
- assert len (first_formatter + all_other_formatters ) == expected_result_formatters_len
296
+
297
+ # the expected result formatters length is 2
298
+ assert len (first_formatter + all_other_formatters ) == 2
261
299
262
300
263
301
def keywords (module , keyword_one , keyword_two ):
0 commit comments