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

Commit

Permalink
Merge pull request #131 from iotaledger/feature/130-fix_getTips_resul…
Browse files Browse the repository at this point in the history
…t_type

Fix result type for `get_tips()`
  • Loading branch information
todofixthis committed Jan 6, 2018
2 parents 3a09bb9 + bc17a0a commit f31c6f7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
8 changes: 6 additions & 2 deletions iota/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

__all__ = [
'BaseCommand',
'CustomCommand',
'command_registry',
'discover_commands',
'CustomCommand',
'FilterCommand',
'RequestFilter',
'ResponseFilter',
]

command_registry = {} # type: Dict[Text, CommandMeta]
Expand Down Expand Up @@ -91,7 +95,7 @@ class BaseCommand(with_metaclass(CommandMeta)):
command = None # Text

def __init__(self, adapter):
# type: (BaseAdapter, bool) -> None
# type: (BaseAdapter) -> None
"""
:param adapter:
Adapter that will send request payloads to the node.
Expand Down
4 changes: 2 additions & 2 deletions iota/commands/core/get_tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import filters as f

from iota import Address
from iota.commands import FilterCommand, RequestFilter, ResponseFilter
from iota.filters import Trytes
from iota.transaction.types import TransactionHash

__all__ = [
'GetTipsCommand',
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self):
f.Array
| f.FilterRepeater(
f.ByteString(encoding='ascii')
| Trytes(result_type=Address)
| Trytes(result_type=TransactionHash)
)
),
})
27 changes: 27 additions & 0 deletions test/commands/core/get_tips_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import filters as f
from filters.test import BaseFilterTestCase

from iota import Address, Iota
from iota.adapter import MockAdapter
from iota.commands.core.get_tips import GetTipsCommand
from iota.transaction.types import TransactionHash


class GetTipsRequestFilterTestCase(BaseFilterTestCase):
Expand Down Expand Up @@ -123,3 +125,28 @@ def test_wireup(self):
Iota(self.adapter).getTips,
GetTipsCommand,
)

def test_type_coercion(self):
"""
The result is coerced to the proper type.
https://github.com/iotaledger/iota.lib.py/issues/130
"""
# noinspection SpellCheckingInspection
self.adapter.seed_response('getTips', {
'duration': 42,
'hashes': [
'TESTVALUE9DONTUSEINPRODUCTION99999ANSVWB'
'CZ9ABZYUK9YYXFRLROGMCMQHRARDQPNMHHZSZ9999',

'TESTVALUE9DONTUSEINPRODUCTION99999HCZURL'
'NFWEDRFCYHWTYGUEMJLJ9ZIJTFASAVSEAZJGA9999',
],
})

gt_response = Iota(self.adapter).get_tips()

self.assertEqual(
list(map(type, gt_response['hashes'])),
[TransactionHash] * 2,
)

0 comments on commit f31c6f7

Please sign in to comment.