uncomment tests, add remove_duplicates param

Cleanup prints and commented out code

remove print

don't do list claims

cleanup
This commit is contained in:
Jeffrey Picard 2021-06-08 22:07:07 -04:00 committed by Victor Shyba
parent 886587848b
commit 9f65799a3d
6 changed files with 30 additions and 43 deletions

View file

@ -2515,7 +2515,6 @@ class Daemon(metaclass=JSONRPCServerType):
wallet = self.wallet_manager.get_wallet_or_default(kwargs.pop('wallet_id', None)) wallet = self.wallet_manager.get_wallet_or_default(kwargs.pop('wallet_id', None))
kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size}) kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size})
txos, blocked, _, total = await self.ledger.claim_search(wallet.accounts, **kwargs) txos, blocked, _, total = await self.ledger.claim_search(wallet.accounts, **kwargs)
print(len(txos))
result = { result = {
"items": txos, "items": txos,
"blocked": blocked, "blocked": blocked,

View file

@ -639,11 +639,6 @@ class CommandTestCase(IntegrationTestCase):
return await self.out(self.daemon.jsonrpc_txo_plot(*args, **kwargs)) return await self.out(self.daemon.jsonrpc_txo_plot(*args, **kwargs))
async def claim_list(self, *args, **kwargs): async def claim_list(self, *args, **kwargs):
if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
kwargs['new_sdk_server'] = "localhost:50051"
kwargs = fix_kwargs_for_hub(**kwargs)
res = await self.out(self.hub.claim_search(**kwargs))
return res
return (await self.out(self.daemon.jsonrpc_claim_list(*args, **kwargs)))['items'] return (await self.out(self.daemon.jsonrpc_claim_list(*args, **kwargs)))['items']
async def stream_list(self, *args, **kwargs): async def stream_list(self, *args, **kwargs):

View file

@ -1,4 +1,3 @@
import base64
import os import os
import copy import copy
import time import time
@ -772,15 +771,11 @@ class Ledger(metaclass=LedgerRegistry):
include_received_tips=False, include_received_tips=False,
hub_server=False) -> Tuple[List[Output], dict, int, int]: hub_server=False) -> Tuple[List[Output], dict, int, int]:
encoded_outputs = await query encoded_outputs = await query
# log.warning(base64.b64decode(encoded_outputs))
# if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
if hub_server: if hub_server:
outputs = Outputs.from_grpc(encoded_outputs) outputs = Outputs.from_grpc(encoded_outputs)
else: else:
outputs = Outputs.from_base64(encoded_outputs or b'') # TODO: why is the server returning None? outputs = Outputs.from_base64(encoded_outputs or b'') # TODO: why is the server returning None?
txs: List[Transaction] = [] txs: List[Transaction] = []
log.warning(outputs)
log.warning(outputs.txs)
if len(outputs.txs) > 0: if len(outputs.txs) > 0:
async for tx in self.request_transactions(tuple(outputs.txs), cached=True): async for tx in self.request_transactions(tuple(outputs.txs), cached=True):
txs.extend(tx.values()) txs.extend(tx.values())

View file

@ -1,6 +1,7 @@
import logging import logging
import asyncio import asyncio
import json import json
import os
import socket import socket
import random import random
from time import perf_counter from time import perf_counter
@ -478,15 +479,15 @@ class Network:
return result['result'] return result['result']
async def new_claim_search(self, server, **kwargs): async def new_claim_search(self, server, **kwargs):
if "offset" in kwargs and type(kwargs["offset"]) == int: if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
kwargs["offset"] = {"value": kwargs["offset"]} if "offset" in kwargs and type(kwargs["offset"]) == int:
if "limit" in kwargs and type(kwargs["limit"]) == int: kwargs["offset"] = {"value": kwargs["offset"]}
kwargs["limit"] = {"value": kwargs["limit"]} if "limit" in kwargs and type(kwargs["limit"]) == int:
async with grpc.aio.insecure_channel(server) as channel: kwargs["limit"] = {"value": kwargs["limit"]}
stub = hub_pb2_grpc.HubStub(channel) async with grpc.aio.insecure_channel(server) as channel:
log.warning(kwargs) stub = hub_pb2_grpc.HubStub(channel)
response = await stub.Search(SearchRequest(**kwargs)) response = await stub.Search(SearchRequest(**kwargs))
return response return response
kwargs['protobuf'] = True kwargs['protobuf'] = True
message = {"method": "claim_search", "params": kwargs} message = {"method": "claim_search", "params": kwargs}

