fix channel argument

This commit is contained in:
Victor Shyba 2020-10-02 15:24:25 -03:00 committed by Lex Berezhny
parent 036e16d1fc
commit 2b62330980
2 changed files with 22 additions and 0 deletions

View file

@ -312,6 +312,17 @@ class Database:
return await self.fetch_result(q.get_purchases, **constraints) return await self.fetch_result(q.get_purchases, **constraints)
async def search_claims(self, **constraints) -> Result[Output]: async def search_claims(self, **constraints) -> Result[Output]:
if 'channel' in constraints:
channel_url = constraints.pop('channel')
match = await self.resolve([channel_url])
if isinstance(match, dict):
for value in match.values():
if isinstance(value, Output):
constraints['channel_hash'] = value.claim_hash
else:
return Result([], 0)
else:
return Result([], 0)
#assert set(constraints).issubset(SEARCH_PARAMS), \ #assert set(constraints).issubset(SEARCH_PARAMS), \
# f"Search query contains invalid arguments: {set(constraints).difference(SEARCH_PARAMS)}" # f"Search query contains invalid arguments: {set(constraints).difference(SEARCH_PARAMS)}"
claims, total, censor = await self.run(q.search_claims, **constraints) claims, total, censor = await self.run(q.search_claims, **constraints)

View file

@ -1127,6 +1127,17 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
self.assertEqual("@Chá#a/Hortelã#c", claim.canonical_url) self.assertEqual("@Chá#a/Hortelã#c", claim.canonical_url)
self.assertEqual("Hortelã#c", claim.short_url) self.assertEqual("Hortelã#c", claim.short_url)
async def test_claim_search_filters(self):
chan1 = await self.get_claim(await self.create_claim(is_channel=True, name="@one"))
chan2 = await self.get_claim(await self.create_claim(is_channel=True, name="@two"))
claim1 = await self.get_claim(await self.create_claim(sign=chan1))
await self.get_claim(await self.create_claim(sign=chan2))
await self.generate(1)
results = await self.db.search_claims(channel="@one")
self.assertEqual([claim1.claim_id], [result.claim_id for result in results])
results = await self.db.search_claims(channel="@404")
self.assertEqual([], results.rows)
class TestClaimtrieSync(SyncingBlockchainTestCase): class TestClaimtrieSync(SyncingBlockchainTestCase):