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
26 changes: 25 additions & 1 deletion hathor/p2p/resources/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ def render_GET(self, request):
})

app = 'Hathor v{}'.format(hathor.__version__)

best_block_tips = []
for tip in self.manager.tx_storage.get_best_block_tips():
tx = self.manager.tx_storage.get_transaction(tip)
meta = tx.get_metadata()
best_block_tips.append({'hash': tx.hash_hex, 'height': meta.height})

best_block = self.manager.tx_storage.get_best_block()

data = {
'server': {
'id': self.manager.connections.my_peer.id,
Expand All @@ -100,6 +109,11 @@ def render_GET(self, request):
'dag': {
'first_timestamp': self.manager.tx_storage.first_timestamp,
'latest_timestamp': self.manager.tx_storage.latest_timestamp,
'best_block_tips': best_block_tips,
'best_block': {
'hash': best_block.hash_hex,
'height': best_block.get_metadata().height,
},
}
}
return json_dumpb(data)
Expand Down Expand Up @@ -170,7 +184,17 @@ def render_GET(self, request):
},
'dag': {
'first_timestamp': 1539271481,
'latest_timestamp': 1539271483
'latest_timestamp': 1539271483,
'best_block_tips': [
{
'hash': '000007eb968a6cdf0499e2d033faf1e163e0dc9cf41876acad4d421836972038', # noqa: E501
'height': 0
}
],
'best_block': {
'hash': '000007eb968a6cdf0499e2d033faf1e163e0dc9cf41876acad4d421836972038', # noqa: E501
'height': 0
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/resources/p2p/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from twisted.internet.defer import inlineCallbacks

import hathor
from hathor.conf.unittests import SETTINGS
from hathor.p2p.resources import StatusResource
from hathor.simulator import FakeConnection
from tests import unittest
Expand All @@ -22,11 +23,32 @@ def setUp(self):
def test_get(self):
response = yield self.web.get("status")
data = response.json_value()

server_data = data.get('server')
self.assertEqual(server_data['app_version'], 'Hathor v{}'.format(hathor.__version__))
self.assertEqual(server_data['network'], 'testnet')
self.assertGreater(server_data['uptime'], 0)

dag_data = data.get('dag')
# We have the genesis block
self.assertEqual(len(dag_data['best_block_tips']), 1)
self.assertIsNotNone(dag_data['best_block_tips'][0])
# As we don't have a type, we must check if the keys are there,
# and the types are correct
self.assertIn('hash', dag_data['best_block_tips'][0])
self.assertIn('height', dag_data['best_block_tips'][0])
self.assertIsInstance(dag_data['best_block_tips'][0]['hash'], str)
self.assertIsInstance(dag_data['best_block_tips'][0]['height'], int)
self.assertEqual(dag_data['best_block_tips'][0]['hash'], SETTINGS.GENESIS_BLOCK_HASH.hex())
self.assertEqual(dag_data['best_block_tips'][0]['height'], 0)
self.assertIsNotNone(dag_data['best_block'])
self.assertIn('hash', dag_data['best_block'])
self.assertIn('height', dag_data['best_block'])
self.assertIsInstance(dag_data['best_block']['hash'], str)
self.assertIsInstance(dag_data['best_block']['height'], int)
self.assertEqual(dag_data['best_block']['hash'], SETTINGS.GENESIS_BLOCK_HASH.hex())
self.assertEqual(dag_data['best_block']['height'], 0)

@inlineCallbacks
def test_handshaking(self):
response = yield self.web.get("status")
Expand Down