View file

@ -497,7 +497,7 @@ def fix_kwargs_for_hub(**kwargs):
"fee_currency", "media_type", "stream_type", "claim_type", "description", "author", "title", "fee_currency", "media_type", "stream_type", "claim_type", "description", "author", "title",
"canonical_url", "short_url", "claim_id"} "canonical_url", "short_url", "claim_id"}
value_fields = {"offset", "limit", "has_channel_signature", "has_source", "has_no_source", value_fields = {"offset", "limit", "has_channel_signature", "has_source", "has_no_source",
"limit_claims_per_channel", "tx_nout", "limit_claims_per_channel", "tx_nout", "remove_duplicates",
"signature_valid", "is_controlling", "amount_order"} "signature_valid", "is_controlling", "amount_order"}
ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'} ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'}
for key in list(kwargs.keys()): for key in list(kwargs.keys()):

View file

@ -73,10 +73,10 @@ class ClaimSearchCommand(ClaimTestCase):
if os.environ.get("GO_HUB") and os.environ["GO_HUB"] == "true": if os.environ.get("GO_HUB") and os.environ["GO_HUB"] == "true":
kwargs['new_sdk_server'] = self.hub.hostname + ":" + str(self.hub.rpcport) kwargs['new_sdk_server'] = self.hub.hostname + ":" + str(self.hub.rpcport)
results = await self.claim_search(**kwargs) results = await self.claim_search(**kwargs)
# for claim, result in zip(claims, results):
# print((claim['txid'], self.get_claim_id(claim)),
# (result['txid'], result['claim_id'], result['height']))
self.assertEqual(len(claims), len(results)) self.assertEqual(len(claims), len(results))
for claim, result in zip(claims, results):
print((claim['txid'], self.get_claim_id(claim)),
(result['txid'], result['claim_id'], result['height']))
for claim, result in zip(claims, results): for claim, result in zip(claims, results):
self.assertEqual( self.assertEqual(
(claim['txid'], self.get_claim_id(claim)), (claim['txid'], self.get_claim_id(claim)),
@ -95,7 +95,7 @@ class ClaimSearchCommand(ClaimTestCase):
# f"(expected {claim['outputs'][0]['name']}) != (got {result['name']})" # f"(expected {claim['outputs'][0]['name']}) != (got {result['name']})"
# ) # )
@skip("okay") # @skip("okay")
async def test_basic_claim_search(self): async def test_basic_claim_search(self):
await self.create_channel() await self.create_channel()
channel_txo = self.channel['outputs'][0] channel_txo = self.channel['outputs'][0]
@ -180,7 +180,7 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims([three], claim_id=self.get_claim_id(three)) await self.assertFindsClaims([three], claim_id=self.get_claim_id(three))
await self.assertFindsClaims([three], claim_id=self.get_claim_id(three), text='*') await self.assertFindsClaims([three], claim_id=self.get_claim_id(three), text='*')
@skip("okay") # @skip("okay")
async def test_source_filter(self): async def test_source_filter(self):
channel = await self.channel_create('@abc') channel = await self.channel_create('@abc')
no_source = await self.stream_create('no-source', data=None) no_source = await self.stream_create('no-source', data=None)
@ -195,22 +195,19 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims([channel_repost, no_source_repost, normal_repost, normal, no_source, channel]) await self.assertFindsClaims([channel_repost, no_source_repost, normal_repost, normal, no_source, channel])
# await self.assertListsClaims([channel_repost, no_source_repost, normal_repost, normal, no_source, channel]) # await self.assertListsClaims([channel_repost, no_source_repost, normal_repost, normal, no_source, channel])
@skip("Okay???") # @skip("okay")
async def test_pagination(self): async def test_pagination(self):
await self.create_channel() await self.create_channel()
await self.create_lots_of_streams() await self.create_lots_of_streams()
channel_id = (await self.daemon.jsonrpc_resolve(f"@abc"))["@abc"].claim_id channel_id = (await self.daemon.jsonrpc_resolve(f"@abc"))["@abc"].claim_id
# FIXME: this doesn't work when jsonrpc_claim_search is called directly
new_sdk_server = self.hub.hostname + ":" + str(self.hub.rpcport)
# with and without totals # with and without totals
results = await self.daemon.jsonrpc_claim_search(new_sdk_server=new_sdk_server) results = await self.daemon.jsonrpc_claim_search()
self.assertEqual(results['total_pages'], 2) self.assertEqual(results['total_pages'], 2)
self.assertEqual(results['total_items'], 25) self.assertEqual(results['total_items'], 25)
# FIXME: Do we still need to support this? results = await self.daemon.jsonrpc_claim_search(no_totals=True)
# results = await self.daemon.jsonrpc_claim_search(no_totals=True, new_sdk_server=new_sdk_server) self.assertNotIn('total_pages', results)
# self.assertNotIn('total_pages', results) self.assertNotIn('total_items', results)
# self.assertNotIn('total_items', results)
# defaults # defaults
page = await self.claim_search(channel_id=channel_id, order_by=['height', '^name']) page = await self.claim_search(channel_id=channel_id, order_by=['height', '^name'])
@ -240,7 +237,7 @@ class ClaimSearchCommand(ClaimTestCase):
out_of_bounds = await self.claim_search(page=4, page_size=20, channel_id=channel_id) out_of_bounds = await self.claim_search(page=4, page_size=20, channel_id=channel_id)
self.assertEqual(out_of_bounds, []) self.assertEqual(out_of_bounds, [])
@skip("okay") # @skip("okay")
async def test_tag_search(self): async def test_tag_search(self):
claim1 = await self.stream_create('claim1', tags=['aBc']) claim1 = await self.stream_create('claim1', tags=['aBc'])
claim2 = await self.stream_create('claim2', tags=['#abc', 'def']) claim2 = await self.stream_create('claim2', tags=['#abc', 'def'])
@ -277,7 +274,7 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims([claim3], all_tags=['abc', 'ghi'], any_tags=['jkl'], not_tags=['mno']) await self.assertFindsClaims([claim3], all_tags=['abc', 'ghi'], any_tags=['jkl'], not_tags=['mno'])
await self.assertFindsClaims([claim4, claim3, claim2], all_tags=['abc'], any_tags=['def', 'ghi']) await self.assertFindsClaims([claim4, claim3, claim2], all_tags=['abc'], any_tags=['def', 'ghi'])
@skip("okay") # @skip("okay")
async def test_order_by(self): async def test_order_by(self):
height = self.ledger.network.remote_height height = self.ledger.network.remote_height
claims = [await self.stream_create(f'claim{i}') for i in range(5)] claims = [await self.stream_create(f'claim{i}') for i in range(5)]
@ -294,7 +291,7 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims(claims, order_by=["^name"]) await self.assertFindsClaims(claims, order_by=["^name"])
@skip("okay") # @skip("okay")
async def test_search_by_fee(self): async def test_search_by_fee(self):
claim1 = await self.stream_create('claim1', fee_amount='1.0', fee_currency='lbc') claim1 = await self.stream_create('claim1', fee_amount='1.0', fee_currency='lbc')
claim2 = await self.stream_create('claim2', fee_amount='0.9', fee_currency='lbc') claim2 = await self.stream_create('claim2', fee_amount='0.9', fee_currency='lbc')
@ -309,7 +306,7 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims([claim3], fee_amount='0.5', fee_currency='lbc') await self.assertFindsClaims([claim3], fee_amount='0.5', fee_currency='lbc')
await self.assertFindsClaims([claim5], fee_currency='usd') await self.assertFindsClaims([claim5], fee_currency='usd')
@skip("okay") # @skip("okay")
async def test_search_by_language(self): async def test_search_by_language(self):
claim1 = await self.stream_create('claim1', fee_amount='1.0', fee_currency='lbc') claim1 = await self.stream_create('claim1', fee_amount='1.0', fee_currency='lbc')
claim2 = await self.stream_create('claim2', fee_amount='0.9', fee_currency='lbc') claim2 = await self.stream_create('claim2', fee_amount='0.9', fee_currency='lbc')
@ -324,7 +321,7 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims([claim5, claim4, claim3], any_languages=['en', 'es']) await self.assertFindsClaims([claim5, claim4, claim3], any_languages=['en', 'es'])
await self.assertFindsClaims([], fee_currency='foo') await self.assertFindsClaims([], fee_currency='foo')
@skip("okay") # @skip("okay")
async def test_search_by_channel(self): async def test_search_by_channel(self):
match = self.assertFindsClaims match = self.assertFindsClaims
@ -380,7 +377,7 @@ class ClaimSearchCommand(ClaimTestCase):
not_channel_ids=[chan2_id], has_channel_signature=True, valid_channel_signature=True) not_channel_ids=[chan2_id], has_channel_signature=True, valid_channel_signature=True)
await match([], not_channel_ids=[chan1_id, chan2_id], has_channel_signature=True, valid_channel_signature=True) await match([], not_channel_ids=[chan1_id, chan2_id], has_channel_signature=True, valid_channel_signature=True)
@skip("okay") # @skip("okay")
async def test_limit_claims_per_channel(self): async def test_limit_claims_per_channel(self):
match = self.assertFindsClaims match = self.assertFindsClaims
chan1_id = self.get_claim_id(await self.channel_create('@chan1')) chan1_id = self.get_claim_id(await self.channel_create('@chan1'))
@ -426,7 +423,7 @@ class ClaimSearchCommand(ClaimTestCase):
height='>218', limit_claims_per_channel=1, height='>218', limit_claims_per_channel=1,
remove_duplicates=True, order_by=['height']) remove_duplicates=True, order_by=['height'])
@skip("okay") # @skip("okay")
async def test_limit_claims_per_channel_across_sorted_pages(self): async def test_limit_claims_per_channel_across_sorted_pages(self):
await self.generate(10) await self.generate(10)
match = self.assertFindsClaims match = self.assertFindsClaims
@ -459,7 +456,7 @@ class ClaimSearchCommand(ClaimTestCase):
limit_claims_per_channel=1, claim_type='stream', order_by=['^height'] limit_claims_per_channel=1, claim_type='stream', order_by=['^height']
) )
@skip("okay") # @skip("okay")
async def test_claim_type_and_media_type_search(self): async def test_claim_type_and_media_type_search(self):
# create an invalid/unknown claim # create an invalid/unknown claim
address = await self.account.receiving.get_or_create_usable_address() address = await self.account.receiving.get_or_create_usable_address()
@ -502,7 +499,7 @@ class ClaimSearchCommand(ClaimTestCase):
await self.assertFindsClaims([], duration='>100') await self.assertFindsClaims([], duration='>100')
await self.assertFindsClaims([], duration='<14') await self.assertFindsClaims([], duration='<14')
@skip("okay") # @skip("okay")
async def test_search_by_text(self): async def test_search_by_text(self):
chan1_id = self.get_claim_id(await self.channel_create('@SatoshiNakamoto')) chan1_id = self.get_claim_id(await self.channel_create('@SatoshiNakamoto'))
chan2_id = self.get_claim_id(await self.channel_create('@Bitcoin')) chan2_id = self.get_claim_id(await self.channel_create('@Bitcoin'))