Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit f154a5a

Browse files
authored
Merge pull request #97 from iotaledger/feature/96_findTransactionsChillOutBro
[#96] Do not include null terms in `findTransactions` reqs.
2 parents 3c0cdf8 + 38e2adc commit f154a5a

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

iota/commands/core/find_transactions.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
unicode_literals
44

55
import filters as f
6+
from six import iteritems
67

78
from iota import Address, Tag, TransactionHash
89
from iota.commands import FilterCommand, RequestFilter, ResponseFilter
@@ -45,7 +46,6 @@ def __init__(self):
4546
| Trytes(result_type=Address)
4647
| f.Unicode(encoding='ascii', normalize=False)
4748
)
48-
| f.Optional(default=[])
4949
),
5050

5151
'approvees': (
@@ -55,7 +55,6 @@ def __init__(self):
5555
| Trytes(result_type=TransactionHash)
5656
| f.Unicode(encoding='ascii', normalize=False)
5757
)
58-
| f.Optional(default=[])
5958
),
6059

6160
'bundles': (
@@ -65,7 +64,6 @@ def __init__(self):
6564
| Trytes(result_type=TransactionHash)
6665
| f.Unicode(encoding='ascii', normalize=False)
6766
)
68-
| f.Optional(default=[])
6967
),
7068

7169
'tags': (
@@ -75,7 +73,6 @@ def __init__(self):
7573
| Trytes(result_type=Tag)
7674
| f.Unicode(encoding='ascii', normalize=False)
7775
)
78-
| f.Optional(default=[])
7976
),
8077
},
8178

@@ -91,16 +88,21 @@ def _apply(self, value):
9188
if self._has_errors:
9289
return value
9390

91+
# Remove null search terms.
92+
# Note: We will assume that empty lists are intentional.
93+
# https://github.com/iotaledger/iota.lib.py/issues/96
94+
search_terms = {
95+
term: query
96+
for term, query in iteritems(value)
97+
if query is not None
98+
}
99+
94100
# At least one search term is required.
95-
if not any((
96-
value['addresses'],
97-
value['approvees'],
98-
value['bundles'],
99-
value['tags'],
100-
)):
101+
if not search_terms:
102+
# Include unfiltered ``value`` in filter error context.
101103
return self._invalid_value(value, self.CODE_NO_SEARCH_VALUES)
102104

103-
return value
105+
return search_terms
104106

105107

106108
class FindTransactionsResponseFilter(ResponseFilter):

test/commands/core/find_transactions_test.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ def test_pass_bundles_only(self):
139139
text_type(TransactionHash(self.trytes2)),
140140
],
141141

142-
'addresses': [],
143-
'approvees': [],
144-
'tags': [],
142+
# Null criteria are not included in the request.
143+
# https://github.com/iotaledger/iota.lib.py/issues/96
144+
# 'addresses': [],
145+
# 'approvees': [],
146+
# 'tags': [],
145147
},
146148
)
147149

@@ -168,9 +170,11 @@ def test_pass_addresses_only(self):
168170
text_type(Address(self.trytes2)),
169171
],
170172

171-
'approvees': [],
172-
'bundles': [],
173-
'tags': [],
173+
# Null criteria are not included in the request.
174+
# https://github.com/iotaledger/iota.lib.py/issues/96
175+
# 'approvees': [],
176+
# 'bundles': [],
177+
# 'tags': [],
174178
},
175179
)
176180

@@ -197,9 +201,11 @@ def test_pass_tags_only(self):
197201
text_type(Tag(self.trytes3)),
198202
],
199203

200-
'addresses': [],
201-
'approvees': [],
202-
'bundles': [],
204+
# Null criteria are not included in the request.
205+
# https://github.com/iotaledger/iota.lib.py/issues/96
206+
# 'addresses': [],
207+
# 'approvees': [],
208+
# 'bundles': [],
203209
},
204210
)
205211

@@ -226,9 +232,11 @@ def test_pass_approvees_only(self):
226232
text_type(TransactionHash(self.trytes3)),
227233
],
228234

229-
'addresses': [],
230-
'bundles': [],
231-
'tags': [],
235+
# Null criteria are not included in the request.
236+
# https://github.com/iotaledger/iota.lib.py/issues/96
237+
# 'addresses': [],
238+
# 'bundles': [],
239+
# 'tags': [],
232240
},
233241
)
234242

@@ -244,23 +252,38 @@ def test_fail_empty(self):
244252
},
245253
)
246254

247-
def test_fail_all_parameters_empty(self):
255+
def test_fail_all_parameters_null(self):
248256
"""
249-
The request contains all parameters, but every one is empty.
257+
The request contains all parameters, but every one is null.
250258
"""
251259
self.assertFilterErrors(
252260
{
253-
'addresses': [],
254-
'approvees': [],
255-
'bundles': [],
256-
'tags': [],
261+
'addresses': None,
262+
'approvees': None,
263+
'bundles': None,
264+
'tags': None,
257265
},
258266

259267
{
260268
'': [FindTransactionsRequestFilter.CODE_NO_SEARCH_VALUES],
261269
},
262270
)
263271

272+
def test_success_all_parameters_empty(self):
273+
"""
274+
All of the parameters are empty lists.
275+
276+
This is technically valid, though probably not very useful.
277+
"""
278+
self.assertFilterPasses(
279+
{
280+
'addresses': [],
281+
'approvees': [],
282+
'bundles': [],
283+
'tags': [],
284+
},
285+
)
286+
264287
def test_fail_unexpected_parameters(self):
265288
"""
266289
The request contains unexpected parameters.

test/commands/extended/get_new_addresses_test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,11 @@ def test_get_addresses_online(self):
438438
{
439439
'command': 'findTransactions',
440440
'addresses': [self.addy_1],
441-
'approvees': [],
442-
'bundles': [],
443-
'tags': [],
444441
},
445442

446443
{
447444
'command': 'findTransactions',
448445
'addresses': [self.addy_2],
449-
'approvees': [],
450-
'bundles': [],
451-
'tags': [],
452446
},
453447
],
454448
)

0 commit comments

Comments
 (0)