diff --git a/client/api/commits.py b/client/api/commits.py index a915390..b94206c 100644 --- a/client/api/commits.py +++ b/client/api/commits.py @@ -3,5 +3,5 @@ class Commits(Resource): - def show(self, height): - return self.with_endpoint('api').request_get(f'commits/{height}') + def show(self, block_number): + return self.with_endpoint('api').request_get(f'commits/{block_number}') diff --git a/client/api/delegates.py b/client/api/delegates.py deleted file mode 100644 index 3457011..0000000 --- a/client/api/delegates.py +++ /dev/null @@ -1,22 +0,0 @@ -from client.resource import Resource - - -class Delegates(Resource): - - def all(self, page=None, limit=100, **kwargs): - extra_params = {name: kwargs[name] for name in kwargs if kwargs[name] is not None} - params = { - 'page': page, - 'limit': limit, - **extra_params - } - return self.with_endpoint('api').request_get('delegates', params) - - def get(self, delegate_id): - return self.with_endpoint('api').request_get(f'delegates/{delegate_id}') - - def blocks(self, delegate_id, **kwargs): - return self.with_endpoint('api').request_get(f'delegates/{delegate_id}/blocks', kwargs) - - def voters(self, delegate_id, **kwargs): - return self.with_endpoint('api').request_get(f'delegates/{delegate_id}/voters', kwargs) diff --git a/client/api/rounds.py b/client/api/rounds.py index e24c5d6..792aeb8 100644 --- a/client/api/rounds.py +++ b/client/api/rounds.py @@ -9,5 +9,5 @@ def all(self, **kwargs): def show(self, round_id): return self.with_endpoint('api').request_get(f'rounds/{round_id}') - def delegates(self, round_id): - return self.with_endpoint('api').request_get(f'rounds/{round_id}/delegates') + def validators(self, round_id): + return self.with_endpoint('api').request_get(f'rounds/{round_id}/validators') diff --git a/client/api/validators.py b/client/api/validators.py new file mode 100644 index 0000000..741367f --- /dev/null +++ b/client/api/validators.py @@ -0,0 +1,22 @@ +from client.resource import Resource + + +class Validators(Resource): + + def all(self, page=None, limit=100, **kwargs): + extra_params = {name: kwargs[name] for name in kwargs if kwargs[name] is not None} + params = { + 'page': page, + 'limit': limit, + **extra_params + } + return self.with_endpoint('api').request_get('validators', params) + + def get(self, validator_id): + return self.with_endpoint('api').request_get(f'validators/{validator_id}') + + def blocks(self, validator_id, **kwargs): + return self.with_endpoint('api').request_get(f'validators/{validator_id}/blocks', kwargs) + + def voters(self, validator_id, **kwargs): + return self.with_endpoint('api').request_get(f'validators/{validator_id}/voters', kwargs) diff --git a/client/client.py b/client/client.py index 813106b..5a907f0 100644 --- a/client/client.py +++ b/client/client.py @@ -4,7 +4,7 @@ from client.api.blockchain import Blockchain from client.api.blocks import Blocks from client.api.commits import Commits -from client.api.delegates import Delegates +from client.api.validators import Validators from client.api.evm import EVM from client.api.node import Node from client.api.peers import Peers @@ -54,14 +54,6 @@ def commits(self): """ return Commits(self.connection) - @property - def delegates(self): - """ - :return: Delegates API - :rtype: client.api.delegates.Delegates - """ - return Delegates(self.connection) - @property def evm(self): """ @@ -110,6 +102,14 @@ def transactions(self): """ return Transactions(self.connection) + @property + def validators(self): + """ + :return: Validators API + :rtype: client.api.validators.Validators + """ + return Validators(self.connection) + @property def votes(self): """ diff --git a/tests/api/test_rounds.py b/tests/api/test_rounds.py index f6a6229..eea73e2 100644 --- a/tests/api/test_rounds.py +++ b/tests/api/test_rounds.py @@ -47,17 +47,17 @@ def test_show_calls_correct_url(): assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/rounds/12345' -def test_delegates_calls_correct_url(): +def test_validators_calls_correct_url(): round_id = '12345' responses.add( responses.GET, - f'http://127.0.0.1:4002/api/rounds/{round_id}/delegates', + f'http://127.0.0.1:4002/api/rounds/{round_id}/validators', json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.rounds.delegates(round_id) + client.rounds.validators(round_id) assert len(responses.calls) == 1 - assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/rounds/12345/delegates' + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/rounds/12345/validators' diff --git a/tests/api/test_delegates.py b/tests/api/test_validators.py similarity index 70% rename from tests/api/test_delegates.py rename to tests/api/test_validators.py index 553203a..e400b2d 100644 --- a/tests/api/test_delegates.py +++ b/tests/api/test_validators.py @@ -8,29 +8,29 @@ def test_all_calls_correct_url_with_default_params(): responses.add( responses.GET, - 'http://127.0.0.1:4002/api/delegates', + 'http://127.0.0.1:4002/api/validators', json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.delegates.all() + client.validators.all() assert len(responses.calls) == 1 - assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/delegates?limit=100' + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/validators?limit=100' def test_all_calls_correct_url_with_passed_in_params(): responses.add( responses.GET, - 'http://127.0.0.1:4002/api/delegates', + 'http://127.0.0.1:4002/api/validators', json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.delegates.all(page=5, limit=69) + client.validators.all(page=5, limit=69) assert len(responses.calls) == 1 - assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/delegates?') + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/validators?') assert 'page=5' in responses.calls[0].request.url assert 'limit=69' in responses.calls[0].request.url @@ -38,67 +38,67 @@ def test_all_calls_correct_url_with_passed_in_params(): def test_all_calls_correct_url_with_additional_params(): responses.add( responses.GET, - 'http://127.0.0.1:4002/api/delegates', + 'http://127.0.0.1:4002/api/validators', json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.delegates.all(page=5, limit=69, orderBy="username") + client.validators.all(page=5, limit=69, orderBy="username") assert len(responses.calls) == 1 - assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/delegates?') + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/validators?') assert 'page=5' in responses.calls[0].request.url assert 'limit=69' in responses.calls[0].request.url assert 'orderBy=username' in responses.calls[0].request.url def test_get_calls_correct_url(): - delegate_id = '12345' + validator_id = '12345' responses.add( responses.GET, - 'http://127.0.0.1:4002/api/delegates/{}'.format(delegate_id), + 'http://127.0.0.1:4002/api/validators/{}'.format(validator_id), json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.delegates.get(delegate_id) + client.validators.get(validator_id) assert len(responses.calls) == 1 - assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/delegates/12345' + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/validators/12345' def test_blocks_calls_correct_url(): - delegate_id = '12345' + validator_id = '12345' responses.add( responses.GET, - 'http://127.0.0.1:4002/api/delegates/{}/blocks'.format(delegate_id), + 'http://127.0.0.1:4002/api/validators/{}/blocks'.format(validator_id), json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.delegates.blocks(delegate_id, limit=100, orderBy='timestamp:desc') + client.validators.blocks(validator_id, limit=100, orderBy='timestamp:desc') assert len(responses.calls) == 1 - assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/delegates/12345/blocks?') + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/validators/12345/blocks?') assert 'limit=100' in responses.calls[0].request.url assert 'orderBy=timestamp%3Adesc' in responses.calls[0].request.url def test_voters_calls_correct_url(): - delegate_id = '12345' + validator_id = '12345' responses.add( responses.GET, - 'http://127.0.0.1:4002/api/delegates/{}/voters'.format(delegate_id), + 'http://127.0.0.1:4002/api/validators/{}/voters'.format(validator_id), json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.delegates.voters(delegate_id, limit=100, orderBy='timestamp:desc') + client.validators.voters(validator_id, limit=100, orderBy='timestamp:desc') assert len(responses.calls) == 1 - assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/delegates/12345/voters?') + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/validators/12345/voters?') assert 'limit=100' in responses.calls[0].request.url assert 'orderBy=timestamp%3Adesc' in responses.calls[0].request.url diff --git a/tests/test_client.py b/tests/test_client.py index 04fb996..5ea70bc 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -11,11 +11,11 @@ def test_client(): assert hasattr(client, 'blockchain') == True assert hasattr(client, 'blocks') == True assert hasattr(client, 'commits') == True - assert hasattr(client, 'delegates') == True assert hasattr(client, 'evm') == True assert hasattr(client, 'node') == True assert hasattr(client, 'peers') == True assert hasattr(client, 'rounds') == True assert hasattr(client, 'transactions') == True + assert hasattr(client, 'validators') == True assert hasattr(client, 'votes') == True assert hasattr(client, 'wallets') == True