tests/unit/db
This commit is contained in:
parent
73ff1d3b3a
commit
597bebb5be
5 changed files with 125 additions and 0 deletions
0
tests/unit/db/__init__.py
Normal file
0
tests/unit/db/__init__.py
Normal file
11
tests/unit/db/test_event.py
Normal file
11
tests/unit/db/test_event.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from lbry.db.query_context import Event
|
||||
|
||||
|
||||
class TestDBEvents(TestCase):
|
||||
|
||||
def test_enum(self):
|
||||
self.assertEqual(Event.BLOCK_READ.value, 1)
|
||||
self.assertEqual(Event.BLOCK_READ.label, "blockchain.sync.block.read")
|
||||
self.assertEqual(Event(1).label, "blockchain.sync.block.read")
|
21
tests/unit/db/test_result.py
Normal file
21
tests/unit/db/test_result.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from lbry.db import Result
|
||||
|
||||
|
||||
class TestResult(TestCase):
|
||||
|
||||
def test_result(self):
|
||||
result = Result([], 0)
|
||||
self.assertFalse(result)
|
||||
self.assertEqual(0, len(result))
|
||||
self.assertEqual(0, result.total)
|
||||
|
||||
result = Result(['a', 'b', 'c'], 100)
|
||||
self.assertTrue(result)
|
||||
self.assertEqual(3, len(result))
|
||||
self.assertEqual(100, result.total)
|
||||
self.assertEqual('b', result[1])
|
||||
self.assertEqual(['a', 'b', 'c'], [o for o in result])
|
||||
self.assertEqual(['a', 'b', 'c'], list(result))
|
||||
self.assertEqual("['a', 'b', 'c']", repr(result))
|
78
tests/unit/db/test_sync.py
Normal file
78
tests/unit/db/test_sync.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from lbry.testcase import UnitDBTestCase
|
||||
|
||||
|
||||
class TestClientDBSync(UnitDBTestCase):
|
||||
|
||||
async def asyncSetUp(self):
|
||||
await super().asyncSetUp()
|
||||
await self.add(self.coinbase())
|
||||
|
||||
async def test_process_inputs(self):
|
||||
await self.add(self.tx())
|
||||
await self.add(self.tx())
|
||||
txo1, txo2a, txo2b, txo3a, txo3b = self.outputs
|
||||
self.assertEqual([
|
||||
(txo1.id, None),
|
||||
(txo2b.id, None),
|
||||
], await self.get_txis())
|
||||
self.assertEqual([
|
||||
(txo1.id, False),
|
||||
(txo2a.id, False),
|
||||
(txo2b.id, False),
|
||||
(txo3a.id, False),
|
||||
(txo3b.id, False),
|
||||
], await self.get_txos())
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([
|
||||
(txo1.id, txo1.get_address(self.ledger)),
|
||||
(txo2b.id, txo2b.get_address(self.ledger)),
|
||||
], await self.get_txis())
|
||||
self.assertEqual([
|
||||
(txo1.id, True),
|
||||
(txo2a.id, False),
|
||||
(txo2b.id, True),
|
||||
(txo3a.id, False),
|
||||
(txo3b.id, False),
|
||||
], await self.get_txos())
|
||||
|
||||
async def test_process_claims(self):
|
||||
claim1 = await self.add(self.create_claim())
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([claim1.claim_id], await self.get_claims())
|
||||
|
||||
claim2 = await self.add(self.create_claim())
|
||||
self.assertEqual([claim1.claim_id], await self.get_claims())
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([claim1.claim_id, claim2.claim_id], await self.get_claims())
|
||||
|
||||
claim3 = await self.add(self.create_claim())
|
||||
claim4 = await self.add(self.create_claim())
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([
|
||||
claim1.claim_id,
|
||||
claim2.claim_id,
|
||||
claim3.claim_id,
|
||||
claim4.claim_id,
|
||||
], await self.get_claims())
|
||||
|
||||
await self.add(self.abandon_claim(claim4))
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([
|
||||
claim1.claim_id, claim2.claim_id, claim3.claim_id
|
||||
], await self.get_claims())
|
||||
|
||||
# create and abandon in same block
|
||||
claim5 = await self.add(self.create_claim())
|
||||
await self.add(self.abandon_claim(claim5))
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([
|
||||
claim1.claim_id, claim2.claim_id, claim3.claim_id
|
||||
], await self.get_claims())
|
||||
|
||||
# create and abandon in different blocks but with bulk sync
|
||||
claim6 = await self.add(self.create_claim())
|
||||
await self.add(self.abandon_claim(claim6))
|
||||
await self.db.process_all_things_after_sync()
|
||||
self.assertEqual([
|
||||
claim1.claim_id, claim2.claim_id, claim3.claim_id
|
||||
], await self.get_claims())
|
15
tests/unit/db/test_utils.py
Normal file
15
tests/unit/db/test_utils.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import unittest
|
||||
from lbry.db.utils import chunk
|
||||
|
||||
|
||||
class TestChunk(unittest.TestCase):
|
||||
|
||||
def test_chunk(self):
|
||||
self.assertEqual(list(chunk([], 3)), [])
|
||||
self.assertEqual(list(chunk(['a'], 3)), [['a']])
|
||||
self.assertEqual(list(chunk(['a', 'b', 'c'], 3)), [['a', 'b', 'c']])
|
||||
self.assertEqual(list(chunk(['a', 'b', 'c', 'd'], 3)), [['a', 'b', 'c'], ['d']])
|
||||
self.assertEqual(
|
||||
list(chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3)),
|
||||
[['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
||||
)
|
Loading…
Reference in a new issue