Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REM-1312: Get particular Atomic Swap information by its identifier #24

Merged
merged 9 commits into from
May 6, 2019

Conversation

anastasiia-bilova
Copy link
Contributor

@anastasiia-bilova anastasiia-bilova commented Apr 22, 2019

Jira references

Description

Get information about Atomic Swap command line interface's command implementation.

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.

Example of the usage:

$ remme atomic-swap get-info \
      --id=033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808 \
      --node-url=node-genesis-testnet.remme.io
{
    "result": {
        "information": {
            "amount": "10.0000",
            "created_at": 1556803765,
            "email_address_encrypted_optional": "",
            "is_initiator": false,
            "receiver_address": "112007484def48e1c6b77cf784aeabcac51222e48ae14f3821697f4040247ba01558b1",
            "secret_key": "",
            "secret_lock": "0728356568862f9da0825aa45ae9d3642d64a6a732ad70b8857b2823dbf2a0b8",
            "sender_address": "1120076ecf036e857f42129b58303bcf1e03723764a1702cbe98529802aad8514ee3cf",
            "sender_address_non_local": "0xe6ca0e7c974f06471759e9a05d18b538c5ced11e",
            "state": "OPENED",
            "swap_id": "033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808"
        }
    }
}

Implemented

— Command line interface's command.
— Service to get particular Atomic Swap information of the atomic swap class.

References

@anastasiia-bilova anastasiia-bilova force-pushed the get-atomic-swap-info-by-its-id branch 2 times, most recently from 4402a5c to e2c2a90 Compare April 22, 2019 16:18
@codecov-io
Copy link

codecov-io commented Apr 22, 2019

Codecov Report

Merging #24 into develop will decrease coverage by <.01%.
The diff coverage is 97.5%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #24      +/-   ##
===========================================
- Coverage    97.43%   97.43%   -0.01%     
===========================================
  Files           29       30       +1     
  Lines          507      545      +38     
===========================================
+ Hits           494      531      +37     
- Misses          13       14       +1
Impacted Files Coverage Δ
cli/atomic_swap/service.py 100% <100%> (ø) ⬆️
cli/atomic_swap/help.py 100% <100%> (ø)
cli/constants.py 100% <100%> (ø) ⬆️
cli/atomic_swap/cli.py 100% <100%> (ø) ⬆️
cli/atomic_swap/forms.py 100% <100%> (ø) ⬆️
cli/generic/forms/fields.py 100% <100%> (ø) ⬆️
cli/atomic_swap/interfaces.py 60% <50%> (-6.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 666eb09...881434c. Read the comment docs.

README.md Outdated
@@ -158,6 +159,36 @@ $ remme atomic-swap get-public-key --node-url=node-6-testnet.remme.io
}
```

Get information about atomic swap by swap identifier — ``remme atomic-swap get-info``:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by swap identifier > by its identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -18,6 +23,8 @@
print_result,
)

loop = asyncio.get_event_loop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need a loop in the CLI layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -102,3 +103,23 @@ def _deserialize(self, value, attr, data, **kwargs):
raise ValidationError(f'The following public key address `{public_key_address}` is invalid.')

return value


class SwapIdField(fields.Field):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SwapIdField > SwapIdentifierField.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class GetAtomicSwapInformationForm(Schema):
"""
Get information about atomic swap of the atomic swap form.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get information about atomic swap by its identifier form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:
swap_info = loop.run_until_complete(self.service.swap.get_info(swap_id=swap_id))

except RpcGenericServerDefinedError as error:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add except RpcGenericServerDefinedError to method get_public_key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ticket is not related to get_public_key. It should be fixed in another ticket.

"""
Validate data (swap identifier) that was passed to field.
"""
swap_identifier = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more detail, variable value says nothing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You create a class that named SwapIdentifierField that have docs that say

Implements validation of the swap identifier.

and you have a method _deserialize that also have docs:

Validate data (swap identifier) that was passed to field.

Marshmallow

Example of creating a field

Also, you validate one variable and return another, it not logical.

Copy link
Contributor

@dmytrostriletskyi dmytrostriletskyi May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alladin9393,

  1. Documentation could lag behind code during the project life.
  2. Sometimes programmers read the code but not the docs.

These points are the core arguments why we should create the separated explicit (!) variable and return it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmytrostriletskyi, ok, but we don't return swap_identifier, we validate one argument, but return other value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alladin9393, refresh page.

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

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
assert re.match(pattern=ADDRESS_REGEXP, string=swap_info.get('sender_address')) is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you check just pattern? Check, please equality swap_id or if swap_id in data. Add/Replace more one checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alladin9393, done.

@@ -7,6 +7,7 @@
PUBLIC_KEY_REGEXP = r'^[0-9a-f]{66}$'
PUBLIC_KEY_ADDRESS_REGEXP = r'^[0-9a-f]{70}$'
HEADER_SIGNATURE_REGEXP = r'^[0-9a-f]{128}$'
SWAP_IDENTIFIER_REGEXP = r'^[a-f0-9]{64}$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change according to alphabetical order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constants not in alphabetical order. It should be fixed in another ticket for technical dept.

@@ -1,3 +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.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get information about swap by..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alladin9393, done.

def test_get_swap_info():
"""
Case: get information about atomic swap by its identifier.
Expect: information about swap is returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the swap is returned..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alladin9393, done.

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_identifier) is not None
assert isinstance(int(float(swap_info.get('amount'))), int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this test here for? We will always have an int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alladin9393, done.

def test_get_swap_info_invalid_swap_id():
"""
Case: get information about atomic swap by its invalid identifier.
Expect: the following swap identifier is invalid error message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap identifier is an invalid error message..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Remmeauth Remmeauth deleted a comment from Alladin9393 May 3, 2019
@Remmeauth Remmeauth deleted a comment from Alladin9393 May 3, 2019

def test_get_swap_info_non_existing_swap_id():
"""
Case: get information about atomic swap by passing non-existing identifier.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Case: get information about atomic swap by passing non-existing identifier.
Case: get information about atomic swap by passing a non-existing identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anastasiia-bilova anastasiia-bilova merged commit f7852ff into develop May 6, 2019
@delete-merged-branch delete-merged-branch bot deleted the get-atomic-swap-info-by-its-id branch May 6, 2019 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants