forked from LBRYCommunity/lbry-sdk
return none for unconfirmed time estimation
This commit is contained in:
parent
238707bd93
commit
b2f70c7120
2 changed files with 8 additions and 0 deletions
|
@ -136,6 +136,8 @@ class Headers:
|
||||||
raise IndexError(f"failed to get {height}, at {len(self)}")
|
raise IndexError(f"failed to get {height}, at {len(self)}")
|
||||||
|
|
||||||
def estimated_timestamp(self, height):
|
def estimated_timestamp(self, height):
|
||||||
|
if height <= 0:
|
||||||
|
return
|
||||||
return int(self.first_block_timestamp + (height * self.timestamp_average_offset))
|
return int(self.first_block_timestamp + (height * self.timestamp_average_offset))
|
||||||
|
|
||||||
def estimated_julian_day(self, height):
|
def estimated_julian_day(self, height):
|
||||||
|
|
|
@ -147,6 +147,12 @@ class TestHeaders(AsyncioTestCase):
|
||||||
await headers.repair(start_height=10)
|
await headers.repair(start_height=10)
|
||||||
self.assertEqual(19, headers.height)
|
self.assertEqual(19, headers.height)
|
||||||
|
|
||||||
|
def test_do_not_estimate_unconfirmed(self):
|
||||||
|
headers = Headers(':memory:')
|
||||||
|
self.assertIsNone(headers.estimated_timestamp(-1))
|
||||||
|
self.assertIsNone(headers.estimated_timestamp(0))
|
||||||
|
self.assertIsNotNone(headers.estimated_timestamp(1))
|
||||||
|
|
||||||
async def test_misalignment_triggers_repair_on_open(self):
|
async def test_misalignment_triggers_repair_on_open(self):
|
||||||
headers = Headers(':memory:')
|
headers = Headers(':memory:')
|
||||||
headers.io.seek(0)
|
headers.io.seek(0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue