From c7c29c1353f1d2af3bb8725b5661290eaabdc253 Mon Sep 17 00:00:00 2001 From: Anastasiia Bilova Date: Mon, 20 May 2019 13:45:39 +0300 Subject: [PATCH] Solve weekly technical debt (#56) --- README.md | 150 +++++++++--------- cli/account/forms.py | 4 +- cli/atomic_swap/cli.py | 2 +- cli/atomic_swap/forms.py | 6 +- cli/atomic_swap/interfaces.py | 2 +- cli/atomic_swap/service.py | 2 +- cli/batch/cli.py | 41 ++--- cli/batch/forms.py | 9 +- cli/batch/help.py | 14 +- cli/block/cli.py | 1 + cli/block/forms.py | 3 +- cli/block/interfaces.py | 14 ++ cli/clis/__init__.py | 0 cli/constants.py | 18 +-- cli/generic/forms/fields.py | 85 +++------- cli/node/cli.py | 2 +- cli/node/forms.py | 12 +- cli/node/interfaces.py | 2 +- cli/node/service.py | 14 +- cli/node_account/forms.py | 2 +- cli/public_key/forms.py | 4 +- cli/receipt/forms.py | 2 +- cli/services/__init__.py | 0 cli/state/cli.py | 7 +- cli/state/forms.py | 9 +- cli/state/interfaces.py | 1 + cli/transaction/cli.py | 34 ++-- cli/transaction/forms.py | 10 +- cli/transaction/help.py | 14 +- cli/transaction/interfaces.py | 8 +- cli/transaction/service.py | 14 +- pytest.ini | 4 + tests/__init.py | 0 tests/account/test_get_balance.py | 12 +- tests/account/test_transfer_tokens.py | 44 ++--- tests/atomic_swap/test_get_info.py | 16 +- tests/atomic_swap/test_get_public_key.py | 20 +-- tests/batch/test_get_batch.py | 28 ++-- tests/batch/test_get_batch_status.py | 31 ++-- ...et_list_batches.py => test_get_batches.py} | 93 ++++++----- tests/block/test_get_block.py | 16 +- tests/block/test_get_blocks.py | 25 ++- tests/config/test_config_file.py | 10 +- tests/config/test_node_private_key_file.py | 4 +- tests/constants.py | 3 - tests/generic/forms/test_fields.py | 0 tests/node/test_get_configs.py | 16 +- tests/node/test_get_information.py | 8 +- tests/node/test_get_initial_stake.py | 2 +- tests/node/test_get_peers.py | 14 +- tests/node_account/test_get_.py | 2 +- .../test_get_public_key_addresses.py | 14 +- tests/public_key/test_get_public_key_info.py | 20 +-- tests/state/test_get_state.py | 14 +- tests/state/test_get_states.py | 69 +++++++- tests/test_entrypoint.py | 2 +- tests/transaction/test_get_transaction.py | 35 ++-- ...ansactions.py => test_get_transactions.py} | 66 ++++---- 58 files changed, 524 insertions(+), 530 deletions(-) delete mode 100644 cli/clis/__init__.py delete mode 100644 cli/services/__init__.py create mode 100644 pytest.ini delete mode 100644 tests/__init.py rename tests/batch/{test_get_list_batches.py => test_get_batches.py} (83%) delete mode 100644 tests/constants.py delete mode 100644 tests/generic/forms/test_fields.py rename tests/transaction/{test_get_list_transactions.py => test_get_transactions.py} (86%) diff --git a/README.md b/README.md index d5f46ac..9a29674 100644 --- a/README.md +++ b/README.md @@ -160,10 +160,10 @@ Options: Get balance of the account by its address — ``remme account get-balance``: -| Arguments | Type | Required | Description | -| :-------: | :----: | :-------: | ------------------------------------ | -| address | String | Yes | Account address to get a balance by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------------ | +| address | String | Yes | Account address to get a balance by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme account get-balance \ @@ -178,12 +178,12 @@ $ remme account get-balance \ Transfer tokens to address — ``remme account transfer-tokens``: -| Arguments | Type | Required | Description | -| :---------: | :-----: | :-------: | ---------------------------------------------- | -| private-key | String | Yes | Account's private key to transfer tokens from. | -| address-to | String | Yes | Account address to transfer tokens to. | -| amount | Integer | Yes | Amount to transfer. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :---------: | :-----: | :------: | ---------------------------------------------- | +| private-key | String | Yes | Account's private key to transfer tokens from. | +| address-to | String | Yes | Account address to transfer tokens to. | +| amount | Integer | Yes | Amount to transfer. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme account transfer-tokens \ @@ -202,10 +202,10 @@ $ remme account transfer-tokens \ Get information about the node account by its address — ``remme node-account get``: -| Arguments | Type | Required | Description | -| :---------: | :----: | :------: | -------------------------------------------------------------- | -| address | String | Yes | Node account address to get information about node account by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | -------------------------------------------------------------- | +| address | String | Yes | Node account address to get information about node account by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme node-account get \ @@ -238,14 +238,14 @@ $ remme node-account get \ Get a list of blocks — ``remme block get-list``: -| Arguments | Type | Required | Description | -| :---------: | :-----: | :-------: | -------------------------------------------------- | -| ids | String | No | Identifiers to get a list of blocks by. | -| limit | Integer | No | Maximum amount of blocks to return. | -| head | Integer | No | Block identifier to get a list of transactions to. | -| ids-only | Bool | No | The flag to get a list of blocks' identifiers. | -| reverse | Bool | No | Parameter to reverse result. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :-----: | :------: | -------------------------------------------------- | +| ids | String | No | Identifiers to get a list of blocks by. | +| limit | Integer | No | Maximum amount of blocks to return. | +| head | Integer | No | Block identifier to get a list of transactions to. | +| ids-only | Bool | No | The flag to get a list of blocks' identifiers. | +| reverse | Bool | No | Parameter to reverse result. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme block get-list \ @@ -327,10 +327,10 @@ $ remme block get-list --ids-only --node-url=node-6-testnet.remme.io Get information about the block by its identifier — ``remme block get``: -| Arguments | Type | Required | Description | -| :-------: | :----: | :-------: | ------------------------------------------------------ | -| id | String | Yes | Identifier of the block to fetch information about by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------------------------------ | +| id | String | Yes | Identifier of the block to fetch information about by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme block get \ @@ -473,10 +473,10 @@ $ remme atomic-swap get-info \ Get a batch by identifier — ``remme batch get``: -| Arguments | Type | Required | Description | -| :-------: | :----: | :-------: | -------------------------------- | -| id | String | Yes | Identifier to get a batch by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------- | +| id | String | Yes | Identifier to get a batch by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme batch get \ @@ -521,10 +521,10 @@ $ remme batch get \ Get a batch status by its identifier — ``remme batch get-status``: -| Arguments | Type | Required | Description | -| :---------: | :----: | :-------: | ------------------------------------ | -| id | String | Yes | Identifier to get a batch status by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------------ | +| id | String | Yes | Identifier to get a batch status by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme batch get-status \ @@ -537,15 +537,15 @@ $ remme batch get-status \ Get a list of batches — ``remme batch get-list``: -| Arguments | Type | Required | Description | -| :--------: | :----: | :-------: | ----------------------------------------------------- | -| ids | String | No | Identifiers to get a list of batches by. | -| start | String | No | Batch identifier to get a list of batches starting from.| -| limit | Integer| No | Maximum amount of batches to return. | -| head | String | No | Block identifier to get a list of batches from. | -| reverse | Bool | No | Parameter to reverse result. | -| ids-only | Bool | No | The flag to get a list of batches' identifiers. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :-----: | :------: | -------------------------------------------------------- | +| ids | String | No | Identifiers to get a list of batches by. | +| start | String | No | Batch identifier to get a list of batches starting from. | +| limit | Integer | No | Maximum amount of batches to return. | +| head | String | No | Block identifier to get a list of batches from. | +| reverse | Bool | No | Parameter to reverse result. | +| ids-only | Bool | No | The flag to get a list of batches' identifiers. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme batch get-list \ @@ -600,8 +600,8 @@ Get a list of batches' identifiers (can be combined with other parameters like ` $ remme batch get-list --ids-only --node-url=node-6-testnet.remme.io { "result": [ - "e4d5089f2ef1...6b0f185b3b6ca", - "df5e555f...317f039501", + "6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e", + "7a5daba99d5757adc997ea6a0b1b83263b3c16604dbd83c0153dc01c9fd780af4b570338c2ec60e086b1db58a4397a4dc661d6c93b0a7250fe75642e15b26e81", ... ] } @@ -609,11 +609,11 @@ $ remme batch get-list --ids-only --node-url=node-6-testnet.remme.io ### Node -Get node configurations — ``remme node get-configs``: +Get the node configurations — ``remme node get-configs``: -| Arguments | Type | Required | Description | -| :-------: | :----: | :-------: | ------------------------------- | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------- | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme node get-configs --node-url=node-genesis-testnet.remme.io @@ -629,9 +629,9 @@ $ remme node get-configs --node-url=node-genesis-testnet.remme.io Get the node's peers — ``remme node get-peers``: -| Arguments | Type | Required | Description | -| :-------: | :----: | :-------: | ------------------------------- | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------- | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme node get-peers --node-url=node-genesis-testnet.remme.io @@ -754,13 +754,13 @@ $ remme state get \ Get a list of states — ``remme state get-list``: -| Arguments | Type | Required | Description | -| :---------: | :----: | :-------: | ----------------------------------------------------- | -| address | String | No | Account address to get a list of states by. | -| limit | Integer| No | Maximum amount of transactions to return. | -| head | String | No | Block identifier to get a list of states to. | -| reverse | Bool | No | Parameter to reverse result. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :-----: | :------: | -------------------------------------------- | +| address | String | No | Account address to get a list of states by. | +| limit | Integer | No | Maximum amount of transactions to return. | +| head | String | No | Block identifier to get a list of states to. | +| reverse | Bool | No | Parameter to reverse result. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme state get-list \ @@ -783,16 +783,16 @@ $ remme state get-list \ Get a list of transactions — ``remme transaction get-list``: -| Arguments | Type | Required | Description | -| :---------: | :----: | :-------: | ----------------------------------------------------- | -| ids | String | No | Identifiers to get a list of transactions by. | -| start | String | No | Transaction identifier to get a list transaction starting from.| -| limit | Integer| No | Maximum amount of transactions to return. | -| head | String | No | Block identifier to get a list of transactions from. | -| reverse | Bool | No | Parameter to reverse result. | -| ids-only | Bool | No | The flag to get a list of transactions' identifiers. | -| node-url | String | No | Node URL to apply a command to. | -| family-name | String | No | List of transactions by its family name. | +| Arguments | Type | Required | Description | +| :---------: | :-----: | :------: | -------------------------------------------------------------- | +| ids | String | No | Identifiers to get a list of transactions by. | +| start | String | No | Transaction identifier to get a list transaction starting from. | +| limit | Integer | No | Maximum amount of transactions to return. | +| head | String | No | Block identifier to get a list of transactions from. | +| reverse | Bool | No | Parameter to reverse result. | +| ids-only | Bool | No | The flag to get a list of transactions' identifiers. | +| family-name | String | No | List of transactions by its family name. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme transaction get-list \ @@ -855,10 +855,10 @@ $ remme transaction get-list --ids-only --node-url=node-6-testnet.remme.io Get a transaction by identifier — ``remme transaction get``: -| Arguments | Type | Required | Description | -| :---------: | :----: | :-------: | -------------------------------- | -| id | String | Yes | Identifier to get transaction by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | --------------------------------- | +| id | String | Yes | Identifier to get transaction by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme transaction get \ @@ -972,8 +972,10 @@ $ docker exec -it remme-core-cli bash And now being in the container, you can develop the project. For instance, run tests and linters: ```bash -$ pytest -vv tests/ +$ coverage run -m pytest -vv tests +$ coverage report -m && coverage xml $ flake8 cli && flake8 tests/ +$ bash <(curl -s https://linters.io/isort-diff) cli tests ``` When you have developed new functionality, check it with the following command. This command creates the ``Python package`` diff --git a/cli/account/forms.py b/cli/account/forms.py index d0c455e..0c22848 100644 --- a/cli/account/forms.py +++ b/cli/account/forms.py @@ -20,7 +20,7 @@ class GetAccountBalanceForm(Schema): """ address = AccountAddressField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class TransferTokensForm(Schema): @@ -37,4 +37,4 @@ class TransferTokensForm(Schema): validate.Range(min=1, error='Amount must be greater than 0.'), ], ) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/atomic_swap/cli.py b/cli/atomic_swap/cli.py index 14af8d6..20b78f1 100644 --- a/cli/atomic_swap/cli.py +++ b/cli/atomic_swap/cli.py @@ -35,7 +35,7 @@ def atomic_swap_commands(): @atomic_swap_commands.command('get-public-key') def get_public_key(node_url): """ - Get public key of atomic swap. + Get the public key of atomic swap. """ arguments, errors = GetAtomicSwapPublicKeyForm().load({ 'node_url': node_url, diff --git a/cli/atomic_swap/forms.py b/cli/atomic_swap/forms.py index 7969484..1bb7035 100644 --- a/cli/atomic_swap/forms.py +++ b/cli/atomic_swap/forms.py @@ -15,12 +15,12 @@ class GetAtomicSwapInformationForm(Schema): """ id = SwapIdentifierField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetAtomicSwapPublicKeyForm(Schema): """ - Get public key of the atomic swap form. + Get the public key of the atomic swap form. """ - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/atomic_swap/interfaces.py b/cli/atomic_swap/interfaces.py index 8e88e87..cc4e29c 100644 --- a/cli/atomic_swap/interfaces.py +++ b/cli/atomic_swap/interfaces.py @@ -10,7 +10,7 @@ class AtomicSwapInterface: def get_public_key(self): """ - Get public key of atomic swap. + Get the public key of atomic swap. """ pass diff --git a/cli/atomic_swap/service.py b/cli/atomic_swap/service.py index a48d503..90590d5 100644 --- a/cli/atomic_swap/service.py +++ b/cli/atomic_swap/service.py @@ -28,7 +28,7 @@ def __init__(self, service): def get_public_key(self): """ - Get public key of atomic swap. + Get the public key of atomic swap. """ try: public_key = loop.run_until_complete(self.service.swap.get_public_key()) diff --git a/cli/batch/cli.py b/cli/batch/cli.py index 5f99ac6..f4a64c3 100644 --- a/cli/batch/cli.py +++ b/cli/batch/cli.py @@ -12,14 +12,14 @@ GetBatchStatusForm, ) from cli.batch.help import ( - BATCH_HEAD_ARGUMENT_HELP_MESSAGE, - BATCH_ID_ARGUMENT_HELP_MESSAGE, - BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE, - BATCH_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE, - BATCH_LIMIT_ARGUMENT_HELP_MESSAGE, - BATCH_REVERSE_ARGUMENT_HELP_MESSAGE, - BATCH_START_ARGUMENT_HELP_MESSAGE, + BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE, BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE, + BATCHES_HEAD_ARGUMENT_HELP_MESSAGE, + BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE, + BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE, + BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE, + BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE, + BATCHES_START_ARGUMENT_HELP_MESSAGE, ) from cli.batch.service import Batch from cli.constants import ( @@ -41,7 +41,7 @@ def batch_commands(): pass -@click.option('--id', required=True, type=str, help=BATCH_ID_ARGUMENT_HELP_MESSAGE) +@click.option('--id', required=True, type=str, help=BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE) @click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) @batch_commands.command('get') def get_batch(id, node_url): @@ -105,12 +105,12 @@ def get_batch_status(id, node_url): print_result(result=result) -@click.option('--ids', required=False, type=str, help=BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE) -@click.option('--start', required=False, type=str, help=BATCH_START_ARGUMENT_HELP_MESSAGE) -@click.option('--limit', required=False, type=int, help=BATCH_LIMIT_ARGUMENT_HELP_MESSAGE) -@click.option('--head', required=False, type=str, help=BATCH_HEAD_ARGUMENT_HELP_MESSAGE) -@click.option('--reverse', required=False, is_flag=True, help=BATCH_REVERSE_ARGUMENT_HELP_MESSAGE) -@click.option('--ids-only', required=False, is_flag=True, help=BATCH_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE) +@click.option('--ids', required=False, type=str, help=BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE) +@click.option('--start', required=False, type=str, help=BATCHES_START_ARGUMENT_HELP_MESSAGE) +@click.option('--limit', required=False, type=int, help=BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE) +@click.option('--head', required=False, type=str, help=BATCHES_HEAD_ARGUMENT_HELP_MESSAGE) +@click.option('--reverse', required=False, is_flag=True, help=BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE) +@click.option('--ids-only', required=False, is_flag=True, help=BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE) @click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) @batch_commands.command('get-list') def get_batches(ids, start, limit, head, reverse, ids_only, node_url): @@ -135,6 +135,7 @@ def get_batches(ids, start, limit, head, reverse, ids_only, node_url): start = arguments.get('start') limit = arguments.get('limit') head = arguments.get('head') + reverse = arguments.get('reverse') ids_only = arguments.get('ids_only') node_url = arguments.get('node_url') @@ -144,19 +145,11 @@ def get_batches(ids, start, limit, head, reverse, ids_only, node_url): if ids_only: result, errors = Batch(service=remme).get_list_ids( - ids=batch_ids, - start=start, - limit=limit, - head=head, - reverse=reverse, + ids=batch_ids, start=start, limit=limit, head=head, reverse=reverse, ) else: result, errors = Batch(service=remme).get_list( - ids=batch_ids, - start=start, - limit=limit, - head=head, - reverse=reverse, + ids=batch_ids, start=start, limit=limit, head=head, reverse=reverse, ) if errors is not None: diff --git a/cli/batch/forms.py b/cli/batch/forms.py index eead417..657a8b8 100644 --- a/cli/batch/forms.py +++ b/cli/batch/forms.py @@ -19,8 +19,8 @@ class GetBatchForm(Schema): Get a batch by its identifier form. """ - id = BatchIdentifierField(allow_none=False, required=True) - node_url = NodeUrlField(required=False) + id = BatchIdentifierField(required=True) + node_url = NodeUrlField(required=True) class GetBatchStatusForm(Schema): @@ -29,7 +29,7 @@ class GetBatchStatusForm(Schema): """ id = BatchIdentifierField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetBatchesListForm(Schema): @@ -48,5 +48,6 @@ class GetBatchesListForm(Schema): validate.Range(min=1, error='Limit must be greater than 0.'), ], ) + reverse = fields.Boolean(required=False) ids_only = fields.Boolean(required=False) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/batch/help.py b/cli/batch/help.py index bcb7433..eba8928 100644 --- a/cli/batch/help.py +++ b/cli/batch/help.py @@ -1,11 +1,11 @@ """ Provide help messages for command line interface's batch commands. """ -BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.' -BATCH_START_ARGUMENT_HELP_MESSAGE = 'Batch identifier to get a list of batches starting from.' -BATCH_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of batches to return.' -BATCH_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of batches from.' -BATCH_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.' +BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch by.' BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch status by.' -BATCH_ID_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch by.' -BATCH_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of batches\' identifiers.' +BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.' +BATCHES_START_ARGUMENT_HELP_MESSAGE = 'Batch identifier to get a list of batches starting from.' +BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of batches to return.' +BATCHES_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of batches to.' +BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.' +BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of batches\' identifiers.' diff --git a/cli/block/cli.py b/cli/block/cli.py index 454b324..6fe70a5 100644 --- a/cli/block/cli.py +++ b/cli/block/cli.py @@ -65,6 +65,7 @@ def get_blocks(ids, head, limit, reverse, ids_only, node_url): block_ids = arguments.get('ids') limit = arguments.get('limit') head = arguments.get('head') + reverse = arguments.get('reverse') ids_only = arguments.get('ids_only') node_url = arguments.get('node_url') diff --git a/cli/block/forms.py b/cli/block/forms.py index fea78ca..a0e0eec 100644 --- a/cli/block/forms.py +++ b/cli/block/forms.py @@ -29,8 +29,9 @@ class GetBlocksListForm(Schema): ], ) head = BlockIdentifierField(allow_none=True, required=False) + reverse = fields.Boolean(required=False) ids_only = fields.Boolean(required=False) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetBlockByIdentifierForm(Schema): diff --git a/cli/block/interfaces.py b/cli/block/interfaces.py index e59128a..96e00e4 100644 --- a/cli/block/interfaces.py +++ b/cli/block/interfaces.py @@ -27,3 +27,17 @@ def get_list(self, ids, head, limit, reverse): reverse (bool, optional): parameter to reverse result. """ pass + + def get_list_ids(self, ids, head, limit, reverse): + """ + Get a list of blocks identifiers. + + A list of blocks identifiers could be filtered by blocks identifiers, limit, head, reverse. + + Arguments: + ids (list, optional): identifiers to get a list of blocks by. + limit (int, optional): maximum amount of blocks to return. + head (string, optional): block identifier to get a list of transactions to. + reverse (bool, optional): parameter to reverse result. + """ + pass diff --git a/cli/clis/__init__.py b/cli/clis/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/cli/constants.py b/cli/constants.py index 368b095..775ed68 100644 --- a/cli/constants.py +++ b/cli/constants.py @@ -1,18 +1,18 @@ """ Provide constants for command line interface. """ +from remme.models.general.patterns import RemmePatterns from remme.models.utils.family_name import RemmeFamilyName -ADDRESS_REGEXP = r'^[0-9a-f]{70}$' -BLOCK_IDENTIFIER_REGEXP = r'^[0-9a-f]{128}$' -BATCH_ID_REGEXP = r'^[0-9a-f]{128}$' -PUBLIC_KEY_REGEXP = r'^[0-9a-f]{66}$' -PRIVATE_KEY_REGEXP = r'^[a-f0-9]{64}$' -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}$' -TRANSACTION_HEADER_SIGNATURE_REGEXP = r'^[0-9a-f]{128}$' +ADDRESS_REGEXP = RemmePatterns.ADDRESS.value +BATCH_IDENTIFIER_REGEXP = RemmePatterns.HEADER_SIGNATURE.value +BLOCK_IDENTIFIER_REGEXP = RemmePatterns.HEADER_SIGNATURE.value DOMAIN_NAME_REGEXP = r'(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]' +PRIVATE_KEY_REGEXP = RemmePatterns.PRIVATE_KEY.value +PUBLIC_KEY_ADDRESS_REGEXP = RemmePatterns.ADDRESS.value +PUBLIC_KEY_REGEXP = RemmePatterns.PUBLIC_KEY.value +SWAP_IDENTIFIER_REGEXP = RemmePatterns.SWAP_ID.value +TRANSACTION_IDENTIFIER_REGEXP = RemmePatterns.HEADER_SIGNATURE.value PASSED_EXIT_FROM_COMMAND_CODE = 0 FAILED_EXIT_FROM_COMMAND_CODE = -1 diff --git a/cli/generic/forms/fields.py b/cli/generic/forms/fields.py index 0a80b7e..14fed99 100644 --- a/cli/generic/forms/fields.py +++ b/cli/generic/forms/fields.py @@ -1,5 +1,8 @@ """ Provide implementation of the generic form fields. + +References: + - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ import re @@ -10,23 +13,20 @@ from cli.constants import ( ADDRESS_REGEXP, + BATCH_IDENTIFIER_REGEXP, BLOCK_IDENTIFIER_REGEXP, DOMAIN_NAME_REGEXP, FAMILY_NAMES, - HEADER_SIGNATURE_REGEXP, PRIVATE_KEY_REGEXP, PUBLIC_KEY_ADDRESS_REGEXP, SWAP_IDENTIFIER_REGEXP, - TRANSACTION_HEADER_SIGNATURE_REGEXP, + TRANSACTION_IDENTIFIER_REGEXP, ) class AccountAddressField(fields.Field): """ Implements validation of the account address. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): @@ -44,45 +44,23 @@ def _deserialize(self, value, attr, obj, **kwargs): class FamilyNameField(fields.Field): """ Implements validation of the family name. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): """ Validate data (family name) that was passed to field. """ - if value not in FAMILY_NAMES: - raise ValidationError(f'The following family name `{value}` is invalid.') - - return value - - -class StateIdentifierField(fields.Field): - """ - Implements validation of the state identifier. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html - """ + family_name = value - def _deserialize(self, value, attr, obj, **kwargs): - """ - Validate data (state identifier) that was passed to field. - """ - if re.match(pattern=HEADER_SIGNATURE_REGEXP, string=value) is None: - raise ValidationError(f'The following identifier `{value}` is invalid.') + if family_name not in FAMILY_NAMES: + raise ValidationError(f'The following family name `{family_name}` is invalid.') - return value + return family_name class TransactionIdentifiersListField(fields.Field): """ Implements validation of the list of the identifiers. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): @@ -94,7 +72,7 @@ def _deserialize(self, value, attr, obj, **kwargs): for identifier in value.split(','): identifier = identifier.strip() - if re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=identifier) is None: + if re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=identifier) is None: raise ValidationError(f'The following identifier `{identifier}` is invalid.') validated_identifiers.append(identifier) @@ -105,27 +83,23 @@ def _deserialize(self, value, attr, obj, **kwargs): class TransactionIdentifierField(fields.Field): """ Implements validation of the identifier. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): """ Validate data (identifier) that was passed to field. """ - if re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=value) is None: - raise ValidationError(f'The following identifier `{value}` is invalid.') + transaction_identifier = value + + if re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is None: + raise ValidationError(f'The following identifier `{transaction_identifier}` is invalid.') - return value + return transaction_identifier class BatchIdentifiersListField(fields.Field): """ Implements validation of the list of the identifiers. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): @@ -137,7 +111,7 @@ def _deserialize(self, value, attr, obj, **kwargs): for identifier in value.split(','): identifier = identifier.strip() - if re.match(pattern=HEADER_SIGNATURE_REGEXP, string=identifier) is None: + if re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=identifier) is None: raise ValidationError(f'The following identifier `{identifier}` is invalid.') validated_identifiers.append(identifier) @@ -148,9 +122,6 @@ def _deserialize(self, value, attr, obj, **kwargs): class BatchIdentifierField(fields.Field): """ Implements validation of the identifier. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): @@ -159,7 +130,7 @@ def _deserialize(self, value, attr, obj, **kwargs): """ batch_identifier = value - if re.match(pattern=HEADER_SIGNATURE_REGEXP, string=batch_identifier) is None: + if re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is None: raise ValidationError(f'The following identifier `{batch_identifier}` is invalid.') return batch_identifier @@ -170,9 +141,6 @@ class NodeUrlField(fields.Field): Implements validation of the node URL. If node URL is localhost, it means client didn't passed any URL, so nothing to validate. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): @@ -196,9 +164,6 @@ def _deserialize(self, value, attr, obj, **kwargs): class PrivateKeyField(fields.Field): """ Implements validation of the private key. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, data, **kwargs): @@ -210,15 +175,12 @@ def _deserialize(self, value, attr, data, **kwargs): if re.match(pattern=PRIVATE_KEY_REGEXP, string=private_key) is None: raise ValidationError(f'The following private key `{private_key}` is invalid.') - return value + return private_key class PublicKeyAddressField(fields.Field): """ Implements validation of the public key address. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, data, **kwargs): @@ -230,15 +192,12 @@ def _deserialize(self, value, attr, data, **kwargs): if re.match(pattern=PUBLIC_KEY_ADDRESS_REGEXP, string=public_key_address) is None: raise ValidationError(f'The following public key address `{public_key_address}` is invalid.') - return value + return public_key_address class SwapIdentifierField(fields.Field): """ Implements validation of the swap identifier. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, data, **kwargs): @@ -256,9 +215,6 @@ def _deserialize(self, value, attr, data, **kwargs): class BlockIdentifierField(fields.Field): """ Implements validation of the block identifier. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, data, **kwargs): @@ -276,9 +232,6 @@ def _deserialize(self, value, attr, data, **kwargs): class BlockIdentifiersListField(fields.Field): """ Implements validation of the list of block identifiers. - - References: - - https://marshmallow.readthedocs.io/en/3.0/custom_fields.html """ def _deserialize(self, value, attr, obj, **kwargs): diff --git a/cli/node/cli.py b/cli/node/cli.py index 4628e66..a8e2c4c 100644 --- a/cli/node/cli.py +++ b/cli/node/cli.py @@ -36,7 +36,7 @@ def node_commands(): @node_commands.command('get-configs') def get_config(node_url): """ - Get node configurations. + Get the node configurations. """ arguments, errors = GetNodeConfigurationsForm().load({ 'node_url': node_url, diff --git a/cli/node/forms.py b/cli/node/forms.py index 6d054b0..3e2ad03 100644 --- a/cli/node/forms.py +++ b/cli/node/forms.py @@ -8,18 +8,18 @@ class GetNodeConfigurationsForm(Schema): """ - Get node configurations. + Get the node configurations form. """ - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetNodePeersForm(Schema): """ - Get the node's peers. + Get the node's peers form. """ - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetNodeInformationForm(Schema): @@ -27,7 +27,7 @@ class GetNodeInformationForm(Schema): Get the node information form. """ - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetNodeInitialStakeForm(Schema): @@ -35,4 +35,4 @@ class GetNodeInitialStakeForm(Schema): Get the initial stake of the node form. """ - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/node/interfaces.py b/cli/node/interfaces.py index a2872bf..334b916 100644 --- a/cli/node/interfaces.py +++ b/cli/node/interfaces.py @@ -10,7 +10,7 @@ class NodeInterface: def get_configs(self): """ - Get node configurations. + Get the node configurations. """ pass diff --git a/cli/node/service.py b/cli/node/service.py index 9df63be..ee7d286 100644 --- a/cli/node/service.py +++ b/cli/node/service.py @@ -27,16 +27,16 @@ def __init__(self, service): def get_configs(self): """ - Get node configurations. + Get the node configurations. """ try: - configurations = loop.run_until_complete(self.service.node_management.get_node_config()) + node_configurations = loop.run_until_complete(self.service.node_management.get_node_config()) except Exception as error: return None, str(error) return { - 'configurations': configurations.data, + 'configurations': node_configurations.data, }, None def get_peers(self): @@ -44,13 +44,13 @@ def get_peers(self): Get the node's peers. """ try: - peers = loop.run_until_complete(self.service.blockchain_info.get_peers()) + node_peers = loop.run_until_complete(self.service.blockchain_info.get_peers()) except Exception as error: return None, str(error) return { - 'peers': peers, + 'peers': node_peers, }, None def get_info(self): @@ -72,9 +72,9 @@ def get_initial_stake(self): Get the initial stake of the node. """ try: - initial_stake = loop.run_until_complete(self.service.node_management.get_initial_stake()) + node_initial_stake = loop.run_until_complete(self.service.node_management.get_initial_stake()) except Exception as error: return None, str(error) - return initial_stake, None + return node_initial_stake, None diff --git a/cli/node_account/forms.py b/cli/node_account/forms.py index 735e8b2..4643660 100644 --- a/cli/node_account/forms.py +++ b/cli/node_account/forms.py @@ -15,4 +15,4 @@ class GetNodeAccountInformationForm(Schema): """ address = AccountAddressField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/public_key/forms.py b/cli/public_key/forms.py index 43099dc..a3a4820 100644 --- a/cli/public_key/forms.py +++ b/cli/public_key/forms.py @@ -16,7 +16,7 @@ class GetPublicKeyInformationForm(Schema): """ address = PublicKeyAddressField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetPublicKeysForm(Schema): @@ -25,4 +25,4 @@ class GetPublicKeysForm(Schema): """ address = AccountAddressField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/receipt/forms.py b/cli/receipt/forms.py index af2d048..616bfa4 100644 --- a/cli/receipt/forms.py +++ b/cli/receipt/forms.py @@ -15,4 +15,4 @@ class GetReceiptsForm(Schema): """ ids = TransactionIdentifiersListField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/services/__init__.py b/cli/services/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/cli/state/cli.py b/cli/state/cli.py index b7b5819..bc80cd9 100644 --- a/cli/state/cli.py +++ b/cli/state/cli.py @@ -82,6 +82,7 @@ def get_states(address, limit, head, reverse, node_url): 'address': address, 'limit': limit, 'head': head, + 'reverse': reverse, 'node_url': node_url, }) @@ -92,6 +93,7 @@ def get_states(address, limit, head, reverse, node_url): address = arguments.get('address') limit = arguments.get('limit') head = arguments.get('head') + reverse = arguments.get('reverse') node_url = arguments.get('node_url') remme = Remme(network_config={ @@ -99,10 +101,7 @@ def get_states(address, limit, head, reverse, node_url): }) result, errors = State(service=remme).get_list( - address=address, - limit=limit, - head=head, - reverse=reverse, + address=address, limit=limit, head=head, reverse=reverse, ) if errors is not None: diff --git a/cli/state/forms.py b/cli/state/forms.py index 667ae22..da80b29 100644 --- a/cli/state/forms.py +++ b/cli/state/forms.py @@ -9,8 +9,8 @@ from cli.generic.forms.fields import ( AccountAddressField, + BlockIdentifierField, NodeUrlField, - StateIdentifierField, ) @@ -20,7 +20,7 @@ class GetStateForm(Schema): """ address = AccountAddressField(required=True) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetStateListForm(Schema): @@ -29,7 +29,7 @@ class GetStateListForm(Schema): """ address = AccountAddressField(allow_none=True, required=False) - head = StateIdentifierField(allow_none=True, required=False) + head = BlockIdentifierField(allow_none=True, required=False) limit = fields.Integer( allow_none=True, strict=True, @@ -38,4 +38,5 @@ class GetStateListForm(Schema): validate.Range(min=1, error='Limit must be greater than 0.'), ], ) - node_url = NodeUrlField(required=False) + reverse = fields.Boolean(required=False) + node_url = NodeUrlField(required=True) diff --git a/cli/state/interfaces.py b/cli/state/interfaces.py index a60a5b5..e7fe4cf 100644 --- a/cli/state/interfaces.py +++ b/cli/state/interfaces.py @@ -26,3 +26,4 @@ def get_list(self, address, limit, head, reverse): head (string, optional): block identifier to get a list of states to. reverse (bool, optional): parameter to reverse result. """ + pass diff --git a/cli/transaction/cli.py b/cli/transaction/cli.py index e0b598c..8346717 100644 --- a/cli/transaction/cli.py +++ b/cli/transaction/cli.py @@ -15,14 +15,14 @@ GetTransactionsListForm, ) from cli.transaction.help import ( - TRANSACTION_FAMILY_NAME_ARGUMENT_HELP_MESSAGE, - TRANSACTION_HEAD_ARGUMENT_HELP_MESSAGE, TRANSACTION_ID_ARGUMENT_HELP_MESSAGE, - TRANSACTION_IDS_ARGUMENT_HELP_MESSAGE, - TRANSACTION_LIMIT_ARGUMENT_HELP_MESSAGE, - TRANSACTION_REVERSE_ARGUMENT_HELP_MESSAGE, - TRANSACTION_START_ARGUMENT_HELP_MESSAGE, + TRANSACTIONS_FAMILY_NAME_ARGUMENT_HELP_MESSAGE, + TRANSACTIONS_HEAD_ARGUMENT_HELP_MESSAGE, TRANSACTIONS_IDENTIFIERS_ARGUMENT_HELP_MESSAGE, + TRANSACTIONS_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE, + TRANSACTIONS_LIMIT_ARGUMENT_HELP_MESSAGE, + TRANSACTIONS_REVERSE_ARGUMENT_HELP_MESSAGE, + TRANSACTIONS_START_ARGUMENT_HELP_MESSAGE, ) from cli.transaction.service import Transaction from cli.utils import ( @@ -40,13 +40,13 @@ def transaction_command(): pass -@click.option('--ids', required=False, type=str, help=TRANSACTION_IDS_ARGUMENT_HELP_MESSAGE) -@click.option('--start', required=False, type=str, help=TRANSACTION_START_ARGUMENT_HELP_MESSAGE) -@click.option('--limit', required=False, type=int, help=TRANSACTION_LIMIT_ARGUMENT_HELP_MESSAGE) -@click.option('--head', required=False, type=str, help=TRANSACTION_HEAD_ARGUMENT_HELP_MESSAGE) -@click.option('--reverse', required=False, is_flag=True, help=TRANSACTION_REVERSE_ARGUMENT_HELP_MESSAGE) -@click.option('--family-name', required=False, type=str, help=TRANSACTION_FAMILY_NAME_ARGUMENT_HELP_MESSAGE) -@click.option('--ids-only', required=False, is_flag=True, help=TRANSACTIONS_IDENTIFIERS_ARGUMENT_HELP_MESSAGE) +@click.option('--ids', required=False, type=str, help=TRANSACTIONS_IDENTIFIERS_ARGUMENT_HELP_MESSAGE) +@click.option('--start', required=False, type=str, help=TRANSACTIONS_START_ARGUMENT_HELP_MESSAGE) +@click.option('--limit', required=False, type=int, help=TRANSACTIONS_LIMIT_ARGUMENT_HELP_MESSAGE) +@click.option('--head', required=False, type=str, help=TRANSACTIONS_HEAD_ARGUMENT_HELP_MESSAGE) +@click.option('--reverse', required=False, is_flag=True, help=TRANSACTIONS_REVERSE_ARGUMENT_HELP_MESSAGE) +@click.option('--family-name', required=False, type=str, help=TRANSACTIONS_FAMILY_NAME_ARGUMENT_HELP_MESSAGE) +@click.option('--ids-only', required=False, is_flag=True, help=TRANSACTIONS_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE) @click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) @transaction_command.command('get-list') def get_transactions(ids, start, limit, head, reverse, family_name, ids_only, node_url): @@ -72,6 +72,7 @@ def get_transactions(ids, start, limit, head, reverse, family_name, ids_only, no start = arguments.get('start') limit = arguments.get('limit') head = arguments.get('head') + reverse = arguments.get('reverse') family_name = arguments.get('family_name') node_url = arguments.get('node_url') @@ -86,12 +87,7 @@ def get_transactions(ids, start, limit, head, reverse, family_name, ids_only, no else: result, errors = Transaction(service=remme).get_list( - transaction_ids=transaction_ids, - start=start, - limit=limit, - head=head, - family_name=family_name, - reverse=reverse, + ids=transaction_ids, start=start, limit=limit, head=head, family_name=family_name, reverse=reverse, ) if errors is not None: diff --git a/cli/transaction/forms.py b/cli/transaction/forms.py index 6c1ce3f..fa1dee2 100644 --- a/cli/transaction/forms.py +++ b/cli/transaction/forms.py @@ -31,14 +31,16 @@ class GetTransactionsListForm(Schema): validate.Range(min=1, error='Limit must be greater than 0.'), ], ) + reverse = fields.Boolean(required=False) + ids_only = fields.Boolean(required=False) family_name = FamilyNameField(allow_none=True, required=False) - node_url = NodeUrlField(required=False) + node_url = NodeUrlField(required=True) class GetTransactionForm(Schema): """ - Get transaction form. + Get transaction by its identifier form. """ - id = TransactionIdentifierField(allow_none=True, required=True) - node_url = NodeUrlField(required=False) + id = TransactionIdentifierField(required=True) + node_url = NodeUrlField(required=True) diff --git a/cli/transaction/help.py b/cli/transaction/help.py index 9bfa67d..c78cebe 100644 --- a/cli/transaction/help.py +++ b/cli/transaction/help.py @@ -1,11 +1,11 @@ """ Provide help messages for command line interface's transaction commands. """ -TRANSACTION_IDS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of transactions by.' -TRANSACTION_START_ARGUMENT_HELP_MESSAGE = 'Transaction identifier to get a list transaction starting from.' -TRANSACTION_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of transactions to return.' -TRANSACTION_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of transactions from.' -TRANSACTION_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.' -TRANSACTION_FAMILY_NAME_ARGUMENT_HELP_MESSAGE = 'List of transactions by its family name.' TRANSACTION_ID_ARGUMENT_HELP_MESSAGE = 'Identifier to get a transaction by.' -TRANSACTIONS_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of transactions\' identifiers.' +TRANSACTIONS_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of transactions by.' +TRANSACTIONS_START_ARGUMENT_HELP_MESSAGE = 'Transaction identifier to get a list transaction starting from.' +TRANSACTIONS_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of transactions to return.' +TRANSACTIONS_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of transactions to.' +TRANSACTIONS_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.' +TRANSACTIONS_FAMILY_NAME_ARGUMENT_HELP_MESSAGE = 'List of transactions by its family name.' +TRANSACTIONS_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of transactions\' identifiers.' diff --git a/cli/transaction/interfaces.py b/cli/transaction/interfaces.py index aec671b..baa93ed 100644 --- a/cli/transaction/interfaces.py +++ b/cli/transaction/interfaces.py @@ -8,7 +8,7 @@ class TransactionInterface: Implements transaction interface. """ - def get_list(self, transaction_ids, start, limit, head, reverse, family_name): + def get_list(self, ids, start, limit, head, reverse, family_name): """ Get a list of transactions. @@ -16,11 +16,11 @@ def get_list(self, transaction_ids, start, limit, head, reverse, family_name): reverse, family name. Arguments: - transaction_ids (list, optional): identifiers to get a list of transactions by. + ids (list, optional): identifiers to get a list of transactions by. start (string, optional): transaction identifier to get a list transaction starting from. limit (int, optional): maximum amount of transactions to return. head (string, optional): block identifier to get a list of transactions from. - reverse (string, optional): parameter to reverse result. + reverse (bool, optional): parameter to reverse result. family_name (string, optional): list of a transactions by its family name. """ pass @@ -38,7 +38,7 @@ def get_list_ids(self, ids, start, limit, head, reverse, family_name): limit (int, optional): maximum amount of blocks to return. head (string, optional): block identifier to get a list of transactions to. reverse (bool, optional): parameter to reverse result. - family_name (bool, optional): list of a transactions by its family name. + family_name (string, optional): list of a transactions by its family name. """ pass diff --git a/cli/transaction/service.py b/cli/transaction/service.py index da8897a..1dea47f 100644 --- a/cli/transaction/service.py +++ b/cli/transaction/service.py @@ -26,24 +26,22 @@ def __init__(self, service): """ self.service = service - def get_list(self, transaction_ids, start, limit, head, reverse, family_name): + def get_list(self, ids, start, limit, head, reverse, family_name): """ Get a list of transactions. Arguments: - transaction_ids (list, optional): identifiers to get a list of transactions by. + ids (list, optional): identifiers to get a list of transactions by. start (string, optional): transaction identifier to get a list transaction starting from. limit (int, optional): maximum amount of transactions to return. head (string, optional): block identifier to get a list of transactions from. - reverse (string, optional): parameter to reverse result. + reverse (bool, optional): parameter to reverse result. family_name (string, optional): list of a transactions by its family name. """ - reverse = '' if reverse else 'false' - try: transactions = loop.run_until_complete( self.service.blockchain_info.get_transactions(query={ - 'ids': transaction_ids, + 'ids': ids, 'start': start, 'limit': limit, 'head': head, @@ -73,10 +71,10 @@ def get_list_ids(self, ids, start, limit, head, reverse, family_name): limit (int, optional): maximum amount of blocks to return. head (string, optional): block identifier to get a list of transactions to. reverse (bool, optional): parameter to reverse result. - family_name (bool, optional): list of a transactions by its family name. + family_name (string, optional): list of a transactions by its family name. """ transactions, errors = self.get_list( - transaction_ids=ids, start=start, head=head, limit=limit, reverse=reverse, family_name=family_name, + ids=ids, start=start, head=head, limit=limit, reverse=reverse, family_name=family_name, ) if errors is not None: diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..5b9f41d --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +filterwarnings = + ignore::DeprecationWarning + ignore::RuntimeWarning diff --git a/tests/__init.py b/tests/__init.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/account/test_get_balance.py b/tests/account/test_get_balance.py index a7c9348..80f1cea 100644 --- a/tests/account/test_get_balance.py +++ b/tests/account/test_get_balance.py @@ -68,7 +68,7 @@ def test_get_account_balance_invalid_address(): def test_get_account_balance_without_node_url(mocker): """ Case: get a balance of an account by address without passing node URL. - Expect: balance is returned from node on localhost. + Expect: balance is returned from a node on localhost. """ balance = 13500 @@ -95,7 +95,7 @@ def test_get_account_balance_without_node_url(mocker): def test_get_account_balance_invalid_node_url(): """ - Case: get a balance of an account by passing invalid node URL. + Case: get a balance of an account by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -125,8 +125,8 @@ def test_get_account_balance_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_account_balance_node_url_with_protocol(node_url_with_protocol): """ - Case: get a balance of an account by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get a balance of an account by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -152,8 +152,8 @@ def test_get_account_balance_node_url_with_protocol(node_url_with_protocol): def test_get_account_balance_non_existing_node_url(): """ - Case: get a balance of an account by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get a balance of an account by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/account/test_transfer_tokens.py b/tests/account/test_transfer_tokens.py index 56fab81..aad1620 100644 --- a/tests/account/test_transfer_tokens.py +++ b/tests/account/test_transfer_tokens.py @@ -8,7 +8,7 @@ from click.testing import CliRunner from cli.constants import ( - BATCH_ID_REGEXP, + BATCH_IDENTIFIER_REGEXP, DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, FAILED_EXIT_FROM_COMMAND_CODE, @@ -18,6 +18,8 @@ from cli.entrypoint import cli from cli.utils import dict_to_pretty_json +ADDRESS_PRESENTED_ON_THE_TEST_NODE = '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202' + def test_transfer_tokens(): """ @@ -31,7 +33,7 @@ def test_transfer_tokens(): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', '1000', '--node-url', @@ -41,12 +43,12 @@ def test_transfer_tokens(): batch_id = json.loads(result.output).get('result').get('batch_identifier') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert re.match(pattern=BATCH_ID_REGEXP, string=batch_id) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_id) is not None def test_transfer_tokens_invalid_private_key(): """ - Case: transfer tokens to address with invalid private key. + Case: transfer tokens to address with an invalid private key. Expect: the following private key is invalid error message. """ invalid_private_key = 'b03e31d2f310305eab249133b53b5fb327' @@ -58,7 +60,7 @@ def test_transfer_tokens_invalid_private_key(): '--private-key', invalid_private_key, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', '1000', '--node-url', @@ -79,7 +81,7 @@ def test_transfer_tokens_invalid_private_key(): def test_transfer_tokens_invalid_address_to(): """ - Case: transfer tokens to invalid address. + Case: transfer tokens to an invalid address. Expect: the following address to is invalid error message. """ invalid_address_to = '1120076ecf036e857f42129b5830' @@ -112,7 +114,7 @@ def test_transfer_tokens_invalid_address_to(): def test_transfer_tokens_invalid_amount(): """ - Case: transfer tokens to address with invalid amount. + Case: transfer tokens to address with the invalid amount. Expect: amount is not a valid integer error message. """ invalid_amount = 'je682' @@ -124,7 +126,7 @@ def test_transfer_tokens_invalid_amount(): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', invalid_amount, '--node-url', @@ -138,7 +140,7 @@ def test_transfer_tokens_invalid_amount(): @pytest.mark.parametrize('insufficient_amount', [-1, 0]) def test_transfer_tokens_with_insufficient_amount(insufficient_amount): """ - Case: transfer tokens to address with insufficient amount. + Case: transfer tokens to address with the insufficient amount. Expect: amount must be greater than 0 error message. """ runner = CliRunner() @@ -148,7 +150,7 @@ def test_transfer_tokens_with_insufficient_amount(insufficient_amount): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', insufficient_amount, '--node-url', @@ -170,7 +172,7 @@ def test_transfer_tokens_with_insufficient_amount(insufficient_amount): def test_transfer_tokens_without_node_url(mocker, sent_transaction): """ Case: transfer tokens to address without passing node URL. - Expect: batch identifier is returned from node on localhost. + Expect: batch identifier is returned from a node on localhost. """ mock_account_transfer_tokens = mocker.patch('cli.account.service.loop.run_until_complete') mock_account_transfer_tokens.return_value = sent_transaction @@ -182,7 +184,7 @@ def test_transfer_tokens_without_node_url(mocker, sent_transaction): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', '1000', ]) @@ -190,12 +192,12 @@ def test_transfer_tokens_without_node_url(mocker, sent_transaction): batch_id = json.loads(result.output).get('result').get('batch_identifier') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert re.match(pattern=BATCH_ID_REGEXP, string=batch_id) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_id) is not None def test_transfer_tokens_invalid_node_url(): """ - Case: transfer tokens to address by passing invalid node URL. + Case: transfer tokens to address by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -207,7 +209,7 @@ def test_transfer_tokens_invalid_node_url(): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', '1000', '--node-url', @@ -229,8 +231,8 @@ def test_transfer_tokens_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_transfer_tokens_node_url_with_protocol(node_url_with_protocol): """ - Case: transfer tokens to address by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: transfer tokens to address by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -239,7 +241,7 @@ def test_transfer_tokens_node_url_with_protocol(node_url_with_protocol): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', '1000', '--node-url', @@ -260,8 +262,8 @@ def test_transfer_tokens_node_url_with_protocol(node_url_with_protocol): def test_transfer_tokens_non_existing_node_url(): """ - Case: transfer tokens to address by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: transfer tokens to address by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' @@ -272,7 +274,7 @@ def test_transfer_tokens_non_existing_node_url(): '--private-key', DEV_BRANCH_NODE_PRIVATE_KEY_WITH_MONEY, '--address-to', - '112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202', + ADDRESS_PRESENTED_ON_THE_TEST_NODE, '--amount', '1000', '--node-url', diff --git a/tests/atomic_swap/test_get_info.py b/tests/atomic_swap/test_get_info.py index cb69067..05a335a 100644 --- a/tests/atomic_swap/test_get_info.py +++ b/tests/atomic_swap/test_get_info.py @@ -49,7 +49,7 @@ def test_get_swap_info(): def test_get_swap_info_without_node_url(mocker, swap_info): """ Case: get information about atomic swap by its identifier without passing node URL. - Expect: information about the swap is returned from node on localhost. + Expect: information about the swap is returned from a 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 @@ -103,8 +103,8 @@ def test_get_swap_info_invalid_swap_id(): def test_get_swap_info_non_existing_swap_id(): """ - Case: get information about atomic swap by passing non-existing identifier. - Expect: atomic swap with identifier not found error message. + Case: get information about atomic swap by passing the non-existing identifier. + Expect: atomic swap with an identifier not found error message. """ non_existing_swap_id = '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6809' @@ -128,8 +128,8 @@ def test_get_swap_info_non_existing_swap_id(): def test_get_swap_info_non_existing_node_url(): """ - Case: get information about atomic swap by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get information about atomic swap by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' @@ -153,7 +153,7 @@ def test_get_swap_info_non_existing_node_url(): def test_get_swap_info_invalid_node_url(): """ - Case: get information about atomic swap by passing invalid node URL. + Case: get information about atomic swap by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -183,8 +183,8 @@ def test_get_swap_info_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_swap_info_node_url_with_protocol(node_url_with_protocol): """ - Case: get information about atomic swap by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get information about atomic swap by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ diff --git a/tests/atomic_swap/test_get_public_key.py b/tests/atomic_swap/test_get_public_key.py index 0e21a61..d41b3d2 100644 --- a/tests/atomic_swap/test_get_public_key.py +++ b/tests/atomic_swap/test_get_public_key.py @@ -1,5 +1,5 @@ """ -Provide tests for command line interface's get public key of the atomic swap commands. +Provide tests for command line interface's get the public key of the atomic swap commands. """ import json import re @@ -19,8 +19,8 @@ def test_get_public_key(): """ - Case: get the public key of atomic swap. - Expect: public key is returned. + Case: get the public key of the atomic swap. + Expect: a public key is returned. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -38,8 +38,8 @@ def test_get_public_key(): def test_get_public_key_without_node_url(mocker): """ - Case: get the public key of atomic swap without passing node URL. - Expect: public key is returned from node on localhost. + Case: get the public key of the atomic swap without passing node URL. + Expect: a public key is returned from node on localhost. """ public_key = '03738df3f4ac3621ba8e89413d3ff4ad036c3a0a4dbb164b695885aab6aab614ad' mock_swap_get_public_key = mocker.patch('cli.node.service.loop.run_until_complete') @@ -63,7 +63,7 @@ def test_get_public_key_without_node_url(mocker): def test_get_public_key_invalid_node_url(): """ - Case: get the public key of atomic swap by passing invalid node URL. + Case: get the public key of the atomic swap by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -91,8 +91,8 @@ def test_get_public_key_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_public_key_node_url_with_protocol(node_url_with_protocol): """ - Case: get the public key of atomic swap by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get the public key of the atomic swap by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -116,8 +116,8 @@ def test_get_public_key_node_url_with_protocol(node_url_with_protocol): def test_get_public_key_non_existing_node_url(): """ - Case: get the public key of atomic swap by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get the public key of the atomic swap by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/batch/test_get_batch.py b/tests/batch/test_get_batch.py index 7e10538..f47f72a 100644 --- a/tests/batch/test_get_batch.py +++ b/tests/batch/test_get_batch.py @@ -14,21 +14,21 @@ from cli.entrypoint import cli from cli.utils import dict_to_pretty_json +BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE = 'ccb529856e538325b435c6a75261702d1bdb52d3873b29189a722330cda628a6' \ + '62028a7b39d1f5475cb78f5fc12efb986a35553ce8f1b63580b97fc6ab9e9655' + def test_get_batch(): """ Case: get a batch by identifier. Expect: batch is returned. """ - batch_id = 'ccb529856e538325b435c6a75261702d1bdb52d3873b29189a722330cda628a6' \ - '62028a7b39d1f5475cb78f5fc12efb986a35553ce8f1b63580b97fc6ab9e9655' - runner = CliRunner() result = runner.invoke(cli, [ 'batch', 'get', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) @@ -69,10 +69,10 @@ def test_get_batch_with_invalid_id(): def test_get_batch_without_node_url(mocker): """ Case: get a batch by its identifier without passing node URL. - Expect: batch is returned from node on localhost. + Expect: batch is returned from a node on localhost. """ batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' \ + '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' expected_result = { "data": { @@ -126,20 +126,17 @@ def test_get_batch_without_node_url(mocker): def test_get_batch_with_invalid_node_url(): """ - Case: get a batch by its identifier by by passing invalid node URL. + Case: get a batch by its identifier by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'my-node-url.com' - batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' - runner = CliRunner() result = runner.invoke(cli, [ 'batch', 'get', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', invalid_node_url, ]) @@ -155,18 +152,15 @@ def test_get_batch_with_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_batch_node_url_with_protocol(node_url_with_protocol): """ - Case: get a batch by its identifier by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get a batch by its identifier by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ - batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' - runner = CliRunner() result = runner.invoke(cli, [ 'batch', 'get', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', node_url_with_protocol, ]) diff --git a/tests/batch/test_get_batch_status.py b/tests/batch/test_get_batch_status.py index 2c71862..58d73b8 100644 --- a/tests/batch/test_get_batch_status.py +++ b/tests/batch/test_get_batch_status.py @@ -14,11 +14,14 @@ from cli.entrypoint import cli from cli.utils import dict_to_pretty_json +BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ + '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' + def test_get_committed_batch_status(): """ Case: get committed batch status by its identifier. - Expect: committed message is returned. + Expect: the committed message is returned. """ batch_id = 'ccb529856e538325b435c6a75261702d1bdb52d3873b29189a722330cda628a6' \ '62028a7b39d1f5475cb78f5fc12efb986a35553ce8f1b63580b97fc6ab9e9655' @@ -42,7 +45,7 @@ def test_get_committed_batch_status(): def test_get_unknown_batch_status(): """ Case: get non-existing batch status by its identifier. - Expect: unknown message is returned. + Expect: the unknown message is returned. """ batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8752' @@ -97,9 +100,6 @@ def test_get_batch_status_without_node_url(mocker): Case: get a batch status by its identifier without passing node URL. Expect: batch status is returned from a node on localhost. """ - batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' \ - committed_status = 'COMMITTED' expected_result = { @@ -114,7 +114,7 @@ def test_get_batch_status_without_node_url(mocker): 'batch', 'get-status', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, ]) assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code @@ -123,19 +123,17 @@ def test_get_batch_status_without_node_url(mocker): def test_get_batch_status_with_invalid_node_url(): """ - Case: get a batch status by its identifier by passing invalid node URL. + Case: get a batch status by its identifier by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' - batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' runner = CliRunner() result = runner.invoke(cli, [ 'batch', 'get-status', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', invalid_node_url, ]) @@ -155,18 +153,15 @@ def test_get_batch_status_with_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_batch_status_node_url_with_protocol(node_url_with_protocol): """ - Case: get batch a status by its identifier by passing node URL with explicit protocol. + Case: get batch a status by its identifier by passing node URL with an explicit protocol. Expect: the following node URL contains the protocol error message. """ - batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' - runner = CliRunner() result = runner.invoke(cli, [ 'batch', 'get-status', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', node_url_with_protocol, ]) @@ -185,19 +180,17 @@ def test_get_batch_status_node_url_with_protocol(node_url_with_protocol): def test_get_batch_status_with_non_existing_node_url(): """ - Case: get a batch status by its identifier by passing non-existing node URL. + Case: get a batch status by its identifier by passing the non-existing node URL. Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' - batch_id = '6f200995e766da7218ec2a3d0aeabbe1151128063cdf4e954cd08390a879b28e' \ - '085a06f8708d2e6bb34f6501e8ddc981f0353627c1d4f90c80a656a8090c8751' runner = CliRunner() result = runner.invoke(cli, [ 'batch', 'get-status', '--id', - batch_id, + BATCH_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', non_existing_node_url, ]) diff --git a/tests/batch/test_get_list_batches.py b/tests/batch/test_get_batches.py similarity index 83% rename from tests/batch/test_get_list_batches.py rename to tests/batch/test_get_batches.py index 29d2569..fa6f435 100644 --- a/tests/batch/test_get_list_batches.py +++ b/tests/batch/test_get_batches.py @@ -8,10 +8,9 @@ from click.testing import CliRunner from cli.constants import ( - BLOCK_IDENTIFIER_REGEXP, + BATCH_IDENTIFIER_REGEXP, DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, FAILED_EXIT_FROM_COMMAND_CODE, - HEADER_SIGNATURE_REGEXP, PASSED_EXIT_FROM_COMMAND_CODE, ) from cli.entrypoint import cli @@ -29,7 +28,7 @@ '1c1bdbbce01984ad73a12277dedfd0fe5f7af3d0f6139952b9b5ac09481ccd94' -def test_get_list_batches_with_all_parameters(): +def test_get_batches_with_all_parameters(): """ Case: get a list of batches by identifiers, identifier starting from, limit, head, reverse. Expect: batches are returned from a node on localhost. @@ -46,22 +45,22 @@ def test_get_list_batches_with_all_parameters(): 1, '--head', VALID_BLOCK_IDENTIFIER, + '--reverse', '--node-url', DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, - '--reverse', ]) - result_blocks = json.loads(result.output).get('result') + result_batches = json.loads(result.output).get('result') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - for block in result_blocks: - block_identifier = block.get('header_signature') + for batch in result_batches: + batch_identifier = batch.get('header_signature') - assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=block_identifier) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is not None -def test_get_list_batches_with_ids(): +def test_get_batches_with_ids(): """ Case: get a list of batches by identifiers. Expect: batches with specified identifiers are returned. @@ -76,15 +75,15 @@ def test_get_list_batches_with_ids(): DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) - result_blocks = json.loads(result.output).get('result') + result_batches = json.loads(result.output).get('result') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - for block in result_blocks: - block_identifier = block.get('header_signature') + for batch in result_batches: + batch_identifier = batch.get('header_signature') - assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=block_identifier) is not None - assert block_identifier in COMMITTED_BATCH_IDENTIFIERS + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is not None + assert batch_identifier in COMMITTED_BATCH_IDENTIFIERS def test_get_batches_identifiers(): @@ -106,10 +105,10 @@ def test_get_batches_identifiers(): assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code for batch_identifier in batches: - assert re.match(pattern=HEADER_SIGNATURE_REGEXP, string=batch_identifier) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is not None -def test_get_list_batches_with_invalid_ids(): +def test_get_batches_with_invalid_ids(): """ Case: get a list of batches by invalid identifiers. Expect: the following identifier is invalid error message. @@ -141,7 +140,7 @@ def test_get_list_batches_with_invalid_ids(): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_batches_with_start(): +def test_get_batches_with_start(): """ Case: get a list of batches by batch identifier starting from. Expect: batches are returned starting from the batch with an identifier which matches specified start parameter. @@ -159,19 +158,19 @@ def test_get_list_batches_with_start(): DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) - result_blocks = json.loads(result.output).get('result') - first_block_identifier = result_blocks[0].get('header_signature') + result_batches = json.loads(result.output).get('result') + first_batch_identifier = result_batches[0].get('header_signature') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert start_identifier == first_block_identifier + assert start_identifier == first_batch_identifier - for block in result_blocks: - block_identifier = block.get('header_signature') + for batch in result_batches: + batch_identifier = batch.get('header_signature') - assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=block_identifier) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is not None -def test_get_list_batches_with_reverse(): +def test_get_batches_with_reverse(): """ Case: get a list of batches by reverse. Expect: reversed list of batches is returned. @@ -185,20 +184,20 @@ def test_get_list_batches_with_reverse(): DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) - result_blocks = json.loads(result.output).get('result') + result_batches = json.loads(result.output).get('result') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - for block in result_blocks: - block_identifier = block.get('header_signature') + for batch in result_batches: + batch_identifier = batch.get('header_signature') - assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=block_identifier) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is not None -def test_get_list_batches_by_head(): +def test_get_batches_by_head(): """ Case: get a list of batches by block identifier. - Expect: batches from specified block are returned. + Expect: batches from the specified block are returned. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -214,7 +213,7 @@ def test_get_list_batches_by_head(): @pytest.mark.parametrize('command_flag', ('--start', '--head', '--ids')) -def test_get_list_batches_by_non_existing_start_head_ids(command_flag): +def test_get_batches_by_non_existing_start_head_ids(command_flag): """ Case: get a list of batches by non-existing batch identifier, block identifier and batch identifier starting from. Expect: list of batches not found error message. @@ -241,7 +240,7 @@ def test_get_list_batches_by_non_existing_start_head_ids(command_flag): @pytest.mark.parametrize('command_flag', ('--start', '--head', '--ids')) -def test_get_list_batches_with_invalid_start_head_ids(command_flag): +def test_get_batches_with_invalid_start_head_ids(command_flag): """ Case: get a list of batches by invalid batch identifier, block identifier and batch identifier starting from. Expect: the following identifier is invalid error message. @@ -270,7 +269,7 @@ def test_get_list_batches_with_invalid_start_head_ids(command_flag): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_batches_with_limit(): +def test_get_batches_with_limit(): """ Case: get a list of batches by limit. Expect: batch is returned. @@ -287,18 +286,18 @@ def test_get_list_batches_with_limit(): DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) - result_blocks = json.loads(result.output).get('result') + result_batches = json.loads(result.output).get('result') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert len(result_blocks) == limit + assert len(result_batches) == limit - for block in result_blocks: - block_identifier = block.get('header_signature') + for batch in result_batches: + batch_identifier = batch.get('header_signature') - assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=block_identifier) is not None + assert re.match(pattern=BATCH_IDENTIFIER_REGEXP, string=batch_identifier) is not None -def test_get_list_batches_with_negative_limit(): +def test_get_batches_with_negative_limit(): """ Case: get a list of batches limiting by a negative number. Expect: limit must be greater than 0 error message. @@ -327,7 +326,7 @@ def test_get_list_batches_with_negative_limit(): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_batches_with_invalid_limit(): +def test_get_batches_with_invalid_limit(): """ Case: get a list of batches limiting by an invalid number. Expect: invalid limit count error message. @@ -352,9 +351,9 @@ def test_get_list_batches_with_invalid_limit(): assert dict_to_pretty_json(expected_error) in result.output -def test_get_list_batches_with_invalid_node_url(): +def test_get_batches_with_invalid_node_url(): """ - Case: get a list of batches by passing invalid node URL. + Case: get a list of batches by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -381,7 +380,7 @@ def test_get_list_batches_with_invalid_node_url(): assert dict_to_pretty_json(expected_error) in result.output -def test_get_list_batches_without_node_url(mocker): +def test_get_batches_without_node_url(mocker): """ Case: get a list of batches by identifier without passing node URL. Expect: batches are returned from a node on localhost. @@ -447,9 +446,9 @@ def test_get_list_batches_without_node_url(mocker): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) -def test_get_list_batches_node_url_with_protocol(node_url_with_protocol): +def test_get_batches_node_url_with_protocol(node_url_with_protocol): """ - Case: get a list of batches by passing node URL with explicit protocol. + Case: get a list of batches by passing node URL with an explicit protocol. Expect: the following node URL contains the protocol error message. """ runner = CliRunner() @@ -474,9 +473,9 @@ def test_get_list_batches_node_url_with_protocol(node_url_with_protocol): assert dict_to_pretty_json(expected_error) in result.output -def test_get_list_batches_with_non_existing_node_url(): +def test_get_batches_with_non_existing_node_url(): """ - Case: get a list of batches by passing non-existing node URL. + Case: get a list of batches by passing the non-existing node URL. Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/block/test_get_block.py b/tests/block/test_get_block.py index ea71a2d..cf9a2f2 100644 --- a/tests/block/test_get_block.py +++ b/tests/block/test_get_block.py @@ -72,7 +72,7 @@ def test_get_block_invalid_identifier(): def test_get_block_without_node_url(mocker): """ Case: get a block by identifier without passing node URL. - Expect: blocks is returned from a node on localhost. + Expect: block data is returned from a node on localhost. """ block = { 'data': { @@ -164,7 +164,7 @@ def test_get_block_without_node_url(mocker): def test_get_block_invalid_node_url(): """ - Case: get a block by identifier by passing invalid node URL. + Case: get a block by identifier by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -194,8 +194,8 @@ def test_get_block_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_block_node_url_with_protocol(node_url_with_protocol): """ - Case: get a block by identifier by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get a block by identifier by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -221,8 +221,8 @@ def test_get_block_node_url_with_protocol(node_url_with_protocol): def test_get_block_non_existing_node_url(): """ - Case: get a block by identifier by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get a block by identifier by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' @@ -246,8 +246,8 @@ def test_get_block_non_existing_node_url(): def test_get_block_non_existing_identifier(): """ - Case: get a block by identifier by passing non-existing identifier. - Expect: block with identifier not found error message. + Case: get a block by identifier by passing the non-existing identifier. + Expect: block with an identifier not found error message. """ non_existing_block_identifier = '7a7897650db9863aca34874778e6c5802f86c3df0e22b39cfea730bc83654357' \ '037a422f8ef51ac85a9bc61d2484bd0f37be10cfc861588c41dc6f1bbfd92cde' diff --git a/tests/block/test_get_blocks.py b/tests/block/test_get_blocks.py index e1a1555..6252d9b 100644 --- a/tests/block/test_get_blocks.py +++ b/tests/block/test_get_blocks.py @@ -16,6 +16,11 @@ from cli.entrypoint import cli from cli.utils import dict_to_pretty_json +EXISTING_BLOCKS_IDENTIFIERS = 'b757c74fbcd57ae12577b71490878affb6b688434c2e20170138760e72e937ca' \ + '1bb3d6773e2ef37b5151ed74dcb663114a181072e0870e7a4d452c58659a6dbb, ' \ + '585f23725d1236e90e2b961b0c0c1404aba0ba5a96e4d85cd2f048b1d61b0276' \ + '69153e3618c84fc09a8041f8e149b97d50a89ee7761d0458cd57c63d5f354cbd' + def test_get_blocks_all_parameters(): """ @@ -24,11 +29,6 @@ def test_get_blocks_all_parameters(): """ limit = 2 - blocks_ids = 'b757c74fbcd57ae12577b71490878affb6b688434c2e20170138760e72e937ca' \ - '1bb3d6773e2ef37b5151ed74dcb663114a181072e0870e7a4d452c58659a6dbb, ' \ - '585f23725d1236e90e2b961b0c0c1404aba0ba5a96e4d85cd2f048b1d61b0276' \ - '69153e3618c84fc09a8041f8e149b97d50a89ee7761d0458cd57c63d5f354cbd' - head_identifier = '585f23725d1236e90e2b961b0c0c1404aba0ba5a96e4d85cd2f048b1d61b0276' \ '69153e3618c84fc09a8041f8e149b97d50a89ee7761d0458cd57c63d5f354cbd' @@ -37,7 +37,7 @@ def test_get_blocks_all_parameters(): 'block', 'get-list', '--ids', - blocks_ids, + EXISTING_BLOCKS_IDENTIFIERS, '--head', head_identifier, '--limit', @@ -91,17 +91,12 @@ def test_get_blocks_with_ids(): Case: get a list of blocks by its identifiers. Expect: blocks with header signatures which matches specified identifiers are returned. """ - blocks_ids = 'b757c74fbcd57ae12577b71490878affb6b688434c2e20170138760e72e937ca' \ - '1bb3d6773e2ef37b5151ed74dcb663114a181072e0870e7a4d452c58659a6dbb, ' \ - '585f23725d1236e90e2b961b0c0c1404aba0ba5a96e4d85cd2f048b1d61b0276' \ - '69153e3618c84fc09a8041f8e149b97d50a89ee7761d0458cd57c63d5f354cbd' - runner = CliRunner() result = runner.invoke(cli, [ 'block', 'get-list', '--ids', - blocks_ids, + EXISTING_BLOCKS_IDENTIFIERS, '--node-url', DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) @@ -114,7 +109,7 @@ def test_get_blocks_with_ids(): block_identifier = block.get('header_signature') assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=block_identifier) is not None - assert block_identifier in blocks_ids + assert block_identifier in EXISTING_BLOCKS_IDENTIFIERS def test_get_blocks_invalid_ids(): @@ -236,7 +231,7 @@ def test_get_blocks_invalid_head(): def test_get_blocks_with_limit(): """ Case: get a list of blocks limiting by a number. - Expect: specified number of blocks are returned. + Expect: a specified number of blocks are returned. """ limit = 2 @@ -339,7 +334,7 @@ def test_get_blocks_identifiers(): def test_get_blocks_invalid_node_url(): """ - Case: get a list of blocks by passing invalid node URL. + Case: get a list of blocks by passing an invalid node URL. Expect: the following node URL is an invalid error message. """ invalid_node_url = 'domainwithoutextention' diff --git a/tests/config/test_config_file.py b/tests/config/test_config_file.py index 1348faa..19e1689 100644 --- a/tests/config/test_config_file.py +++ b/tests/config/test_config_file.py @@ -9,8 +9,8 @@ def test_get_node_url(create_config_file): """ - Case: get node url from configuration file. - Expect: node url address in string format. + Case: get node URL from the configuration file. + Expect: node URL address in string format. """ config = ConfigFile().parse() @@ -19,7 +19,7 @@ def test_get_node_url(create_config_file): def test_get_node_url_without_node_url(create_config_file_without_node_url): """ - Case: get node url from configuration file without node url. + Case: get node URL from a configuration file without node URL. Expect: none is returned. """ config = ConfigFile().parse(name=CLI_CONFIG_FILE_NAME_WITHOUT_URL) @@ -29,7 +29,7 @@ def test_get_node_url_without_node_url(create_config_file_without_node_url): def test_get_node_url_from_empty_file(create_empty_config_file): """ - Case: get node url from empty configuration file. + Case: get node URL from the empty configuration file. Expect: none is returned. """ config = ConfigFile().parse(name=CLI_CONFIG_FILE_NAME_EMPTY_FILE) @@ -39,7 +39,7 @@ def test_get_node_url_from_empty_file(create_empty_config_file): def test_get_node_url_without_file(): """ - Case: get node url without configuration file. + Case: get node URL without a configuration file. Expect: none is returned. """ config = ConfigFile().parse() diff --git a/tests/config/test_node_private_key_file.py b/tests/config/test_node_private_key_file.py index d8f288b..5675a6c 100644 --- a/tests/config/test_node_private_key_file.py +++ b/tests/config/test_node_private_key_file.py @@ -20,7 +20,7 @@ def test_node_private_key_get(create_node_private_key_file, node_private_key_fil def test_node_private_key_get_not_supported_os(operating_system, node_private_key_file_path, mocker): """ Case: get the node's private key from not supported operating system. - Expect: operating system is not supported to get the node's private key error message. + Expect: the operating system is not supported to get the node's private key error message. """ mock_account_get_balance = mocker.patch('platform.system') mock_account_get_balance.return_value = operating_system @@ -33,7 +33,7 @@ def test_node_private_key_get_not_supported_os(operating_system, node_private_ke def test_node_private_key_get_from_non_existing_file(node_private_key_file_path): """ - Case: get the node's private key from non-existing file. + Case: get the node's private key from the non-existing file. Expect: private key hasn't been founded on the machine error message. """ with pytest.raises(FileNotFoundError) as error: diff --git a/tests/constants.py b/tests/constants.py deleted file mode 100644 index 7fe979a..0000000 --- a/tests/constants.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -Provide constants for testing a command line interface. -""" diff --git a/tests/generic/forms/test_fields.py b/tests/generic/forms/test_fields.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/node/test_get_configs.py b/tests/node/test_get_configs.py index 6a3f3b1..1a5f271 100644 --- a/tests/node/test_get_configs.py +++ b/tests/node/test_get_configs.py @@ -44,10 +44,10 @@ def test_get_node_configs(): def test_get_node_configs_without_node_url(mocker, node_configurations): """ Case: get node configurations without passing node URL. - Expect: batch identifier is returned from node on localhost. + Expect: batch identifier is returned from a node on localhost. """ - mock_account_get_balance = mocker.patch('cli.node.service.loop.run_until_complete') - mock_account_get_balance.return_value = node_configurations + mock_get_node_configs = mocker.patch('cli.node.service.loop.run_until_complete') + mock_get_node_configs.return_value = node_configurations runner = CliRunner() result = runner.invoke(cli, [ @@ -67,7 +67,7 @@ def test_get_node_configs_without_node_url(mocker, node_configurations): def test_get_node_configs_invalid_node_url(): """ - Case: get node configurations by passing invalid node URL. + Case: get node configurations by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -95,8 +95,8 @@ def test_get_node_configs_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_node_configs_node_url_with_protocol(node_url_with_protocol): """ - Case: get node configurations by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get node configurations by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -120,8 +120,8 @@ def test_get_node_configs_node_url_with_protocol(node_url_with_protocol): def test_get_node_configs_non_existing_node_url(): """ - Case: get node configurations by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get node configurations by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/node/test_get_information.py b/tests/node/test_get_information.py index fb3b43e..11eeaee 100644 --- a/tests/node/test_get_information.py +++ b/tests/node/test_get_information.py @@ -64,7 +64,7 @@ def test_get_node_info_without_node_url(mocker, node_information): def test_get_node_info_invalid_node_url(): """ - Case: get information about synchronization and peer count of the node by passing invalid node URL. + Case: get information about synchronization and peer count of the node by an passing invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -93,7 +93,7 @@ def test_get_node_info_invalid_node_url(): def test_get_node_info_node_url_with_protocol(node_url_with_protocol): """ Case: get information about synchronization and peer count of the node by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -117,8 +117,8 @@ def test_get_node_info_node_url_with_protocol(node_url_with_protocol): def test_get_node_info_non_existing_node_url(): """ - Case: get information about synchronization and peer count of the node by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get information about synchronization and peer count of the node by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/node/test_get_initial_stake.py b/tests/node/test_get_initial_stake.py index c2051f7..3fbd3b7 100644 --- a/tests/node/test_get_initial_stake.py +++ b/tests/node/test_get_initial_stake.py @@ -61,7 +61,7 @@ def test_get_initial_stake_without_node_url(mocker): def test_get_initial_stake_invalid_node_url(): """ Case: get the initial stake of the node by passing an invalid node URL. - Expect: the following node URL is an invalid error message. + Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' diff --git a/tests/node/test_get_peers.py b/tests/node/test_get_peers.py index 6cdf081..d1aaba2 100644 --- a/tests/node/test_get_peers.py +++ b/tests/node/test_get_peers.py @@ -15,7 +15,7 @@ from cli.utils import dict_to_pretty_json -def test_get_node_peers_configs(): +def test_get_node_peers(): """ Case: get the node's peers. Expect: node peers are returned. @@ -40,7 +40,7 @@ def test_get_node_peers_configs(): def test_get_node_peers_without_node_url(mocker): """ Case: get the node's peers without passing node URL. - Expect: node peers are returned from node on localhost. + Expect: node peers are returned from a node on localhost. """ peers = [ 'tcp://node-26-testnet.remme.io:8800', @@ -71,7 +71,7 @@ def test_get_node_peers_without_node_url(mocker): def test_get_node_peers_invalid_node_url(): """ - Case: get the node's peers by passing invalid node URL. + Case: get the node's peers by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -99,8 +99,8 @@ def test_get_node_peers_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_node_peers_node_url_with_protocol(node_url_with_protocol): """ - Case: get the node's peers by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get the node's peers by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -124,8 +124,8 @@ def test_get_node_peers_node_url_with_protocol(node_url_with_protocol): def test_get_node_peers_non_existing_node_url(): """ - Case: get the node's peers by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get the node's peers by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/node_account/test_get_.py b/tests/node_account/test_get_.py index 63e9a68..c000739 100644 --- a/tests/node_account/test_get_.py +++ b/tests/node_account/test_get_.py @@ -94,7 +94,7 @@ def test_get_information_invalid_address(): def test_get_information_invalid_node_url(): """ - Case: get information about the node account by passing invalid node URL. + Case: get information about the node account by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' diff --git a/tests/public_key/test_get_public_key_addresses.py b/tests/public_key/test_get_public_key_addresses.py index e9b8778..101fd00 100644 --- a/tests/public_key/test_get_public_key_addresses.py +++ b/tests/public_key/test_get_public_key_addresses.py @@ -73,7 +73,7 @@ def test_get_public_keys_invalid_address(): def test_get_public_keys_without_node_url(mocker): """ Case: get a list of the addresses of the public keys without passing node URL. - Expect: list of the addresses of the public keys is returned from node on localhost. + Expect: list of the addresses of the public keys is returned from a node on localhost. """ public_key_addresses = [ 'a23be14785e7b073b50e24f72e086675289795b969a895a7f02202404086946e8ddc5b', @@ -103,7 +103,7 @@ def test_get_public_keys_without_node_url(mocker): def test_get_public_keys_invalid_node_url(): """ - Case: get a list of the addresses of the public keys by passing invalid node URL. + Case: get a list of the addresses of the public keys by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -133,8 +133,8 @@ def test_get_public_keys_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_public_keys_node_url_with_protocol(node_url_with_protocol): """ - Case: get a list of the addresses of the public keys by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get a list of the addresses of the public keys by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -160,7 +160,7 @@ def test_get_public_keys_node_url_with_protocol(node_url_with_protocol): def test_get_public_keys_non_existing_address(): """ - Case: get a list of the addresses of the public keys by passing non-existing address. + Case: get a list of the addresses of the public keys by passing the non-existing address. Expect: empty list of the addresses of the public keys is returned. """ non_existing_address = '1120076ecf036e857f42129b58303bcf1e03723764a1702cbe98529802aad8514ee3c1' @@ -184,8 +184,8 @@ def test_get_public_keys_non_existing_address(): def test_get_public_keys_non_existing_node_url(): """ - Case: get a list of the addresses of the public keys by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get a list of the addresses of the public keys by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/public_key/test_get_public_key_info.py b/tests/public_key/test_get_public_key_info.py index 338d514..fcf655f 100644 --- a/tests/public_key/test_get_public_key_info.py +++ b/tests/public_key/test_get_public_key_info.py @@ -11,9 +11,9 @@ ADDRESS_REGEXP, DEV_CONSENSUS_GENESIS_NODE_IP_ADDRESS_FOR_TESTING, FAILED_EXIT_FROM_COMMAND_CODE, - HEADER_SIGNATURE_REGEXP, PASSED_EXIT_FROM_COMMAND_CODE, PUBLIC_KEY_REGEXP, + TRANSACTION_IDENTIFIER_REGEXP, ) from cli.entrypoint import cli from cli.utils import dict_to_pretty_json @@ -25,7 +25,7 @@ def test_get_public_key_info(): """ Case: get information about public key by its address. - Expect: dictionary of public key information, keys matched regexp checking. + Expect: a dictionary of public key information, keys matched regexp checking. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -41,7 +41,7 @@ def test_get_public_key_info(): assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code assert re.match(pattern=ADDRESS_REGEXP, string=public_key_info.get('address')) is not None - assert re.match(pattern=HEADER_SIGNATURE_REGEXP, string=public_key_info.get('entity_hash')) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=public_key_info.get('entity_hash')) is not None assert re.match(pattern=PUBLIC_KEY_REGEXP, string=public_key_info.get('owner_public_key')) is not None assert isinstance(public_key_info.get('valid_from'), int) assert isinstance(public_key_info.get('valid_to'), int) @@ -81,7 +81,7 @@ def test_get_public_key_info_invalid_address(): def test_get_public_key_info_without_node_url(mocker, public_key_information): """ Case: get information about public key without passing node URL. - Expect: dictionary of public key information is returned from node on localhost. + Expect: a dictionary of public key information is returned from a node on localhost. """ mock_public_key_get_info = mocker.patch('cli.public_key.service.loop.run_until_complete') mock_public_key_get_info.return_value = public_key_information @@ -106,7 +106,7 @@ def test_get_public_key_info_without_node_url(mocker, public_key_information): def test_get_public_key_info_invalid_node_url(): """ - Case: get information about public key by passing invalid node URL. + Case: get information about public key by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' @@ -136,8 +136,8 @@ def test_get_public_key_info_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_public_key_info_node_url_with_protocol(node_url_with_protocol): """ - Case: get information about public key by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get information about public key by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -163,7 +163,7 @@ def test_get_public_key_info_node_url_with_protocol(node_url_with_protocol): def test_get_public_key_info_non_existing_address(): """ - Case: get information about public key by passing non-existing address. + Case: get information about public key by passing the non-existing address. Expect: public key information not found error message. """ non_existing_address = 'a23be14785e7b073b50e24f72e086675289795b969a895a7f02202404086946e8ddc5c' @@ -188,8 +188,8 @@ def test_get_public_key_info_non_existing_address(): def test_get_public_key_info_non_existing_node_url(): """ - Case: get information about public key by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get information about public key by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'non-existing-node.com' diff --git a/tests/state/test_get_state.py b/tests/state/test_get_state.py index ac9acf0..cceb54e 100644 --- a/tests/state/test_get_state.py +++ b/tests/state/test_get_state.py @@ -8,9 +8,9 @@ from click.testing import CliRunner from cli.constants import ( + BLOCK_IDENTIFIER_REGEXP, DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, FAILED_EXIT_FROM_COMMAND_CODE, - HEADER_SIGNATURE_REGEXP, PASSED_EXIT_FROM_COMMAND_CODE, ) from cli.entrypoint import cli @@ -22,7 +22,7 @@ def test_get_state_with_address(): """ Case: get a state by its address. - Expect: state is returned. + Expect: the state is returned. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -37,7 +37,7 @@ def test_get_state_with_address(): result_header_signature = json.loads(result.output).get('result').get('state').get('head') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert re.match(pattern=HEADER_SIGNATURE_REGEXP, string=result_header_signature) is not None + assert re.match(pattern=BLOCK_IDENTIFIER_REGEXP, string=result_header_signature) is not None def test_get_state_with_invalid_address(): @@ -97,7 +97,7 @@ def test_get_state_with_non_existing_address(): def test_get_state_without_node_url(mocker): """ Case: get a state by its address without passing node URL. - Expect: state is returned from node on localhost. + Expect: the state is returned from a node on localhost. """ expected_result = { "data": "CAE=", @@ -124,7 +124,7 @@ def test_get_state_without_node_url(mocker): def test_get_state_with_invalid_node_url(): """ - Case: get a state by passing invalid node URL. + Case: get a state by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'my-node-url.com' @@ -150,8 +150,8 @@ def test_get_state_with_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_state_node_url_with_protocol(node_url_with_protocol): """ - Case: get a state by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get a state by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ diff --git a/tests/state/test_get_states.py b/tests/state/test_get_states.py index e0bc5f2..714f50f 100644 --- a/tests/state/test_get_states.py +++ b/tests/state/test_get_states.py @@ -166,7 +166,7 @@ def test_get_states_with_limit(): single_state_address = single_state_result[0].get('address') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert re.match(pattern=ADDRESS_WITH_STATE, string=single_state_address) is not None + assert re.match(pattern=ADDRESS_REGEXP, string=single_state_address) is not None assert len(single_state_result) == limit @@ -224,6 +224,61 @@ def test_get_states_with_non_existing_limit(): assert dict_to_pretty_json(expected_error_message) in result.output +def test_get_states_with_invalid_head(): + """ + Case: get a list of states by its invalid head. + Expect: the following block identifier is invalid error message. + """ + invalid_head = '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' + + runner = CliRunner() + result = runner.invoke(cli, [ + 'state', + 'get-list', + '--head', + invalid_head, + '--node-url', + DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, + ]) + + expected_error_message = { + 'errors': { + 'head': [ + f'The following block identifier `{invalid_head}` is invalid.', + ], + }, + } + + assert FAILED_EXIT_FROM_COMMAND_CODE == result.exit_code + assert dict_to_pretty_json(expected_error_message) in result.output + + +def test_get_states_with_non_existing_head(): + """ + Case: get a list of states by its non-existing head. + Expect: block not found error message. + """ + non_existing_head = '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' \ + '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240ca' + + runner = CliRunner() + result = runner.invoke(cli, [ + 'state', + 'get-list', + '--head', + non_existing_head, + '--node-url', + DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, + ]) + + expected_error_message = { + 'errors': 'Block not found.', + } + + assert FAILED_EXIT_FROM_COMMAND_CODE == result.exit_code + assert dict_to_pretty_json(expected_error_message) in result.output + + def test_get_states_with_reverse(): """ Case: get a list of states by reverse. @@ -248,7 +303,7 @@ def test_get_states_with_reverse(): def test_get_states_without_node_url(mocker): """ Case: get a list of states by its address without passing node URL. - Expect: list of states is returned from node on localhost. + Expect: list of states is returned from a node on localhost. """ expected_result = { "data": [ @@ -276,8 +331,8 @@ def test_get_states_without_node_url(mocker): def test_get_states_non_existing_node_url(): """ - Case: get a list of states by passing non-existing node URL. - Expect: check if node running at URL error message. + Case: get a list of states by passing the non-existing node URL. + Expect: check if node running at the URL error message. """ non_existing_node_url = 'my-node-url.com' @@ -300,8 +355,8 @@ def test_get_states_non_existing_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_states_node_url_with_protocol(node_url_with_protocol): """ - Case: get a list of states by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get a list of states by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ runner = CliRunner() result = runner.invoke(cli, [ @@ -325,7 +380,7 @@ def test_get_states_node_url_with_protocol(node_url_with_protocol): def test_get_states_invalid_node_url(): """ - Case: get a list of states by passing invalid node URL. + Case: get a list of states by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'domainwithoutextention' diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index 857554a..4857891 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -6,7 +6,7 @@ def test_name(): """ - Case: get the name of the CLI entrypoint function. + Case: get the name of the CLI entrypoint function. Expect: the name is the same as in setup.py (`cli`). """ assert 'cli' == cli.name diff --git a/tests/transaction/test_get_transaction.py b/tests/transaction/test_get_transaction.py index 766ce53..bccba66 100644 --- a/tests/transaction/test_get_transaction.py +++ b/tests/transaction/test_get_transaction.py @@ -14,21 +14,21 @@ from cli.entrypoint import cli from cli.utils import dict_to_pretty_json +TRANSACTION_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE = '640fe45794d2f63fbe1850aa99d0ac830ed94e1ac9b475e1e8c841f714b6250e' \ + '64bc6fbd9f821147ee1eab4d76e5437f5b878a9b5288f1d4c1dc192060a82cf1' + def test_get_transaction(): """ Case: get a transaction by identifier. Expect: transaction is returned. """ - transaction_id = '640fe45794d2f63fbe1850aa99d0ac830ed94e1ac9b475e1e8c841f714b6250e' \ - '64bc6fbd9f821147ee1eab4d76e5437f5b878a9b5288f1d4c1dc192060a82cf1' - runner = CliRunner() result = runner.invoke(cli, [ 'transaction', 'get', '--id', - transaction_id, + TRANSACTION_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, ]) @@ -36,7 +36,7 @@ def test_get_transaction(): result_transaction = json.loads(result.output).get('result').get('data') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code - assert transaction_id == result_transaction.get('header_signature') + assert TRANSACTION_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE == result_transaction.get('header_signature') def test_get_transaction_with_invalid_id(): @@ -72,11 +72,8 @@ def test_get_transaction_with_invalid_id(): def test_get_transaction_without_node_url(mocker): """ Case: get a transaction by identifier without passing node URL. - Expect: transaction is returned from node on localhost. + Expect: transaction is returned from a node on localhost. """ - transaction_id = '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' \ - '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240c5' - expected_result = { 'data': { 'header': { @@ -99,8 +96,8 @@ def test_get_transaction_without_node_url(mocker): 'dependencies': [], 'nonce': '', }, - 'header_signature': '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' - '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240c5', + 'header_signature': '640fe45794d2f63fbe1850aa99d0ac830ed94e1ac9b475e1e8c841f714b6250e' + '64bc6fbd9f821147ee1eab4d76e5437f5b878a9b5288f1d4c1dc192060a82cf1', 'payload': 'CAESRAoic2F3dG9vdGgudmFsaWRhdG9yLmJhdGNoX2luamVj' 'dG9ycxIKYmxvY2tfaW5mbxoSMHhhNGY2YzZhZWMxOWQ1OTBi', }, @@ -114,7 +111,7 @@ def test_get_transaction_without_node_url(mocker): 'transaction', 'get', '--id', - transaction_id, + TRANSACTION_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, ]) assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code @@ -123,7 +120,7 @@ def test_get_transaction_without_node_url(mocker): def test_get_transaction_with_invalid_node_url(): """ - Case: get a transaction by passing invalid node URL. + Case: get a transaction by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'my-node-url.com' @@ -133,8 +130,7 @@ def test_get_transaction_with_invalid_node_url(): 'transaction', 'get', '--id', - '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' - '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240c5', + TRANSACTION_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', invalid_node_url, ]) @@ -150,18 +146,15 @@ def test_get_transaction_with_invalid_node_url(): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) def test_get_transaction_node_url_with_protocol(node_url_with_protocol): """ - Case: get transaction by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get transaction by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ - transaction_id = '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' \ - '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240c5' - runner = CliRunner() result = runner.invoke(cli, [ 'transaction', 'get', '--id', - transaction_id, + TRANSACTION_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', node_url_with_protocol, ]) diff --git a/tests/transaction/test_get_list_transactions.py b/tests/transaction/test_get_transactions.py similarity index 86% rename from tests/transaction/test_get_list_transactions.py rename to tests/transaction/test_get_transactions.py index f5e3020..cf3fc77 100644 --- a/tests/transaction/test_get_list_transactions.py +++ b/tests/transaction/test_get_transactions.py @@ -11,16 +11,16 @@ DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, FAILED_EXIT_FROM_COMMAND_CODE, PASSED_EXIT_FROM_COMMAND_CODE, - TRANSACTION_HEADER_SIGNATURE_REGEXP, + TRANSACTION_IDENTIFIER_REGEXP, ) from cli.entrypoint import cli from cli.utils import dict_to_pretty_json -def test_get_list_transactions_with_all_parameters(mocker): +def test_get_transactions_with_all_parameters(mocker): """ Case: get a list transactions by identifier, identifier starting from, limit, head, family name, reverse. - Expect: transaction are returned from node on localhost. + Expect: transactions is returned from a node on localhost. """ transaction_id = '79a2780e9f07ca58d97b9de346730ddaba85dbb520778eb3d704cd214f6c580f' \ '4f7fe4aa0e4fa9238e535f4af7e2dbae4134b4a726b36a5369c1cb4e971a2568' @@ -77,9 +77,9 @@ def test_get_list_transactions_with_all_parameters(mocker): assert expected_result == json.loads(result.output).get('result') -def test_get_list_transactions_with_ids(): +def test_get_transactions_with_ids(): """ - Case: get a list transactions by identifiers. + Case: get a list of transactions by identifiers. Expect: transactions are returned. """ transaction_ids = 'af249a738ab2c584c0e3a6899588c6ae2a6267cb7c7dfde9f6927c3b9b65c598' \ @@ -105,13 +105,13 @@ def test_get_list_transactions_with_ids(): transaction_identifier = transaction.get('header_signature') assert transaction_identifier in transaction_ids - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None -def test_get_list_transactions_with_invalid_ids(): +def test_get_transactions_with_invalid_ids(): """ - Case: get a list transactions by invalid identifiers. - Expect: the following identifier are not valid error message. + Case: get a list of transactions by invalid identifiers. + Expect: the following identifier is not valid error message. """ invalid_id = '044c7' transaction_ids = '044c7db163cf21ab9eafc9b267693e2d732411056c7530e54282946ec47cc180' \ @@ -140,7 +140,7 @@ def test_get_list_transactions_with_invalid_ids(): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_transactions_with_start(): +def test_get_transactions_with_start(): """ Case: get a list transactions by transaction identifier starting from. Expect: transactions are returned. @@ -167,10 +167,10 @@ def test_get_list_transactions_with_start(): for transaction in result_transactions: transaction_identifier = transaction.get('header_signature') - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None -def test_get_list_transactions_with_reverse(): +def test_get_transactions_with_reverse(): """ Case: get a list transactions by reverse. Expect: reverse list transactions are returned. @@ -191,10 +191,10 @@ def test_get_list_transactions_with_reverse(): for transaction in result_transactions: transaction_identifier = transaction.get('header_signature') - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None -def test_get_list_transactions_by_head(): +def test_get_transactions_by_head(): """ Case: get a list transactions by block identifier. Expect: transactions are returned. @@ -221,7 +221,7 @@ def test_get_list_transactions_by_head(): for transaction in result_transactions: transaction_identifier = transaction.get('header_signature') - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None def test_get_transactions_identifiers(): @@ -243,11 +243,11 @@ def test_get_transactions_identifiers(): assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code for transaction_identifier in result_transactions: - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None @pytest.mark.parametrize('command_flag', ('--start', '--head')) -def test_get_list_transactions_with_invalid_start_head(command_flag): +def test_get_transactions_with_invalid_start_head(command_flag): """ Case: get a list transactions by invalid block identifier and transaction identifier starting from. Expect: the following identifier is not valid error message. @@ -276,10 +276,10 @@ def test_get_list_transactions_with_invalid_start_head(command_flag): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_transactions_with_limit(): +def test_get_transactions_with_limit(): """ Case: get a list transactions by limit. - Expect: transaction is returned. + Expect: transactions are returned. """ limit = 2 @@ -301,10 +301,10 @@ def test_get_list_transactions_with_limit(): for transaction in result_transactions: transaction_identifier = transaction.get('header_signature') - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None -def test_get_list_transactions_with_invalid_limit(): +def test_get_transactions_with_invalid_limit(): """ Case: get a list transactions by invalid limit. Expect: the following limit should be a positive error message. @@ -333,7 +333,7 @@ def test_get_list_transactions_with_invalid_limit(): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_transactions_with_family_name(): +def test_get_transactions_with_family_name(): """ Case: get a list transactions by family name. Expect: transactions are returned. @@ -358,11 +358,11 @@ def test_get_list_transactions_with_family_name(): transaction_identifier = transaction.get('header_signature') transaction_family_name = transaction.get('header').get('family_name') - assert re.match(pattern=TRANSACTION_HEADER_SIGNATURE_REGEXP, string=transaction_identifier) is not None + assert re.match(pattern=TRANSACTION_IDENTIFIER_REGEXP, string=transaction_identifier) is not None assert family_name == transaction_family_name -def test_get_list_transactions_with_invalid_family_name(): +def test_get_transactions_with_invalid_family_name(): """ Case: get a list transactions by invalid family name. Expect: the following family name is not valid error message. @@ -391,9 +391,9 @@ def test_get_list_transactions_with_invalid_family_name(): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_transactions_with_invalid_node_url(): +def test_get_transactions_with_invalid_node_url(): """ - Case: get a list of transactions by passing invalid node URL. + Case: get a list of transactions by passing an invalid node URL. Expect: the following node URL is invalid error message. """ invalid_node_url = 'my-node-url.com' @@ -417,10 +417,10 @@ def test_get_list_transactions_with_invalid_node_url(): assert dict_to_pretty_json(expected_error_message) in result.output -def test_get_list_transactions_without_node_url(mocker): +def test_get_transactions_without_node_url(mocker): """ Case: get a list transactions by identifier without passing node URL. - Expect: transactions are returned from node on localhost. + Expect: transactions are returned from a node on localhost. """ transaction_id = '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' \ '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240c5' @@ -454,8 +454,8 @@ def test_get_list_transactions_without_node_url(mocker): }, } - mock_get_transaction_by_ids = mocker.patch('cli.transaction.service.loop.run_until_complete') - mock_get_transaction_by_ids.return_value = expected_result + mock_get_transactions = mocker.patch('cli.transaction.service.loop.run_until_complete') + mock_get_transactions.return_value = expected_result runner = CliRunner() result = runner.invoke(cli, [ @@ -470,10 +470,10 @@ def test_get_list_transactions_without_node_url(mocker): @pytest.mark.parametrize('node_url_with_protocol', ['http://masternode.com', 'https://masternode.com']) -def test_get_list_transactions_node_url_with_protocol(node_url_with_protocol): +def test_get_transactions_node_url_with_protocol(node_url_with_protocol): """ - Case: get list transactions by passing node URL with explicit protocol. - Expect: the following node URL contains protocol error message. + Case: get list transactions by passing node URL with an explicit protocol. + Expect: the following node URL contains a protocol error message. """ transaction_id = '8d8cb28c58f7785621b51d220b6a1d39fe5829266495d28eaf0362dc85d7e91c' \ '205c1c4634604443dc566c56e1a4c0cf2eb122ac42cb482ef1436694634240c5'