Skip to content

Commit

Permalink
Add check for test case get swap info, refactor readme
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiia-bilova committed May 3, 2019
1 parent a92a23d commit cef8365
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* [Requirements](#getting-started-requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Nodes](#nodes)
* [Configuration file](#configuration-file)
* [Service](#service)
* [Account](#account)
Expand Down Expand Up @@ -161,10 +160,10 @@ $ remme atomic-swap get-public-key --node-url=node-6-testnet.remme.io

Get information about atomic swap by its identifier — ``remme atomic-swap get-info``:

| Arguments | Type | Required | Description |
| :-------: | :----: | :------: | ---------------------------------------------------- |
| id | String | Yes | Swap identifier to get an information about swap by. |
| node-url | String | No | Node URL to apply a command to. |
| Arguments | Type | Required | Description |
| :-------: | :----: | :------: | ------------------------------------------------- |
| id | String | Yes | Swap identifier to get information about swap by. |
| node-url | String | No | Node URL to apply a command to. |

```bash
$ remme atomic-swap get-info \
Expand Down
2 changes: 1 addition & 1 deletion cli/atomic_swap/help.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Provide help messages for command line interface's atomic swap commands.
"""
SWAP_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Swap identifier to get an information about swap by.'
SWAP_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Swap identifier to get information about swap by.'
2 changes: 1 addition & 1 deletion cli/generic/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ def _deserialize(self, value, attr, data, **kwargs):
if re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_identifier) is None:
raise ValidationError(f'The following swap identifier `{swap_identifier}` is invalid.')

return value
return swap_identifier
23 changes: 13 additions & 10 deletions tests/atomic_swap/test_get_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,39 @@
from cli.entrypoint import cli
from cli.utils import dict_to_pretty_json

SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE = '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808'


def test_get_swap_info():
"""
Case: get information about atomic swap by its identifier.
Expect: information about swap is returned.
Expect: information about the swap is returned.
"""
runner = CliRunner()
result = runner.invoke(cli, [
'atomic-swap',
'get-info',
'--id',
'033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808',
SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE,
'--node-url',
NODE_27_IN_TESTNET_ADDRESS,
])

swap_info = json.loads(result.output).get('result').get('information')
swap_identifier = swap_info.get('swap_id')

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
assert SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE == swap_identifier
assert re.match(pattern=ADDRESS_REGEXP, string=swap_info.get('sender_address')) is not None
assert re.match(pattern=ADDRESS_REGEXP, string=swap_info.get('receiver_address')) is not None
assert re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_info.get('swap_id')) is not None
assert isinstance(int(float(swap_info.get('amount'))), int)
assert re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_identifier) is not None
assert isinstance(swap_info.get('is_initiator'), bool)


def test_get_swap_info_without_node_url(mocker, swap_info):
"""
Case: get information about atomic swap by its without passing node URL.
Expect: information about swap is returned from node on localhost.
Case: get information about atomic swap by its identifier without passing node URL.
Expect: information about the swap is returned from node on localhost.
"""
mock_swap_get_info = mocker.patch('cli.atomic_swap.service.loop.run_until_complete')
mock_swap_get_info.return_value = swap_info
Expand All @@ -56,7 +59,7 @@ def test_get_swap_info_without_node_url(mocker, swap_info):
'atomic-swap',
'get-info',
'--id',
'033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808',
SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE,
])

expected_result = {
Expand Down Expand Up @@ -135,7 +138,7 @@ def test_get_swap_info_non_existing_node_url():
'atomic-swap',
'get-info',
'--id',
'033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808',
SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE,
'--node-url',
non_existing_node_url,
])
Expand All @@ -160,7 +163,7 @@ def test_get_swap_info_invalid_node_url():
'atomic-swap',
'get-info',
'--id',
'033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808',
SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE,
'--node-url',
invalid_node_url,
])
Expand Down Expand Up @@ -188,7 +191,7 @@ def test_get_swap_info_node_url_with_protocol(node_url_with_protocol):
'atomic-swap',
'get-info',
'--id',
'033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808',
SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE,
'--node-url',
node_url_with_protocol,
])
Expand Down

0 comments on commit cef8365

Please sign in to comment.