Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/api/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
22 changes: 0 additions & 22 deletions client/api/delegates.py

This file was deleted.

4 changes: 2 additions & 2 deletions client/api/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
22 changes: 22 additions & 0 deletions client/api/validators.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 9 additions & 9 deletions client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/api/test_rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
42 changes: 21 additions & 21 deletions tests/api/test_delegates.py → tests/api/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,97 +8,97 @@
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


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
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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